mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-23 00:17:00 +00:00
Minor fixes
This commit is contained in:
@@ -42,6 +42,9 @@ void VehicleParser(Client*c,const std::string& Pckt){
|
|||||||
std::string Data = Packet.substr(3),pid,vid;
|
std::string Data = Packet.substr(3),pid,vid;
|
||||||
switch(Code){ //Spawned Destroyed Switched/Moved NotFound Reset
|
switch(Code){ //Spawned Destroyed Switched/Moved NotFound Reset
|
||||||
case 's':
|
case 's':
|
||||||
|
#ifdef DEBUG
|
||||||
|
debug(std::string(Sec("got 'Os' packet: '")) + Packet + Sec("' (") + std::to_string(Packet.size()) + Sec(")"));
|
||||||
|
#endif
|
||||||
if(Data.at(0) == '0'){
|
if(Data.at(0) == '0'){
|
||||||
int CarID = c->GetOpenCarID();
|
int CarID = c->GetOpenCarID();
|
||||||
debug(c->GetName() + Sec(" created a car with ID ") + std::to_string(CarID));
|
debug(c->GetName() + Sec(" created a car with ID ") + std::to_string(CarID));
|
||||||
@@ -61,6 +64,9 @@ void VehicleParser(Client*c,const std::string& Pckt){
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case 'c':
|
case 'c':
|
||||||
|
#ifdef DEBUG
|
||||||
|
debug(std::string(Sec("got 'Oc' packet: '")) + Packet + Sec("' (") + std::to_string(Packet.size()) + Sec(")"));
|
||||||
|
#endif
|
||||||
pid = Data.substr(0,Data.find('-'));
|
pid = Data.substr(0,Data.find('-'));
|
||||||
vid = Data.substr(Data.find('-')+1,Data.find(':',1)-Data.find('-')-1);
|
vid = Data.substr(Data.find('-')+1,Data.find(':',1)-Data.find('-')-1);
|
||||||
if(pid.find_first_not_of("0123456789") == std::string::npos && vid.find_first_not_of("0123456789") == std::string::npos){
|
if(pid.find_first_not_of("0123456789") == std::string::npos && vid.find_first_not_of("0123456789") == std::string::npos){
|
||||||
@@ -81,6 +87,9 @@ void VehicleParser(Client*c,const std::string& Pckt){
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case 'd':
|
case 'd':
|
||||||
|
#ifdef DEBUG
|
||||||
|
debug(std::string(Sec("got 'Od' packet: '")) + Packet + Sec("' (") + std::to_string(Packet.size()) + Sec(")"));
|
||||||
|
#endif
|
||||||
pid = Data.substr(0,Data.find('-'));
|
pid = Data.substr(0,Data.find('-'));
|
||||||
vid = Data.substr(Data.find('-')+1);
|
vid = Data.substr(Data.find('-')+1);
|
||||||
if(pid.find_first_not_of("0123456789") == std::string::npos && vid.find_first_not_of("0123456789") == std::string::npos){
|
if(pid.find_first_not_of("0123456789") == std::string::npos && vid.find_first_not_of("0123456789") == std::string::npos){
|
||||||
@@ -96,11 +105,14 @@ void VehicleParser(Client*c,const std::string& Pckt){
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case 'r':
|
case 'r':
|
||||||
|
#ifdef DEBUG
|
||||||
|
debug(std::string(Sec("got 'Or' packet: '")) + Packet + Sec("' (") + std::to_string(Packet.size()) + Sec(")"));
|
||||||
|
#endif
|
||||||
SendToAll(c,Packet,false,true);
|
SendToAll(c,Packet,false,true);
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
warn(std::string(Sec("possibly not implemented: '") + Packet + Sec("'")));
|
warn(std::string(Sec("possibly not implemented: '") + Packet + Sec("' (") + std::to_string(Packet.size()) + Sec(")")));
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -161,9 +173,8 @@ void HandleEvent(Client*c ,const std::string&Data){
|
|||||||
|
|
||||||
void GlobalParser(Client*c, const std::string& Pack){
|
void GlobalParser(Client*c, const std::string& Pack){
|
||||||
Assert(c);
|
Assert(c);
|
||||||
[[maybe_unused]] static int lastRecv = 0;
|
|
||||||
if(Pack.empty() || c == nullptr)return;
|
if(Pack.empty() || c == nullptr)return;
|
||||||
std::string Packet = Pack.substr(0,Pack.find(char(0)));
|
std::string Packet = Pack.substr(0,strlen(Pack.c_str()));
|
||||||
std::string pct;
|
std::string pct;
|
||||||
char Code = Packet.at(0);
|
char Code = Packet.at(0);
|
||||||
|
|
||||||
@@ -176,6 +187,9 @@ void GlobalParser(Client*c, const std::string& Pack){
|
|||||||
|
|
||||||
switch (Code) {
|
switch (Code) {
|
||||||
case 'P': // initial connection
|
case 'P': // initial connection
|
||||||
|
#ifdef DEBUG
|
||||||
|
debug(std::string(Sec("got 'P' packet: '")) + Pack + Sec("' (") + std::to_string(Packet.size()) + Sec(")"));
|
||||||
|
#endif
|
||||||
Respond(c, Sec("P") + std::to_string(c->GetID()),true);
|
Respond(c, Sec("P") + std::to_string(c->GetID()),true);
|
||||||
SyncClient(c);
|
SyncClient(c);
|
||||||
return;
|
return;
|
||||||
@@ -190,9 +204,15 @@ void GlobalParser(Client*c, const std::string& Pack){
|
|||||||
ParseVeh(c,Packet);
|
ParseVeh(c,Packet);
|
||||||
return;
|
return;
|
||||||
case 'J':
|
case 'J':
|
||||||
|
#ifdef DEBUG
|
||||||
|
debug(std::string(Sec("got 'J' packet: '")) + Pack + Sec("' (") + std::to_string(Packet.size()) + Sec(")"));
|
||||||
|
#endif
|
||||||
SendToAll(c,Packet,false,true);
|
SendToAll(c,Packet,false,true);
|
||||||
return;
|
return;
|
||||||
case 'C':
|
case 'C':
|
||||||
|
#ifdef DEBUG
|
||||||
|
debug(std::string(Sec("got 'C' packet: '")) + Pack + Sec("' (") + std::to_string(Packet.size()) + Sec(")"));
|
||||||
|
#endif
|
||||||
if(Packet.length() < 4 || Packet.find(':', 3) == std::string::npos)break;
|
if(Packet.length() < 4 || Packet.find(':', 3) == std::string::npos)break;
|
||||||
if (TriggerLuaEvent(Sec("onChatMessage"), false, nullptr,
|
if (TriggerLuaEvent(Sec("onChatMessage"), false, nullptr,
|
||||||
std::unique_ptr<LuaArg>(new LuaArg{
|
std::unique_ptr<LuaArg>(new LuaArg{
|
||||||
@@ -201,6 +221,9 @@ void GlobalParser(Client*c, const std::string& Pack){
|
|||||||
SendToAll(nullptr, Packet, true, true);
|
SendToAll(nullptr, Packet, true, true);
|
||||||
return;
|
return;
|
||||||
case 'E':
|
case 'E':
|
||||||
|
#ifdef DEBUG
|
||||||
|
debug(std::string(Sec("got 'E' packet: '")) + Pack + Sec("' (") + std::to_string(Packet.size()) + Sec(")"));
|
||||||
|
#endif
|
||||||
HandleEvent(c,Packet);
|
HandleEvent(c,Packet);
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -54,24 +54,43 @@ bool CheckBytes(Client*c,int32_t BytesRcv){
|
|||||||
|
|
||||||
void TCPRcv(Client*c){
|
void TCPRcv(Client*c){
|
||||||
Assert(c);
|
Assert(c);
|
||||||
static int32_t Header,BytesRcv,Temp;
|
static thread_local int32_t Header,BytesRcv,Temp;
|
||||||
if(c == nullptr || c->GetStatus() < 0)return;
|
if(c == nullptr || c->GetStatus() < 0)return;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
BytesRcv = recv(c->GetTCPSock(), reinterpret_cast<char*>(&Header), sizeof(Header),0);
|
BytesRcv = recv(c->GetTCPSock(), reinterpret_cast<char*>(&Header), sizeof(Header),0);
|
||||||
#else
|
#else
|
||||||
BytesRcv = recv(c->GetTCPSock(), reinterpret_cast<void*>(&Header), sizeof(Header), 0);
|
BytesRcv = recv(c->GetTCPSock(), reinterpret_cast<void*>(&Header), sizeof(Header), 0);
|
||||||
#endif
|
#endif
|
||||||
if(!CheckBytes(c,BytesRcv))return;
|
#ifdef DEBUG
|
||||||
|
//debug(std::string(__func__) + Sec(": expecting ") + std::to_string(Header) + Sec(" bytes."));
|
||||||
|
#endif // DEBUG
|
||||||
|
if(!CheckBytes(c,BytesRcv)) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
error(std::string(__func__) + Sec(": failed on CheckBytes"));
|
||||||
|
#endif // DEBUG
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// TODO: std::vector
|
||||||
char* Data = new char[Header];
|
char* Data = new char[Header];
|
||||||
|
Assert(Data);
|
||||||
BytesRcv = 0;
|
BytesRcv = 0;
|
||||||
do{
|
do{
|
||||||
Temp = recv(c->GetTCPSock(), Data+BytesRcv, Header-BytesRcv,0);
|
Temp = recv(c->GetTCPSock(), Data+BytesRcv, Header-BytesRcv,0);
|
||||||
if(!CheckBytes(c,Temp)){
|
if(!CheckBytes(c,Temp)){
|
||||||
|
#ifdef DEBUG
|
||||||
|
error(std::string(__func__) + Sec(": failed on CheckBytes in while(BytesRcv < Header)"));
|
||||||
|
#endif // DEBUG
|
||||||
delete[] Data;
|
delete[] Data;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
//debug(std::string(__func__) + Sec(": Temp: ") + std::to_string(Temp) + Sec(", BytesRcv: ") + std::to_string(BytesRcv));
|
||||||
|
#endif // DEBUG
|
||||||
BytesRcv += Temp;
|
BytesRcv += Temp;
|
||||||
}while(BytesRcv < Header);
|
}while(BytesRcv < Header);
|
||||||
|
#ifdef DEBUG
|
||||||
|
//debug(std::string(__func__) + Sec(": finished recv with Temp: ") + std::to_string(Temp) + Sec(", BytesRcv: ") + std::to_string(BytesRcv));
|
||||||
|
#endif // DEBUG
|
||||||
std::string Ret = std::string(Data,Header);
|
std::string Ret = std::string(Data,Header);
|
||||||
delete[] Data;
|
delete[] Data;
|
||||||
if (Ret.substr(0, 4) == "ABG:") {
|
if (Ret.substr(0, 4) == "ABG:") {
|
||||||
|
|||||||
@@ -45,7 +45,13 @@ std::string getDate() {
|
|||||||
<< Hour << ":"
|
<< Hour << ":"
|
||||||
<< Min << ":"
|
<< Min << ":"
|
||||||
<< Secs
|
<< Secs
|
||||||
<< "] ";
|
<< "] "
|
||||||
|
#ifdef DEBUG
|
||||||
|
<< std::this_thread::get_id()
|
||||||
|
<< " ";
|
||||||
|
#else
|
||||||
|
;
|
||||||
|
#endif
|
||||||
return date.str();
|
return date.str();
|
||||||
}
|
}
|
||||||
void InitLog() {
|
void InitLog() {
|
||||||
|
|||||||
Reference in New Issue
Block a user