summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2008-04-01 17:13:32 +0000
committerDavid Athay <ko2fan@gmail.com>2008-04-01 17:13:32 +0000
commitfabc9567b86e5e6a9b7b463f47869fc13e7ae33b (patch)
treeae16d0ff935b55532ccb4b33ef5ec038475d4f30 /src
parentc95ad0a99169868a2c3169999f0498b8de391a12 (diff)
downloadmana-fabc9567b86e5e6a9b7b463f47869fc13e7ae33b.tar.gz
mana-fabc9567b86e5e6a9b7b463f47869fc13e7ae33b.tar.bz2
mana-fabc9567b86e5e6a9b7b463f47869fc13e7ae33b.tar.xz
mana-fabc9567b86e5e6a9b7b463f47869fc13e7ae33b.zip
Fixed up chat and guilds
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp2
-rw-r--r--src/gui/chat.cpp16
-rw-r--r--src/gui/guildwindow.cpp21
-rw-r--r--src/gui/guildwindow.h5
-rw-r--r--src/net/guildhandler.cpp6
5 files changed, 32 insertions, 18 deletions
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 <algorithm>
-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;
}