mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-24 00:46:59 +00:00
Fix issue with not cancelling events on linux (fix #29)
This commit is contained in:
@@ -74,15 +74,13 @@ std::any FutureWait(TLuaFile* lua, const std::string& R, std::shared_ptr<TLuaArg
|
|||||||
|
|
||||||
std::any TriggerLuaEvent(const std::string& Event, bool local, TLuaFile* Caller, std::shared_ptr<TLuaArg> arg, bool Wait) {
|
std::any TriggerLuaEvent(const std::string& Event, bool local, TLuaFile* Caller, std::shared_ptr<TLuaArg> arg, bool Wait) {
|
||||||
std::any R;
|
std::any R;
|
||||||
std::string Type;
|
|
||||||
int Ret = 0;
|
int Ret = 0;
|
||||||
for (auto& Script : Engine().LuaFiles()) {
|
for (auto& Script : Engine().LuaFiles()) {
|
||||||
if (Script->IsRegistered(Event)) {
|
if (Script->IsRegistered(Event)) {
|
||||||
if (local) {
|
if (local) {
|
||||||
if (Script->GetPluginName() == Caller->GetPluginName()) {
|
if (Script->GetPluginName() == Caller->GetPluginName()) {
|
||||||
R = FutureWait(Script.get(), Script->GetRegistered(Event), arg, Wait);
|
R = FutureWait(Script.get(), Script->GetRegistered(Event), arg, Wait);
|
||||||
Type = R.type().name();
|
if (R.type() == typeid(int)) {
|
||||||
if (Type.find("int") != std::string::npos) {
|
|
||||||
if (std::any_cast<int>(R))
|
if (std::any_cast<int>(R))
|
||||||
Ret++;
|
Ret++;
|
||||||
} else if (Event == "onPlayerAuth")
|
} else if (Event == "onPlayerAuth")
|
||||||
@@ -90,8 +88,7 @@ std::any TriggerLuaEvent(const std::string& Event, bool local, TLuaFile* Caller,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
R = FutureWait(Script.get(), Script->GetRegistered(Event), arg, Wait);
|
R = FutureWait(Script.get(), Script->GetRegistered(Event), arg, Wait);
|
||||||
Type = R.type().name();
|
if (R.type() == typeid(int)) {
|
||||||
if (Type.find("int") != std::string::npos) {
|
|
||||||
if (std::any_cast<int>(R))
|
if (std::any_cast<int>(R))
|
||||||
Ret++;
|
Ret++;
|
||||||
} else if (Event == "onPlayerAuth")
|
} else if (Event == "onPlayerAuth")
|
||||||
|
|||||||
@@ -327,11 +327,10 @@ void TNetwork::Authentication(SOCKET TCPSock) {
|
|||||||
|
|
||||||
auto arg = std::make_unique<TLuaArg>(TLuaArg { { Client->GetName(), Client->GetRoles(), Client->IsGuest() } });
|
auto arg = std::make_unique<TLuaArg>(TLuaArg { { Client->GetName(), Client->GetRoles(), Client->IsGuest() } });
|
||||||
std::any Res = TriggerLuaEvent("onPlayerAuth", false, nullptr, std::move(arg), true);
|
std::any Res = TriggerLuaEvent("onPlayerAuth", false, nullptr, std::move(arg), true);
|
||||||
std::string Type = Res.type().name();
|
if (Res.type() == typeid(int) && std::any_cast<int>(Res)) {
|
||||||
if (Type.find("int") != std::string::npos && std::any_cast<int>(Res)) {
|
|
||||||
ClientKick(*Client, "you are not allowed on the server!");
|
ClientKick(*Client, "you are not allowed on the server!");
|
||||||
return;
|
return;
|
||||||
} else if (Type.find("string") != std::string::npos) {
|
} else if (Res.type() == typeid(std::string)) {
|
||||||
ClientKick(*Client, std::any_cast<std::string>(Res));
|
ClientKick(*Client, std::any_cast<std::string>(Res));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -164,10 +164,10 @@ void TServer::HandleEvent(TClient& c, const std::string& Data) {
|
|||||||
a++;
|
a++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool TServer::IsUnicycle(TClient &c, const std::string &CarJson) {
|
bool TServer::IsUnicycle(TClient& c, const std::string& CarJson) {
|
||||||
rapidjson::Document Car;
|
rapidjson::Document Car;
|
||||||
Car.Parse(CarJson.c_str(), CarJson.size());
|
Car.Parse(CarJson.c_str(), CarJson.size());
|
||||||
if(Car.HasParseError()){
|
if (Car.HasParseError()) {
|
||||||
error("Failed to parse vehicle data -> " + CarJson);
|
error("Failed to parse vehicle data -> " + CarJson);
|
||||||
} else if (Car["jbm"].IsString() && std::string(Car["jbm"].GetString()) == "unicycle") {
|
} else if (Car["jbm"].IsString() && std::string(Car["jbm"].GetString()) == "unicycle") {
|
||||||
return true;
|
return true;
|
||||||
@@ -176,11 +176,11 @@ bool TServer::IsUnicycle(TClient &c, const std::string &CarJson) {
|
|||||||
}
|
}
|
||||||
bool TServer::ShouldSpawn(TClient& c, const std::string& CarJson, int ID) {
|
bool TServer::ShouldSpawn(TClient& c, const std::string& CarJson, int ID) {
|
||||||
|
|
||||||
if(c.GetUnicycleID() > -1 && (c.GetCarCount() - 1) < Application::Settings.MaxCars){
|
if (c.GetUnicycleID() > -1 && (c.GetCarCount() - 1) < Application::Settings.MaxCars) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(IsUnicycle(c,CarJson)){
|
if (IsUnicycle(c, CarJson)) {
|
||||||
c.SetUnicycleID(ID);
|
c.SetUnicycleID(ID);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -239,12 +239,12 @@ void TServer::ParseVehicle(TClient& c, const std::string& Pckt, TNetwork& Networ
|
|||||||
std::make_unique<TLuaArg>(TLuaArg { { c.GetID(), VID, Packet.substr(3) } }),
|
std::make_unique<TLuaArg>(TLuaArg { { c.GetID(), VID, Packet.substr(3) } }),
|
||||||
true);
|
true);
|
||||||
|
|
||||||
if ((c.GetUnicycleID() != VID || IsUnicycle(c,Packet.substr(Packet.find('{'))))
|
if ((c.GetUnicycleID() != VID || IsUnicycle(c, Packet.substr(Packet.find('{'))))
|
||||||
&& std::any_cast<int>(Res) == 0) {
|
&& std::any_cast<int>(Res) == 0) {
|
||||||
Network.SendToAll(&c, Packet, false, true);
|
Network.SendToAll(&c, Packet, false, true);
|
||||||
Apply(c, VID, Packet);
|
Apply(c, VID, Packet);
|
||||||
} else {
|
} else {
|
||||||
if(c.GetUnicycleID() == VID){
|
if (c.GetUnicycleID() == VID) {
|
||||||
c.SetUnicycleID(-1);
|
c.SetUnicycleID(-1);
|
||||||
}
|
}
|
||||||
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);
|
||||||
@@ -266,7 +266,7 @@ void TServer::ParseVehicle(TClient& c, const std::string& Pckt, TNetwork& Networ
|
|||||||
VID = stoi(vid);
|
VID = stoi(vid);
|
||||||
}
|
}
|
||||||
if (PID != -1 && VID != -1 && PID == c.GetID()) {
|
if (PID != -1 && VID != -1 && PID == c.GetID()) {
|
||||||
if(c.GetUnicycleID() == VID){
|
if (c.GetUnicycleID() == VID) {
|
||||||
c.SetUnicycleID(-1);
|
c.SetUnicycleID(-1);
|
||||||
}
|
}
|
||||||
Network.SendToAll(nullptr, Packet, true, true);
|
Network.SendToAll(nullptr, Packet, true, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user