diff options
-rw-r--r-- | src/commandhandler.cpp | 1 | ||||
-rw-r--r-- | src/gui/socialwindow.cpp | 89 | ||||
-rw-r--r-- | src/gui/socialwindow.h | 8 | ||||
-rw-r--r-- | src/net/chathandler.h | 2 | ||||
-rw-r--r-- | src/net/manaserv/chathandler.h | 2 | ||||
-rw-r--r-- | src/net/net.cpp | 6 | ||||
-rw-r--r-- | src/net/net.h | 2 | ||||
-rw-r--r-- | src/net/tmwa/chathandler.cpp | 35 | ||||
-rw-r--r-- | src/net/tmwa/chathandler.h | 2 | ||||
-rw-r--r-- | src/net/tmwa/generalhandler.cpp | 2 | ||||
-rw-r--r-- | src/net/tmwa/generalhandler.h | 1 | ||||
-rw-r--r-- | src/net/tmwa/loginhandler.cpp | 2 |
12 files changed, 150 insertions, 2 deletions
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index addb7367..b9fb631a 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -24,6 +24,7 @@ #include "actorspritemanager.h" #include "channelmanager.h" #include "game.h" +#include "gui/chatwindow.h" #include "localplayer.h" #include "playerrelations.h" diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index 9ba64e9f..d57db749 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -40,13 +40,16 @@ #include "gui/widgets/tabbedarea.h" #include "net/net.h" +#include "net/chathandler.h" #include "net/guildhandler.h" #include "net/partyhandler.h" #include "resources/theme.h" +#include "socialwindow.h" #include "utils/gettext.h" #include "utils/stringutils.h" +#include "widgets/avatarlistbox.h" #include <memory> @@ -231,6 +234,76 @@ private: Party *mParty; }; +class PlayerList : public AvatarListModel +{ +public: + + void addAvatars(const std::vector<Avatar*> &onlineUsers) { + mPlayers = onlineUsers; + } + + void clearPlayerList() { + for (unsigned i = 0; i < mPlayers.size(); ++i) + { + delete mPlayers[i]; + } + mPlayers.clear(); + } + + /** + * Get size of members list. + * @return Returns the number of members in the party. + */ + int getNumberOfElements() override { + return mPlayers.size(); + } + + Avatar *getAvatarAt(int index) override { + return mPlayers[index]; + } + +private: + std::vector<Avatar*> mPlayers; +}; + +class PlayerListTab : public SocialTab +{ +public: + PlayerListTab() + { + setCaption("Online Players"); + + mPlayerList = new PlayerList; + + mList = std::make_unique<AvatarListBox>(mPlayerList); + mScroll = std::make_unique<ScrollArea>(mList.get()); + + mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO); + mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_AUTO); + + Net::getChatHandler()->refreshList(); + } + ~PlayerListTab() + { + delete mPlayerList; + } + void clearPlayerList() + { + mPlayerList->clearPlayerList(); + } + void addOnlinePlayers(const std::vector<Avatar*> &onlineUsers) + { + mPlayerList->addAvatars(onlineUsers); + } + +protected: + void invite() override {} + void leave() override {} + +private: + PlayerList *mPlayerList; +}; + /*class BuddyTab : public SocialTab { // TODO? @@ -305,17 +378,22 @@ SocialWindow::SocialWindow() : mCreateButton = new Button(_("Create"), "create", this); mInviteButton = new Button(_("Invite"), "invite", this); mLeaveButton = new Button(_("Leave"), "leave", this); + mRefreshButton = new Button(_("Refresh"), "refresh", this); mTabs = new TabbedArea; place(0, 0, mCreateButton); place(1, 0, mInviteButton); place(2, 0, mLeaveButton); + place(3, 0, mRefreshButton); place(0, 1, mTabs, 4, 4); widgetResized(nullptr); mCreatePopup = new CreatePopup(); + mPlayerListTab = new PlayerListTab(); + mTabs->addTab(mPlayerListTab, mPlayerListTab->mScroll.get()); + if (local_player->getParty()) { addTab(local_player->getParty()); @@ -345,6 +423,7 @@ SocialWindow::~SocialWindow() mPartyInviter.clear(); } delete mCreatePopup; + delete mPlayerListTab; } bool SocialWindow::addTab(Guild *guild) @@ -462,6 +541,10 @@ void SocialWindow::action(const gcn::ActionEvent &event) { static_cast<SocialTab*>(mTabs->getSelectedTab())->leave(); } + else if (event.getId() == "refresh") + { + Net::getChatHandler()->refreshList(); + } else if (event.getId() == "create guild") { std::string name = mGuildCreateDialog->getText(); @@ -605,6 +688,12 @@ void SocialWindow::showPartyCreate() mPartyCreateDialog->addActionListener(this); } +void SocialWindow::setPlayersOnline(const std::vector<Avatar*> &onlineUsers) +{ + mPlayerListTab->clearPlayerList(); + mPlayerListTab->addOnlinePlayers(onlineUsers); +} + void SocialWindow::updateButtons() { bool hasTabs = mTabs->getNumberOfTabs() > 0; diff --git a/src/gui/socialwindow.h b/src/gui/socialwindow.h index 8575f3b2..0c269e26 100644 --- a/src/gui/socialwindow.h +++ b/src/gui/socialwindow.h @@ -28,12 +28,15 @@ #include <string> #include <map> +#include <vector> +class Avatar; class Button; class ConfirmDialog; class CreatePopup; class Guild; class Party; +class PlayerListTab; class SocialTab; class Tab; class TabbedArea; @@ -74,6 +77,8 @@ public: void showPartyCreate(); + void setPlayersOnline(const std::vector<Avatar*> &onlineUsers); + protected: friend class SocialTab; @@ -92,9 +97,12 @@ protected: CreatePopup *mCreatePopup; + PlayerListTab *mPlayerListTab; + Button *mCreateButton; Button *mInviteButton; Button *mLeaveButton; + Button *mRefreshButton; TabbedArea *mTabs; }; 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 86f7dc13..a56565cd 100644 --- a/src/net/net.cpp +++ b/src/net/net.cpp @@ -55,6 +55,7 @@ Net::GuildHandler *guildHandler = nullptr; Net::NpcHandler *npcHandler = nullptr; Net::PartyHandler *partyHandler = nullptr; Net::PlayerHandler *playerHandler = nullptr; +Net::PlayerListHandler *playerListHandler = nullptr; Net::SpecialHandler *specialHandler = nullptr; Net::TradeHandler *tradeHandler = nullptr; @@ -113,6 +114,11 @@ Net::PlayerHandler *Net::getPlayerHandler() return playerHandler; } +Net::PlayerListHandler *Net::getPlayerListHandler() +{ + return playerListHandler; +} + Net::SpecialHandler *Net::getSpecialHandler() { return specialHandler; diff --git a/src/net/net.h b/src/net/net.h index 135f2cb7..8aba9e2d 100644 --- a/src/net/net.h +++ b/src/net/net.h @@ -45,6 +45,7 @@ class LoginHandler; class NpcHandler; class PartyHandler; class PlayerHandler; +class PlayerListHandler; class SpecialHandler; class TradeHandler; @@ -59,6 +60,7 @@ LoginHandler *getLoginHandler(); NpcHandler *getNpcHandler(); PartyHandler *getPartyHandler(); PlayerHandler *getPlayerHandler(); +PlayerListHandler *getPlayerListHandler(); SpecialHandler *getSpecialHandler(); TradeHandler *getTradeHandler(); diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp index a1e2d375..a282a943 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" @@ -50,6 +53,7 @@ ChatHandler::ChatHandler() SMSG_WHISPER_RESPONSE, SMSG_GM_CHAT, SMSG_SCRIPT_MESSAGE, + SMSG_ONLINE_LIST, 0 }; handledMessages = _messages; @@ -252,6 +256,32 @@ void ChatHandler::handleMessage(MessageIn &msg) SERVER_NOTICE(msg.readString(chatMsgLength)) 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; + } + } } @@ -332,4 +362,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 832d6973..5fefae78 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -169,10 +169,10 @@ void GeneralHandler::load() mNetwork->registerHandler(mItemHandler.get()); mNetwork->registerHandler(mLoginHandler.get()); mNetwork->registerHandler(mNpcHandler.get()); + mNetwork->registerHandler(mPartyHandler.get()); mNetwork->registerHandler(mPlayerHandler.get()); mNetwork->registerHandler(mSpecialHandler.get()); mNetwork->registerHandler(mTradeHandler.get()); - mNetwork->registerHandler(mPartyHandler.get()); } void GeneralHandler::reload() diff --git a/src/net/tmwa/generalhandler.h b/src/net/tmwa/generalhandler.h index f105da96..d0916c8b 100644 --- a/src/net/tmwa/generalhandler.h +++ b/src/net/tmwa/generalhandler.h @@ -67,6 +67,7 @@ class GeneralHandler final : public MessageHandler, public Net::GeneralHandler, MessageHandlerPtr mNpcHandler; MessageHandlerPtr mPartyHandler; MessageHandlerPtr mPlayerHandler; + MessageHandlerPtr mPlayerListHandler; MessageHandlerPtr mSpecialHandler; MessageHandlerPtr mTradeHandler; }; diff --git a/src/net/tmwa/loginhandler.cpp b/src/net/tmwa/loginhandler.cpp index 8ee5e102..24bc9ab2 100644 --- a/src/net/tmwa/loginhandler.cpp +++ b/src/net/tmwa/loginhandler.cpp @@ -321,7 +321,7 @@ void LoginHandler::sendLoginRegister(const std::string &username, const std::string &password) { MessageOut outMsg(CMSG_LOGIN_REGISTER); - outMsg.writeInt32(6); // client version + outMsg.writeInt32(8); // client version outMsg.writeString(username, 24); outMsg.writeString(password, 24); |