From fb3cbeddd6f5d59e3f83da059b2a1d4bed2cb80f Mon Sep 17 00:00:00 2001 From: David Athay Date: Thu, 28 Feb 2008 12:31:04 +0000 Subject: Work in Progress commit of guilds. --- src/net/guildhandler.cpp | 150 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 src/net/guildhandler.cpp (limited to 'src/net/guildhandler.cpp') diff --git a/src/net/guildhandler.cpp b/src/net/guildhandler.cpp new file mode 100644 index 00000000..48d2e837 --- /dev/null +++ b/src/net/guildhandler.cpp @@ -0,0 +1,150 @@ +/* + * guildhandler.cpp + * A file part of The Mana World + * + * Created by David Athay on 01/03/2007. + * + * Copyright (c) 2007, The Mana World Development Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * My name may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE + * + * $Id$ + */ + +#include "guildhandler.h" + +#include "protocol.h" +#include "messagein.h" + +#include "chatserver/chatserver.h" +#include "chatserver/guild.h" + +#include "../gui/guildwindow.h" +#include "../guild.h" +#include "../log.h" +#include "../localplayer.h" + +GuildHandler::GuildHandler() +{ + static const Uint16 _messages[] = { + CPMSG_GUILD_CREATE_RESPONSE, + CPMSG_GUILD_INVITE_RESPONSE, + CPMSG_GUILD_ACCEPT_RESPONSE, + CPMSG_GUILD_GET_MEMBERS_RESPONSE, + CPMSG_GUILD_JOINED, + CPMSG_GUILD_LEFT, + CPMSG_GUILD_INVITED, + CPMSG_GUILD_REJOIN, + 0 + }; + handledMessages = _messages; + +} + +void GuildHandler::handleMessage(MessageIn &msg) +{ + switch (msg.getId()) + { + case CPMSG_GUILD_CREATE_RESPONSE: + { + logger->log("Received CPMSG_GUILD_CREATE_RESPONSE"); + if(msg.readInt8() == ERRMSG_OK) + { + short guildId = msg.readInt16(); + std::string guildName = msg.readString(); + // TODO - Acknowledge guild was created + joinedGuild(guildId, guildName, true); + } + } break; + + case CPMSG_GUILD_INVITE_RESPONSE: + { + logger->log("Received CPMSG_GUILD_INVITE_RESPONSE"); + if(msg.readInt8() == ERRMSG_OK) + { + // TODO - Acknowledge invite was sent + } + } break; + + case CPMSG_GUILD_ACCEPT_RESPONSE: + { + logger->log("Received CPMSG_GUILD_ACCEPT_RESPONSE"); + if(msg.readInt8() == ERRMSG_OK) + { + // TODO - Acknowledge accepted into guild + short guildId = msg.readInt16(); + std::string guildName = msg.readString(); + joinedGuild(guildId, guildName, false); + } + } break; + + case CPMSG_GUILD_GET_MEMBERS_RESPONSE: + { + logger->log("Received CPMSG_GUILD_GET_MEMBERS_RESPONSE"); + if(msg.readInt8() == ERRMSG_OK) + { + std::string guildMember; + Guild *guild; + short guildId = msg.readInt16(); + guild = player_node->findGuildById(guildId); + while(msg.getUnreadLength()) + { + guildMember = msg.readString(); + if(guildMember != "") + { + guild->addMember(guildMember); + } + } + guildWindow->updateTab(); + } + } break; + + case CPMSG_GUILD_INVITED: + { + logger->log("Received CPMSG_GUILD_INVITED"); + std::string inviterName = msg.readString(); + std::string guildName = msg.readString(); + + // Open a dialog asking if the player accepts joining the guild. + guildWindow->openAcceptDialog(inviterName, guildName); + } break; + + case CPMSG_GUILD_REJOIN: + { + logger->log("Received CPMSG_GUILD_REJOIN"); + std::string guildName = msg.readString(); + short guildId = msg.readInt16(); + bool leader = msg.readInt8(); + + joinedGuild(guildId, guildName, leader); + } break; + } +} + +void GuildHandler::joinedGuild(short guildId, const std::string &guildName, bool leader) +{ + // Add guild to player and create new guild tab + player_node->addGuild(guildId, leader); + Guild *guild = player_node->findGuildById(guildId); + guild->setName(guildName); + guildWindow->newGuildTab(guildName); + + guildWindow->requestMemberList(guildId); +} -- cgit v1.2.3-60-g2f50 From 431a0b17e7eee6b27f98b74f4d073f2131a089dd Mon Sep 17 00:00:00 2001 From: David Athay Date: Wed, 5 Mar 2008 18:44:03 +0000 Subject: Fixed guild creation. --- ChangeLog | 3 +++ src/gui/guildwindow.cpp | 4 ++-- src/localplayer.cpp | 62 +++++------------------------------------------- src/localplayer.h | 31 ------------------------ src/net/guildhandler.cpp | 28 +++++++++++----------- src/player.cpp | 45 +++++++++++++++++++++++++++++++++++ src/player.h | 30 +++++++++++++++++++++++ 7 files changed, 100 insertions(+), 103 deletions(-) (limited to 'src/net/guildhandler.cpp') diff --git a/ChangeLog b/ChangeLog index 0329d509..9479626b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,9 @@ * src/game.cpp, src/gui/guildwindow.cpp: Fixed key presses during text dialog in guild window and changed license to standard GPL. + * src/localplayer.cpp, src/localplayer.h, src/player.cpp, + src/player.h, src/gui/guildwindow.cpp, src/net/guildhandler.cpp: + Fixed guild creation. 2008-03-04 Bjørn Lindeijer diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp index c7a828b9..30305ca4 100644 --- a/src/gui/guildwindow.cpp +++ b/src/gui/guildwindow.cpp @@ -153,7 +153,7 @@ void GuildWindow::newGuildTab(const std::string &guildName) tab->setHeight(getHeight() - 2 * tab->getBorderSize()); tab->setOpaque(false); ListBox *list = new ListBox(); - list->setListModel(player_node->findGuildByName(guildName)); + list->setListModel(player_node->getGuild(guildName)); ScrollArea *sa = new ScrollArea(list); sa->setDimension(gcn::Rectangle(5, 5, 135, 250)); tab->add(sa); @@ -192,7 +192,7 @@ bool GuildWindow::isFocused() short GuildWindow::getSelectedGuild() { - return mPlayer->findGuildByName(mGuildsContainer->getActiveWidget())->getId(); + return mPlayer->getGuild(mGuildsContainer->getActiveWidget())->getId(); } void GuildWindow::openAcceptDialog(const std::string &inviterName, const std::string &guildName) diff --git a/src/localplayer.cpp b/src/localplayer.cpp index f581db27..1614b7e7 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -26,6 +26,7 @@ #include "equipment.h" #include "floor_item.h" #include "game.h" +#include "guild.h" #include "inventory.h" #include "item.h" #include "main.h" @@ -116,65 +117,14 @@ void LocalPlayer::nextStep() Player::nextStep(); } -void LocalPlayer::addGuild(short guildId, bool inviteRights) -{ - Guild *guild = new Guild(guildId, inviteRights); - mGuilds.push_back(guild); -} - -void LocalPlayer::removeGuild(short guildId) -{ - std::vector::iterator itr; - for (itr = mGuilds.begin(); itr != mGuilds.end(); ++itr) - { - Guild *guild = (*itr); - if (guild->getId() == guildId) - { - delete guild; - mGuilds.erase(itr); - return; - } - } -} - -Guild* LocalPlayer::findGuildById(short guildId) -{ - for (unsigned int i = 0; i < mGuilds.size(); ++i) - { - if (mGuilds[i]->getId() == guildId) - { - return mGuilds[i]; - } - } - - // not found return NULL - return NULL; -} - -Guild* LocalPlayer::findGuildByName(const std::string &guildName) +bool LocalPlayer::checkInviteRights(const std::string &guildName) { - for (unsigned int i = 0; i < mGuilds.size(); ++i) + Guild *guild = getGuild(guildName); + if (guild) { - if(mGuilds[i]->getName() == guildName) - { - return mGuilds[i]; - } + return guild->getInviteRights(); } - - // Not found, so return NULL - return NULL; -} -short LocalPlayer::getNumberOfGuilds() -{ - return mGuilds.size(); -} - -bool LocalPlayer::checkInviteRights(const std::string &guildName) -{ - Guild *guild = findGuildByName(guildName); - if(guild) - return guild->getInviteRights(); return false; } @@ -446,7 +396,7 @@ void LocalPlayer::lowerAttribute(size_t attr) const std::string& LocalPlayer::getSkillName(int skill) { static const std::string skills[CHAR_SKILL_NB + 1] = - { + { _("Unarmed"), // CHAR_SKILL_WEAPON_NONE _("Knife"), // CHAR_SKILL_WEAPON_KNIFE _("Sword"), // CHAR_SKILL_WEAPON_SWORD diff --git a/src/localplayer.h b/src/localplayer.h index 9b4c7eb3..9bad9436 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -24,7 +24,6 @@ #ifndef _TMW_LOCALPLAYER_H #define _TMW_LOCALPLAYER_H -#include "guild.h" #include "player.h" // TODO move into some sane place... @@ -152,33 +151,6 @@ class LocalPlayer : public Player virtual void drawName(Graphics *, int, int) {}; - /** - * Adds a guild to the local player. - */ - void addGuild(short guildId, bool inviteRights); - - /** - * Removers a guild from the local player. - */ - void removeGuild(short guildId); - - /** - * Finds a guild the local player belongs to, by the guildId - * @return returns the guild associated with the guildId - */ - Guild* findGuildById(short guildId); - - /** - * Finds a guild the local player belongs to, by the guild's name. - * @return returns the guild with that name - */ - Guild* findGuildByName(const std::string &guildName); - - /** - * Get number of guilds the player belongs to - */ - short getNumberOfGuilds(); - /** * Check the player has permission to invite users */ @@ -369,9 +341,6 @@ class LocalPlayer : public Player protected: void walk(unsigned char dir); - // Character guild information - std::vector mGuilds; - // Character status: std::vector mAttributeBase; std::vector mAttributeEffective; diff --git a/src/net/guildhandler.cpp b/src/net/guildhandler.cpp index 48d2e837..5bacaaa1 100644 --- a/src/net/guildhandler.cpp +++ b/src/net/guildhandler.cpp @@ -3,7 +3,7 @@ * A file part of The Mana World * * Created by David Athay on 01/03/2007. - * + * * Copyright (c) 2007, The Mana World Development Team * All rights reserved. * @@ -27,7 +27,7 @@ * * $Id$ */ - +#include #include "guildhandler.h" #include "protocol.h" @@ -55,7 +55,7 @@ GuildHandler::GuildHandler() 0 }; handledMessages = _messages; - + } void GuildHandler::handleMessage(MessageIn &msg) @@ -73,7 +73,7 @@ void GuildHandler::handleMessage(MessageIn &msg) joinedGuild(guildId, guildName, true); } } break; - + case CPMSG_GUILD_INVITE_RESPONSE: { logger->log("Received CPMSG_GUILD_INVITE_RESPONSE"); @@ -82,7 +82,7 @@ void GuildHandler::handleMessage(MessageIn &msg) // TODO - Acknowledge invite was sent } } break; - + case CPMSG_GUILD_ACCEPT_RESPONSE: { logger->log("Received CPMSG_GUILD_ACCEPT_RESPONSE"); @@ -94,7 +94,7 @@ void GuildHandler::handleMessage(MessageIn &msg) joinedGuild(guildId, guildName, false); } } break; - + case CPMSG_GUILD_GET_MEMBERS_RESPONSE: { logger->log("Received CPMSG_GUILD_GET_MEMBERS_RESPONSE"); @@ -103,7 +103,9 @@ void GuildHandler::handleMessage(MessageIn &msg) std::string guildMember; Guild *guild; short guildId = msg.readInt16(); - guild = player_node->findGuildById(guildId); + guild = player_node->getGuild(guildId); + if (!guild) + return; while(msg.getUnreadLength()) { guildMember = msg.readString(); @@ -115,24 +117,24 @@ void GuildHandler::handleMessage(MessageIn &msg) guildWindow->updateTab(); } } break; - + case CPMSG_GUILD_INVITED: { logger->log("Received CPMSG_GUILD_INVITED"); std::string inviterName = msg.readString(); std::string guildName = msg.readString(); - + // Open a dialog asking if the player accepts joining the guild. guildWindow->openAcceptDialog(inviterName, guildName); } break; - + case CPMSG_GUILD_REJOIN: { logger->log("Received CPMSG_GUILD_REJOIN"); std::string guildName = msg.readString(); short guildId = msg.readInt16(); bool leader = msg.readInt8(); - + joinedGuild(guildId, guildName, leader); } break; } @@ -141,10 +143,8 @@ void GuildHandler::handleMessage(MessageIn &msg) void GuildHandler::joinedGuild(short guildId, const std::string &guildName, bool leader) { // Add guild to player and create new guild tab - player_node->addGuild(guildId, leader); - Guild *guild = player_node->findGuildById(guildId); + Guild *guild = player_node->addGuild(guildId, leader); guild->setName(guildName); guildWindow->newGuildTab(guildName); - guildWindow->requestMemberList(guildId); } diff --git a/src/player.cpp b/src/player.cpp index b8789256..2f1fc648 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -26,6 +26,7 @@ #include "animatedsprite.h" #include "game.h" #include "graphics.h" +#include "guild.h" #include "log.h" #include "resources/itemdb.h" @@ -146,3 +147,47 @@ void Player::setSprite(int slot, int id, const std::string &color) Being::setSprite(slot, id, color); } + +Guild* Player::addGuild(short guildId, bool inviteRights) +{ + Guild *guild = new Guild(guildId, inviteRights); + mGuilds.insert(std::pair(guildId, guild)); + return guild; +} + +void Player::removeGuild(int id) +{ + mGuilds.erase(id); +} + +Guild* Player::getGuild(const std::string &guildName) +{ + std::map::iterator itr, itr_end = mGuilds.end(); + for (itr = mGuilds.begin(); itr != itr_end; ++itr) + { + Guild *guild = itr->second; + if (guild->getName() == guildName) + { + return guild; + } + } + + return NULL; +} + +Guild* Player::getGuild(int id) +{ + std::map::iterator itr; + itr = mGuilds.find(id); + if (itr != mGuilds.end()) + { + return itr->second; + } + + return NULL; +} + +short Player::getNumberOfGuilds() +{ + return mGuilds.size(); +} diff --git a/src/player.h b/src/player.h index f6ecbd59..aff75221 100644 --- a/src/player.h +++ b/src/player.h @@ -28,6 +28,7 @@ class Graphics; class Map; +class Guild; enum Gender { GENDER_MALE = 0, @@ -87,6 +88,35 @@ class Player : public Being virtual void setSprite(int slot, int id, const std::string &color = ""); + /** + * Adds a guild to the player. + */ + Guild* addGuild(short guildId, bool inviteRights); + + /** + * Removers a guild from the player. + */ + void removeGuild(int id); + + /** + * Returns a pointer to the specified guild + */ + Guild* getGuild(const std::string &guildName); + + /** + * Returns a pointer to the guild with matching id + */ + Guild* getGuild(int id); + + /** + * Get number of guilds the player belongs to + */ + short getNumberOfGuilds(); + + protected: + // Character guild information + std::map mGuilds; + private: Gender mGender; Uint8 mHairStyle; -- cgit v1.2.3-60-g2f50 From 15014d358424bf5f74a2d9b7afd08692b591a448 Mon Sep 17 00:00:00 2001 From: David Athay Date: Thu, 6 Mar 2008 15:07:47 +0000 Subject: Fixed rejoining guilds after closing client --- ChangeLog | 5 +++++ src/net/guildhandler.cpp | 27 ++++++++++++++++----------- src/net/guildhandler.h | 8 ++++---- 3 files changed, 25 insertions(+), 15 deletions(-) (limited to 'src/net/guildhandler.cpp') diff --git a/ChangeLog b/ChangeLog index 9479626b..0df6b3fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-03-06 David Athay + + * src/net/guildhandler.cpp, src/net/guildhandler.hpp: Fixed + rejoining guilds after quitting. + 2008-03-05 David Athay * src/game.cpp, src/gui/guildwindow.cpp: Fixed key presses during diff --git a/src/net/guildhandler.cpp b/src/net/guildhandler.cpp index 5bacaaa1..88528584 100644 --- a/src/net/guildhandler.cpp +++ b/src/net/guildhandler.cpp @@ -37,6 +37,7 @@ #include "chatserver/guild.h" #include "../gui/guildwindow.h" +#include "../gui/chat.h" #include "../guild.h" #include "../log.h" #include "../localplayer.h" @@ -67,10 +68,8 @@ void GuildHandler::handleMessage(MessageIn &msg) logger->log("Received CPMSG_GUILD_CREATE_RESPONSE"); if(msg.readInt8() == ERRMSG_OK) { - short guildId = msg.readInt16(); - std::string guildName = msg.readString(); // TODO - Acknowledge guild was created - joinedGuild(guildId, guildName, true); + joinedGuild(msg); } } break; @@ -89,9 +88,7 @@ void GuildHandler::handleMessage(MessageIn &msg) if(msg.readInt8() == ERRMSG_OK) { // TODO - Acknowledge accepted into guild - short guildId = msg.readInt16(); - std::string guildName = msg.readString(); - joinedGuild(guildId, guildName, false); + joinedGuild(msg); } } break; @@ -131,20 +128,28 @@ void GuildHandler::handleMessage(MessageIn &msg) case CPMSG_GUILD_REJOIN: { logger->log("Received CPMSG_GUILD_REJOIN"); - std::string guildName = msg.readString(); - short guildId = msg.readInt16(); - bool leader = msg.readInt8(); - joinedGuild(guildId, guildName, leader); + joinedGuild(msg); } break; } } -void GuildHandler::joinedGuild(short guildId, const std::string &guildName, bool leader) +void GuildHandler::joinedGuild(MessageIn &msg) { + std::string guildName = msg.readString(); + short guildId = msg.readInt16(); + bool leader = msg.readInt8(); + short channelId = msg.readInt16(); + // Add guild to player and create new guild tab Guild *guild = player_node->addGuild(guildId, leader); guild->setName(guildName); guildWindow->newGuildTab(guildName); guildWindow->requestMemberList(guildId); + + // Automatically create the guild channel + // COMMENT: Should this go here?? + chatWindow->addChannel(channelId, guildName); + chatWindow->createNewChannelTab(guildName); + chatWindow->chatLog("Guild Channel", BY_SERVER, guildName); } diff --git a/src/net/guildhandler.h b/src/net/guildhandler.h index c76682b2..5ac0a52e 100644 --- a/src/net/guildhandler.h +++ b/src/net/guildhandler.h @@ -3,7 +3,7 @@ * A file part of The Mana World * * Created by David Athay on 01/03/2007. - * + * * Copyright (c) 2007, The Mana World Development Team * All rights reserved. * @@ -39,11 +39,11 @@ class GuildHandler : public MessageHandler { public: GuildHandler(); - + void handleMessage(MessageIn &msg); - + protected: - void joinedGuild(short guildId, const std::string &guildName, bool leader); + void joinedGuild(MessageIn &msg); }; #endif -- cgit v1.2.3-60-g2f50 From 3a275cc81fe9aa1cb6736cdf12211e13e93cf2cf Mon Sep 17 00:00:00 2001 From: David Athay Date: Wed, 12 Mar 2008 10:44:11 +0000 Subject: Added ability to quit guilds. --- ChangeLog | 7 + src/gui/guildwindow.cpp | 56 +- src/gui/guildwindow.h | 27 +- src/net/chatserver/guild.cpp | 26 +- src/net/chatserver/guild.h | 11 +- src/net/guildhandler.cpp | 14 +- src/net/guildhandler.h | 2 +- tmw.cbp | 1965 ++++++++---------------------------------- 8 files changed, 469 insertions(+), 1639 deletions(-) (limited to 'src/net/guildhandler.cpp') diff --git a/ChangeLog b/ChangeLog index fd37f97c..f7760321 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-03-12 David Athay + + * src/gui/guildwindow.cpp, src/gui/guildwindow.h, + src/net/guildhandler.cpp, src/net/guildhandler.h, + src/net/chatserver.cpp, src/net/chatserver.h: Added ability to + quit guilds. + 2008-03-09 Philipp Sehmisch * src/particle.cpp, src/particle.h, src/particleemitter.cpp, diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp index 30305ca4..f81d9209 100644 --- a/src/gui/guildwindow.cpp +++ b/src/gui/guildwindow.cpp @@ -33,12 +33,15 @@ #include "textdialog.h" #include "windowcontainer.h" +#include "widgets/layout.h" + #include "../guild.h" #include "../log.h" #include "../localplayer.h" #include "../net/chatserver/guild.h" #include "../utils/dtor.h" +#include "../utils/gettext.h" GuildWindow::GuildWindow(LocalPlayer *player): Window(player->getName()), @@ -53,19 +56,23 @@ GuildWindow::GuildWindow(LocalPlayer *player): setDefaultSize(124, 41, 288, 330); // Set button events Id - mGuildButton[0] = new Button("Create Guild", "CREATE_GUILD", this); - mGuildButton[1] = new Button("Invite User", "INVITE_USER", this); - mGuildButton[0]->setPosition(15,10); - mGuildButton[1]->setPosition(115,10); + mGuildButton[0] = new Button(_("Create Guild"), "CREATE_GUILD", this); + mGuildButton[1] = new Button(_("Invite User"), "INVITE_USER", this); + mGuildButton[2] = new Button(_("Quit Guild"), "QUIT_GUILD", this); mGuildButton[1]->setEnabled(false); + mGuildButton[2]->setEnabled(false); mGuildsContainer = new TabbedContainer(); mGuildsContainer->setOpaque(false); - add(mGuildButton[0]); - add(mGuildButton[1]); - add(mGuildsContainer); + place(0, 0, mGuildButton[0]); + place(1, 0, mGuildButton[1]); + place(2, 0, mGuildButton[2]); + place(0, 1, mGuildsContainer); + Layout &layout = getLayout(); + layout.setColWidth(0, 48); + layout.setColWidth(1, 65); loadWindowState(player->getName()); } @@ -94,6 +101,13 @@ void GuildWindow::action(const gcn::ActionEvent &event) // Stats Part if (eventId == "CREATE_GUILD") { + if (mGuildsContainer->getNumberOfTabs() > 1) + { + // This is just to limit the number of guild tabs that are created + // TODO: Either limit this server side, or fix the interface issue + chatWindow->chatLog("Current maximum number of guilds ownable is 2", BY_SERVER); + return; + } // Set focus so that guild name to be created can be typed. mFocus = true; guildDialog = new TextDialog("Guild Name", "Choose your guild's name", this); @@ -108,6 +122,15 @@ void GuildWindow::action(const gcn::ActionEvent &event) inviteDialog->setOKButtonActionId("INVITE_USER_OK"); inviteDialog->addActionListener(this); } + else if (eventId == "QUIT_GUILD") + { + short guild = getSelectedGuild(); + if (guild) + { + Net::ChatServer::Guild::quitGuild(guild); + chatWindow->chatLog("Guild " + mGuildsContainer->getActiveWidget() + " quit", BY_SERVER); + } + } else if (eventId == "CREATE_GUILD_OK") { std::string name = guildDialog->getText(); @@ -153,7 +176,7 @@ void GuildWindow::newGuildTab(const std::string &guildName) tab->setHeight(getHeight() - 2 * tab->getBorderSize()); tab->setOpaque(false); ListBox *list = new ListBox(); - list->setListModel(player_node->getGuild(guildName)); + list->setListModel(mPlayer->getGuild(guildName)); ScrollArea *sa = new ScrollArea(list); sa->setDimension(gcn::Rectangle(5, 5, 135, 250)); tab->add(sa); @@ -173,7 +196,6 @@ void GuildWindow::updateTab() void GuildWindow::setTab(const std::string &guildName) { - // Only enable invite button if user has rights if(mPlayer->checkInviteRights(guildName)) { @@ -183,6 +205,8 @@ void GuildWindow::setTab(const std::string &guildName) { mGuildButton[1]->setEnabled(false); } + + mGuildButton[2]->setEnabled(true); } bool GuildWindow::isFocused() @@ -192,7 +216,13 @@ bool GuildWindow::isFocused() short GuildWindow::getSelectedGuild() { - return mPlayer->getGuild(mGuildsContainer->getActiveWidget())->getId(); + Guild *guild = mPlayer->getGuild(mGuildsContainer->getActiveWidget()); + if (guild) + { + return guild->getId(); + } + + return 0; } void GuildWindow::openAcceptDialog(const std::string &inviterName, const std::string &guildName) @@ -211,3 +241,9 @@ void GuildWindow::requestMemberList(short guildId) // Get the list of members for displaying in the guild window. Net::ChatServer::Guild::getGuildMembers(guildId); } + +void GuildWindow::removeTab() +{ + mGuildsContainer->removeTab(mGuildsContainer->getActiveWidget()); + mGuildsContainer->logic(); +} diff --git a/src/gui/guildwindow.h b/src/gui/guildwindow.h index 2f494a9a..e40727b6 100644 --- a/src/gui/guildwindow.h +++ b/src/gui/guildwindow.h @@ -3,7 +3,7 @@ * A file part of The Mana World * * Created by David Athay on 06/03/2007. - * + * * Copyright (c) 2007, The Mana World Development Team * All rights reserved. * @@ -56,7 +56,7 @@ public: * Constructor. */ GuildWindow(LocalPlayer *player); - + /** * Destructor. */ @@ -76,47 +76,52 @@ public: * Updates this dialog. */ void update(); - + /** * Create a new tab for a guild list. */ void newGuildTab(const std::string &guildName); - + /** * Display guild's member list to active tab */ void setTab(const std::string &guildName); - + /** * Update the contents of the active tab */ void updateTab(); - + /** * Check if the window is in focus */ bool isFocused(); - + /** * Create a dialog for accepting an invite */ void openAcceptDialog(const std::string &inviterName, const std::string &guildName); - + /** * Request member list */ void requestMemberList(short guildId); - + + /** + * Removes the selected tab + */ + void removeTab(); + protected: /** * Get selected guild tab * @return Returns selected guild */ short getSelectedGuild(); - + private: LocalPlayer *mPlayer; - gcn::Button *mGuildButton[2]; + gcn::Button *mGuildButton[3]; TextDialog *guildDialog; TextDialog *inviteDialog; ConfirmDialog *acceptDialog; diff --git a/src/net/chatserver/guild.cpp b/src/net/chatserver/guild.cpp index 441a52c2..c1114065 100644 --- a/src/net/chatserver/guild.cpp +++ b/src/net/chatserver/guild.cpp @@ -36,9 +36,9 @@ void Net::ChatServer::Guild::createGuild(const std::string &name) { logger->log("Sending PCMSG_GUILD_CREATE"); MessageOut msg(PCMSG_GUILD_CREATE); - + msg.writeString(name); - + Net::ChatServer::connection->send(msg); } @@ -46,10 +46,10 @@ void Net::ChatServer::Guild::invitePlayer(const std::string &name, short guildId { logger->log("Sending PCMSG_GUILD_INVITE"); MessageOut msg(PCMSG_GUILD_INVITE); - + msg.writeInt16(guildId); msg.writeString(name); - + Net::ChatServer::connection->send(msg); } @@ -57,9 +57,9 @@ void Net::ChatServer::Guild::acceptInvite(const std::string &name) { logger->log("Sending PCMSG_GUILD_ACCEPT"); MessageOut msg(PCMSG_GUILD_ACCEPT); - + msg.writeString(name); - + Net::ChatServer::connection->send(msg); } @@ -67,8 +67,18 @@ void Net::ChatServer::Guild::getGuildMembers(short guildId) { logger->log("Sending PCMSG_GUILD_GET_MEMBERS"); MessageOut msg(PCMSG_GUILD_GET_MEMBERS); - + msg.writeInt16(guildId); - + + Net::ChatServer::connection->send(msg); +} + +void Net::ChatServer::Guild::quitGuild(short guildId) +{ + logger->log("Sending PCMSG_GUILD_QUIT"); + MessageOut msg(PCMSG_GUILD_QUIT); + + msg.writeInt16(guildId); + Net::ChatServer::connection->send(msg); } diff --git a/src/net/chatserver/guild.h b/src/net/chatserver/guild.h index 849cd0a4..5800c738 100644 --- a/src/net/chatserver/guild.h +++ b/src/net/chatserver/guild.h @@ -37,21 +37,26 @@ namespace Net * Create guild. */ void createGuild(const std::string &name); - + /** * Invite a player to your guild. */ void invitePlayer(const std::string &name, short guildId); - + /** * Accept an invite another player has sent to join their guild. */ void acceptInvite(const std::string &name); - + /** * Get a list of members in a guild. */ void getGuildMembers(short guildId); + + /** + * Quit guild. + */ + void quitGuild(short guildId); } } } diff --git a/src/net/guildhandler.cpp b/src/net/guildhandler.cpp index 88528584..0b36f8e4 100644 --- a/src/net/guildhandler.cpp +++ b/src/net/guildhandler.cpp @@ -25,8 +25,9 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE * - * $Id$ + * $Id:$ */ + #include #include "guildhandler.h" @@ -53,6 +54,7 @@ GuildHandler::GuildHandler() CPMSG_GUILD_LEFT, CPMSG_GUILD_INVITED, CPMSG_GUILD_REJOIN, + CPMSG_GUILD_QUIT_RESPONSE, 0 }; handledMessages = _messages; @@ -131,6 +133,16 @@ void GuildHandler::handleMessage(MessageIn &msg) joinedGuild(msg); } break; + + case CPMSG_GUILD_QUIT_RESPONSE: + { + logger->log("Received CPMSG_GUILD_QUIT_RESPONSE"); + + if (msg.readInt8() == ERRMSG_OK) + { + guildWindow->removeTab(); + } + } break; } } diff --git a/src/net/guildhandler.h b/src/net/guildhandler.h index 5ac0a52e..ec5780fc 100644 --- a/src/net/guildhandler.h +++ b/src/net/guildhandler.h @@ -25,7 +25,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE * - * $Id$ + * $Id:$ */ #ifndef _TMW_NET_GUILDHANDLER_H diff --git a/tmw.cbp b/tmw.cbp index 20896c77..c7320210 100644 --- a/tmw.cbp +++ b/tmw.cbp @@ -1,1617 +1,372 @@ - - + - + - -- cgit v1.2.3-60-g2f50 From fabc9567b86e5e6a9b7b463f47869fc13e7ae33b Mon Sep 17 00:00:00 2001 From: David Athay Date: Tue, 1 Apr 2008 17:13:32 +0000 Subject: Fixed up chat and guilds --- ChangeLog | 7 +++++++ src/game.cpp | 2 +- src/gui/chat.cpp | 16 ++++++++++++---- src/gui/guildwindow.cpp | 21 ++++++++++++--------- src/gui/guildwindow.h | 5 ++--- src/net/guildhandler.cpp | 6 +++++- 6 files changed, 39 insertions(+), 18 deletions(-) (limited to 'src/net/guildhandler.cpp') diff --git a/ChangeLog b/ChangeLog index 59f3e486..1a5db191 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-04-01 David Athay + + * src/game.cpp, src/gui/guildwindow.h, src/gui/chat.cpp, + src/gui/guildwindow.cpp, src/net/guildhandler.cpp: Fixed up chat + and guilds. + + 2008-03-31 Philipp Sehmisch * src/main.cpp, src/npc.cpp, src/npc.h, src/resources/npcdb.h, diff --git a/src/game.cpp b/src/game.cpp index 985b7ddc..fcbc5aba 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -201,7 +201,7 @@ void createGuiWindows() //chargeDialog = new ChargeDialog(); tradeWindow = new TradeWindow; //buddyWindow = new BuddyWindow(); - guildWindow = new GuildWindow(player_node); + guildWindow = new GuildWindow(); helpWindow = new HelpWindow(); debugWindow = new DebugWindow(); itemShortcutWindow = new ItemShortcutWindow(); diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index e9bed822..d2ec0ec9 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -286,8 +286,12 @@ void ChatWindow::chatSend(std::string const &nick, std::string const &msg, } else { - int channelId = channelManager->findByName(channelName)->getId(); - Net::ChatServer::chat(channelId, msg); + Channel *channel = channelManager->findByName(channelName); + if (channel) + { + int channelId = channel->getId(); + Net::ChatServer::chat(channelId, msg); + } } return; } @@ -497,8 +501,12 @@ ChatWindow::enterChannel(std::string channel, std::string password) void ChatWindow::sendToChannel(short channelId, std::string user, std::string msg) { - std::string channelName = channelManager->findById(channelId)->getName(); - chatLog(user + ": " + msg, user == player_node->getName() ? BY_PLAYER : BY_OTHER, channelName); + Channel *channel = channelManager->findById(channelId); + if (channel) + { + std::string channelName = channel->getName(); + chatLog(user + ": " + msg, user == player_node->getName() ? BY_PLAYER : BY_OTHER, channelName); + } } void diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp index 76e1a436..970c6ce1 100644 --- a/src/gui/guildwindow.cpp +++ b/src/gui/guildwindow.cpp @@ -45,9 +45,8 @@ #include -GuildWindow::GuildWindow(LocalPlayer *player): - Window(player->getName()), - mPlayer(player), +GuildWindow::GuildWindow(): + Window(player_node->getName()), mFocus(false) { setCaption("Guild"); @@ -76,7 +75,7 @@ GuildWindow::GuildWindow(LocalPlayer *player): layout.setColWidth(0, 48); layout.setColWidth(1, 65); - loadWindowState(player->getName()); + loadWindowState(player_node->getName()); } GuildWindow::~GuildWindow() @@ -178,7 +177,7 @@ void GuildWindow::newGuildTab(const std::string &guildName) tab->setHeight(getHeight() - 2 * tab->getBorderSize()); tab->setOpaque(false); ListBox *list = new ListBox(); - list->setListModel(mPlayer->getGuild(guildName)); + list->setListModel(player_node->getGuild(guildName)); ScrollArea *sa = new ScrollArea(list); sa->setDimension(gcn::Rectangle(5, 5, 135, 250)); tab->add(sa); @@ -199,7 +198,7 @@ void GuildWindow::updateTab() void GuildWindow::setTab(const std::string &guildName) { // Only enable invite button if user has rights - if(mPlayer->checkInviteRights(guildName)) + if(player_node->checkInviteRights(guildName)) { mGuildButton[1]->setEnabled(true); } @@ -218,7 +217,7 @@ bool GuildWindow::isFocused() short GuildWindow::getSelectedGuild() { - Guild *guild = mPlayer->getGuild(mGuildsContainer->getActiveWidget()); + Guild *guild = player_node->getGuild(mGuildsContainer->getActiveWidget()); if (guild) { return guild->getId(); @@ -244,8 +243,12 @@ void GuildWindow::requestMemberList(short guildId) Net::ChatServer::Guild::getGuildMembers(guildId); } -void GuildWindow::removeTab() +void GuildWindow::removeTab(int guildId) { - mGuildsContainer->removeTab(mGuildsContainer->getActiveWidget()); + Guild* guild = player_node->getGuild(guildId); + if (guild) + { + mGuildsContainer->removeTab(guild->getName()); + } mGuildsContainer->logic(); } diff --git a/src/gui/guildwindow.h b/src/gui/guildwindow.h index e40727b6..5f7600e5 100644 --- a/src/gui/guildwindow.h +++ b/src/gui/guildwindow.h @@ -55,7 +55,7 @@ public: /** * Constructor. */ - GuildWindow(LocalPlayer *player); + GuildWindow(); /** * Destructor. @@ -110,7 +110,7 @@ public: /** * Removes the selected tab */ - void removeTab(); + void removeTab(int guildId); protected: /** @@ -120,7 +120,6 @@ protected: short getSelectedGuild(); private: - LocalPlayer *mPlayer; gcn::Button *mGuildButton[3]; TextDialog *guildDialog; TextDialog *inviteDialog; diff --git a/src/net/guildhandler.cpp b/src/net/guildhandler.cpp index 0b36f8e4..70529121 100644 --- a/src/net/guildhandler.cpp +++ b/src/net/guildhandler.cpp @@ -140,7 +140,11 @@ void GuildHandler::handleMessage(MessageIn &msg) if (msg.readInt8() == ERRMSG_OK) { - guildWindow->removeTab(); + // Must remove tab first, as it wont find the guild + // name after its removed from the player + int guildId = msg.readInt16(); + guildWindow->removeTab(guildId); + player_node->removeGuild(guildId); } } break; } -- cgit v1.2.3-60-g2f50 From bcf5c0057dfafbe56f6b83b7300016c57a98041d Mon Sep 17 00:00:00 2001 From: David Athay Date: Thu, 3 Apr 2008 16:41:57 +0000 Subject: Added updating guild member list --- ChangeLog | 2 ++ src/net/guildhandler.cpp | 17 +++++++++++++++-- src/net/protocol.h | 13 ++++++------- 3 files changed, 23 insertions(+), 9 deletions(-) (limited to 'src/net/guildhandler.cpp') diff --git a/ChangeLog b/ChangeLog index 1d9b5f8d..bffdd1c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,8 @@ * src/gui/connection.cpp, src/gui/login.cpp, src/gui/char_select.cpp, src/main.cpp: Added patch from postalworker bug id=117 to fix cancel connecting to a sick server. + * src/net/guildhandler.cpp, src/net/protocol.h: Added updating guild + member list. 2008-04-01 David Athay diff --git a/src/net/guildhandler.cpp b/src/net/guildhandler.cpp index 70529121..494dcdc0 100644 --- a/src/net/guildhandler.cpp +++ b/src/net/guildhandler.cpp @@ -50,8 +50,7 @@ GuildHandler::GuildHandler() CPMSG_GUILD_INVITE_RESPONSE, CPMSG_GUILD_ACCEPT_RESPONSE, CPMSG_GUILD_GET_MEMBERS_RESPONSE, - CPMSG_GUILD_JOINED, - CPMSG_GUILD_LEFT, + CPMSG_GUILD_UPDATE_LIST, CPMSG_GUILD_INVITED, CPMSG_GUILD_REJOIN, CPMSG_GUILD_QUIT_RESPONSE, @@ -117,6 +116,20 @@ void GuildHandler::handleMessage(MessageIn &msg) } } break; + case CPMSG_GUILD_UPDATE_LIST: + { + logger->log("Received CPMSG_GUILD_UPDATE_LIST"); + short guildId = msg.readInt16(); + std::string guildMember = msg.readString(); + + Guild *guild = player_node->getGuild(guildId); + if (guild) + { + guild->addMember(guildMember); + } + guildWindow->updateTab(); + } break; + case CPMSG_GUILD_INVITED: { logger->log("Received CPMSG_GUILD_INVITED"); diff --git a/src/net/protocol.h b/src/net/protocol.h index acabb77b..748a4e11 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -133,20 +133,19 @@ enum { // Guild PCMSG_GUILD_CREATE = 0x0350, // S name - CPMSG_GUILD_CREATE_RESPONSE = 0x0351, // B error, W id, S name + CPMSG_GUILD_CREATE_RESPONSE = 0x0351, // B error, W guild, B rights, W channel PCMSG_GUILD_INVITE = 0x0352, // W id, S name CPMSG_GUILD_INVITE_RESPONSE = 0x0353, // B error PCMSG_GUILD_ACCEPT = 0x0354, // W id - CPMSG_GUILD_ACCEPT_RESPONSE = 0x0355, // B error, W id, S name, W leader + CPMSG_GUILD_ACCEPT_RESPONSE = 0x0355, // B error, W guild, B rights, W channel PCMSG_GUILD_GET_MEMBERS = 0x0356, // W id CPMSG_GUILD_GET_MEMBERS_RESPONSE = 0x0357, // S names + CPMSG_GUILD_UPDATE_LIST = 0x0358, // W id, S name PCMSG_GUILD_QUIT = 0x0360, // W id CPMSG_GUILD_QUIT_RESPONSE = 0x0361, // B error - - CPMSG_GUILD_INVITED = 0x0370, // S name, S name - CPMSG_GUILD_REJOIN = 0x0371, // S name, W id, W rights - CPMSG_GUILD_JOINED = 0x90, - CPMSG_GUILD_LEFT = 0x90, + + CPMSG_GUILD_INVITED = 0x0370, // S char name, S guild name, W id + CPMSG_GUILD_REJOIN = 0x0371, // S name, W guild, B rights, W channel // Chat CPMSG_ERROR = 0x0401, // B error -- cgit v1.2.3-60-g2f50 From e2e4ceb9fa8a72ad94853f74724676fff82b15c0 Mon Sep 17 00:00:00 2001 From: David Athay Date: Tue, 15 Apr 2008 15:42:04 +0000 Subject: Added online status of guild members --- ChangeLog | 11 +++++++++++ data/graphics/gui/circle-gray.png | Bin 0 -> 295 bytes data/graphics/gui/circle-green.png | Bin 0 -> 299 bytes src/Makefile.am | 2 ++ src/gui/guildlistbox.cpp | 35 ++++++++++++++++++++++++++--------- src/gui/guildlistbox.h | 26 +++++++++++++++++--------- src/gui/guildwindow.cpp | 18 +++++++++++++++--- src/gui/guildwindow.h | 7 ++++++- src/gui/widgets/tabbedarea.cpp | 15 ++++++++++++++- src/gui/widgets/tabbedarea.h | 6 ++++++ src/net/chathandler.cpp | 23 ++++++++++++++++++++++- src/net/chatserver/chatserver.cpp | 9 +++++++++ src/net/chatserver/chatserver.h | 2 ++ src/net/guildhandler.cpp | 11 +++++++++++ src/net/protocol.h | 2 +- tmw.cbp | 5 ++--- 16 files changed, 144 insertions(+), 28 deletions(-) create mode 100644 data/graphics/gui/circle-gray.png create mode 100644 data/graphics/gui/circle-green.png (limited to 'src/net/guildhandler.cpp') diff --git a/ChangeLog b/ChangeLog index 63d46e50..f45af6e5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-04-15 David Athay + + * src/gui/guildlistbox.cpp, src/gui/guildwindow.h + src/gui/widgets/tabbedarea.h, src/gui/widgets/tabbedarea.cpp, + src/gui/guildlistbox.h, src/gui/guildwindow.cpp, + src/net/guildhandler.cpp, src/net/protocol.h, src/net/chathandler.cpp, + src/net/chatserver/chatserver.cpp, src/net/chatserver/chatserver.h, + src/Makefile.am, data/graphics/gui/circle-green.png + data/graphics/gui/circle-gray.png, tmw.cbp: Added online status of + guild members. + 2008-04-14 Yohann Ferreira * src/CMakeLists.txt: Fixed (again) a compilation error using CMake. diff --git a/data/graphics/gui/circle-gray.png b/data/graphics/gui/circle-gray.png new file mode 100644 index 00000000..719b0b10 Binary files /dev/null and b/data/graphics/gui/circle-gray.png differ diff --git a/data/graphics/gui/circle-green.png b/data/graphics/gui/circle-green.png new file mode 100644 index 00000000..bab39e05 Binary files /dev/null and b/data/graphics/gui/circle-green.png differ diff --git a/src/Makefile.am b/src/Makefile.am index c46fe481..3cfa64ea 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,6 +7,8 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/widgets/layout.h \ gui/widgets/resizegrip.cpp \ gui/widgets/resizegrip.h \ + gui/widgets/tabbedarea.cpp \ + gui/widgets/tabbedarea.h \ gui/box.h \ gui/box.cpp \ gui/browserbox.cpp \ diff --git a/src/gui/guildlistbox.cpp b/src/gui/guildlistbox.cpp index 11661235..1c14fd55 100644 --- a/src/gui/guildlistbox.cpp +++ b/src/gui/guildlistbox.cpp @@ -1,6 +1,6 @@ /* * The Mana World - * Copyright 2004 The Mana World Development Team + * Copyright 2008 The Mana World Development Team * * This file is part of The Mana World. * @@ -18,25 +18,32 @@ * along with The Mana World; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id$ + * $Id $ */ #include "guildlistbox.h" #include "../graphics.h" +#include "../resources/image.h" +#include "../resources/resourcemanager.h" + #include GuildListBox::GuildListBox(): ListBox(NULL) { + onlineIcon = ResourceManager::getInstance()->getImage("graphics/gui/circle-green.png"); + offlineIcon = ResourceManager::getInstance()->getImage("graphics/gui/circle-gray.png"); } -void GuildListBox::draw(gcn::Graphics *graphics) +void GuildListBox::draw(gcn::Graphics *gcnGraphics) { if (!mListModel) return; + Graphics *graphics = static_cast(gcnGraphics); + graphics->setColor(gcn::Color(110, 160, 255)); graphics->setFont(getFont()); @@ -48,17 +55,22 @@ void GuildListBox::draw(gcn::Graphics *graphics) getWidth(), fontHeight)); } - // TODO: Add online status image - // Draw the list elements for (int i = 0, y = 0; i < mListModel->getNumberOfElements(); ++i, y += fontHeight) { - graphics->drawText(mListModel->getElementAt(i), 1, y); + // Draw online status + bool online = mUsers[mListModel->getElementAt(i)]; + Image *icon = online ? onlineIcon : offlineIcon; + if (icon) + graphics->drawImage(icon, 1, y); + // Draw Name + graphics->setColor(gcn::Color(0, 0, 0)); + graphics->drawText(mListModel->getElementAt(i), 33, y); } } - +/* void GuildListBox::setSelected(int selected) { if (!mListModel) @@ -84,14 +96,19 @@ void GuildListBox::setSelected(int selected) distributeValueChangedEvent(); } - +*/ void GuildListBox::mousePressed(gcn::MouseEvent &event) { if (event.getButton() == gcn::MouseEvent::LEFT) { - // TODO: Add guild functions, ie private messaging int y = event.getY(); setSelected(y / getFont()->getHeight()); distributeActionEvent(); } + // TODO: Add guild functions, ie private messaging +} + +void GuildListBox::setOnlineStatus(const std::string &user, bool online) +{ + mUsers[user] = online; } diff --git a/src/gui/guildlistbox.h b/src/gui/guildlistbox.h index 262012a4..0f030d0a 100644 --- a/src/gui/guildlistbox.h +++ b/src/gui/guildlistbox.h @@ -1,6 +1,6 @@ /* * The Mana World - * Copyright 2004 The Mana World Development Team + * Copyright 2008 The Mana World Development Team * * This file is part of The Mana World. * @@ -18,17 +18,20 @@ * along with The Mana World; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id$ + * $Id $ */ #ifndef _TMW_GUI_GUILDLISTBOX_H #define _TMW_GUI_GUILDLISTBOX_H +#include #include #include #include "listbox.h" +class Image; + class GuildListBox : public ListBox { public: @@ -37,22 +40,27 @@ public: */ GuildListBox(); - /** - * Set ListModel - */ - void setList(gcn::ListModel *listModel); - /** * Draws the list box. */ - void draw(gcn::Graphics *graphics); + void draw(gcn::Graphics *gcnGraphics); void mousePressed(gcn::MouseEvent &event); /** * Sets the index of the selected element. */ - void setSelected(int selected); +// void setSelected(int selected); + + /** + * Set whether a member is online or offline + */ + void setOnlineStatus(const std::string &user, bool online); + +private: + Image *onlineIcon; + Image *offlineIcon; + std::map mUsers; }; #endif diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp index 7b69f9bf..7237a870 100644 --- a/src/gui/guildwindow.cpp +++ b/src/gui/guildwindow.cpp @@ -84,7 +84,7 @@ GuildWindow::~GuildWindow() void GuildWindow::update() { - + updateTab(); } void GuildWindow::draw(gcn::Graphics *g) @@ -172,7 +172,7 @@ void GuildWindow::newGuildTab(const std::string &guildName) { // Create new tab - ListBox *list = new ListBox(); + GuildListBox *list = new GuildListBox(); list->setListModel(player_node->getGuild(guildName)); ScrollArea *sa = new ScrollArea(list); sa->setDimension(gcn::Rectangle(5, 5, 135, 250)); @@ -224,7 +224,8 @@ short GuildWindow::getSelectedGuild() return 0; } -void GuildWindow::openAcceptDialog(const std::string &inviterName, const std::string &guildName) +void GuildWindow::openAcceptDialog(const std::string &inviterName, + const std::string &guildName) { std::string msg = inviterName + " has invited you to join the guild " + guildName; chatWindow->chatLog(msg, BY_SERVER); @@ -248,6 +249,17 @@ void GuildWindow::removeTab(int guildId) { gcn::Tab *tab = mGuildTabs->getTab(guild->getName()); mGuildTabs->removeTab(tab); + updateTab(); } mGuildTabs->logic(); } + +void GuildWindow::setOnline(const std::string &guildName, const std::string &member, + bool online) +{ + GuildListBox *box = dynamic_cast(mGuildTabs->getWidget(guildName)); + if (box) + { + box->setOnlineStatus(member, online); + } +} diff --git a/src/gui/guildwindow.h b/src/gui/guildwindow.h index f6cb38fd..b85ca3a5 100644 --- a/src/gui/guildwindow.h +++ b/src/gui/guildwindow.h @@ -112,6 +112,12 @@ public: */ void removeTab(int guildId); + /** + * Set guild member status in userlist + */ + void setOnline(const std::string &guildName, const std::string &member, + bool online); + protected: /** * Get selected guild tab @@ -125,7 +131,6 @@ private: TextDialog *inviteDialog; ConfirmDialog *acceptDialog; TabbedArea *mGuildTabs; - GuildListBox *mGuildMembersList; ScrollArea *mScrollArea; bool mFocus; std::string invitedGuild; diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index 6ba27622..20c100e5 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -56,7 +56,6 @@ void TabbedArea::draw(gcn::Graphics *graphics) return; } - std::vector< std::pair >::iterator itr; unsigned int i; for (i = 0; i < mTabs.size(); i++) { @@ -71,3 +70,17 @@ void TabbedArea::draw(gcn::Graphics *graphics) gcn::TabbedArea::draw(graphics); } + +gcn::Widget* TabbedArea::getWidget(const std::string &name) +{ + unsigned int i; + for (i = 0; i < mTabs.size(); i++) + { + if (mTabs[i].first->getCaption() == name) + { + return mTabs[i].second; + } + } + + return NULL; +} diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h index 42275fae..3f58acde 100644 --- a/src/gui/widgets/tabbedarea.h +++ b/src/gui/widgets/tabbedarea.h @@ -24,6 +24,7 @@ #ifndef _TMW_TABBEDAREA_H #define _TMW_TABBEDAREA_H +#include #include #include @@ -54,6 +55,11 @@ class TabbedArea : public gcn::TabbedArea * Return tab with specified name as caption */ gcn::Tab* getTab(const std::string &name); + + /** + * Return selected tab's widget + */ + gcn::Widget* getWidget(const std::string &name); }; #endif diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp index 4d48865a..d8a228ea 100644 --- a/src/net/chathandler.cpp +++ b/src/net/chathandler.cpp @@ -35,6 +35,7 @@ #include "../game.h" #include "../gui/chat.h" +#include "../gui/guildwindow.h" #include "../utils/tostring.h" @@ -49,6 +50,7 @@ ChatHandler::ChatHandler() CPMSG_LIST_CHANNELS_RESPONSE, CPMSG_PUBMSG, CPMSG_QUIT_CHANNEL_RESPONSE, + CPMSG_LIST_CHANNELUSERS_RESPONSE, /* SMSG_BEING_CHAT, SMSG_PLAYER_CHAT, @@ -106,9 +108,13 @@ void ChatHandler::handleMessage(MessageIn &msg) channelName = msg.readString(); std::string announcement = msg.readString(); std::vector userList; + std::string user; while(msg.getUnreadLength()) { - userList.push_back(msg.readString()); + user = msg.readString(); + if (user == "") + break; + userList.push_back(user); } chatWindow->addChannel(channelId, channelName); chatWindow->createNewChannelTab(channelName); @@ -125,6 +131,8 @@ void ChatHandler::handleMessage(MessageIn &msg) while(msg.getUnreadLength()) { channelName = msg.readString(); + if (channelName == "") + break; std::ostringstream numUsers; numUsers << msg.readInt16(); if(channelName != "") @@ -164,6 +172,19 @@ void ChatHandler::handleMessage(MessageIn &msg) chatWindow->removeChannel(channelId); } break; + + case CPMSG_LIST_CHANNELUSERS_RESPONSE: + channelName = msg.readString(); + while(msg.getUnreadLength()) + { + userNick = msg.readString(); + if (userNick == "") + { + break; + } + guildWindow->setOnline(channelName, userNick, true); + } + break; /* // Received speech from being case SMSG_BEING_CHAT: diff --git a/src/net/chatserver/chatserver.cpp b/src/net/chatserver/chatserver.cpp index 93fdc828..67cb5796 100644 --- a/src/net/chatserver/chatserver.cpp +++ b/src/net/chatserver/chatserver.cpp @@ -128,3 +128,12 @@ void Net::ChatServer::getChannelList() connection->send(msg); } + +void Net::ChatServer::getUserList(const std::string &channel) +{ + MessageOut msg(PCMSG_LIST_CHANNELUSERS); + + msg.writeString(channel); + + connection->send(msg); +} diff --git a/src/net/chatserver/chatserver.h b/src/net/chatserver/chatserver.h index c4e0003d..b49d0c9e 100644 --- a/src/net/chatserver/chatserver.h +++ b/src/net/chatserver/chatserver.h @@ -54,6 +54,8 @@ namespace Net void getChannelList(); + void getUserList(const std::string &channel); + } } diff --git a/src/net/guildhandler.cpp b/src/net/guildhandler.cpp index 494dcdc0..fd23546c 100644 --- a/src/net/guildhandler.cpp +++ b/src/net/guildhandler.cpp @@ -99,20 +99,30 @@ void GuildHandler::handleMessage(MessageIn &msg) if(msg.readInt8() == ERRMSG_OK) { std::string guildMember; + std::string guildName; Guild *guild; + short guildId = msg.readInt16(); guild = player_node->getGuild(guildId); + if (!guild) return; + + guildName = guild->getName(); + while(msg.getUnreadLength()) { guildMember = msg.readString(); if(guildMember != "") { guild->addMember(guildMember); + guildWindow->setOnline(guildName, guildMember, false); } } + guildWindow->updateTab(); + + Net::ChatServer::getUserList(guildName); } } break; @@ -126,6 +136,7 @@ void GuildHandler::handleMessage(MessageIn &msg) if (guild) { guild->addMember(guildMember); + guildWindow->setOnline(guild->getName(), guildMember, false); } guildWindow->updateTab(); } break; diff --git a/src/net/protocol.h b/src/net/protocol.h index 748a4e11..79e1f2ca 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -171,7 +171,7 @@ enum { CPMSG_USERJOINED = 0x0450, // W channel, S name CPMSG_USERLEFT = 0x0451, // W channel, S name PCMSG_LIST_CHANNELUSERS = 0x0460, // S channel - CPMSG_LIST_CHANNELUSERS_RESPONSE = 0x0461, // S users + CPMSG_LIST_CHANNELUSERS_RESPONSE = 0x0461, // S channel, S users XXMSG_INVALID = 0x7FFF }; diff --git a/tmw.cbp b/tmw.cbp index d503d01d..d30bb0e2 100644 --- a/tmw.cbp +++ b/tmw.cbp @@ -303,9 +303,6 @@ - -