From 26632bbb8a14ce0c258d812171728c55fb78ede8 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 18 Dec 2013 18:17:17 +0000 Subject: Fixed 1.7 player disconnection not calling hook This fixes #357 --- src/ClientHandle.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 9565fc41f..c72240ab5 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1216,12 +1216,13 @@ void cClientHandle::HandleRespawn(void) void cClientHandle::HandleDisconnect(const AString & a_Reason) { - LOGD("Received d/c packet from \"%s\" with reason \"%s\"", m_Username.c_str(), a_Reason.c_str()); + LOGD("Received d/c packet from %s with reason \"%s\"", m_Username.c_str(), a_Reason.c_str()); if (!cRoot::Get()->GetPluginManager()->CallHookDisconnect(m_Player, a_Reason)) { AString DisconnectMessage; - Printf(DisconnectMessage, "%s disconnected: %s", m_Username.c_str(), a_Reason.c_str()); - m_Player->GetWorld()->BroadcastChat(DisconnectMessage, this); + Printf(DisconnectMessage, "%s[LEAVE] %s%s has left the game", cChatColor::Yellow.c_str(), cChatColor::White.c_str(), m_Username.c_str()); + cRoot::Get()->BroadcastChat(DisconnectMessage); + LOGINFO("Player %s has left the game.", m_Username.c_str()); } m_HasSentDC = true; Destroy(); @@ -2287,7 +2288,16 @@ void cClientHandle::SocketClosed(void) { // The socket has been closed for any reason - LOGD("Client \"%s\" @ %s disconnected", m_Username.c_str(), m_IPString.c_str()); + LOGD("Player %s @ %s disconnected", m_Username.c_str(), m_IPString.c_str()); + + if (!cRoot::Get()->GetPluginManager()->CallHookDisconnect(m_Player, "Player disconnected")) + { + AString DisconnectMessage; + Printf(DisconnectMessage, "%s[LEAVE] %s%s has left the game", cChatColor::Yellow.c_str(), cChatColor::White.c_str(), m_Username.c_str()); + cRoot::Get()->BroadcastChat(DisconnectMessage); + LOGINFO("Player %s has left the game.", m_Username.c_str()); + } + Destroy(); } -- cgit v1.2.3 From aaaa53ce9d5c0d1e8840e68d9b039dab8325ee37 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 18 Dec 2013 18:18:06 +0000 Subject: The "<>" of a player name is now coloured --- src/ClientHandle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index c72240ab5..c9f4854c6 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -998,7 +998,7 @@ void cClientHandle::HandleChat(const AString & a_Message) // Not a command, broadcast as a simple message: AString Msg; - Printf(Msg, "<%s%s%s> %s", + Printf(Msg, "%s<%s>%s %s", m_Player->GetColor().c_str(), m_Player->GetName().c_str(), cChatColor::White.c_str(), -- cgit v1.2.3 From b4ac4a14fa8b1d7d16e8ccbb1913fe0d9d8939e4 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 18 Dec 2013 22:05:41 +0000 Subject: Prettified command error messages Using the magic of overlords (overloads) and standards compliance. --- src/Bindings/PluginManager.cpp | 25 +++++++++++++++++-------- src/Bindings/PluginManager.h | 7 ++++++- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index 732da24fa..832dc4249 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -9,6 +9,7 @@ #include "../Root.h" #include "../Server.h" #include "../CommandOutput.h" +#include "../ChatColor.h" #include "inifile/iniFile.h" #include "../Entities/Player.h" @@ -230,19 +231,25 @@ bool cPluginManager::CallHookBlockToPickups( bool cPluginManager::CallHookChat(cPlayer * a_Player, AString & a_Message) { - if (ExecuteCommand(a_Player, a_Message)) + bool WasCommandForbidden = false; + if (HandleCommand(a_Player, a_Message, true, WasCommandForbidden)) // We use HandleCommand as opposed to ExecuteCommand to accomodate the need to the WasCommandForbidden bool { - return true; + return true; // Chat message was handled as command + } + else if (WasCommandForbidden) // Couldn't be handled as command, was it because of insufficient permissions? + { + return true; // Yes - message was sent in HandleCommand, abort } // Check if it was a standard command (starts with a slash) + // If it was, we know that it was completely unrecognised (WasCommandForbidden == false) if (!a_Message.empty() && (a_Message[0] == '/')) { AStringVector Split(StringSplit(a_Message, " ")); ASSERT(!Split.empty()); // This should not happen - we know there's at least one char in the message so the split needs to be at least one item long - a_Player->SendMessage(Printf("Unknown Command: \"%s\"", Split[0].c_str())); - LOGINFO("Player \"%s\" issued an unknown command: \"%s\"", a_Player->GetName().c_str(), a_Message.c_str()); - return true; // Cancel sending + a_Player->SendMessage(Printf("%s[INFO] %sUnknown command: \"%s\"", cChatColor::Yellow.c_str(), cChatColor::White.c_str(), Split[0].c_str())); + LOGINFO("Player %s issued an unknown command: \"%s\"", a_Player->GetName().c_str(), a_Message.c_str()); + return true; // Cancel sending } HookMap::iterator Plugins = m_Hooks.find(HOOK_CHAT); @@ -1251,7 +1258,7 @@ bool cPluginManager::CallHookWorldTick(cWorld & a_World, float a_Dt, int a_LastT -bool cPluginManager::HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions) +bool cPluginManager::HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions, bool & a_WasCommandForbidden) { ASSERT(a_Player != NULL); @@ -1271,7 +1278,7 @@ bool cPluginManager::HandleCommand(cPlayer * a_Player, const AString & a_Command // Ask plugins first if a command is okay to execute the command: if (CallHookExecuteCommand(a_Player, Split)) { - LOGINFO("Player \"%s\" tried executing command \"%s\" that was stopped by the HOOK_EXECUTE_COMMAND hook", a_Player->GetName().c_str(), Split[0].c_str()); + LOGINFO("Player %s tried executing command \"%s\" that was stopped by the HOOK_EXECUTE_COMMAND hook", a_Player->GetName().c_str(), Split[0].c_str()); return false; } @@ -1281,7 +1288,9 @@ bool cPluginManager::HandleCommand(cPlayer * a_Player, const AString & a_Command !a_Player->HasPermission(cmd->second.m_Permission) ) { - LOGINFO("Player \"%s\" tried to execute forbidden command \"%s\".", a_Player->GetName().c_str(), Split[0].c_str()); + a_Player->SendMessage(Printf("%s[INFO] %sForbidden command; insufficient privileges: \"%s\"", cChatColor::Rose.c_str(), cChatColor::White.c_str(), Split[0].c_str())); + LOGINFO("Player %s tried to execute forbidden command: \"%s\"", a_Player->GetName().c_str(), Split[0].c_str()); + a_WasCommandForbidden = true; return false; } diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index b69f402c0..04d6470c7 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -289,7 +289,12 @@ private: bool AddPlugin(cPlugin * a_Plugin); /// Tries to match a_Command to the internal table of commands, if a match is found, the corresponding plugin is called. Returns true if the command is handled. - bool HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions); + bool HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions, bool & a_WasCommandForbidden); + bool HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions) + { + bool DummyBoolean = false; + return HandleCommand(a_Player, a_Command, a_ShouldCheckPermissions, DummyBoolean); + } } ; // tolua_export -- cgit v1.2.3 From 2dd823da097e1b39e28343af69e415364eb8ed5c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 18 Dec 2013 22:06:36 +0000 Subject: Disconnection message no longer shown if ping --- src/ClientHandle.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index c9f4854c6..9550e3afe 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2290,12 +2290,15 @@ void cClientHandle::SocketClosed(void) LOGD("Player %s @ %s disconnected", m_Username.c_str(), m_IPString.c_str()); - if (!cRoot::Get()->GetPluginManager()->CallHookDisconnect(m_Player, "Player disconnected")) + if (m_Username != "") // Ignore client pings { - AString DisconnectMessage; - Printf(DisconnectMessage, "%s[LEAVE] %s%s has left the game", cChatColor::Yellow.c_str(), cChatColor::White.c_str(), m_Username.c_str()); - cRoot::Get()->BroadcastChat(DisconnectMessage); - LOGINFO("Player %s has left the game.", m_Username.c_str()); + if (!cRoot::Get()->GetPluginManager()->CallHookDisconnect(m_Player, "Player disconnected")) + { + AString DisconnectMessage; + Printf(DisconnectMessage, "%s[LEAVE] %s%s has left the game", cChatColor::Yellow.c_str(), cChatColor::White.c_str(), m_Username.c_str()); + cRoot::Get()->BroadcastChat(DisconnectMessage); + LOGINFO("Player %s has left the game.", m_Username.c_str()); + } } Destroy(); -- cgit v1.2.3 From 56076c3baae5d07ab2d88efe3d508fb52a1d0db6 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Thu, 19 Dec 2013 11:30:24 +0000 Subject: Update Contributing.md Fixes #351 --- CONTRIBUTING.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9ce4c9ff3..5aba6ac9e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,10 @@ + Code Stuff ---------- + * Because some devs use MSVC2008, we use C++03 - no C++11 magic for now at least :( + * Use the provided wrappers for OS stuff: + - Threading is done by inheriting from cIsThread, thread synchronization through cCriticalSection, cSemaphore and cEvent, file access and filesystem operations through the cFile class, high-precision timers through cTimer, high-precision sleep through cSleep * No magic numbers, use named constants: - E_ITEM_XXX, E_BLOCK_XXX and E_META_XXX for items and blocks - E_ENTITY_TYPE_XXX for mob types -- cgit v1.2.3