diff --git a/CMakeLists.txt b/CMakeLists.txt index 41ad31d..13b4cce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,15 +26,6 @@ endif() set(HTTPLIB_REQUIRE_OPENSSL ON) set(SENTRY_BUILD_SHARED_LIBS OFF) -include_directories("${CMAKE_CURRENT_SOURCE_DIR}/deps/asio/asio/include") -include_directories("${CMAKE_CURRENT_SOURCE_DIR}/deps/rapidjson/include") -include_directories("${CMAKE_CURRENT_SOURCE_DIR}/deps/websocketpp") -include_directories("${CMAKE_CURRENT_SOURCE_DIR}/deps/commandline") -include_directories("${CMAKE_CURRENT_SOURCE_DIR}/deps/sol2/include") -include_directories("${CMAKE_CURRENT_SOURCE_DIR}/deps/cpp-httplib") -include_directories("${CMAKE_CURRENT_SOURCE_DIR}/deps/json/single_include") -include_directories("${CMAKE_CURRENT_SOURCE_DIR}/deps") - add_compile_definitions(CPPHTTPLIB_OPENSSL_SUPPORT=1) # ------------------------ APPLE --------------------------------- @@ -62,17 +53,15 @@ elseif (WIN32) STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) # ------------------------ LINUX --------------------------------- elseif (UNIX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -static-libstdc++ -static-libgcc") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fno-builtin") option(SANITIZE "Turns on thread and UB sanitizers" OFF) if (SANITIZE) message(STATUS "sanitize is ON") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined,thread") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize={address,thread,undefined}") endif (SANITIZE) endif () -include_directories("include/sentry-native/include") set(BUILD_SHARED_LIBS OFF) # ------------------------ SENTRY --------------------------------- message(STATUS "Checking for Sentry URL") @@ -131,19 +120,57 @@ set(BeamMP_Sources ) set(BeamMP_Includes - "${CMAKE_CURRENT_SOURCE_DIR}/include" - "${CMAKE_CURRENT_SOURCE_DIR}/commandline" ${LUA_INCLUDE_DIR} ${CURL_INCLUDE_DIRS} - "include/tomlplusplus" - "include/sentry-native/include" - "include/curl/include" + "${CMAKE_CURRENT_SOURCE_DIR}/deps/cpp-httplib" + "${CMAKE_CURRENT_SOURCE_DIR}/deps/commandline" + "${CMAKE_CURRENT_SOURCE_DIR}/deps/json/single_include" + "${CMAKE_CURRENT_SOURCE_DIR}/deps/sol2/include" + "${CMAKE_CURRENT_SOURCE_DIR}/deps/rapidjson/include" + "${CMAKE_CURRENT_SOURCE_DIR}/deps/asio/asio/include" + "${CMAKE_CURRENT_SOURCE_DIR}/deps" ) set(BeamMP_Definitions SECRET_SENTRY_URL="${BEAMMP_SECRET_SENTRY_URL}" ) +if (UNIX) + set(BeamMP_CompileOptions + -Wall + -Wextra + -Wpedantic + + -Werror=uninitialized + -Werror=float-equal + -Werror=pointer-arith + -Werror=double-promotion + -Werror=write-strings + -Werror=cast-qual + -Werror=init-self + -Werror=cast-align + -Werror=unreachable-code + -Werror=strict-aliasing -fstrict-aliasing + -Werror=redundant-decls + -Werror=missing-declarations + -Werror=missing-field-initializers + -Werror=write-strings + -Werror=inline + -Werror=disabled-optimization + -Werror=ctor-dtor-privacy + -Werror=switch-enum + -Werror=switch-default + -Werror=old-style-cast + -Werror=overloaded-virtual + -Werror=zero-as-null-pointer-constant + -Werror=overloaded-virtual + -Werror=missing-include-dirs + -Werror=unused-result + + -fstack-protector + ) +endif() + set(BeamMP_Libraries doctest::doctest OpenSSL::SSL @@ -173,7 +200,15 @@ target_compile_definitions(BeamMP-Server PRIVATE DOCTEST_CONFIG_DISABLE ) -target_include_directories(BeamMP-Server PUBLIC +target_compile_options(BeamMP-Server PRIVATE + ${BeamMP_CompileOptions} +) + +target_include_directories(BeamMP-Server PRIVATE + "${CMAKE_CURRENT_SOURCE_DIR}/include" +) + +target_include_directories(BeamMP-Server SYSTEM PRIVATE ${BeamMP_Includes} ) @@ -195,11 +230,19 @@ if(BUILD_TESTS) target_compile_definitions(BeamMP-Server-tests PRIVATE ${BeamMP_Definitions} ) - - target_include_directories(BeamMP-Server-tests PUBLIC - ${BeamMP_Includes} + + target_compile_options(BeamMP-Server-tests PRIVATE + ${BeamMP_CompileOptions} ) + target_include_directories(BeamMP-Server-tests PRIVATE + "${CMAKE_CURRENT_SOURCE_DIR}/include" + ) + + target_include_directories(BeamMP-Server-tests SYSTEM PRIVATE + ${BeamMP_Includes} + ) + target_link_libraries(BeamMP-Server-tests ${BeamMP_Libraries} ${BeamMP_PlatformLibs} diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 0c1ba10..f439b19 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -1,5 +1,4 @@ include_directories("${PROJECT_SOURCE_DIR}/deps") -include_directories("${PROJECT_SOURCE_DIR}/deps/commandline") add_subdirectory("${PROJECT_SOURCE_DIR}/deps/commandline") add_subdirectory("${PROJECT_SOURCE_DIR}/deps/fmt") diff --git a/include/Common.h b/include/Common.h index 37c891f..3b0f205 100644 --- a/include/Common.h +++ b/include/Common.h @@ -4,7 +4,6 @@ extern TSentry Sentry; #include -#include #include #include #include @@ -15,14 +14,13 @@ extern TSentry Sentry; #include #include #include +#include #include #include #include namespace fs = std::filesystem; -#include "Compat.h" - #include "TConsole.h" struct Version { @@ -34,7 +32,7 @@ struct Version { std::string AsString(); }; -template +template using SparseArray = std::unordered_map; // static class handling application start, shutdown, etc. @@ -277,11 +275,11 @@ inline T Comp(const T& Data) { // obsolete C.fill(0); z_stream defstream; - defstream.zalloc = Z_NULL; - defstream.zfree = Z_NULL; - defstream.opaque = Z_NULL; - defstream.avail_in = (uInt)Data.size(); - defstream.next_in = (Bytef*)&Data[0]; + defstream.zalloc = nullptr; + defstream.zfree = nullptr; + defstream.opaque = nullptr; + defstream.avail_in = uInt(Data.size()); + defstream.next_in = const_cast(reinterpret_cast(&Data[0])); defstream.avail_out = Biggest; defstream.next_out = reinterpret_cast(C.data()); deflateInit(&defstream, Z_BEST_COMPRESSION); @@ -302,13 +300,13 @@ inline T DeComp(const T& Compressed) { // not needed C.fill(0); z_stream infstream; - infstream.zalloc = Z_NULL; - infstream.zfree = Z_NULL; - infstream.opaque = Z_NULL; + infstream.zalloc = nullptr; + infstream.zfree = nullptr; + infstream.opaque = nullptr; infstream.avail_in = Biggest; - infstream.next_in = (Bytef*)(&Compressed[0]); + infstream.next_in = const_cast(reinterpret_cast(&Compressed[0])); infstream.avail_out = Biggest; - infstream.next_out = (Bytef*)(C.data()); + infstream.next_out = const_cast(reinterpret_cast(C.data())); inflateInit(&infstream); inflate(&infstream, Z_SYNC_FLUSH); inflate(&infstream, Z_FINISH); @@ -323,5 +321,3 @@ inline T DeComp(const T& Compressed) { std::string GetPlatformAgnosticErrorString(); #define S_DSN SU_RAW - -void LogChatMessage(const std::string& name, int id, const std::string& msg); diff --git a/include/Http.h b/include/Http.h index 4850470..0898f2e 100644 --- a/include/Http.h +++ b/include/Http.h @@ -9,6 +9,8 @@ #if defined(BEAMMP_LINUX) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#pragma GCC diagnostic ignored "-Wcast-qual" +#pragma GCC diagnostic ignored "-Wold-style-cast" #endif #include #if defined(BEAMMP_LINUX) diff --git a/src/Common.cpp b/src/Common.cpp index 728bbf7..5a8b276 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -9,6 +9,7 @@ #include #include +#include "Compat.h" #include "CustomAssert.h" #include "Http.h" @@ -170,6 +171,8 @@ void Application::SetSubsystemStatus(const std::string& Subsystem, Status status case Status::Shutdown: beammp_trace("Subsystem '" + Subsystem + "': Shutdown"); break; + default: + beammp_assert_not_reachable(); } std::unique_lock Lock(mSystemStatusMapMutex); mSystemStatusMap[Subsystem] = status; @@ -347,5 +350,7 @@ std::string GetPlatformAgnosticErrorString() { } #elif defined(BEAMMP_LINUX) || defined(BEAMMP_APPLE) return std::strerror(errno); +#else + return "(no human-readable errors on this platform)"; #endif } diff --git a/src/Compat.cpp b/src/Compat.cpp index 53dfe0c..a843099 100644 --- a/src/Compat.cpp +++ b/src/Compat.cpp @@ -7,7 +7,7 @@ static struct termios old, current; -void initTermios(int echo) { +static void initTermios(int echo) { tcgetattr(0, &old); /* grab old terminal i/o settings */ current = old; /* make new settings same as old settings */ current.c_lflag &= ~ICANON; /* disable buffered i/o */ @@ -19,7 +19,7 @@ void initTermios(int echo) { tcsetattr(0, TCSANOW, ¤t); /* use these new terminal i/o settings now */ } -void resetTermios(void) { +static void resetTermios(void) { tcsetattr(0, TCSANOW, &old); } @@ -47,7 +47,7 @@ TEST_CASE("init and reset termios") { } } -char getch_(int echo) { +static char getch_(int echo) { char ch; initTermios(echo); read(STDIN_FILENO, &ch, 1); diff --git a/src/Http.cpp b/src/Http.cpp index edc627e..9f87ea4 100644 --- a/src/Http.cpp +++ b/src/Http.cpp @@ -4,7 +4,6 @@ #include "Common.h" #include "CustomAssert.h" #include "LuaAPI.h" -#include "httplib.h" #include #include @@ -177,6 +176,8 @@ void Http::Server::THttpServerInstance::operator()() try { case Application::Status::Bad: SystemsBad++; break; + default: + beammp_assert_not_reachable(); } } res.set_content( diff --git a/src/LuaAPI.cpp b/src/LuaAPI.cpp index e26a1eb..30a0b86 100644 --- a/src/LuaAPI.cpp +++ b/src/LuaAPI.cpp @@ -1,6 +1,7 @@ #include "LuaAPI.h" #include "Client.h" #include "Common.h" +#include "CustomAssert.h" #include "TLuaEngine.h" #include @@ -74,8 +75,10 @@ std::string LuaAPI::LuaToString(const sol::object Value, size_t Indent, bool Quo ss << "[[function: " << Value.as().pointer() << "]]"; return ss.str(); } + case sol::type::poly: + return ""; default: - return "((unprintable type))"; + return ""; } } @@ -114,21 +117,20 @@ static inline std::pair InternalTriggerClientEvent(int Player std::string Packet = "E:" + EventName + ":" + Data; if (PlayerID == -1) { LuaAPI::MP::Engine->Network().SendToAll(nullptr, Packet, true, true); - return {true, ""}; + return { true, "" }; } else { auto MaybeClient = GetClient(LuaAPI::MP::Engine->Server(), PlayerID); if (!MaybeClient || MaybeClient.value().expired()) { beammp_lua_errorf("TriggerClientEvent invalid Player ID '{}'", PlayerID); - return {false, "Invalid Player ID"}; + return { false, "Invalid Player ID" }; } auto c = MaybeClient.value().lock(); if (!LuaAPI::MP::Engine->Network().Respond(*c, Packet, true)) { beammp_lua_errorf("Respond failed, dropping client {}", PlayerID); LuaAPI::MP::Engine->Network().ClientKick(*c, "Disconnected after failing to receive packets"); - return {false, "Respond failed, dropping client"}; - + return { false, "Respond failed, dropping client" }; } - return {true, ""}; + return { true, "" }; } } @@ -141,11 +143,11 @@ std::pair LuaAPI::MP::DropPlayer(int ID, std::optionalServer(), ID); if (!MaybeClient || MaybeClient.value().expired()) { beammp_lua_errorf("Tried to drop client with id {}, who doesn't exist", ID); - return {false, "Player does not exist"}; + return { false, "Player does not exist" }; } auto c = MaybeClient.value().lock(); LuaAPI::MP::Engine->Network().ClientKick(*c, MaybeReason.value_or("No reason")); - return {true, ""}; + return { true, "" }; } std::pair LuaAPI::MP::SendChatMessage(int ID, const std::string& Message) { @@ -165,7 +167,10 @@ std::pair LuaAPI::MP::SendChatMessage(int ID, const std::stri return Result; } LogChatMessage(" (to \"" + c->GetName() + "\")", -1, Message); - Engine->Network().Respond(*c, Packet, true); + if (!Engine->Network().Respond(*c, Packet, true)) { + beammp_errorf("Failed to send chat message back to sender (id {}) - did the sender disconnect?", ID); + // TODO: should we return an error here? + } Result.first = true; } else { beammp_lua_error("SendChatMessage invalid argument [1] invalid ID"); @@ -521,7 +526,7 @@ static void JsonEncodeRecursive(nlohmann::json& json, const sol::object& left, c beammp_lua_error("json serialize will not go deeper than 100 nested tables, internal references assumed, aborted this path"); return; } - std::string key; + std::string key{}; switch (left.get_type()) { case sol::type::lua_nil: case sol::type::none: @@ -540,6 +545,8 @@ static void JsonEncodeRecursive(nlohmann::json& json, const sol::object& left, c case sol::type::number: key = std::to_string(left.as()); break; + default: + beammp_assert_not_reachable(); } nlohmann::json value; switch (right.get_type()) { @@ -582,6 +589,8 @@ static void JsonEncodeRecursive(nlohmann::json& json, const sol::object& left, c } break; } + default: + beammp_assert_not_reachable(); } if (is_array) { json.push_back(value); diff --git a/src/TConfig.cpp b/src/TConfig.cpp index fc3a1d1..1d0c795 100644 --- a/src/TConfig.cpp +++ b/src/TConfig.cpp @@ -167,7 +167,7 @@ void TConfig::TryReadValue(toml::value& Table, const std::string& Category, cons void TConfig::TryReadValue(toml::value& Table, const std::string& Category, const std::string_view& Key, int& OutValue) { if (Table[Category.c_str()][Key.data()].is_integer()) { - OutValue = Table[Category.c_str()][Key.data()].as_integer(); + OutValue = int(Table[Category.c_str()][Key.data()].as_integer()); } } diff --git a/src/TConsole.cpp b/src/TConsole.cpp index e2a39b5..5420d39 100644 --- a/src/TConsole.cpp +++ b/src/TConsole.cpp @@ -62,8 +62,7 @@ static inline void SplitString(std::string const& str, const char delim, std::ve } } - -std::string GetDate() { +static std::string GetDate() { std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); time_t tt = std::chrono::system_clock::to_time_t(now); auto local_tm = std::localtime(&tt); @@ -156,10 +155,10 @@ void TConsole::ChangeToLuaConsole(const std::string& LuaStateId) { mStateId = LuaStateId; mIsLuaConsole = true; if (mStateId != mDefaultStateId) { - Application::Console().WriteRaw("Attached to Lua state '" + mStateId + "'. For help, type `:help`. To detach, type `:detach`"); + Application::Console().WriteRaw("Attached to Lua state '" + mStateId + "'. For help, type `:help`. To detach, type `:exit`"); mCommandline.set_prompt("lua @" + LuaStateId + "> "); } else { - Application::Console().WriteRaw("Attached to Lua. For help, type `:help`. To detach, type `:detach`"); + Application::Console().WriteRaw("Attached to Lua. For help, type `:help`. To detach, type `:exit`"); mCommandline.set_prompt("lua> "); } mCachedRegularHistory = mCommandline.history(); @@ -271,9 +270,10 @@ void TConsole::Command_Kick(const std::string&, const std::vector& } beammp_trace("attempt to kick '" + Name + "' for '" + Reason + "'"); bool Kicked = false; + // TODO: this sucks, tolower is locale-dependent. auto NameCompare = [](std::string Name1, std::string Name2) -> bool { - std::for_each(Name1.begin(), Name1.end(), [](char& c) { c = tolower(c); }); - std::for_each(Name2.begin(), Name2.end(), [](char& c) { c = tolower(c); }); + std::for_each(Name1.begin(), Name1.end(), [](char& c) { c = char(std::tolower(char(c))); }); + std::for_each(Name2.begin(), Name2.end(), [](char& c) { c = char(std::tolower(char(c))); }); return StringStartsWith(Name1, Name2) || StringStartsWith(Name2, Name1); }; mLuaEngine->Server().ForEachClient([&](std::weak_ptr Client) -> bool { @@ -332,7 +332,9 @@ std::tuple> TConsole::ParseCommand(const s } ++Ptr; } - Arg = std::string(PrevPtr, Ptr - PrevPtr); + // this is required, otherwise we get negative int to unsigned cast in the next operations + beammp_assert(PrevPtr <= Ptr); + Arg = std::string(PrevPtr, std::string::size_type(Ptr - PrevPtr)); // remove quotes if enclosed in quotes for (char Quote : { '"', '\'', '`' }) { if (!Arg.empty() && Arg.at(0) == Quote && Arg.at(Arg.size() - 1) == Quote) { @@ -448,6 +450,8 @@ void TConsole::Command_Status(const std::string&, const std::vector SystemsShutdown++; SystemsShutdownList += NameStatusPair.first + ", "; break; + default: + beammp_assert_not_reachable(); } } // remove ", " at the end @@ -466,7 +470,7 @@ void TConsole::Command_Status(const std::string&, const std::vector << "\tConnected Players: " << ConnectedCount << "\n" << "\tGuests: " << GuestCount << "\n" << "\tCars: " << CarCount << "\n" - << "\tUptime: " << ElapsedTime << "ms (~" << size_t(ElapsedTime / 1000.0 / 60.0 / 60.0) << "h) \n" + << "\tUptime: " << ElapsedTime << "ms (~" << size_t(double(ElapsedTime) / 1000.0 / 60.0 / 60.0) << "h) \n" << "\tLua:\n" << "\t\tQueued results to check: " << mLuaEngine->GetResultsToCheckSize() << "\n" << "\t\tStates: " << mLuaEngine->GetLuaStateCount() << "\n" @@ -630,7 +634,7 @@ TConsole::TConsole() { beammp_error("Console died with: " + std::string(e.what()) + ". This could be a fatal error and could cause the server to terminate."); } }; - mCommandline.on_autocomplete = [this](Commandline& c, std::string stub, int cursorPos) { + mCommandline.on_autocomplete = [this](Commandline&, std::string stub, int) { std::vector suggestions; try { if (mIsLuaConsole) { // if lua @@ -638,7 +642,7 @@ TConsole::TConsole() { beammp_info("Lua not started yet, please try again in a second"); } else { std::string prefix {}; // stores non-table part of input - for (size_t i = stub.length(); i > 0; i--) { //separate table from input + for (size_t i = stub.length(); i > 0; i--) { // separate table from input if (!std::isalnum(stub[i - 1]) && stub[i - 1] != '_' && stub[i - 1] != '.') { prefix = stub.substr(0, i); stub = stub.substr(i); diff --git a/src/TLuaEngine.cpp b/src/TLuaEngine.cpp index b493296..3f8b01a 100644 --- a/src/TLuaEngine.cpp +++ b/src/TLuaEngine.cpp @@ -7,7 +7,6 @@ #include #include -#include #include #include #include @@ -679,6 +678,8 @@ static void JsonDecodeRecursive(sol::state_view& StateView, sol::table& table, c return; case nlohmann::detail::value_t::discarded: return; + default: + beammp_assert_not_reachable(); } } diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index be9b773..ecdea11 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -57,7 +57,7 @@ void TNetwork::UDPServerMain() { serverAddr.sin_port = htons(uint16_t(Application::Settings.Port)); // Convert from little to big endian // Try and bind the socket to the IP and port - if (bind(mUDPSock, (sockaddr*)&serverAddr, sizeof(serverAddr)) != 0) { + if (bind(mUDPSock, reinterpret_cast(&serverAddr), sizeof(serverAddr)) != 0) { beammp_error("bind() failed: " + GetPlatformAgnosticErrorString()); std::this_thread::sleep_for(std::chrono::seconds(5)); exit(-1); // TODO: Wtf. @@ -134,7 +134,7 @@ void TNetwork::TCPServerMain() { addr.sin_addr.s_addr = INADDR_ANY; addr.sin_family = AF_INET; addr.sin_port = htons(uint16_t(Application::Settings.Port)); - if (bind(Listener, (sockaddr*)&addr, sizeof(addr)) < 0) { + if (bind(Listener, reinterpret_cast(&addr), sizeof(addr)) < 0) { beammp_error("bind() failed, the server cannot operate and will shut down now. " "Error: " + GetPlatformAgnosticErrorString()); @@ -166,7 +166,7 @@ void TNetwork::TCPServerMain() { int ret = ::setsockopt(client.Socket, SOL_SOCKET, SO_SNDTIMEO, reinterpret_cast(&SendTimeoutMS), sizeof(SendTimeoutMS)); #else // POSIX struct timeval optval; - optval.tv_sec = (int)(SendTimeoutMS / 1000); + optval.tv_sec = int(SendTimeoutMS / 1000); optval.tv_usec = (SendTimeoutMS % 1000) * 1000; ret = ::setsockopt(client.Socket, SOL_SOCKET, SO_SNDTIMEO, reinterpret_cast(&optval), sizeof(optval)); #endif @@ -237,13 +237,13 @@ void TNetwork::HandleDownload(SOCKET TCPSock) { }); } -static int get_ip_str(const struct sockaddr* sa, char* strBuf, size_t strBufSize) { +static int get_ip_str(const struct sockaddr* sa, char* strBuf, socklen_t strBufSize) { switch (sa->sa_family) { case AF_INET: - inet_ntop(AF_INET, &(((struct sockaddr_in*)sa)->sin_addr), strBuf, strBufSize); + inet_ntop(AF_INET, &reinterpret_cast(sa)->sin_addr, strBuf, strBufSize); break; case AF_INET6: - inet_ntop(AF_INET6, &(((struct sockaddr_in6*)sa)->sin6_addr), strBuf, strBufSize); + inet_ntop(AF_INET6, &reinterpret_cast(sa)->sin6_addr, strBuf, strBufSize); break; default: return 1; @@ -453,7 +453,7 @@ bool TNetwork::CheckBytes(TClient& c, int32_t BytesRcv) { } std::string TNetwork::TCPRcv(TClient& c) { - int32_t Header, BytesRcv = 0, Temp; + int32_t Header {}, BytesRcv = 0, Temp {}; if (c.GetStatus() < 0) return ""; @@ -470,7 +470,7 @@ std::string TNetwork::TCPRcv(TClient& c) { if (!CheckBytes(c, BytesRcv)) { return ""; } - if (Header < 100 * MB) { + if (Header < int32_t(100 * MB)) { Data.resize(Header); } else { ClientKick(c, "Header size limit exceeded"); @@ -822,7 +822,6 @@ uint8_t* /* end ptr */ TNetwork::SendSplit(TClient& c, SOCKET Socket, uint8_t* D void TNetwork::SplitLoad(TClient& c, size_t Sent, size_t Size, bool D, const std::string& Name) { std::ifstream f(Name.c_str(), std::ios::binary); - auto Buf = f.rdbuf(); uint32_t Split = 125 * MB; std::vector Data; if (Size > Split) @@ -1018,7 +1017,7 @@ bool TNetwork::UDPSend(TClient& Client, std::string Data) const { size_t len = Data.size(); #endif // WIN32 - sendOk = sendto(mUDPSock, Data.c_str(), len, 0, (sockaddr*)&Addr, int(AddrSize)); + sendOk = sendto(mUDPSock, Data.c_str(), len, 0, reinterpret_cast(&Addr), int(AddrSize)); if (sendOk == -1) { beammp_debug("(UDP) sendto() failed: " + GetPlatformAgnosticErrorString()); if (Client.GetStatus() > -1) @@ -1039,7 +1038,7 @@ std::string TNetwork::UDPRcvFromClient(sockaddr_in& client) const { #ifdef WIN32 auto Rcv = recvfrom(mUDPSock, Ret.data(), int(Ret.size()), 0, (sockaddr*)&client, (int*)&clientLength); #else // unix - int64_t Rcv = recvfrom(mUDPSock, Ret.data(), Ret.size(), 0, (sockaddr*)&client, (socklen_t*)&clientLength); + int64_t Rcv = recvfrom(mUDPSock, Ret.data(), Ret.size(), 0, reinterpret_cast(&client), reinterpret_cast(&clientLength)); #endif // WIN32 if (Rcv == -1) { diff --git a/src/TSentry.cpp b/src/TSentry.cpp index 7f2b416..ceab947 100644 --- a/src/TSentry.cpp +++ b/src/TSentry.cpp @@ -6,7 +6,7 @@ #include TSentry::TSentry() { - if (std::strlen(S_DSN) == 0) { + if (std::strlen(S_DSN) == /* DISABLES CODE */ (0)) { mValid = false; } else { mValid = true; diff --git a/src/TServer.cpp b/src/TServer.cpp index b9d7d2d..291d2c3 100644 --- a/src/TServer.cpp +++ b/src/TServer.cpp @@ -22,10 +22,10 @@ static std::optional> GetPidVid(const std::string& str) { if (pid.find_first_not_of("0123456789") == std::string::npos && vid.find_first_not_of("0123456789") == std::string::npos) { try { - int PID = stoi(pid); - int VID = stoi(vid); - return {{ PID, VID }}; - } catch(const std::exception&) { + int PID = stoi(pid); + int VID = stoi(vid); + return { { PID, VID } }; + } catch (const std::exception&) { return std::nullopt; } } @@ -75,7 +75,6 @@ TEST_CASE("GetPidVid") { } } - TServer::TServer(const std::vector& Arguments) { beammp_info("BeamMP Server v" + Application::ServerVersionString()); Application::SetSubsystemStatus("Server", Application::Status::Starting); @@ -256,7 +255,7 @@ void TServer::ParseVehicle(TClient& c, const std::string& Pckt, TNetwork& Networ std::string Packet = Pckt; char Code = Packet.at(1); int PID = -1; - int VID = -1, Pos; + int VID = -1; std::string Data = Packet.substr(3), pid, vid; switch (Code) { // Spawned Destroyed Switched/Moved NotFound Reset case 's': diff --git a/src/main.cpp b/src/main.cpp index 4650570..54f0f62 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,7 +2,6 @@ #include "ArgsParser.h" #include "Common.h" -#include "CustomAssert.h" #include "Http.h" #include "LuaAPI.h" #include "SignalHandling.h" @@ -13,7 +12,6 @@ #include "TPPSMonitor.h" #include "TPluginMonitor.h" #include "TResourceManager.h" -#include "TScopedTimer.h" #include "TServer.h" #include @@ -56,7 +54,7 @@ int BeamMPServerMain(MainArguments Arguments); int main(int argc, char** argv) { MainArguments Args { argc, argv, {}, argv[0] }; - Args.List.reserve(argc); + Args.List.reserve(size_t(argc)); for (int i = 1; i < argc; ++i) { Args.List.push_back(argv[i]); }