diff --git a/src/Init/Config.cpp b/src/Init/Config.cpp index c4b8b7c..76cf798 100644 --- a/src/Init/Config.cpp +++ b/src/Init/Config.cpp @@ -135,18 +135,20 @@ void Default() { _Exit(0); } void DebugData() { - debug(std::string(("Debug : ")) + (Debug ? "true" : "false")); - debug(std::string(("Private : ")) + (Private ? "true" : "false")); - debug(("Port : ") + std::to_string(Port)); - debug(("Max Cars : ") + std::to_string(MaxCars)); - debug(("MaxPlayers : ") + std::to_string(MaxPlayers)); - debug(("MapName : ") + MapName); - debug(("ServerName : ") + ServerName); - debug(("ServerDesc : ") + ServerDesc); - debug(("File : ") + Resource); - debug(("Key length: ") + std::to_string(Key.length())); + debug(std::string("Debug : ") + (Debug ? "true" : "false")); + debug(std::string("Private : ") + (Private ? "true" : "false")); + debug("Port : " + std::to_string(Port)); + debug("Max Cars : " + std::to_string(MaxCars)); + debug("MaxPlayers : " + std::to_string(MaxPlayers)); + debug("MapName : " + MapName); + debug("ServerName : " + ServerName); + debug("ServerDesc : " + ServerDesc); + debug("File : " + Resource); + debug("Key length: " + std::to_string(Key.length())); } void InitConfig() { + ////TODO: Move to json after update 4 + std::ifstream IFS; IFS.open(("Server.cfg")); if (IFS.good()) diff --git a/src/Init/Startup.cpp b/src/Init/Startup.cpp index 9c2d7e4..4a17669 100644 --- a/src/Init/Startup.cpp +++ b/src/Init/Startup.cpp @@ -16,7 +16,7 @@ std::string GetSVer() { return "1.20"; } std::string GetCVer() { - return "1.72"; + return "1.80"; } void Args(int argc, char* argv[]) { info("BeamMP Server Running version " + GetSVer()); diff --git a/src/Network/Auth.cpp b/src/Network/Auth.cpp index 92662b9..307aae2 100644 --- a/src/Network/Auth.cpp +++ b/src/Network/Auth.cpp @@ -69,7 +69,7 @@ void Authentication(SOCKET TCPSock) { json::Document d; d.Parse(Rc.c_str()); if(Rc == "-1" || d.HasParseError()){ - ClientKick(c,"Invalid key!"); + ClientKick(c,"Invalid key! Please restart your game."); return; } diff --git a/src/Network/GParser.cpp b/src/Network/GParser.cpp index cfefc20..037ee64 100644 --- a/src/Network/GParser.cpp +++ b/src/Network/GParser.cpp @@ -14,25 +14,36 @@ #include "UnixCompat.h" #include #include +#include "Json.h" -int FC(const std::string& s, const std::string& p, int n) { - auto i = s.find(p); - int j; - for (j = 1; j < n && i != std::string::npos; ++j) { - i = s.find(p, i + 1); - } - if (j == n) - return int(i); - else - return -1; -} void Apply(Client* c, int VID, const std::string& pckt) { Assert(c); - std::string Packet = pckt; - std::string VD = c->GetCarData(VID); - Packet = Packet.substr(FC(Packet, ",", 2) + 1); - Packet = VD.substr(0, FC(VD, ",", 2) + 1) + Packet.substr(0, Packet.find_last_of('"') + 1) + VD.substr(FC(VD, ",\"", 7)); - c->SetCarData(VID, Packet); + std::string Packet = pckt.substr(pckt.find('{')), VD = c->GetCarData(VID); + std::string Header = VD.substr(0,VD.find('{')); + VD = VD.substr(VD.find('{')); + rapidjson::Document Veh, Pack; + Veh.Parse(VD.c_str()); + if(Veh.HasParseError()){ + error("Could not get vehicle config!"); + return; + } + Pack.Parse(Packet.c_str()); + if(Pack.HasParseError() || Pack.IsNull()){ + error("Could not get active vehicle config!"); + return; + } + + for(auto& M : Pack.GetObjectA()){ + if(Veh[M.name].IsNull()){ + Veh.AddMember(M.name,M.value,Veh.GetAllocator()); + }else{ + Veh[M.name] = Pack[M.name]; + } + } + rapidjson::StringBuffer Buffer; + rapidjson::Writer writer(Buffer); + Veh.Accept(writer); + c->SetCarData(VID, Header + Buffer.GetString()); } void VehicleParser(Client* c, const std::string& Pckt) { diff --git a/src/Network/VehicleData.cpp b/src/Network/VehicleData.cpp index 188a24a..edf16b0 100644 --- a/src/Network/VehicleData.cpp +++ b/src/Network/VehicleData.cpp @@ -19,8 +19,6 @@ #include #include -int FC(const std::string& s, const std::string& p, int n); - SOCKET UDPSock; void UDPSend(Client* c, std::string Data) { Assert(c);