diff options
author | Mattes D <github@xoft.cz> | 2016-08-24 21:45:03 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2016-08-24 22:26:53 +0200 |
commit | d2e8643607424cd74616e2e863f5609e7b8458a5 (patch) | |
tree | d5afab6035ca6bb0b58fd03ad5cfe3b3f8e1da55 /Tools/ProtoProxy | |
parent | Merge pull request #3342 from cuberite/FixEmptyHeader (diff) | |
download | cuberite-d2e8643607424cd74616e2e863f5609e7b8458a5.tar cuberite-d2e8643607424cd74616e2e863f5609e7b8458a5.tar.gz cuberite-d2e8643607424cd74616e2e863f5609e7b8458a5.tar.bz2 cuberite-d2e8643607424cd74616e2e863f5609e7b8458a5.tar.lz cuberite-d2e8643607424cd74616e2e863f5609e7b8458a5.tar.xz cuberite-d2e8643607424cd74616e2e863f5609e7b8458a5.tar.zst cuberite-d2e8643607424cd74616e2e863f5609e7b8458a5.zip |
Diffstat (limited to 'Tools/ProtoProxy')
-rw-r--r-- | Tools/ProtoProxy/CMakeLists.txt | 12 | ||||
-rw-r--r-- | Tools/ProtoProxy/Connection.cpp | 14 | ||||
-rw-r--r-- | Tools/ProtoProxy/Globals.h | 6 | ||||
-rw-r--r-- | Tools/ProtoProxy/ProtoProxy.cpp | 23 | ||||
-rw-r--r-- | Tools/ProtoProxy/Server.cpp | 8 | ||||
-rw-r--r-- | Tools/ProtoProxy/Server.h | 2 |
6 files changed, 33 insertions, 32 deletions
diff --git a/Tools/ProtoProxy/CMakeLists.txt b/Tools/ProtoProxy/CMakeLists.txt index ea9799780..5c83123c3 100644 --- a/Tools/ProtoProxy/CMakeLists.txt +++ b/Tools/ProtoProxy/CMakeLists.txt @@ -7,18 +7,10 @@ set_lib_flags() # Set include paths to the used libraries: -include_directories("../../lib") -include_directories("../../lib/polarssl/include") +include_directories(SYSTEM "../../lib") +include_directories(SYSTEM "../../lib/polarssl/include") include_directories("../../src") -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=shorten-64-to-32") - add_flags_cxx("-Wno-error=old-style-cast") - if ("${CLANG_VERSION}" VERSION_GREATER 3.5) - add_flags_cxx("-Wno-error=keyword-macro") - endif() -endif() - function(flatten_files arg1) set(res "") foreach(f ${${arg1}}) diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp index 62d64c49e..2804a881c 100644 --- a/Tools/ProtoProxy/Connection.cpp +++ b/Tools/ProtoProxy/Connection.cpp @@ -151,7 +151,7 @@ AString PrintableAbsIntTriplet(int a_X, int a_Y, int a_Z, double a_Divisor) { return Printf("<%d, %d, %d> ~ {%.02f, %.02f, %.02f}", a_X, a_Y, a_Z, - (double)a_X / a_Divisor, (double)a_Y / a_Divisor, (double)a_Z / a_Divisor + static_cast<double>(a_X) / a_Divisor, static_cast<double>(a_Y) / a_Divisor, static_cast<double>(a_Z) / a_Divisor ); } @@ -212,7 +212,7 @@ cConnection::cConnection(SOCKET a_ClientSocket, cServer & a_Server) : mkdir("Logs", 0777); #endif - Printf(m_LogNameBase, "Logs/Log_%d_%d", (int)time(NULL), a_ClientSocket); + Printf(m_LogNameBase, "Logs/Log_%d_%d", static_cast<int>(time(nullptr)), static_cast<int>(a_ClientSocket)); AString fnam(m_LogNameBase); fnam.append(".log"); #ifdef _WIN32 @@ -352,7 +352,7 @@ bool cConnection::ConnectToServer(void) localhost.sin_family = AF_INET; localhost.sin_port = htons(m_Server.GetConnectPort()); localhost.sin_addr.s_addr = htonl(0x7f000001); // localhost - if (connect(m_ServerSocket, (sockaddr *)&localhost, sizeof(localhost)) != 0) + if (connect(m_ServerSocket, reinterpret_cast<const sockaddr *>(&localhost), sizeof(localhost)) != 0) { printf("connection to server failed: %d\n", SocketError); return false; @@ -485,13 +485,13 @@ bool cConnection::SendData(SOCKET a_Socket, cByteBuffer & a_Data, const char * a bool cConnection::SendEncryptedData(SOCKET a_Socket, cAesCfb128Encryptor & a_Encryptor, const char * a_Data, size_t a_Size, const char * a_Peer) { DataLog(a_Data, a_Size, "Encrypting %d bytes to %s", a_Size, a_Peer); - const Byte * Data = (const Byte *)a_Data; + const Byte * Data = reinterpret_cast<const Byte *>(a_Data); while (a_Size > 0) { Byte Buffer[64 KiB]; size_t NumBytes = (a_Size > sizeof(Buffer)) ? sizeof(Buffer) : a_Size; a_Encryptor.ProcessData(Buffer, Data, NumBytes); - bool res = SendData(a_Socket, (const char *)Buffer, NumBytes, a_Peer); + bool res = SendData(a_Socket, reinterpret_cast<const char *>(Buffer), NumBytes, a_Peer); if (!res) { return false; @@ -1313,7 +1313,7 @@ bool cConnection::HandleServerLoginEncryptionKeyRequest(void) } Log("Got PACKET_ENCRYPTION_KEY_REQUEST from the SERVER:"); Log(" ServerID = %s", ServerID.c_str()); - DataLog(PublicKey.data(), PublicKey.size(), " Public key (%u bytes)", (unsigned)PublicKey.size()); + DataLog(PublicKey.data(), PublicKey.size(), " Public key (%u bytes)", static_cast<unsigned>(PublicKey.size())); // Reply to the server: SendEncryptionKeyResponse(PublicKey, Nonce); @@ -2942,7 +2942,7 @@ void cConnection::SendEncryptionKeyResponse(const AString & a_ServerPublicKey, c // Encrypt the nonce: Byte EncryptedNonce[128]; - res = PubKey.Encrypt((const Byte *)a_Nonce.data(), a_Nonce.size(), EncryptedNonce, sizeof(EncryptedNonce)); + res = PubKey.Encrypt(reinterpret_cast<const Byte *>(a_Nonce.data()), a_Nonce.size(), EncryptedNonce, sizeof(EncryptedNonce)); if (res < 0) { Log("Nonce encryption failed: %d (0x%x)", res, res); diff --git a/Tools/ProtoProxy/Globals.h b/Tools/ProtoProxy/Globals.h index c69931bd5..b15c36cd3 100644 --- a/Tools/ProtoProxy/Globals.h +++ b/Tools/ProtoProxy/Globals.h @@ -29,9 +29,6 @@ // TODO: Can GCC explicitly mark classes as abstract (no instances can be created)? #define abstract - // TODO: Can GCC mark virtual methods as overriding (forcing them to have a virtual function of the same signature in the base class) - #define override - #define OBSOLETE __attribute__((deprecated)) #define ALIGN_8 __attribute__((aligned(8))) @@ -52,9 +49,6 @@ // Explicitly mark classes as abstract (no instances can be created) #define abstract - // Mark virtual methods as overriding (forcing them to have a virtual function of the same signature in the base class) - #define override - // Mark functions as obsolete, so that their usage results in a compile-time warning #define OBSOLETE diff --git a/Tools/ProtoProxy/ProtoProxy.cpp b/Tools/ProtoProxy/ProtoProxy.cpp index 06a486778..ac5858d02 100644 --- a/Tools/ProtoProxy/ProtoProxy.cpp +++ b/Tools/ProtoProxy/ProtoProxy.cpp @@ -27,14 +27,29 @@ int main(int argc, char ** argv) cLogger::InitiateMultithreading(); - int ListenPort = (argc > 1) ? atoi(argv[1]) : 25564; - int ConnectPort = (argc > 2) ? atoi(argv[2]) : 25565; - printf("Initializing ProtoProxy. Listen port %d, connect port %d.\n", ListenPort, ConnectPort); + UInt16 ListenPort = 25564; + UInt16 ConnectPort = 25565; + if (argc > 1) + { + if (!StringToInteger(argv[1], ListenPort)) + { + LOGERROR("Invalid argument 1, expected port number, got \"%s\". Aborting.", argv[1]); + return 1; + } + if (argc > 2) + { + if (!StringToInteger(argv[2], ConnectPort)) + { + LOGERROR("Invalid argument 2, expected port number, got \"%s\". Aborting.", argv[2]); + return 2; + } + } + } cServer Server; int res = Server.Init(ListenPort, ConnectPort); if (res != 0) { - printf("Server initialization failed: %d", res); + LOGERROR("Server initialization failed: %d", res); return res; } diff --git a/Tools/ProtoProxy/Server.cpp b/Tools/ProtoProxy/Server.cpp index 98baec8da..60998798c 100644 --- a/Tools/ProtoProxy/Server.cpp +++ b/Tools/ProtoProxy/Server.cpp @@ -20,7 +20,7 @@ cServer::cServer(void) -int cServer::Init(short a_ListenPort, short a_ConnectPort) +int cServer::Init(UInt16 a_ListenPort, UInt16 a_ConnectPort) { m_ConnectPort = a_ConnectPort; @@ -50,7 +50,7 @@ int cServer::Init(short a_ListenPort, short a_ConnectPort) local.sin_family = AF_INET; local.sin_addr.s_addr = INADDR_ANY; // All interfaces local.sin_port = htons(a_ListenPort); - if (bind(m_ListenSocket, (sockaddr *)&local, sizeof(local)) != 0) + if (bind(m_ListenSocket, reinterpret_cast<const sockaddr *>(&local), sizeof(local)) != 0) { #ifdef _WIN32 int err = WSAGetLastError(); @@ -70,7 +70,7 @@ int cServer::Init(short a_ListenPort, short a_ConnectPort) printf("Failed to listen on socket: %d\n", err); return err; } - LOGINFO("Listening on port %d, connecting to localhost:%d", a_ListenPort, a_ConnectPort); + LOGINFO("Listening for client connections on port %d, connecting to server at localhost:%d", a_ListenPort, a_ConnectPort); LOGINFO("Generating protocol encryption keypair..."); m_PrivateKey.Generate(); @@ -91,7 +91,7 @@ void cServer::Run(void) sockaddr_in Addr; memset(&Addr, 0, sizeof(Addr)); socklen_t AddrSize = sizeof(Addr); - SOCKET client = accept(m_ListenSocket, (sockaddr *)&Addr, &AddrSize); + SOCKET client = accept(m_ListenSocket, reinterpret_cast<sockaddr *>(&Addr), &AddrSize); if (client == INVALID_SOCKET) { printf("accept returned an error: %d; bailing out.\n", SocketError); diff --git a/Tools/ProtoProxy/Server.h b/Tools/ProtoProxy/Server.h index 9782503fb..bfa16c36c 100644 --- a/Tools/ProtoProxy/Server.h +++ b/Tools/ProtoProxy/Server.h @@ -26,7 +26,7 @@ class cServer public: cServer(void); - int Init(short a_ListenPort, short a_ConnectPort); + int Init(UInt16 a_ListenPort, UInt16 a_ConnectPort); void Run(void); cRsaPrivateKey & GetPrivateKey(void) { return m_PrivateKey; } |