summaryrefslogtreecommitdiffstats
path: root/Tools/ProtoProxy
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Tools/ProtoProxy/CMakeLists.txt4
-rw-r--r--Tools/ProtoProxy/Connection.cpp69
-rw-r--r--Tools/ProtoProxy/Globals.h20
-rw-r--r--Tools/ProtoProxy/Server.cpp23
4 files changed, 68 insertions, 48 deletions
diff --git a/Tools/ProtoProxy/CMakeLists.txt b/Tools/ProtoProxy/CMakeLists.txt
index 2178705a8..f8a01a134 100644
--- a/Tools/ProtoProxy/CMakeLists.txt
+++ b/Tools/ProtoProxy/CMakeLists.txt
@@ -77,8 +77,8 @@ endfunction()
# Include the libraries:
-file(GLOB CRYPTOPP_SRC "../../lib/CryptoPP/*.cpp")
-file(GLOB CRYPTOPP_HDR "../../lib/CryptoPP/*.h")
+file(GLOB CRYPTOPP_SRC "../../lib/cryptopp/*.cpp")
+file(GLOB CRYPTOPP_HDR "../../lib/cryptopp/*.h")
flatten_files(CRYPTOPP_SRC)
flatten_files(CRYPTOPP_HDR)
source_group("CryptoPP" FILES ${CRYPTOPP_SRC} ${CRYPTOPP_HDR})
diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp
index e91b9935e..34da9b700 100644
--- a/Tools/ProtoProxy/Connection.cpp
+++ b/Tools/ProtoProxy/Connection.cpp
@@ -155,6 +155,32 @@ AString PrintableAbsIntTriplet(int a_X, int a_Y, int a_Z, double a_Divisor = 32)
+struct sCoords
+{
+ int x, y, z;
+
+ sCoords(int a_X, int a_Y, int a_Z) : x(a_X), y(a_Y), z(a_Z) {}
+} ;
+
+
+
+
+
+struct sChunkMeta
+{
+ int m_ChunkX, m_ChunkZ;
+ short m_PrimaryBitmap;
+ short m_AddBitmap;
+ sChunkMeta(int a_ChunkX, int a_ChunkZ, short a_PrimaryBitmap, short a_AddBitmap) :
+ m_ChunkX(a_ChunkX), m_ChunkZ(a_ChunkZ), m_PrimaryBitmap(a_PrimaryBitmap), m_AddBitmap(a_AddBitmap)
+ {
+ }
+} ;
+
+
+
+
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cConnection:
@@ -220,7 +246,7 @@ void cConnection::Run(void)
int res = select(2, &ReadFDs, NULL, NULL, NULL);
if (res <= 0)
{
- printf("select() failed: %d; aborting client", WSAGetLastError());
+ printf("select() failed: %d; aborting client", SocketError);
break;
}
if (FD_ISSET(m_ServerSocket, &ReadFDs))
@@ -249,12 +275,10 @@ void cConnection::Run(void)
void cConnection::Log(const char * a_Format, ...)
{
- va_list args, argsCopy;
+ va_list args;
va_start(args, a_Format);
- va_start(argsCopy, a_Format);
AString msg;
- AppendVPrintf(msg, a_Format, args, argsCopy);
- va_end(argsCopy);
+ AppendVPrintf(msg, a_Format, args);
va_end(args);
AString FullMsg;
Printf(FullMsg, "[%5.3f] %s\n", GetRelativeTime(), msg.c_str());
@@ -276,12 +300,10 @@ void cConnection::Log(const char * a_Format, ...)
void cConnection::DataLog(const void * a_Data, int a_Size, const char * a_Format, ...)
{
- va_list args, argsCopy;
+ va_list args;
va_start(args, a_Format);
- va_start(argsCopy, a_Format);
AString msg;
- AppendVPrintf(msg, a_Format, args, argsCopy);
- va_end(argsCopy);
+ AppendVPrintf(msg, a_Format, args);
va_end(args);
AString FullMsg;
AString Hex;
@@ -323,7 +345,7 @@ bool cConnection::ConnectToServer(void)
localhost.sin_addr.s_addr = htonl(0x7f000001); // localhost
if (connect(m_ServerSocket, (sockaddr *)&localhost, sizeof(localhost)) != 0)
{
- printf("connection to server failed: %d\n", WSAGetLastError());
+ printf("connection to server failed: %d\n", SocketError);
return false;
}
Log("Connected to SERVER");
@@ -340,7 +362,7 @@ bool cConnection::RelayFromServer(void)
int res = recv(m_ServerSocket, Buffer, sizeof(Buffer), 0);
if (res <= 0)
{
- Log("Server closed the socket: %d; %d; aborting connection", res, WSAGetLastError());
+ Log("Server closed the socket: %d; %d; aborting connection", res, SocketError);
return false;
}
@@ -380,7 +402,7 @@ bool cConnection::RelayFromClient(void)
int res = recv(m_ClientSocket, Buffer, sizeof(Buffer), 0);
if (res <= 0)
{
- Log("Client closed the socket: %d; %d; aborting connection", res, WSAGetLastError());
+ Log("Client closed the socket: %d; %d; aborting connection", res, SocketError);
return false;
}
@@ -428,7 +450,7 @@ bool cConnection::SendData(SOCKET a_Socket, const char * a_Data, int a_Size, con
int res = send(a_Socket, a_Data, a_Size, 0);
if (res <= 0)
{
- Log("%s closed the socket: %d, %d; aborting connection", a_Peer, res, WSAGetLastError());
+ Log("%s closed the socket: %d, %d; aborting connection", a_Peer, res, SocketError);
return false;
}
return true;
@@ -1668,12 +1690,6 @@ bool cConnection::HandleServerExplosion(void)
HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, PosZ);
HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, Force);
HANDLE_SERVER_PACKET_READ(ReadBEInt, int, NumRecords);
- struct sCoords
- {
- int x, y, z;
-
- sCoords(int a_X, int a_Y, int a_Z) : x(a_X), y(a_Y), z(a_Z) {}
- } ;
std::vector<sCoords> Records;
Records.reserve(NumRecords);
int PosXI = (int)PosX, PosYI = (int)PosY, PosZI = (int)PosZ;
@@ -1868,16 +1884,6 @@ bool cConnection::HandleServerMapChunkBulk(void)
// Read individual chunk metas.
// Need to read them first and only then start logging (in case we don't have the full packet yet)
- struct sChunkMeta
- {
- int m_ChunkX, m_ChunkZ;
- short m_PrimaryBitmap;
- short m_AddBitmap;
- sChunkMeta(int a_ChunkX, int a_ChunkZ, short a_PrimaryBitmap, short a_AddBitmap) :
- m_ChunkX(a_ChunkX), m_ChunkZ(a_ChunkZ), m_PrimaryBitmap(a_PrimaryBitmap), m_AddBitmap(a_AddBitmap)
- {
- }
- } ;
typedef std::vector<sChunkMeta> sChunkMetas;
sChunkMetas ChunkMetas;
ChunkMetas.reserve(ChunkCount);
@@ -1907,7 +1913,6 @@ bool cConnection::HandleServerMapChunkBulk(void)
// TODO: Save the compressed data into a file for later analysis
COPY_TO_CLIENT();
- Sleep(50);
return true;
}
@@ -2857,8 +2862,8 @@ void cConnection::SendEncryptionKeyResponse(const AString & a_ServerPublicKey, c
int EncryptedLength = rsaEncryptor.FixedCiphertextLength();
ASSERT(EncryptedLength <= sizeof(EncryptedSecret));
rsaEncryptor.Encrypt(rng, SharedSecret, sizeof(SharedSecret), EncryptedSecret);
- m_ServerEncryptor.SetKey(SharedSecret, 16, MakeParameters(Name::IV(), ConstByteArrayParameter(SharedSecret, 16))(Name::FeedbackSize(), 1));
- m_ServerDecryptor.SetKey(SharedSecret, 16, MakeParameters(Name::IV(), ConstByteArrayParameter(SharedSecret, 16))(Name::FeedbackSize(), 1));
+ m_ServerEncryptor.SetKey(SharedSecret, 16, MakeParameters(Name::IV(), ConstByteArrayParameter(SharedSecret, 16, true))(Name::FeedbackSize(), 1));
+ m_ServerDecryptor.SetKey(SharedSecret, 16, MakeParameters(Name::IV(), ConstByteArrayParameter(SharedSecret, 16, true))(Name::FeedbackSize(), 1));
// Encrypt the nonce:
byte EncryptedNonce[128];
diff --git a/Tools/ProtoProxy/Globals.h b/Tools/ProtoProxy/Globals.h
index 8424aca81..7415c9e62 100644
--- a/Tools/ProtoProxy/Globals.h
+++ b/Tools/ProtoProxy/Globals.h
@@ -95,6 +95,7 @@ typedef unsigned short UInt16;
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <winsock2.h>
+ #include <ws2tcpip.h>
// Windows SDK defines min and max macros, messing up with our std::min and std::max usage
#undef min
@@ -104,6 +105,8 @@ typedef unsigned short UInt16;
#ifdef GetFreeSpace
#undef GetFreeSpace
#endif // GetFreeSpace
+
+ #define SocketError WSAGetLastError()
#else
#include <sys/types.h>
#include <sys/stat.h> // for mkdir
@@ -116,6 +119,7 @@ typedef unsigned short UInt16;
#include <dirent.h>
#include <errno.h>
#include <iostream>
+ #include <unistd.h>
#include <cstdio>
#include <cstring>
@@ -123,6 +127,14 @@ typedef unsigned short UInt16;
#include <semaphore.h>
#include <errno.h>
#include <fcntl.h>
+
+ typedef int SOCKET;
+ enum
+ {
+ INVALID_SOCKET = -1,
+ };
+ #define closesocket close
+ #define SocketError errno
#if !defined(ANDROID_NDK)
#include <tr1/memory>
#endif
@@ -211,10 +223,10 @@ public:
-#include "CryptoPP/randpool.h"
-#include "CryptoPP/aes.h"
-#include "CryptoPP/rsa.h"
-#include "CryptoPP/modes.h"
+#include "cryptopp/randpool.h"
+#include "cryptopp/aes.h"
+#include "cryptopp/rsa.h"
+#include "cryptopp/modes.h"
using namespace CryptoPP;
diff --git a/Tools/ProtoProxy/Server.cpp b/Tools/ProtoProxy/Server.cpp
index 35732764c..71b5ecb94 100644
--- a/Tools/ProtoProxy/Server.cpp
+++ b/Tools/ProtoProxy/Server.cpp
@@ -22,13 +22,16 @@ cServer::cServer(void)
int cServer::Init(short a_ListenPort, short a_ConnectPort)
{
m_ConnectPort = a_ConnectPort;
- WSAData wsa;
- int res = WSAStartup(0x0202, &wsa);
- if (res != 0)
- {
- printf("Cannot initialize WinSock: %d\n", res);
- return res;
- }
+
+ #ifdef _WIN32
+ WSAData wsa;
+ int res = WSAStartup(0x0202, &wsa);
+ if (res != 0)
+ {
+ printf("Cannot initialize WinSock: %d\n", res);
+ return res;
+ }
+ #endif // _WIN32
printf("Generating protocol encryption keypair...\n");
time_t CurTime = time(NULL);
@@ -62,12 +65,12 @@ void cServer::Run(void)
while (true)
{
sockaddr_in Addr;
- ZeroMemory(&Addr, sizeof(Addr));
- int AddrSize = sizeof(Addr);
+ memset(&Addr, 0, sizeof(Addr));
+ socklen_t AddrSize = sizeof(Addr);
SOCKET client = accept(m_ListenSocket, (sockaddr *)&Addr, &AddrSize);
if (client == INVALID_SOCKET)
{
- printf("accept returned an error: %d; bailing out.\n", WSAGetLastError());
+ printf("accept returned an error: %d; bailing out.\n", SocketError);
return;
}
printf("Client connected, proxying...\n");