From b93903db23289eb38126325801c4e3f9192ff123 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 24 Jan 2015 13:32:13 +0100 Subject: Fixed RCONClient compilation. --- Tools/RCONClient/Globals.h | 42 +++++++++++++++++++++++++++++++++++++++-- Tools/RCONClient/RCONClient.cpp | 19 ++++++++++--------- Tools/RCONClient/RCONClient.sln | 8 +++++--- 3 files changed, 55 insertions(+), 14 deletions(-) (limited to 'Tools') diff --git a/Tools/RCONClient/Globals.h b/Tools/RCONClient/Globals.h index a3a2f2846..dc7669270 100644 --- a/Tools/RCONClient/Globals.h +++ b/Tools/RCONClient/Globals.h @@ -22,6 +22,18 @@ #define ALIGN_8 #define ALIGN_16 + #define FORMATSTRING(formatIndex, va_argsIndex) + + // MSVC has its own custom version of zu format + #define SIZE_T_FMT "%Iu" + #define SIZE_T_FMT_PRECISION(x) "%" #x "Iu" + #define SIZE_T_FMT_HEX "%Ix" + + #define NORETURN __declspec(noreturn) + + // Use non-standard defines in + #define _USE_MATH_DEFINES + #elif defined(__GNUC__) // TODO: Can GCC explicitly mark classes as abstract (no instances can be created)? @@ -38,6 +50,29 @@ // Some portability macros :) #define stricmp strcasecmp + #define FORMATSTRING(formatIndex, va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex))) + + #if defined(_WIN32) + // We're compiling on MinGW, which uses an old MSVCRT library that has no support for size_t printfing. + // We need direct size formats: + #if defined(_WIN64) + #define SIZE_T_FMT "%I64u" + #define SIZE_T_FMT_PRECISION(x) "%" #x "I64u" + #define SIZE_T_FMT_HEX "%I64x" + #else + #define SIZE_T_FMT "%u" + #define SIZE_T_FMT_PRECISION(x) "%" #x "u" + #define SIZE_T_FMT_HEX "%x" + #endif + #else + // We're compiling on Linux, so we can use libc's size_t printf format: + #define SIZE_T_FMT "%zu" + #define SIZE_T_FMT_PRECISION(x) "%" #x "zu" + #define SIZE_T_FMT_HEX "%zx" + #endif + + #define NORETURN __attribute((__noreturn__)) + #else #error "You are using an unsupported compiler, you might need to #define some stuff here for your compiler" @@ -74,6 +109,8 @@ typedef unsigned long long UInt64; typedef unsigned int UInt32; typedef unsigned short UInt16; +typedef unsigned char Byte; + @@ -94,7 +131,7 @@ typedef unsigned short UInt16; #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN - #define _WIN32_WINNT 0x501 // We want to target WinXP and higher + #define _WIN32_WINNT 0x502 // We want to target WinXP SP2 and higher #include #include @@ -175,7 +212,8 @@ typedef unsigned short UInt16; #include "StringUtils.h" #include "OSSupport/CriticalSection.h" #include "OSSupport/File.h" -#include "MCLogger.h" +#include "OSSupport/Event.h" +#include "Logger.h" diff --git a/Tools/RCONClient/RCONClient.cpp b/Tools/RCONClient/RCONClient.cpp index 288363a66..7d6cf6d8f 100644 --- a/Tools/RCONClient/RCONClient.cpp +++ b/Tools/RCONClient/RCONClient.cpp @@ -80,14 +80,14 @@ bool cRCONPacketizer::SendPacket(int a_PacketType, const AString & a_PacketPaylo size_t Length = Packet.size(); if (!m_Socket.Send((const char *)&Length, 4)) { - fprintf(stderr, "Network error while sending packet: %d (%s). Aborting.", + fprintf(stderr, "Network error while sending packet: %d (%s). Aborting.\n", cSocket::GetLastError(), cSocket::GetLastErrorString().c_str() ); return false; } if (!m_Socket.Send(Packet.data(), Packet.size())) { - fprintf(stderr, "Network error while sending packet: %d (%s). Aborting.", + fprintf(stderr, "Network error while sending packet: %d (%s). Aborting.\n", cSocket::GetLastError(), cSocket::GetLastErrorString().c_str() ); return false; @@ -110,12 +110,12 @@ bool cRCONPacketizer::ReceiveResponse(void) int NumReceived = m_Socket.Receive(buf, sizeof(buf), 0); if (NumReceived == 0) { - fprintf(stderr, "The remote end closed the connection. Aborting."); + fprintf(stderr, "The remote end closed the connection. Aborting.\n"); return false; } if (NumReceived < 0) { - fprintf(stderr, "Network error while receiving response: %d, %d (%s). Aborting.", + fprintf(stderr, "Network error while receiving response: %d, %d (%s). Aborting.\n", NumReceived, cSocket::GetLastError(), cSocket::GetLastErrorString().c_str() ); return false; @@ -156,13 +156,13 @@ bool cRCONPacketizer::ParsePacket(cByteBuffer & a_Buffer, int a_PacketLength) { if ((RequestID == -1) && (m_RequestID == 0)) { - fprintf(stderr, "Login failed. Aborting."); + fprintf(stderr, "Login failed. Aborting.\n"); IsValid = false; // Continue, so that the payload is printed before the program aborts. } else { - fprintf(stderr, "The server returned an invalid request ID, got %d, exp. %d. Aborting.", RequestID, m_RequestID); + fprintf(stderr, "The server returned an invalid request ID, got %d, exp. %d. Aborting.\n", RequestID, m_RequestID); return false; } } @@ -172,7 +172,7 @@ bool cRCONPacketizer::ParsePacket(cByteBuffer & a_Buffer, int a_PacketLength) VERIFY(a_Buffer.ReadLEInt(PacketType)); if (PacketType != ptCommand) { - fprintf(stderr, "The server returned an unknown packet type: %d. Aborting.", PacketType); + fprintf(stderr, "The server returned an unknown packet type: %d. Aborting.\n", PacketType); IsValid = false; // Continue, so that the payload is printed before the program aborts. } @@ -200,8 +200,8 @@ bool cRCONPacketizer::ParsePacket(cByteBuffer & a_Buffer, int a_PacketLength) int RealMain(int argc, char * argv[]) { - new cMCLogger; // Create a new logger - + cLogger::InitiateMultithreading(); + // Parse the cmdline params for server IP, port, password and the commands to send: AString ServerAddress, Password; int ServerPort = -1; @@ -301,6 +301,7 @@ int RealMain(int argc, char * argv[]) } } + // Send each command: for (AStringVector::const_iterator itr = Commands.begin(), end = Commands.end(); itr != end; ++itr) { if (g_IsVerbose) diff --git a/Tools/RCONClient/RCONClient.sln b/Tools/RCONClient/RCONClient.sln index 0a8596e43..5c977fc81 100644 --- a/Tools/RCONClient/RCONClient.sln +++ b/Tools/RCONClient/RCONClient.sln @@ -1,7 +1,9 @@  -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual C++ Express 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RCONClient", "RCONClient.vcproj", "{1A48B032-07D0-4DDD-8362-66C0FC7F7849}" +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 2013 for Windows Desktop +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RCONClient", "RCONClient.vcxproj", "{1A48B032-07D0-4DDD-8362-66C0FC7F7849}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution -- cgit v1.2.3 From 5797f99defa2f8afb0641d5f6ec0cc7557e069ee Mon Sep 17 00:00:00 2001 From: Creaprog Date: Sun, 15 Feb 2015 14:29:11 +0100 Subject: Fixed Server.cpp Performance improvement. --- Tools/ProtoProxy/Server.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Tools') diff --git a/Tools/ProtoProxy/Server.cpp b/Tools/ProtoProxy/Server.cpp index 9545af852..77d1af827 100644 --- a/Tools/ProtoProxy/Server.cpp +++ b/Tools/ProtoProxy/Server.cpp @@ -33,7 +33,7 @@ int cServer::Init(short a_ListenPort, short a_ConnectPort) } #endif // _WIN32 - printf("Generating protocol encryption keypair...\n"); + puts("Generating protocol encryption keypair..."); m_PrivateKey.Generate(); m_PublicKeyDER = m_PrivateKey.GetPubKeyDER(); @@ -85,7 +85,7 @@ int cServer::Init(short a_ListenPort, short a_ConnectPort) void cServer::Run(void) { - printf("Server running.\n"); + puts("Server running."); while (true) { sockaddr_in Addr; @@ -97,10 +97,10 @@ void cServer::Run(void) printf("accept returned an error: %d; bailing out.\n", SocketError); return; } - printf("Client connected, proxying...\n"); + puts("Client connected, proxying..."); cConnection Connection(client, *this); Connection.Run(); - printf("Client disconnected. Ready for another connection.\n"); + puts("Client disconnected. Ready for another connection."); } } -- cgit v1.2.3 From a063da939868abfb9aa4169ca714bfadab708c48 Mon Sep 17 00:00:00 2001 From: Creaprog Date: Sun, 15 Feb 2015 17:28:19 +0100 Subject: Fixed Server.cpp --- Tools/ProtoProxy/Server.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Tools') diff --git a/Tools/ProtoProxy/Server.cpp b/Tools/ProtoProxy/Server.cpp index 77d1af827..7d890124d 100644 --- a/Tools/ProtoProxy/Server.cpp +++ b/Tools/ProtoProxy/Server.cpp @@ -33,7 +33,7 @@ int cServer::Init(short a_ListenPort, short a_ConnectPort) } #endif // _WIN32 - puts("Generating protocol encryption keypair..."); + LOG("Generating protocol encryption keypair..."); m_PrivateKey.Generate(); m_PublicKeyDER = m_PrivateKey.GetPubKeyDER(); @@ -85,7 +85,7 @@ int cServer::Init(short a_ListenPort, short a_ConnectPort) void cServer::Run(void) { - puts("Server running."); + LOG("Server running."); while (true) { sockaddr_in Addr; @@ -97,10 +97,10 @@ void cServer::Run(void) printf("accept returned an error: %d; bailing out.\n", SocketError); return; } - puts("Client connected, proxying..."); + LOG("Client connected, proxying..."); cConnection Connection(client, *this); Connection.Run(); - puts("Client disconnected. Ready for another connection."); + LOG("Client disconnected. Ready for another connection."); } } -- cgit v1.2.3 From cbd2a0913511ad4130c482055ffb123085f505be Mon Sep 17 00:00:00 2001 From: Creaprog Date: Sun, 15 Feb 2015 18:28:33 +0100 Subject: Fixed Server.cpp --- Tools/ProtoProxy/Server.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'Tools') diff --git a/Tools/ProtoProxy/Server.cpp b/Tools/ProtoProxy/Server.cpp index 7d890124d..2932b37e3 100644 --- a/Tools/ProtoProxy/Server.cpp +++ b/Tools/ProtoProxy/Server.cpp @@ -6,6 +6,7 @@ #include "Globals.h" #include "Server.h" #include "Connection.h" +#include "Logger.h" -- cgit v1.2.3 From 6f9c62172bb1f6679f733f05e10e712ca7bc3c47 Mon Sep 17 00:00:00 2001 From: Creaprog Date: Sun, 15 Feb 2015 20:39:53 +0100 Subject: Fixed Server.cpp --- Tools/ProtoProxy/Server.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'Tools') diff --git a/Tools/ProtoProxy/Server.cpp b/Tools/ProtoProxy/Server.cpp index 2932b37e3..e27c86e10 100644 --- a/Tools/ProtoProxy/Server.cpp +++ b/Tools/ProtoProxy/Server.cpp @@ -6,7 +6,6 @@ #include "Globals.h" #include "Server.h" #include "Connection.h" -#include "Logger.h" @@ -34,7 +33,7 @@ int cServer::Init(short a_ListenPort, short a_ConnectPort) } #endif // _WIN32 - LOG("Generating protocol encryption keypair..."); + LOGINFO("Generating protocol encryption keypair..."); m_PrivateKey.Generate(); m_PublicKeyDER = m_PrivateKey.GetPubKeyDER(); @@ -98,10 +97,10 @@ void cServer::Run(void) printf("accept returned an error: %d; bailing out.\n", SocketError); return; } - LOG("Client connected, proxying..."); + LOGINFO("Client connected, proxying..."); cConnection Connection(client, *this); Connection.Run(); - LOG("Client disconnected. Ready for another connection."); + LOGINFO("Client disconnected. Ready for another connection."); } } -- cgit v1.2.3 From 9fab1d85bc5508a941a1cb80e61e7a23b29c51ea Mon Sep 17 00:00:00 2001 From: Creaprog Date: Mon, 16 Feb 2015 09:27:52 +0100 Subject: Fixed Server.cpp --- Tools/ProtoProxy/Server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Tools') diff --git a/Tools/ProtoProxy/Server.cpp b/Tools/ProtoProxy/Server.cpp index e27c86e10..5bba98057 100644 --- a/Tools/ProtoProxy/Server.cpp +++ b/Tools/ProtoProxy/Server.cpp @@ -85,7 +85,7 @@ int cServer::Init(short a_ListenPort, short a_ConnectPort) void cServer::Run(void) { - LOG("Server running."); + LOGINFO("Server running."); while (true) { sockaddr_in Addr; -- cgit v1.2.3