Re-add SendChatMessage

This commit is contained in:
Lion Kortlepel 2021-09-17 12:58:07 +02:00
parent c2b73d93b5
commit fd3088c78f
No known key found for this signature in database
GPG Key ID: 4322FF2B4C71259B
3 changed files with 17 additions and 2 deletions

View File

@ -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);

View File

@ -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());
}

View File

@ -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<std::string> MaybeReason) {
void LuaAPI::MP::SendChatMessage(int ID, const std::string& Message) {
std::string Packet = "C:Server: " + Message;
if (ID == -1) {
//LogChatMessage("<Server> (to everyone) ", -1, Message);
LogChatMessage("<Server> (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("<Server> (to \"" + c->GetName() + "\")", -1, msg);
LogChatMessage("<Server> (to \"" + c->GetName() + "\")", -1, msg);
Engine->Network().Respond(*c, Packet, true);
} else {
beammp_lua_error("SendChatMessage invalid argument [1] invalid ID");