Implement Assertion properly, TID printing in debug builds

This commit is contained in:
Lion Kortlepel
2020-11-03 10:13:52 +01:00
parent 69f20bdf41
commit 2ec65d5b84
12 changed files with 62 additions and 12 deletions

View File

@@ -90,6 +90,8 @@ std::string GenerateM(RSA*key){
}
void Identification(SOCKET TCPSock,Hold*S,RSA*Skey){
Assert(S);
Assert(Skey);
S->TCPSock = TCPSock;
std::thread Timeout(Check,S);
Timeout.detach();

View File

@@ -21,6 +21,7 @@ int FC(const std::string& s,const std::string& p,int n) {
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);
@@ -31,6 +32,7 @@ void Apply(Client*c,int VID,const std::string& pckt){
}
void VehicleParser(Client*c,const std::string& Pckt){
Assert(c);
if(c == nullptr || Pckt.length() < 4)return;
std::string Packet = Pckt;
char Code = Packet.at(1);
@@ -94,10 +96,12 @@ void VehicleParser(Client*c,const std::string& Pckt){
SendToAll(c,Packet,false,true);
return;
default:
AssertNotReachable();
return;
}
}
void SyncClient(Client*c){
Assert(c);
if(c->isSynced)return;
c->isSynced = true;
std::this_thread::sleep_for(std::chrono::seconds(1));
@@ -119,6 +123,7 @@ void SyncClient(Client*c){
info(c->GetName() + Sec(" is now synced!"));
}
void ParseVeh(Client*c, const std::string& Packet){
Assert(c);
#ifdef __WIN32
__try{
VehicleParser(c,Packet);
@@ -129,6 +134,7 @@ void ParseVeh(Client*c, const std::string& Packet){
}
void HandleEvent(Client*c ,const std::string&Data){
Assert(c);
std::stringstream ss(Data);
std::string t,Name;
int a = 0;
@@ -149,6 +155,7 @@ void HandleEvent(Client*c ,const std::string&Data){
}
void GlobalParser(Client*c, const std::string& Pack){
Assert(c);
[[maybe_unused]] static int lastRecv = 0;
if(Pack.empty() || c == nullptr)return;
std::string Packet = Pack.substr(0,Pack.find(char(0)));
@@ -196,6 +203,7 @@ void GlobalParser(Client*c, const std::string& Pack){
}
void GParser(Client*c, const std::string& Packet){
Assert(c);
#ifdef __WIN32
__try{
GlobalParser(c, Packet);

View File

@@ -3,6 +3,7 @@
///
#define CURL_STATICLIB
#include "Curl/curl.h"
#include "Assert.h"
#include <iostream>
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp){
((std::string*)userp)->append((char*)contents, size * nmemb);
@@ -13,6 +14,7 @@ std::string HttpRequest(const std::string& IP,int port){
CURLcode res;
std::string readBuffer;
curl = curl_easy_init();
Assert(curl);
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, IP.c_str());
curl_easy_setopt(curl, CURLOPT_PORT, port);
@@ -30,6 +32,7 @@ std::string PostHTTP(const std::string& IP,const std::string& Fields){
CURLcode res;
std::string readBuffer;
curl = curl_easy_init();
Assert(curl);
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, IP.c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, Fields.size());
@@ -42,4 +45,4 @@ std::string PostHTTP(const std::string& IP,const std::string& Fields){
if(res != CURLE_OK)return "-1";
}
return readBuffer;
}
}

View File

@@ -24,6 +24,7 @@ int OpenID(){
return ID;
}
void Respond(Client*c, const std::string& MSG, bool Rel){
Assert(c);
char C = MSG.at(0);
if(Rel || C == 'W' || C == 'Y' || C == 'V' || C == 'E'){
if(C == 'O' || C == 'T' || MSG.length() > 1000)SendLarge(c,MSG);
@@ -31,6 +32,7 @@ void Respond(Client*c, const std::string& MSG, bool Rel){
}else UDPSend(c,MSG);
}
void SendToAll(Client*c, const std::string& Data, bool Self, bool Rel){
Assert(c);
char C = Data.at(0);
for(Client*client : CI->Clients){
if(client != nullptr) {
@@ -55,6 +57,7 @@ void UpdatePlayers(){
SendToAll(nullptr, Packet,true,true);
}
void OnDisconnect(Client*c,bool kicked){
Assert(c);
info(c->GetName() + Sec(" Connection Terminated"));
if(c == nullptr)return;
std::string Packet;
@@ -73,6 +76,7 @@ void OnDisconnect(Client*c,bool kicked){
CI->RemoveClient(c); ///Removes the Client from existence
}
void OnConnect(Client*c){
Assert(c);
info(Sec("Client connected"));
c->SetID(OpenID());
info(Sec("Assigned ID ") + std::to_string(c->GetID()) + Sec(" to ") + c->GetName());
@@ -82,4 +86,4 @@ void OnConnect(Client*c){
Respond(c,"M"+MapName,true); //Send the Map on connect
info(c->GetName() + Sec(" : Connected"));
TriggerLuaEvent(Sec("onPlayerJoining"),false,nullptr,new LuaArg{{c->GetID()}},false);
}
}

View File

@@ -14,6 +14,7 @@
#endif // __linux
void STCPSend(Client* c, std::string Data) {
Assert(c);
if (c == nullptr)
return;
ssize_t BytesSent = send(c->GetTCPSock(), Data.c_str(), size_t(Data.size()), 0);
@@ -28,6 +29,7 @@ void STCPSend(Client* c, std::string Data) {
}
}
void SendFile(Client* c, const std::string& Name) {
Assert(c);
info(c->GetName() + Sec(" requesting : ") + Name.substr(Name.find_last_of('/')));
struct stat Info {};
if (stat(Name.c_str(), &Info) != 0) {
@@ -61,6 +63,7 @@ void SendFile(Client* c, const std::string& Name) {
}
void Parse(Client* c, const std::string& Packet) {
Assert(c);
if (c == nullptr || Packet.empty())
return;
char Code = Packet.at(0), SubCode = 0;
@@ -84,6 +87,7 @@ void Parse(Client* c, const std::string& Packet) {
}
}
bool STCPRecv(Client* c) {
Assert(c);
if (c == nullptr)
return false;
char buf[200];
@@ -109,6 +113,7 @@ bool STCPRecv(Client* c) {
}
void SyncResources(Client* c) {
Assert(c);
if (c == nullptr)
return;
try {

View File

@@ -8,6 +8,7 @@
#include <thread>
void TCPSend(Client*c,const std::string&Data){
Assert(c);
if(c == nullptr)return;
std::string Send = "\n" + Data.substr(0,Data.find(char(0))) + "\n";
ssize_t Sent = send(c->GetTCPSock(), Send.c_str(), size_t(Send.size()), 0);
@@ -19,6 +20,7 @@ void TCPSend(Client*c,const std::string&Data){
}
}
void TCPHandle(Client*c,const std::string& data){
Assert(c);
#ifdef __WIN32
__try{
#endif // __WIN32
@@ -30,6 +32,7 @@ void TCPHandle(Client*c,const std::string& data){
#endif // __WIN32
}
void TCPRcv(Client*c){
Assert(c);
if(c == nullptr || c->GetStatus() < 0)return;
char buf[4096];
size_t len = 4096;
@@ -53,6 +56,7 @@ void TCPRcv(Client*c){
TCPHandle(c,Buf);
}
void TCPClient(Client*c){
Assert(c);
if(c->GetTCPSock() == -1){
CI->RemoveClient(c);
return;