summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexander Harkness <bearbin@gmail.com>2013-12-19 09:02:49 +0100
committerAlexander Harkness <bearbin@gmail.com>2013-12-19 09:02:49 +0100
commit9a29af71516c7e2f8aaaa450fd9981e914fb5bb7 (patch)
tree63186c2bbc3840e120550eaba32f7baa2a55d2a9 /src
parentMerge pull request #440 from mc-server/repeaterfixes (diff)
parentDisconnection message no longer shown if ping (diff)
downloadcuberite-9a29af71516c7e2f8aaaa450fd9981e914fb5bb7.tar
cuberite-9a29af71516c7e2f8aaaa450fd9981e914fb5bb7.tar.gz
cuberite-9a29af71516c7e2f8aaaa450fd9981e914fb5bb7.tar.bz2
cuberite-9a29af71516c7e2f8aaaa450fd9981e914fb5bb7.tar.lz
cuberite-9a29af71516c7e2f8aaaa450fd9981e914fb5bb7.tar.xz
cuberite-9a29af71516c7e2f8aaaa450fd9981e914fb5bb7.tar.zst
cuberite-9a29af71516c7e2f8aaaa450fd9981e914fb5bb7.zip
Diffstat (limited to '')
-rw-r--r--src/Bindings/PluginManager.cpp25
-rw-r--r--src/Bindings/PluginManager.h7
-rw-r--r--src/ClientHandle.cpp23
3 files changed, 41 insertions, 14 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
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 9565fc41f..9550e3afe 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(),
@@ -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,19 @@ 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 (m_Username != "") // Ignore client pings
+ {
+ 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();
}