summaryrefslogtreecommitdiff
path: root/csgo-loader/csgo-server/Networking
diff options
context:
space:
mode:
authorboris <wzn@moneybot.cc>2018-12-29 20:59:57 +1300
committerboris <wzn@moneybot.cc>2018-12-29 20:59:57 +1300
commitbdb6ac5f940008bcd836e3c5f0a708f4b8f04865 (patch)
tree9d3ba5e0816dfd6295f8e38e1a865d061f1168e1 /csgo-loader/csgo-server/Networking
parent81a3987fc17f99d2092018ac266882f4533cc27e (diff)
protection shit
Diffstat (limited to 'csgo-loader/csgo-server/Networking')
-rw-r--r--csgo-loader/csgo-server/Networking/TCPServer.cpp14
-rw-r--r--csgo-loader/csgo-server/Networking/TCPServer.hpp2
-rw-r--r--csgo-loader/csgo-server/Networking/WebSocket.cpp17
3 files changed, 19 insertions, 14 deletions
diff --git a/csgo-loader/csgo-server/Networking/TCPServer.cpp b/csgo-loader/csgo-server/Networking/TCPServer.cpp
index dbd109d..739cbdd 100644
--- a/csgo-loader/csgo-server/Networking/TCPServer.cpp
+++ b/csgo-loader/csgo-server/Networking/TCPServer.cpp
@@ -4,7 +4,7 @@ namespace Networking
{
void TCPConnection::Close()
{
- printf("[<=] %s disconnected!\n", m_IpAddress);
+ printf("[ <= ] %s disconnected!\n", m_IpAddress);
if(m_Socket)
closesocket(m_Socket);
@@ -18,10 +18,12 @@ namespace Networking
// Send data.
int32_t Result = send(m_Socket, (char *)Bytes.data(), (int)Bytes.size(), 0);
- printf("[=>] Sending %zd bytes to %s.\n", Bytes.size(), m_IpAddress);
+ if(m_IpAddress)
+
+ printf("[ => ] Sending %zd bytes to %s.\n", Bytes.size(), m_IpAddress);
if(Result == -1)
- printf("[=>] Failed to send %zd bytes to %s. (Socket %04Ix)\n", Bytes.size(), m_IpAddress, m_Socket);
+ printf("[ => ] Failed to send %zd bytes to %s. (Socket %04Ix)\n", Bytes.size(), m_IpAddress, m_Socket);
}
ByteArray TCPConnection::ReceiveRawBytes()
@@ -49,7 +51,7 @@ namespace Networking
break;
}
- printf("[<=] Received %zd bytes from %s.\n", ReceivedBytes.size(), m_IpAddress);
+ printf("[ <= ] Received %zd bytes from %s.\n", ReceivedBytes.size(), m_IpAddress);
return ReceivedBytes;
}
@@ -88,8 +90,8 @@ namespace Networking
// Set up server context.
m_Context.sin_addr.s_addr = INADDR_ANY;
- m_Context.sin_family = AF_INET;
- m_Context.sin_port = htons(ServerPort);
+ m_Context.sin_family = AF_INET;
+ m_Context.sin_port = htons(ServerPort);
int32_t Bind = bind(m_Socket, (sockaddr *)&m_Context, sizeof sockaddr_in);
diff --git a/csgo-loader/csgo-server/Networking/TCPServer.hpp b/csgo-loader/csgo-server/Networking/TCPServer.hpp
index 388bdc2..092254d 100644
--- a/csgo-loader/csgo-server/Networking/TCPServer.hpp
+++ b/csgo-loader/csgo-server/Networking/TCPServer.hpp
@@ -29,7 +29,7 @@ namespace Networking
TCPConnection(SOCKET Connection, const char *IpAddress, Wrapper::Encryption &RSA) :
m_Encryption(RSA), m_Socket(Connection), m_IpAddress(IpAddress)
{
- printf("[=>] %s connected!\n", IpAddress);
+ printf("[ => ] %s connected!\n", IpAddress);
}
// Release the connection once it goes out of scope.
diff --git a/csgo-loader/csgo-server/Networking/WebSocket.cpp b/csgo-loader/csgo-server/Networking/WebSocket.cpp
index 2c42001..75b5731 100644
--- a/csgo-loader/csgo-server/Networking/WebSocket.cpp
+++ b/csgo-loader/csgo-server/Networking/WebSocket.cpp
@@ -21,27 +21,30 @@ namespace Networking
// Receives a response from a request.
ByteArray WebSocket::Request(const char *File, const char *Header, ByteArray &Data)
{
+ DWORD ReceivedSize{};
ByteArray Response;
InternetHandle WebRequest = HttpOpenRequestA(m_Address, "POST", File, 0, 0, 0, INTERNET_FLAG_SECURE | INTERNET_FLAG_KEEP_CONNECTION, 0);
+ if(!WebRequest)
+ return Response;
+
// Make connection request.
bool Sent = HttpSendRequestA(WebRequest, Header, (DWORD)strlen(Header), Data.data(), (DWORD)Data.size());
if(Sent)
{
- DWORD ReceivedSize{};
-
- uint8_t *Block = (uint8_t *)malloc(4096);
+ // Allocate a buffer to read the response into.
+ uint8_t *Block = (uint8_t *)malloc(0x1000);
// Read response.
- while(InternetReadFile(WebRequest, Block, 4096, &ReceivedSize))
+ while(InternetReadFile(WebRequest, Block, 0x1000, &ReceivedSize))
{
- for(size_t n{}; n < std::min< int >(4096, ReceivedSize); ++n)
- {
+ const size_t RequestRange = std::min< int >(0x1000, ReceivedSize);
+ for(size_t n{}; n < RequestRange; ++n)
Response.push_back(Block[n]);
- }
}
+ // Free the buffer to avoid leaking memory.
free(Block);
}