Lua: Kick properly (with ClientKick), add chat message printing

This commit is contained in:
Lion Kortlepel 2021-10-02 01:28:58 +02:00
parent af14188ec0
commit d027f7f29f
No known key found for this signature in database
GPG Key ID: 4322FF2B4C71259B
4 changed files with 5 additions and 7 deletions

View File

@ -142,6 +142,7 @@ std::string Version::AsString() {
void LogChatMessage(const std::string& name, int id, const std::string& msg) { void LogChatMessage(const std::string& name, int id, const std::string& msg) {
std::stringstream ss; std::stringstream ss;
ss << ThreadName();
ss << "[CHAT] "; ss << "[CHAT] ";
if (id != -1) { if (id != -1) {
ss << "(" << id << ") <" << name << ">"; ss << "(" << id << ") <" << name << ">";
@ -149,6 +150,7 @@ void LogChatMessage(const std::string& name, int id, const std::string& msg) {
ss << name << ""; ss << name << "";
} }
ss << msg; ss << msg;
Application::Console().Write(ss.str());
} }
std::string GetPlatformAgnosticErrorString() { std::string GetPlatformAgnosticErrorString() {

View File

@ -118,15 +118,11 @@ bool LuaAPI::MP::TriggerClientEvent(int PlayerID, const std::string& EventName,
void LuaAPI::MP::DropPlayer(int ID, std::optional<std::string> MaybeReason) { void LuaAPI::MP::DropPlayer(int ID, std::optional<std::string> MaybeReason) {
auto MaybeClient = GetClient(Engine->Server(), ID); auto MaybeClient = GetClient(Engine->Server(), ID);
if (!MaybeClient || MaybeClient.value().expired()) { if (!MaybeClient || MaybeClient.value().expired()) {
beammp_lua_error("Tried to drop client with id " + std::to_string(ID) + ", who doesn't exist");
return; return;
} }
auto c = MaybeClient.value().lock(); auto c = MaybeClient.value().lock();
if (!Engine->Network().Respond(*c, "C:Server:You have been Kicked from the server! Reason: " + MaybeReason.value_or("No reason"), true)) { LuaAPI::MP::Engine->Network().ClientKick(*c, MaybeReason.value_or("No reason"));
// Ignore
}
c->SetStatus(-2);
beammp_info("Closing socket due to kick");
CloseSocketProper(c->GetTCPSock());
} }
void LuaAPI::MP::SendChatMessage(int ID, const std::string& Message) { void LuaAPI::MP::SendChatMessage(int ID, const std::string& Message) {

View File

@ -107,7 +107,6 @@ TConsole::TConsole() {
void TConsole::Write(const std::string& str) { void TConsole::Write(const std::string& str) {
auto ToWrite = GetDate() + str; auto ToWrite = GetDate() + str;
mCommandline.write(ToWrite); mCommandline.write(ToWrite);
// TODO write to logfile, too
} }
void TConsole::WriteRaw(const std::string& str) { void TConsole::WriteRaw(const std::string& str) {

View File

@ -458,6 +458,7 @@ void TNetwork::ClientKick(TClient& c, const std::string& R) {
if (c.GetDownSock()) if (c.GetDownSock())
CloseSocketProper(c.GetDownSock()); CloseSocketProper(c.GetDownSock());
} }
void TNetwork::Looper(const std::weak_ptr<TClient>& c) { void TNetwork::Looper(const std::weak_ptr<TClient>& c) {
while (!c.expired()) { while (!c.expired()) {
auto Client = c.lock(); auto Client = c.lock();