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(-) (limited to 'src/ClientHandle.cpp') 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(-) (limited to 'src/ClientHandle.cpp') 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 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(-) (limited to 'src/ClientHandle.cpp') 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