Modify LUA

This commit is contained in:
2022-09-27 14:28:39 +03:00
parent fb52f01295
commit 842d142a0e
3 changed files with 30 additions and 0 deletions

View File

@@ -36,4 +36,8 @@ namespace LuaAPI {
bool IsFile(const std::string& Path);
std::string ConcatPaths(sol::variadic_args Args);
}
namespace CL {
void SendPacket(int ID, const std::string& Packet);
void SendNotify(int ID, const std::string& Notify);
}
}

View File

@@ -352,3 +352,24 @@ std::string LuaAPI::FS::ConcatPaths(sol::variadic_args Args) {
auto Result = Path.lexically_normal().string();
return Result;
}
void LuaAPI::CL::SendPacket(int ID, const std::string& Packet) {
if (ID == -1) {
LuaAPI::MP::Engine->Network().SendToAll(nullptr, Packet, true, true);
} else {
auto MaybeClient = GetClient(LuaAPI::MP::Engine->Server(), ID);
if (MaybeClient && !MaybeClient.value().expired()) {
auto c = MaybeClient.value().lock();
if (!c->IsSynced())
return;
beammp_info("[LUA] Send packet to <" + c->GetName() + ">: " + Packet);
LuaAPI::MP::Engine->Network().Respond(*c, Packet, true);
} else {
beammp_lua_error("SendChatMessage invalid argument [1] invalid ID");
}
}
}
void LuaAPI::CL::SendNotify(int ID, const std::string& Notify) {
SendPacket(ID, "L:Server: " + Notify);
}

View File

@@ -568,6 +568,11 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, std::atomi
FSTable.set_function("IsDirectory", &LuaAPI::FS::IsDirectory);
FSTable.set_function("IsFile", &LuaAPI::FS::IsFile);
FSTable.set_function("ConcatPaths", &LuaAPI::FS::ConcatPaths);
auto CLTable = StateView.create_named_table("CL");
CLTable.set_function("SendPacket", &LuaAPI::CL::SendPacket);
CLTable.set_function("SendNotify", &LuaAPI::CL::SendNotify);
Start();
}