From c8b1778847fca653c5f9cde610d25586131698ac Mon Sep 17 00:00:00 2001 From: b33duck Date: Thu, 28 May 2015 13:17:21 -0700 Subject: Fixed the way connecting clients receive player lists and broadcast chat to worlds --- src/ClientHandle.cpp | 4 ++-- src/Root.cpp | 10 ++++++++-- src/Root.h | 4 ++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 9644679d7..161bdeb9d 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -382,7 +382,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, // Send player list items SendPlayerListAddPlayer(*m_Player); World->BroadcastPlayerListAddPlayer(*m_Player); - World->SendPlayerList(m_Player); + cRoot::Get()->SendPlayerLists(m_Player); m_Player->Initialize(*World); m_State = csAuthenticated; @@ -1475,7 +1475,7 @@ void cClientHandle::HandleChat(const AString & a_Message) Msg.AddTextPart(AString("<") + m_Player->GetName() + "> ", Color); Msg.ParseText(Message); Msg.UnderlineUrls(); - m_Player->GetWorld()->BroadcastChat(Msg); + cRoot::Get()->BroadcastChat(Msg); } diff --git a/src/Root.cpp b/src/Root.cpp index b28e7c894..b60f6ae3a 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -558,6 +558,14 @@ void cRoot::SaveAllChunks(void) +void cRoot::SendPlayerLists(cPlayer * a_DestPlayer) +{ + for (WorldMap::iterator itr = m_WorldsByName.begin(), end = m_WorldsByName.end(); itr != end; ++itr) + { + itr->second->SendPlayerList(a_DestPlayer); + } // for itr - m_WorldsByName[] +} + void cRoot::BroadcastChat(const AString & a_Message, eMessageType a_ChatPrefix) @@ -582,8 +590,6 @@ void cRoot::BroadcastChat(const cCompositeChat & a_Message) - - bool cRoot::ForEachPlayer(cPlayerListCallback & a_Callback) { for (WorldMap::iterator itr = m_WorldsByName.begin(), itr2 = itr; itr != m_WorldsByName.end(); itr = itr2) diff --git a/src/Root.h b/src/Root.h index ab820427f..73fd6638c 100644 --- a/src/Root.h +++ b/src/Root.h @@ -145,6 +145,10 @@ public: /** Finds the player using it's complete username and calls the callback */ bool DoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback); + /** Send playerlist of all worlds to player */ + void SendPlayerLists(cPlayer * a_DestPlayer); + + // tolua_begin /// Sends a chat message to all connected clients (in all worlds) -- cgit v1.2.3 From 022348645e5f4a39c57ab6c899dd9de12bcb3794 Mon Sep 17 00:00:00 2001 From: b33duck Date: Thu, 28 May 2015 13:17:21 -0700 Subject: Fix for the way connecting clients receive player lists and broadcast chat --- src/ClientHandle.cpp | 6 +++--- src/Root.cpp | 19 +++++++++++++++++-- src/Root.h | 6 ++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 9644679d7..9cba5619d 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -381,8 +381,8 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, // Send player list items SendPlayerListAddPlayer(*m_Player); - World->BroadcastPlayerListAddPlayer(*m_Player); - World->SendPlayerList(m_Player); + cRoot::Get()->BroadcastPlayerListsAddPlayer(*m_Player); + cRoot::Get()->SendPlayerLists(m_Player); m_Player->Initialize(*World); m_State = csAuthenticated; @@ -1475,7 +1475,7 @@ void cClientHandle::HandleChat(const AString & a_Message) Msg.AddTextPart(AString("<") + m_Player->GetName() + "> ", Color); Msg.ParseText(Message); Msg.UnderlineUrls(); - m_Player->GetWorld()->BroadcastChat(Msg); + cRoot::Get()->BroadcastChat(Msg); } diff --git a/src/Root.cpp b/src/Root.cpp index b28e7c894..54e65b6da 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -558,6 +558,23 @@ void cRoot::SaveAllChunks(void) +void cRoot::SendPlayerLists(cPlayer * a_DestPlayer) +{ + for (const auto & itr : m_WorldsByName) + { + itr.second->SendPlayerList(a_DestPlayer); + } // for itr - m_WorldsByName[] +} + + + +void cRoot::BroadcastPlayerListsAddPlayer(const cPlayer & a_Player, const cClientHandle * a_Exclude) +{ + for (const auto & itr : m_WorldsByName) + { + itr.second->BroadcastPlayerListAddPlayer(a_Player); + } // for itr - m_WorldsByName[] +} void cRoot::BroadcastChat(const AString & a_Message, eMessageType a_ChatPrefix) @@ -582,8 +599,6 @@ void cRoot::BroadcastChat(const cCompositeChat & a_Message) - - bool cRoot::ForEachPlayer(cPlayerListCallback & a_Callback) { for (WorldMap::iterator itr = m_WorldsByName.begin(), itr2 = itr; itr != m_WorldsByName.end(); itr = itr2) diff --git a/src/Root.h b/src/Root.h index ab820427f..81551a503 100644 --- a/src/Root.h +++ b/src/Root.h @@ -145,6 +145,12 @@ public: /** Finds the player using it's complete username and calls the callback */ bool DoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback); + /** Send playerlist of all worlds to player */ + void SendPlayerLists(cPlayer * a_DestPlayer); + + /** Broadcast Player through all worlds */ + void BroadcastPlayerListsAddPlayer(const cPlayer & a_Player, const cClientHandle * a_Exclude = nullptr); + // tolua_begin /// Sends a chat message to all connected clients (in all worlds) -- cgit v1.2.3