diff options
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/commandhandler.cpp | 1 | ||||
-rw-r--r-- | src/gui/socialwindow.cpp | 24 | ||||
-rw-r--r-- | src/net/chathandler.h | 2 | ||||
-rw-r--r-- | src/net/manaserv/chathandler.h | 2 | ||||
-rw-r--r-- | src/net/net.cpp | 1 | ||||
-rw-r--r-- | src/net/playerlisthandler.h | 35 | ||||
-rw-r--r-- | src/net/tmwa/chathandler.cpp | 34 | ||||
-rw-r--r-- | src/net/tmwa/chathandler.h | 2 | ||||
-rw-r--r-- | src/net/tmwa/generalhandler.cpp | 3 | ||||
-rw-r--r-- | src/net/tmwa/playerlisthandler.cpp | 88 | ||||
-rw-r--r-- | src/net/tmwa/playerlisthandler.h | 42 |
12 files changed, 52 insertions, 184 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5e5b4078..72b44ac6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -552,8 +552,6 @@ SET(SRCS_TMWA net/tmwa/partyhandler.h net/tmwa/playerhandler.cpp net/tmwa/playerhandler.h - net/tmwa/playerlisthandler.cpp - net/tmwa/playerlisthandler.h net/tmwa/protocol.h net/tmwa/specialhandler.cpp net/tmwa/specialhandler.h diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 5a9063fb..b9fb631a 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -33,7 +33,6 @@ #include "net/chathandler.h" #include "net/net.h" #include "net/partyhandler.h" -#include "net/playerlisthandler.h" #include "utils/gettext.h" #include "utils/stringutils.h" diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index 85f08204..d57db749 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -40,9 +40,9 @@ #include "gui/widgets/tabbedarea.h" #include "net/net.h" +#include "net/chathandler.h" #include "net/guildhandler.h" #include "net/partyhandler.h" -#include "net/playerlisthandler.h" #include "resources/theme.h" @@ -238,11 +238,15 @@ class PlayerList : public AvatarListModel { public: - void addAvatar(Avatar *avatar) { - mPlayers.push_back(avatar); + void addAvatars(const std::vector<Avatar*> &onlineUsers) { + mPlayers = onlineUsers; } void clearPlayerList() { + for (unsigned i = 0; i < mPlayers.size(); ++i) + { + delete mPlayers[i]; + } mPlayers.clear(); } @@ -277,7 +281,7 @@ public: mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO); mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_AUTO); - Net::getPlayerListHandler()->refreshList(); + Net::getChatHandler()->refreshList(); } ~PlayerListTab() { @@ -287,9 +291,9 @@ public: { mPlayerList->clearPlayerList(); } - void addOnlinePlayer(Avatar *avatar) + void addOnlinePlayers(const std::vector<Avatar*> &onlineUsers) { - mPlayerList->addAvatar(avatar); + mPlayerList->addAvatars(onlineUsers); } protected: @@ -539,7 +543,7 @@ void SocialWindow::action(const gcn::ActionEvent &event) } else if (event.getId() == "refresh") { - Net::getPlayerListHandler()->refreshList(); + Net::getChatHandler()->refreshList(); } else if (event.getId() == "create guild") { @@ -687,11 +691,7 @@ void SocialWindow::showPartyCreate() void SocialWindow::setPlayersOnline(const std::vector<Avatar*> &onlineUsers) { mPlayerListTab->clearPlayerList(); - for (auto itr = onlineUsers.begin(); - itr != onlineUsers.end(); ++itr) - { - mPlayerListTab->addOnlinePlayer(*(itr)); - } + mPlayerListTab->addOnlinePlayers(onlineUsers); } void SocialWindow::updateButtons() diff --git a/src/net/chathandler.h b/src/net/chathandler.h index c324c2d8..bdd156b4 100644 --- a/src/net/chathandler.h +++ b/src/net/chathandler.h @@ -58,6 +58,8 @@ class ChatHandler virtual void who() = 0; virtual bool whoSupported() const = 0; + + virtual void refreshList() = 0; }; } diff --git a/src/net/manaserv/chathandler.h b/src/net/manaserv/chathandler.h index c4dc6861..249330c9 100644 --- a/src/net/manaserv/chathandler.h +++ b/src/net/manaserv/chathandler.h @@ -72,6 +72,8 @@ class ChatHandler final : public MessageHandler, public Net::ChatHandler bool whoSupported() const override { return true; } + void refreshList() override {} + private: /** * Handle chat messages sent from the game server. diff --git a/src/net/net.cpp b/src/net/net.cpp index 075288cd..a56565cd 100644 --- a/src/net/net.cpp +++ b/src/net/net.cpp @@ -35,7 +35,6 @@ #include "net/npchandler.h" #include "net/partyhandler.h" #include "net/playerhandler.h" -#include "net/playerlisthandler.h" #include "net/specialhandler.h" #include "net/tradehandler.h" diff --git a/src/net/playerlisthandler.h b/src/net/playerlisthandler.h deleted file mode 100644 index 3390038b..00000000 --- a/src/net/playerlisthandler.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * The Mana Client - * Copyright (C) 2009-2024 The Mana Developers - * - * This file is part of The Mana Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef PLAYERLISTHANDLER_H -#define PLAYERLISTHANDLER_H - -namespace Net { - -class PlayerListHandler -{ - public: - virtual ~PlayerListHandler() = default; - virtual void refreshList() = 0; -}; - -} // namespace Net - -#endif // PLAYERLISTHANDLER_H diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp index e4a551e6..0b111104 100644 --- a/src/net/tmwa/chathandler.cpp +++ b/src/net/tmwa/chathandler.cpp @@ -22,11 +22,14 @@ #include "net/tmwa/chathandler.h" #include "actorspritemanager.h" +#include "avatar.h" #include "being.h" #include "event.h" #include "localplayer.h" #include "playerrelations.h" +#include "gui/socialwindow.h" + #include "net/tmwa/loginhandler.h" #include "net/tmwa/messagein.h" #include "net/tmwa/messageout.h" @@ -49,6 +52,7 @@ ChatHandler::ChatHandler() SMSG_WHISPER, SMSG_WHISPER_RESPONSE, SMSG_GM_CHAT, + SMSG_ONLINE_LIST, 0 }; handledMessages = _messages; @@ -239,6 +243,31 @@ void ChatHandler::handleMessage(MessageIn &msg) } break; } + case SMSG_ONLINE_LIST: + { + int length = msg.readInt16(); + int count = (length - 4) / 31; + std::vector<Avatar*> onlineUsers; + + SERVER_NOTICE(strprintf(_("%d players online."), count)) + for (int i = 0; i < count; i++) + { + int id = msg.readInt32(); + std::string nick = msg.readString(24); + msg.readInt8(); // level + msg.readInt8(); // gm level + msg.readInt8(); // gender + + Avatar *avatar = new Avatar(nick); + avatar->setOnline(true); + onlineUsers.push_back(avatar); + } + + socialWindow->setPlayersOnline(onlineUsers); + + break; + } + } } @@ -319,4 +348,9 @@ void ChatHandler::kickUser(int channelId, const std::string &name) SERVER_NOTICE(_("Channels are not supported!")) } +void ChatHandler::refreshList() +{ + MessageOut outMsg(CMSG_ONLINE_LIST); +} + } // namespace TmwAthena diff --git a/src/net/tmwa/chathandler.h b/src/net/tmwa/chathandler.h index 9f838b2c..b375ad50 100644 --- a/src/net/tmwa/chathandler.h +++ b/src/net/tmwa/chathandler.h @@ -66,6 +66,8 @@ class ChatHandler final : public MessageHandler, public Net::ChatHandler bool whoSupported() const override { return false; } + void refreshList() override; + private: std::queue<std::string> mSentWhispers; }; diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp index 528f468b..5fefae78 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -48,7 +48,6 @@ #include "net/tmwa/npchandler.h" #include "net/tmwa/partyhandler.h" #include "net/tmwa/playerhandler.h" -#include "net/tmwa/playerlisthandler.h" #include "net/tmwa/protocol.h" #include "net/tmwa/tradehandler.h" #include "net/tmwa/specialhandler.h" @@ -86,7 +85,6 @@ GeneralHandler::GeneralHandler(): mNpcHandler(new NpcHandler), mPartyHandler(new PartyHandler), mPlayerHandler(new PlayerHandler), - mPlayerListHandler(new PlayerListHandler), mSpecialHandler(new SpecialHandler), mTradeHandler(new TradeHandler) { @@ -173,7 +171,6 @@ void GeneralHandler::load() mNetwork->registerHandler(mNpcHandler.get()); mNetwork->registerHandler(mPartyHandler.get()); mNetwork->registerHandler(mPlayerHandler.get()); - mNetwork->registerHandler(mPlayerListHandler.get()); mNetwork->registerHandler(mSpecialHandler.get()); mNetwork->registerHandler(mTradeHandler.get()); } diff --git a/src/net/tmwa/playerlisthandler.cpp b/src/net/tmwa/playerlisthandler.cpp deleted file mode 100644 index b15c28c6..00000000 --- a/src/net/tmwa/playerlisthandler.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * The Mana Client - * Copyright (C) 2009-2024 The Mana Developers - * - * This file is part of The Mana Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "net/tmwa/playerlisthandler.h" - -#include "net/tmwa/messagein.h" -#include "net/tmwa/messageout.h" -#include "net/tmwa/protocol.h" - -#include "gui/socialwindow.h" - -#include "utils/gettext.h" - -#include "avatar.h" -#include "event.h" -#include "log.h" - -extern Net::PlayerListHandler *playerListHandler; - -namespace TmwAthena { - -PlayerListHandler::PlayerListHandler() -{ - static const uint16_t _messages[] = { - SMSG_ONLINE_LIST, - 0 - }; - handledMessages = _messages; - playerListHandler = this; -} - -PlayerListHandler::~PlayerListHandler() -{ -} - -void PlayerListHandler::handleMessage(MessageIn &msg) -{ - switch (msg.getId()) - { - case SMSG_ONLINE_LIST: - { - int length = msg.readInt16(); - int count = (length - 4) / 31; - std::vector<Avatar*> onlineUsers; - - SERVER_NOTICE(strprintf(_("%d players online."), count)) - for (int i = 0; i < count; i++) - { - int id = msg.readInt32(); - std::string nick = msg.readString(24); - msg.readInt8(); // level - msg.readInt8(); // gm level - msg.readInt8(); // gender - - Avatar *avatar = new Avatar(nick); - avatar->setOnline(true); - onlineUsers.push_back(avatar); - } - - socialWindow->setPlayersOnline(onlineUsers); - } - break; - } -} - -void PlayerListHandler::refreshList() -{ - MessageOut outMsg(CMSG_ONLINE_LIST); -} - -} // namespace TmwAthena
\ No newline at end of file diff --git a/src/net/tmwa/playerlisthandler.h b/src/net/tmwa/playerlisthandler.h deleted file mode 100644 index c11fb300..00000000 --- a/src/net/tmwa/playerlisthandler.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * The Mana Client - * Copyright (C) 2009-2024 The Mana Developers - * - * This file is part of The Mana Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef NET_TA_PLAYERLISTHANDLER_H -#define NET_TA_PLAYERLISTHANDLER_H - -#include "net/net.h" -#include "net/playerlisthandler.h" - -#include "net/tmwa/messagehandler.h" - -namespace TmwAthena { - -class PlayerListHandler final : public MessageHandler, public Net::PlayerListHandler -{ - public: - PlayerListHandler(); - ~PlayerListHandler() override; - void handleMessage(MessageIn &msg) override; - void refreshList() override; -}; - -} // namespace TmwAthena - -#endif // NET_TA_PARTYHANDLER_H |