mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-03 00:05:34 +00:00
Lua: Kick properly (with ClientKick), add chat message printing
This commit is contained in:
parent
af14188ec0
commit
d027f7f29f
@ -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() {
|
||||||
|
@ -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) {
|
||||||
|
@ -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) {
|
||||||
|
@ -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();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user