diff --git a/include/Common.h b/include/Common.h index d36cf6f..a7e8711 100644 --- a/include/Common.h +++ b/include/Common.h @@ -142,3 +142,5 @@ std::string Comp(std::string Data); std::string DeComp(std::string Compressed); std::string GetPlatformAgnosticErrorString(); + +void LogChatMessage(const std::string& name, int id, const std::string& msg); diff --git a/src/Common.cpp b/src/Common.cpp index 0c535f7..770da76 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -128,3 +128,15 @@ std::string GetPlatformAgnosticErrorString() { return std::strerror(errno); #endif } + +void LogChatMessage(const std::string& name, int id, const std::string& msg) { + std::stringstream ss; + ss << "[CHAT] "; + if (id != -1) { + ss << "(" << id << ") <" << name << ">"; + } else { + ss << name << ""; + } + ss << msg; + Application::Console().Write(ss.str()); +} diff --git a/src/LuaAPI.cpp b/src/LuaAPI.cpp index 89d54db..9c71773 100644 --- a/src/LuaAPI.cpp +++ b/src/LuaAPI.cpp @@ -1,5 +1,6 @@ #include "LuaAPI.h" #include "Client.h" +#include "Common.h" #include "TLuaEngine.h" static std::string LuaToString(const sol::object Value, size_t Indent = 1) { @@ -122,7 +123,7 @@ void LuaAPI::MP::DropPlayer(int ID, std::optional MaybeReason) { void LuaAPI::MP::SendChatMessage(int ID, const std::string& Message) { std::string Packet = "C:Server: " + Message; if (ID == -1) { - //LogChatMessage(" (to everyone) ", -1, Message); + LogChatMessage(" (to everyone) ", -1, Message); Engine->Network().SendToAll(nullptr, Packet, true, true); } else { auto MaybeClient = GetClient(Engine->Server(), ID); @@ -130,7 +131,7 @@ void LuaAPI::MP::SendChatMessage(int ID, const std::string& Message) { auto c = MaybeClient.value().lock(); if (!c->IsSynced()) return; - //LogChatMessage(" (to \"" + c->GetName() + "\")", -1, msg); + LogChatMessage(" (to \"" + c->GetName() + "\")", -1, msg); Engine->Network().Respond(*c, Packet, true); } else { beammp_lua_error("SendChatMessage invalid argument [1] invalid ID");