mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-06-17 22:23:03 +00:00
Crash Handeling
This commit is contained in:
@@ -50,10 +50,10 @@ void FolderList(const std::string& Path,bool HotSwap){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(Script->GetLastWrite() != fs::last_write_time(Script->GetFileName())){
|
if(Script->GetLastWrite() != fs::last_write_time(Script->GetFileName())){
|
||||||
Script->SetLastWrite(fs::last_write_time(Script->GetFileName()));
|
|
||||||
Script->Reload();
|
|
||||||
info("[HOTSWAP] Updated : "+
|
info("[HOTSWAP] Updated : "+
|
||||||
Script->GetFileName().substr(Script->GetFileName().find('\\')));
|
Script->GetFileName().substr(Script->GetFileName().find('\\')));
|
||||||
|
Script->SetLastWrite(fs::last_write_time(Script->GetFileName()));
|
||||||
|
Script->Reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FolderList(path,true);
|
FolderList(path,true);
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ LuaArg* CreateArg(lua_State *L,int T){
|
|||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int TriggerLuaEvent(const std::string& Event,bool local,Lua*Caller,LuaArg* arg){
|
int TriggerLuaEvent(const std::string& Event,bool local,Lua*Caller,LuaArg* arg){
|
||||||
int R = 0;
|
int R = 0;
|
||||||
for(Lua*Script : PluginEngine){
|
for(Lua*Script : PluginEngine){
|
||||||
@@ -102,15 +103,7 @@ void CallAsync(Lua* lua,const std::string& FuncName,LuaArg* args){
|
|||||||
}
|
}
|
||||||
lua->HasThread = true;
|
lua->HasThread = true;
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||||
lua_getglobal(lua->GetState(), FuncName.c_str());
|
lua->CallFunction(FuncName,args);
|
||||||
if(lua_isfunction(lua->GetState(), -1)) {
|
|
||||||
int Size = 0;
|
|
||||||
if(args != nullptr){
|
|
||||||
Size = args->args.size();
|
|
||||||
args->PushArgs(lua->GetState());
|
|
||||||
}
|
|
||||||
CheckLua(lua->GetState(), lua_pcall(lua->GetState(), Size, 0, 0));
|
|
||||||
}
|
|
||||||
lua->HasThread = false;
|
lua->HasThread = false;
|
||||||
}
|
}
|
||||||
int lua_CreateThread(lua_State *L){
|
int lua_CreateThread(lua_State *L){
|
||||||
@@ -120,8 +113,6 @@ int lua_CreateThread(lua_State *L){
|
|||||||
std::string STR = lua_tostring(L,1);
|
std::string STR = lua_tostring(L,1);
|
||||||
std::thread t1(CallAsync,GetScript(L),STR,CreateArg(L,Args));
|
std::thread t1(CallAsync,GetScript(L),STR,CreateArg(L,Args));
|
||||||
t1.detach();
|
t1.detach();
|
||||||
//auto s = std::async();
|
|
||||||
///TODO FIGURE OUT THREAD
|
|
||||||
}else SendError(L,"CreateThread wrong argument [1] need string");
|
}else SendError(L,"CreateThread wrong argument [1] need string");
|
||||||
}else SendError(L,"CreateThread not enough arguments");
|
}else SendError(L,"CreateThread not enough arguments");
|
||||||
return 0;
|
return 0;
|
||||||
@@ -305,7 +296,14 @@ void Lua::Reload(){
|
|||||||
CallFunction("onInit",{});
|
CallFunction("onInit",{});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int Handle(EXCEPTION_POINTERS *ep,char* Origin);
|
||||||
|
char* Lua::GetOrigin(){
|
||||||
|
std::string T = GetFileName().substr(GetFileName().find('\\'));
|
||||||
|
char* Data = new char[T.size()];
|
||||||
|
ZeroMemory(Data,T.size());
|
||||||
|
memcpy_s(Data,T.size(),T.c_str(),T.size());
|
||||||
|
return Data;
|
||||||
|
}
|
||||||
int Lua::CallFunction(const std::string& FuncName,LuaArg* Arg){
|
int Lua::CallFunction(const std::string& FuncName,LuaArg* Arg){
|
||||||
lua_getglobal(luaState, FuncName.c_str());
|
lua_getglobal(luaState, FuncName.c_str());
|
||||||
if(lua_isfunction(luaState, -1)) {
|
if(lua_isfunction(luaState, -1)) {
|
||||||
@@ -314,7 +312,13 @@ int Lua::CallFunction(const std::string& FuncName,LuaArg* Arg){
|
|||||||
Size = Arg->args.size();
|
Size = Arg->args.size();
|
||||||
Arg->PushArgs(luaState);
|
Arg->PushArgs(luaState);
|
||||||
}
|
}
|
||||||
if (CheckLua(luaState, lua_pcall(luaState, Size, 1, 0))) {
|
int R = 0;
|
||||||
|
char* Origin = GetOrigin();
|
||||||
|
__try{
|
||||||
|
R = lua_pcall(luaState, Size, 1, 0);
|
||||||
|
}__except(Handle(GetExceptionInformation(),Origin)){}
|
||||||
|
delete [] Origin;
|
||||||
|
if (CheckLua(luaState, R)){
|
||||||
if (lua_isnumber(luaState, -1)) {
|
if (lua_isnumber(luaState, -1)) {
|
||||||
return lua_tointeger(luaState, -1);
|
return lua_tointeger(luaState, -1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ public:
|
|||||||
std::string GetFileName();
|
std::string GetFileName();
|
||||||
bool HasThread = false;
|
bool HasThread = false;
|
||||||
lua_State* GetState();
|
lua_State* GetState();
|
||||||
|
char* GetOrigin();
|
||||||
void Reload();
|
void Reload();
|
||||||
void Init();
|
void Init();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ void SendLarge(Client*c,const std::string&Data);
|
|||||||
void Respond(Client*c, const std::string& MSG, bool Rel){
|
void Respond(Client*c, const std::string& MSG, bool Rel){
|
||||||
char C = MSG.at(0);
|
char C = MSG.at(0);
|
||||||
if(Rel){
|
if(Rel){
|
||||||
if(C == 'O' || C == 'T' || MSG.length() > 1000)SendLarge(c,MSG);
|
if(C == 'C' || C == 'O' || C == 'T' || MSG.length() > 1000)SendLarge(c,MSG);
|
||||||
else TCPSend(c,MSG);
|
else TCPSend(c,MSG);
|
||||||
}else UDPSend(c,MSG);
|
}else UDPSend(c,MSG);
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ void SendToAll(Client*c, const std::string& Data, bool Self, bool Rel){
|
|||||||
if(Self || client != c){
|
if(Self || client != c){
|
||||||
if(!client->isDownloading){
|
if(!client->isDownloading){
|
||||||
if(Rel){
|
if(Rel){
|
||||||
if(C == 'O' || C == 'T' || Data.length() > 1000)SendLarge(client,Data);
|
if(C == 'C' || C == 'O' || C == 'T' || Data.length() > 1000)SendLarge(client,Data);
|
||||||
else TCPSend(client,Data);
|
else TCPSend(client,Data);
|
||||||
}
|
}
|
||||||
else UDPSend(client,Data);
|
else UDPSend(client,Data);
|
||||||
|
|||||||
@@ -19,8 +19,24 @@ int FC(const std::string& s,const std::string& p,int n) {
|
|||||||
if (j == n)return(i);
|
if (j == n)return(i);
|
||||||
else return(-1);
|
else return(-1);
|
||||||
}
|
}
|
||||||
|
int Handle(EXCEPTION_POINTERS *ep,char* Origin);
|
||||||
|
|
||||||
void VehicleParser(Client*c, std::string Packet){
|
void Apply(Client*c,int VID,const std::string& pckt){
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
void UpdateCarData(Client*c,int VID,const std::string& Packet){
|
||||||
|
__try{
|
||||||
|
Apply(c,VID,Packet);
|
||||||
|
}__except(Handle(GetExceptionInformation(),(char*)"Car Data Updater")){}
|
||||||
|
}
|
||||||
|
void VehicleParser(Client*c,const std::string& Pckt){
|
||||||
|
std::string Packet = Pckt;
|
||||||
char Code = Packet.at(1);
|
char Code = Packet.at(1);
|
||||||
int PID = -1;
|
int PID = -1;
|
||||||
int VID = -1;
|
int VID = -1;
|
||||||
@@ -54,17 +70,13 @@ void VehicleParser(Client*c, std::string Packet){
|
|||||||
if(!TriggerLuaEvent("onVehicleEdited",false,nullptr,
|
if(!TriggerLuaEvent("onVehicleEdited",false,nullptr,
|
||||||
new LuaArg{{c->GetID(),VID,Packet.substr(3)}})) {
|
new LuaArg{{c->GetID(),VID,Packet.substr(3)}})) {
|
||||||
SendToAll(c, Packet, false, true);
|
SendToAll(c, Packet, false, true);
|
||||||
std::string VD = c->GetCarData(VID);
|
UpdateCarData(c,VID,Packet);
|
||||||
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);
|
|
||||||
}else{
|
}else{
|
||||||
std::string Destroy = "Od:" + std::to_string(c->GetID())+"-"+std::to_string(VID);
|
std::string Destroy = "Od:" + std::to_string(c->GetID())+"-"+std::to_string(VID);
|
||||||
Respond(c,Destroy,true);
|
Respond(c,Destroy,true);
|
||||||
c->DeleteCar(VID);
|
c->DeleteCar(VID);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
@@ -105,8 +117,14 @@ void SyncVehicles(Client*c){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern int PPS;
|
extern int PPS;
|
||||||
|
|
||||||
|
void ParseVeh(Client*c, const std::string&Packet){
|
||||||
|
__try{
|
||||||
|
VehicleParser(c,Packet);
|
||||||
|
}__except(Handle(GetExceptionInformation(),(char*)"Vehicle Handler")){}
|
||||||
|
}
|
||||||
|
|
||||||
void GlobalParser(Client*c, const std::string&Packet){
|
void GlobalParser(Client*c, const std::string&Packet){
|
||||||
if(Packet.empty())return;
|
if(Packet.empty())return;
|
||||||
if(Packet.find("TEST")!=std::string::npos)SyncVehicles(c);
|
if(Packet.find("TEST")!=std::string::npos)SyncVehicles(c);
|
||||||
@@ -124,15 +142,15 @@ void GlobalParser(Client*c, const std::string&Packet){
|
|||||||
if(Packet.length() > 1000) {
|
if(Packet.length() > 1000) {
|
||||||
std::cout << "Received data from: " << c->GetName() << " Size: " << Packet.length() << std::endl;
|
std::cout << "Received data from: " << c->GetName() << " Size: " << Packet.length() << std::endl;
|
||||||
}
|
}
|
||||||
VehicleParser(c,Packet);
|
ParseVeh(c,Packet);
|
||||||
return;
|
return;
|
||||||
case 'J':
|
case 'J':
|
||||||
SendToAll(c,Packet,false,true);
|
SendToAll(c,Packet,false,true);
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
if(TriggerLuaEvent("onChatMessage",false,nullptr,
|
|
||||||
new LuaArg{{c->GetID(),c->GetName(),Packet.substr(Packet.find(':',3)+1)}}))break;
|
|
||||||
pct = "C:" + c->GetName() + Packet.substr(Packet.find(':', 3));
|
pct = "C:" + c->GetName() + Packet.substr(Packet.find(':', 3));
|
||||||
|
if (TriggerLuaEvent("onChatMessage", false, nullptr,
|
||||||
|
new LuaArg{{ c->GetID(), c->GetName(), pct.substr(pct.find(':', 3) + 1) }}))break;
|
||||||
SendToAll(nullptr, pct, true, true);
|
SendToAll(nullptr, pct, true, true);
|
||||||
pct.clear();
|
pct.clear();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
#include "Client.hpp"
|
#include "Client.hpp"
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
void TCPServerMain();
|
void TCPServerMain();
|
||||||
void UDPServerMain();
|
void UDPServerMain();
|
||||||
void SLoop();
|
|
||||||
std::set<Client*> Clients;
|
std::set<Client*> Clients;
|
||||||
void NetMain() {
|
void NetMain() {
|
||||||
std::thread TCP(TCPServerMain);
|
std::thread TCP(TCPServerMain);
|
||||||
TCP.detach();
|
TCP.detach();
|
||||||
std::thread Sec(SLoop);
|
|
||||||
Sec.detach();
|
|
||||||
UDPServerMain();
|
UDPServerMain();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,14 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include "Client.hpp"
|
#include "Client.hpp"
|
||||||
|
#include "../logger.h"
|
||||||
#include "../Settings.hpp"
|
#include "../Settings.hpp"
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
void VehicleParser(Client*c, std::string Packet);
|
void VehicleParser(Client*c,const std::string& Pckt);
|
||||||
|
int Handle(EXCEPTION_POINTERS *ep,char* Origin){
|
||||||
|
Exception(ep->ExceptionRecord->ExceptionCode,Origin);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
int Rand(){
|
int Rand(){
|
||||||
std::random_device r;
|
std::random_device r;
|
||||||
std::default_random_engine e1(r());
|
std::default_random_engine e1(r());
|
||||||
@@ -43,9 +48,9 @@ std::string Decrypt(std::string msg){
|
|||||||
[[noreturn]]void SLoop(){
|
[[noreturn]]void SLoop(){
|
||||||
std::thread D(DLoop);
|
std::thread D(DLoop);
|
||||||
D.detach();
|
D.detach();
|
||||||
int A = 0;
|
int A = -1;
|
||||||
while(true) {
|
while(true) {
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(15));
|
std::this_thread::sleep_for(std::chrono::seconds(20));
|
||||||
if (A == Beat)VehicleParser(nullptr, "");
|
if (A == Beat)VehicleParser(nullptr, "");
|
||||||
A = Beat;
|
A = Beat;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,7 +152,6 @@ SplitData*GetSplit(int SplitID){
|
|||||||
SplitPackets.insert(SP);
|
SplitPackets.insert(SP);
|
||||||
return SP;
|
return SP;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalParser(Client*c, const std::string&Packet);
|
void GlobalParser(Client*c, const std::string&Packet);
|
||||||
void HandleChunk(Client*c,const std::string&Data){
|
void HandleChunk(Client*c,const std::string&Data){
|
||||||
int pos1 = int(Data.find(':'))+1,pos2 = Data.find(':',pos1),pos3 = Data.find('/');
|
int pos1 = int(Data.find(':'))+1,pos2 = Data.find(':',pos1),pos3 = Data.find('/');
|
||||||
@@ -178,7 +177,6 @@ void HandleChunk(Client*c,const std::string&Data){
|
|||||||
SplitPackets.erase(SData);
|
SplitPackets.erase(SData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDPParser(Client*c, const std::string&Packet){
|
void UDPParser(Client*c, const std::string&Packet){
|
||||||
if(Packet.substr(0,4) == "ACK:"){
|
if(Packet.substr(0,4) == "ACK:"){
|
||||||
AckID(stoi(Packet.substr(4)));
|
AckID(stoi(Packet.substr(4)));
|
||||||
@@ -194,19 +192,18 @@ void UDPParser(Client*c, const std::string&Packet){
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}else if(Packet.substr(0,2) == "SC"){
|
}else if(Packet.substr(0,2) == "SC"){
|
||||||
|
|
||||||
HandleChunk(c,Packet);
|
HandleChunk(c,Packet);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GlobalParser(c,Packet);
|
GlobalParser(c,Packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StartLoop();
|
void StartLoop();
|
||||||
[[noreturn]] void UDPServerMain(){
|
|
||||||
|
|
||||||
|
[[noreturn]] void UDPServerMain(){
|
||||||
WSADATA data;
|
WSADATA data;
|
||||||
if (WSAStartup(514, &data)) //2.2
|
if (WSAStartup(514, &data)) //2.2
|
||||||
{
|
{
|
||||||
|
|
||||||
std::cout << "Can't start Winsock!" << std::endl;
|
std::cout << "Can't start Winsock!" << std::endl;
|
||||||
//return;
|
//return;
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-3
@@ -6,6 +6,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
void addToLog(const std::string& Data);
|
void addToLog(const std::string& Data);
|
||||||
int loggerlevel;
|
int loggerlevel;
|
||||||
|
|
||||||
@@ -75,7 +76,6 @@ void error(const std::string& toPrint) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void warn(const std::string& toPrint) {
|
void warn(const std::string& toPrint) {
|
||||||
if (loggerlevel <= 3) {
|
if (loggerlevel <= 3) {
|
||||||
std::string Print = getDate().str() + "[WARN] " + toPrint + "\n";
|
std::string Print = getDate().str() + "[WARN] " + toPrint + "\n";
|
||||||
@@ -83,8 +83,6 @@ void warn(const std::string& toPrint) {
|
|||||||
addToLog(Print);
|
addToLog(Print);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void debug(const std::string& toPrint) {
|
void debug(const std::string& toPrint) {
|
||||||
if (loggerlevel <= 1) {
|
if (loggerlevel <= 1) {
|
||||||
std::string Print = getDate().str() + "[DEBUG] " + toPrint + "\n";
|
std::string Print = getDate().str() + "[DEBUG] " + toPrint + "\n";
|
||||||
@@ -92,3 +90,12 @@ void debug(const std::string& toPrint) {
|
|||||||
addToLog(Print);
|
addToLog(Print);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void Exception(unsigned long Code,char* Origin) {
|
||||||
|
char* hex_string = new char[100];
|
||||||
|
sprintf(hex_string, "%lX", Code); //convert number to hex
|
||||||
|
if (loggerlevel <= 4) {
|
||||||
|
std::string Print = getDate().str() + "[EXCEP] code " + hex_string + " Origin: "+ std::string(Origin) +"\n";
|
||||||
|
std::cout << Print;
|
||||||
|
addToLog(Print);
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-2
@@ -2,10 +2,10 @@
|
|||||||
/// Created by Anonymous275 on 4/2/2020.
|
/// Created by Anonymous275 on 4/2/2020.
|
||||||
///
|
///
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string.h>
|
#include <iostream>
|
||||||
|
|
||||||
extern int loggerlevel;
|
extern int loggerlevel;
|
||||||
std::stringstream getDate();
|
std::stringstream getDate();
|
||||||
void setLoggerLevel(int level);
|
void setLoggerLevel(int level);
|
||||||
@@ -13,3 +13,4 @@ void info(const std::string& toPrint);
|
|||||||
void warn(const std::string& toPrint);
|
void warn(const std::string& toPrint);
|
||||||
void error(const std::string& toPrint);
|
void error(const std::string& toPrint);
|
||||||
void debug(const std::string& toPrint);
|
void debug(const std::string& toPrint);
|
||||||
|
void Exception(unsigned long Code,char* Origin);
|
||||||
+1
-2
@@ -1,7 +1,6 @@
|
|||||||
///
|
///
|
||||||
/// Created by Anonymous275 on 28/01/2020
|
/// Created by Anonymous275 on 28/01/2020
|
||||||
///
|
///
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@@ -15,7 +14,7 @@ void ParseConfig();
|
|||||||
void addToLog(const std::string& Data);
|
void addToLog(const std::string& Data);
|
||||||
//void ServerMain(int Port, int MaxClients);
|
//void ServerMain(int Port, int MaxClients);
|
||||||
void HeartbeatInit();
|
void HeartbeatInit();
|
||||||
std::string ServerVersion = "0.50";
|
std::string ServerVersion = "0.51";
|
||||||
std::string ClientVersion = "1.50";
|
std::string ClientVersion = "1.50";
|
||||||
std::string CustomIP;
|
std::string CustomIP;
|
||||||
void HandleResources(std::string path);
|
void HandleResources(std::string path);
|
||||||
|
|||||||
Reference in New Issue
Block a user