From b16e95ca94b709f6a19abedb51e2fb313422a4d5 Mon Sep 17 00:00:00 2001 From: David Athay Date: Mon, 15 Apr 2024 00:31:42 +0100 Subject: WIP: Create avatars and populate the online player list - Currently names are blank or mangled --- src/gui/socialwindow.cpp | 27 +++++++++++++++++++++++++++ src/gui/socialwindow.h | 4 ++++ src/net/tmwa/playerlisthandler.cpp | 24 ++++++++++++++++++++++-- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index 953d347a..85f08204 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -46,6 +46,7 @@ #include "resources/theme.h" +#include "socialwindow.h" #include "utils/gettext.h" #include "utils/stringutils.h" #include "widgets/avatarlistbox.h" @@ -237,6 +238,14 @@ class PlayerList : public AvatarListModel { public: + void addAvatar(Avatar *avatar) { + mPlayers.push_back(avatar); + } + + void clearPlayerList() { + mPlayers.clear(); + } + /** * Get size of members list. * @return Returns the number of members in the party. @@ -274,6 +283,14 @@ public: { delete mPlayerList; } + void clearPlayerList() + { + mPlayerList->clearPlayerList(); + } + void addOnlinePlayer(Avatar *avatar) + { + mPlayerList->addAvatar(avatar); + } protected: void invite() override {} @@ -667,6 +684,16 @@ void SocialWindow::showPartyCreate() mPartyCreateDialog->addActionListener(this); } +void SocialWindow::setPlayersOnline(const std::vector &onlineUsers) +{ + mPlayerListTab->clearPlayerList(); + for (auto itr = onlineUsers.begin(); + itr != onlineUsers.end(); ++itr) + { + mPlayerListTab->addOnlinePlayer(*(itr)); + } +} + void SocialWindow::updateButtons() { bool hasTabs = mTabs->getNumberOfTabs() > 0; diff --git a/src/gui/socialwindow.h b/src/gui/socialwindow.h index 9db8f020..0c269e26 100644 --- a/src/gui/socialwindow.h +++ b/src/gui/socialwindow.h @@ -28,7 +28,9 @@ #include #include +#include +class Avatar; class Button; class ConfirmDialog; class CreatePopup; @@ -75,6 +77,8 @@ public: void showPartyCreate(); + void setPlayersOnline(const std::vector &onlineUsers); + protected: friend class SocialTab; diff --git a/src/net/tmwa/playerlisthandler.cpp b/src/net/tmwa/playerlisthandler.cpp index 530af4c7..fe0b7bab 100644 --- a/src/net/tmwa/playerlisthandler.cpp +++ b/src/net/tmwa/playerlisthandler.cpp @@ -24,8 +24,11 @@ #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" @@ -53,8 +56,25 @@ void PlayerListHandler::handleMessage(MessageIn &msg) { case SMSG_ONLINE_LIST: { - SERVER_NOTICE(_("RECEIVED SMSG_ONLINE_LIST")) - logger->log("GOT SMSG_ONLINE_LIST"); + int length = msg.readInt16(); + int count = (length - 4) / 31; + std::vector 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.readInt32(); // level + msg.readInt32(); // gm level + msg.readInt8(); // gender + + Avatar *avatar = new Avatar(nick); + avatar->setOnline(true); + onlineUsers.push_back(avatar); + } + + socialWindow->setPlayersOnline(onlineUsers); } break; } -- cgit v1.2.3-70-g09d2