diff --git a/CMakeLists.txt b/CMakeLists.txt index 040bfca..d777da4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,9 @@ if (UNIX) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -g") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -s") elseif (WIN32) + # This might cause issues with old windows headers, but it's worth the trouble to keep the code + # completely cross platform. For fixes to common issues arising from /permissive- visit: + # https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /permissive-") endif () diff --git a/include/Client.hpp b/include/Client.hpp index 9c6bfa6..9f2cf9e 100644 --- a/include/Client.hpp +++ b/include/Client.hpp @@ -3,7 +3,7 @@ /// #pragma once -#ifdef __WIN32 +#ifdef WIN32 #include #else #include diff --git a/include/Curl/curl.h b/include/Curl/curl.h index 162b606..3fa143c 100644 --- a/include/Curl/curl.h +++ b/include/Curl/curl.h @@ -38,7 +38,7 @@ * Define WIN32 when build target is Win32 API */ -#if (defined(_WIN32) || defined(__WIN32__)) && \ +#if (defined(_WIN32) || defined(WIN32__)) && \ !defined(WIN32) && !defined(__SYMBIAN32__) #define WIN32 #endif diff --git a/include/UnixCompat.h b/include/UnixCompat.h index a5d23e1..bfaf81f 100644 --- a/include/UnixCompat.h +++ b/include/UnixCompat.h @@ -4,7 +4,7 @@ // This header defines unix equivalents of common win32 functions. -#ifndef __WIN32 +#ifndef WIN32 #include #include @@ -27,4 +27,4 @@ inline void closesocket(int socket) { #define __except(x) /**/ #endif -#endif // __WIN32 +#endif // WIN32 diff --git a/include/Zlib/zconf.h b/include/Zlib/zconf.h index 352f552..545e5b1 100644 --- a/include/Zlib/zconf.h +++ b/include/Zlib/zconf.h @@ -176,7 +176,7 @@ #if defined(_WINDOWS) && !defined(WINDOWS) # define WINDOWS #endif -#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(WIN32__) # ifndef WIN32 # define WIN32 # endif diff --git a/include/Zlib/zutil.h b/include/Zlib/zutil.h index b079ea6..370f7b9 100644 --- a/include/Zlib/zutil.h +++ b/include/Zlib/zutil.h @@ -133,7 +133,7 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ #if defined(MACOS) || defined(TARGET_OS_MAC) # define OS_CODE 7 # ifndef Z_SOLO -# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os +# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != WIN32_os # include /* for fdopen */ # else # ifndef fdopen diff --git a/src/Console.cpp b/src/Console.cpp index a7926ac..5dd99db 100644 --- a/src/Console.cpp +++ b/src/Console.cpp @@ -3,14 +3,14 @@ /// #include "Lua/LuaSystem.hpp" -#ifdef __WIN32 +#ifdef WIN32 #include #include #else // *nix typedef unsigned long DWORD, *PDWORD, *LPDWORD; #include #include -#endif // __WIN32 +#endif // WIN32 #include "Logger.h" #include #include @@ -54,7 +54,7 @@ void ConsoleOut(const std::string& msg){ } } -#ifndef __WIN32 +#ifndef WIN32 static int _getch() { char buf = 0; @@ -77,10 +77,10 @@ static int _getch() // no echo printf("%c\n", buf); return buf; } -#endif // __WIN32 +#endif // WIN32 void SetupConsole(){ -#ifdef __WIN32 +#ifdef WIN32 DWORD outMode = 0; HANDLE stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE); if (stdoutHandle == INVALID_HANDLE_VALUE){ @@ -101,7 +101,7 @@ void SetupConsole(){ exit(GetLastError()); } #else -#endif // __WIN32 +#endif // WIN32 } [[noreturn]] void ReadCin(){ diff --git a/src/Enc.cpp b/src/Enc.cpp index 6522a90..90b9939 100644 --- a/src/Enc.cpp +++ b/src/Enc.cpp @@ -85,7 +85,7 @@ int Dec(int value,int d,int n){ return log_power(value, d, n); } -#ifdef __WIN32 +#ifdef WIN32 int Handle(EXCEPTION_POINTERS *ep,char* Origin){ assert(false); std::stringstream R; @@ -98,7 +98,7 @@ int Handle(EXCEPTION_POINTERS *ep,char* Origin){ #else // stub int Handle(EXCEPTION_POINTERS *, char*) { return 1; } -#endif // __WIN32 +#endif // WIN32 std::string RSA_E(const std::string& Data, RSA*k){ std::stringstream stream; diff --git a/src/Lua/LuaSystem.cpp b/src/Lua/LuaSystem.cpp index d97ab9a..6fc500b 100644 --- a/src/Lua/LuaSystem.cpp +++ b/src/Lua/LuaSystem.cpp @@ -143,7 +143,7 @@ void SafeExecution(Lua* lua,const std::string& FuncName){ lua_getglobal(luaState, FuncName.c_str()); if(lua_isfunction(luaState, -1)) { char* Origin = ThreadOrigin(lua); -#ifdef __WIN32 +#ifdef WIN32 __try{ int R = lua_pcall(luaState, 0, 0, 0); CheckLua(luaState, R); @@ -151,7 +151,7 @@ void SafeExecution(Lua* lua,const std::string& FuncName){ #else // unix int R = lua_pcall(luaState, 0, 0, 0); CheckLua(luaState, R); -#endif // __WIN32 +#endif // WIN32 delete [] Origin; } ClearStack(luaState); @@ -515,18 +515,18 @@ int CallFunction(Lua*lua,const std::string& FuncName,LuaArg* Arg){ } int R = 0; char* Origin = lua->GetOrigin(); -#ifdef __WIN32 +#ifdef WIN32 __try{ -#endif // __WIN32 +#endif // WIN32 R = lua_pcall(luaState, Size, 1, 0); if (CheckLua(luaState, R)){ if (lua_isnumber(luaState, -1)) { return int(lua_tointeger(luaState, -1)); } } -#ifdef __WIN32 +#ifdef WIN32 }__except(Handle(GetExceptionInformation(),Origin)){} -#endif // __WIN32 +#endif // WIN32 delete [] Origin; } ClearStack(luaState); diff --git a/src/Network/Auth.cpp b/src/Network/Auth.cpp index 3da2573..6bf96e9 100644 --- a/src/Network/Auth.cpp +++ b/src/Network/Auth.cpp @@ -158,20 +158,20 @@ void Identify(SOCKET TCPSock){ // reason MSVC defines __try and __except and libg++ defines // __try and __catch so its all a big mess if we leave this in or undefine // the macros -#ifdef __WIN32 +#ifdef WIN32 __try{ -#endif // __WIN32 +#endif // WIN32 Identification(TCPSock,S,Skey); -#ifdef __WIN32 +#ifdef WIN32 }__except(1){ -#endif // __WIN32 +#endif // WIN32 if(TCPSock != -1){ closesocket(TCPSock); } -#ifdef __WIN32 +#ifdef WIN32 } -#endif // __WIN32 +#endif // WIN32 delete Skey; delete S; @@ -179,7 +179,7 @@ void Identify(SOCKET TCPSock){ void TCPServerMain(){ DebugPrintTID(); -#ifdef __WIN32 +#ifdef WIN32 WSADATA wsaData; if (WSAStartup(514, &wsaData)){ error(Sec("Can't start Winsock!")); @@ -249,5 +249,5 @@ void TCPServerMain(){ }while(client); closesocket(client); -#endif // __WIN32 +#endif // WIN32 } diff --git a/src/Network/GParser.cpp b/src/Network/GParser.cpp index 9492bac..f337f20 100644 --- a/src/Network/GParser.cpp +++ b/src/Network/GParser.cpp @@ -124,13 +124,13 @@ void SyncClient(Client*c){ } void ParseVeh(Client*c, const std::string& Packet){ Assert(c); -#ifdef __WIN32 +#ifdef WIN32 __try{ VehicleParser(c,Packet); }__except(Handle(GetExceptionInformation(),Sec("Vehicle Handler"))){} #else // unix VehicleParser(c,Packet); -#endif // __WIN32 +#endif // WIN32 } void HandleEvent(Client*c ,const std::string&Data){ @@ -204,11 +204,11 @@ void GlobalParser(Client*c, const std::string& Pack){ void GParser(Client*c, const std::string& Packet){ Assert(c); -#ifdef __WIN32 +#ifdef WIN32 __try{ GlobalParser(c, Packet); }__except(Handle(GetExceptionInformation(),Sec("Global Handler"))){} #else GlobalParser(c, Packet); -#endif // __WIN32 +#endif // WIN32 } diff --git a/src/Network/TCPHandler.cpp b/src/Network/TCPHandler.cpp index c2c3408..5b80a07 100644 --- a/src/Network/TCPHandler.cpp +++ b/src/Network/TCPHandler.cpp @@ -21,15 +21,15 @@ void TCPSend(Client*c,const std::string&Data){ } void TCPHandle(Client*c,const std::string& data){ Assert(c); -#ifdef __WIN32 +#ifdef WIN32 __try{ -#endif // __WIN32 +#endif // WIN32 c->Handler.Handle(c,data); -#ifdef __WIN32 +#ifdef WIN32 }__except(1){ c->Handler.clear(); } -#endif // __WIN32 +#endif // WIN32 } void TCPRcv(Client*c){ Assert(c); @@ -43,11 +43,11 @@ void TCPRcv(Client*c){ if(c->GetStatus() > -1)c->SetStatus(-1); return; }else if (BytesRcv < 0) { -#ifdef __WIN32 +#ifdef WIN32 debug(Sec("(TCP) recv failed with error: ") + std::to_string(WSAGetLastError())); #else // unix debug(Sec("(TCP) recv failed with error: ") + std::string(strerror(errno))); -#endif // __WIN32 +#endif // WIN32 if(c->GetStatus() > -1)c->SetStatus(-1); closesocket(c->GetTCPSock()); return; @@ -64,13 +64,13 @@ void TCPClient(Client*c){ } OnConnect(c); while (c->GetStatus() > -1)TCPRcv(c); -#ifdef __WIN32 +#ifdef WIN32 __try{ -#endif // __WIN32 +#endif // WIN32 OnDisconnect(c, c->GetStatus() == -2); -#ifdef __WIN32 +#ifdef WIN32 }__except(Handle(GetExceptionInformation(),Sec("OnDisconnect"))){} -#endif // __WIN32 +#endif // WIN32 } void InitClient(Client*c){ std::thread NewClient(TCPClient,c); diff --git a/src/Network/VehicleData.cpp b/src/Network/VehicleData.cpp index 17c68b8..14bd246 100644 --- a/src/Network/VehicleData.cpp +++ b/src/Network/VehicleData.cpp @@ -43,7 +43,7 @@ void UDPSend(Client* c, std::string Data) { Data = "ABG:" + CMP; } ssize_t sendOk = sendto(UDPSock, Data.c_str(), Data.size(), 0, (sockaddr*)&Addr, AddrSize); -#ifdef __WIN32 +#ifdef WIN32 if (sendOk != 0) { debug(Sec("(UDP) Send Failed Code : ") + std::to_string(WSAGetLastError())); if (c->GetStatus() > -1) @@ -55,7 +55,7 @@ void UDPSend(Client* c, std::string Data) { if (c->GetStatus() > -1) c->SetStatus(-1); } -#endif // __WIN32 +#endif // WIN32 } void AckID(int ID) { @@ -168,11 +168,11 @@ std::string UDPRcvFromClient(sockaddr_in& client) { std::string Ret(10240, 0); ssize_t Rcv = recvfrom(UDPSock, &Ret[0], 10240, 0, (sockaddr*)&client, (socklen_t*)&clientLength); if (Rcv == -1) { -#ifdef __WIN32 +#ifdef WIN32 error(Sec("(UDP) Error receiving from Client! Code : ") + std::to_string(WSAGetLastError())); #else // unix error(Sec("(UDP) Error receiving from Client! Code : ") + std::string(strerror(errno))); -#endif // __WIN32 +#endif // WIN32 return ""; } return Ret; @@ -272,7 +272,7 @@ void LOOP() { } } [[noreturn]] void UDPServerMain() { -#ifdef __WIN32 +#ifdef WIN32 WSADATA data; if (WSAStartup(514, &data)) { error(Sec("Can't start Winsock!")); @@ -362,5 +362,5 @@ void LOOP() { /*closesocket(UDPSock); // TODO: Why not this? We did this in TCPServerMain? return; */ -#endif // __WIN32 +#endif // WIN32 } diff --git a/src/logger.cpp b/src/logger.cpp index daded17..357ebf4 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -28,11 +28,11 @@ std::string getDate() { auto s = std::chrono::duration_cast(tp);tp -= s; time_t tt = std::chrono::system_clock::to_time_t(now); tm local_tm{}; -#ifdef __WIN32 +#ifdef WIN32 localtime_s(&local_tm,&tt); #else // unix localtime_r(&tt, &local_tm); -#endif // __WIN32 +#endif // WIN32 std::stringstream date; int S = local_tm.tm_sec; int M = local_tm.tm_min;