summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2008-02-28 12:31:04 +0000
committerDavid Athay <ko2fan@gmail.com>2008-02-28 12:31:04 +0000
commitfb3cbeddd6f5d59e3f83da059b2a1d4bed2cb80f (patch)
tree65e3086f341bb92154e99806f3b6255d9696ed4b /src
parentac2de5e0bd7dfc79e344b6724ee6a13db9994aa4 (diff)
downloadMana-fb3cbeddd6f5d59e3f83da059b2a1d4bed2cb80f.tar.gz
Mana-fb3cbeddd6f5d59e3f83da059b2a1d4bed2cb80f.tar.bz2
Mana-fb3cbeddd6f5d59e3f83da059b2a1d4bed2cb80f.tar.xz
Mana-fb3cbeddd6f5d59e3f83da059b2a1d4bed2cb80f.zip
Work in Progress commit of guilds.
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp10
-rw-r--r--src/game.h1
-rw-r--r--src/gui/gui.cpp4
-rw-r--r--src/gui/guildlistbox.cpp98
-rw-r--r--src/gui/guildlistbox.h76
-rw-r--r--src/gui/guildwindow.cpp223
-rw-r--r--src/gui/guildwindow.h133
-rw-r--r--src/gui/listbox.cpp6
-rw-r--r--src/gui/listbox.h1
-rw-r--r--src/gui/menuwindow.cpp6
-rw-r--r--src/gui/setup.cpp2
-rw-r--r--src/gui/textdialog.cpp93
-rw-r--r--src/gui/textdialog.h67
-rw-r--r--src/gui/truetypefont.h4
-rw-r--r--src/guild.cpp52
-rw-r--r--src/guild.h85
-rw-r--r--src/localplayer.cpp62
-rw-r--r--src/localplayer.h36
-rw-r--r--src/net/chatserver/guild.cpp74
-rw-r--r--src/net/chatserver/guild.h60
-rw-r--r--src/net/guildhandler.cpp150
-rw-r--r--src/net/guildhandler.h49
-rw-r--r--src/net/protocol.h42
-rw-r--r--src/openglgraphics.cpp2
24 files changed, 1323 insertions, 13 deletions
diff --git a/src/game.cpp b/src/game.cpp
index cf6dc547..24eeb88d 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -52,6 +52,7 @@
#include "gui/debugwindow.h"
#include "gui/equipmentwindow.h"
#include "gui/gui.h"
+#include "gui/guildwindow.h"
#include "gui/help.h"
#include "gui/inventorywindow.h"
#include "gui/itemshortcutwindow.h"
@@ -73,6 +74,7 @@
#include "net/beinghandler.h"
#include "net/buysellhandler.h"
#include "net/chathandler.h"
+#include "net/guildhandler.h"
#include "net/inventoryhandler.h"
#include "net/itemhandler.h"
#include "net/network.h"
@@ -117,6 +119,7 @@ EquipmentWindow *equipmentWindow;
//ChargeDialog *chargeDialog;
TradeWindow *tradeWindow;
//BuddyWindow *buddyWindow;
+GuildWindow *guildWindow;
HelpWindow *helpWindow;
DebugWindow *debugWindow;
ItemShortcutWindow *itemShortcutWindow;
@@ -198,6 +201,7 @@ void createGuiWindows()
//chargeDialog = new ChargeDialog();
tradeWindow = new TradeWindow;
//buddyWindow = new BuddyWindow();
+ guildWindow = new GuildWindow(player_node);
helpWindow = new HelpWindow();
debugWindow = new DebugWindow();
itemShortcutWindow = new ItemShortcutWindow();
@@ -244,6 +248,7 @@ void destroyGuiWindows()
//delete newSkillWindow;
delete tradeWindow;
//delete buddyWindow;
+ delete guildWindow;
delete helpWindow;
delete debugWindow;
delete itemShortcutWindow;
@@ -253,6 +258,7 @@ Game::Game():
mBeingHandler(new BeingHandler()),
mBuySellHandler(new BuySellHandler()),
mChatHandler(new ChatHandler()),
+ mGuildHandler(new GuildHandler()),
mInventoryHandler(new InventoryHandler()),
mItemHandler(new ItemHandler()),
mNpcHandler(new NPCHandler()),
@@ -295,6 +301,7 @@ Game::Game():
Net::registerHandler(mBeingHandler.get());
Net::registerHandler(mBuySellHandler.get());
Net::registerHandler(mChatHandler.get());
+ Net::registerHandler(mGuildHandler.get());
Net::registerHandler(mInventoryHandler.get());
Net::registerHandler(mItemHandler.get());
Net::registerHandler(mNpcHandler.get());
@@ -338,7 +345,7 @@ bool saveScreenshot(SDL_Surface *screenshot)
do {
screenshotCount++;
filename.str("");
-#if (defined __USE_UNIX98 || defined __FreeBSD__ || defined __APPLE__)
+#if (defined __USE_UNIX98 || defined __FreeBSD__)
filename << PHYSFS_getUserDir() << ".tmw/";
#elif defined __APPLE__
filename << PHYSFS_getUserDir() << "Desktop/";
@@ -606,6 +613,7 @@ void Game::handleInput()
equipmentWindow->setVisible(false);
helpWindow->setVisible(false);
debugWindow->setVisible(false);
+ guildWindow->setVisible(false);
}
break;
}
diff --git a/src/game.h b/src/game.h
index fc7e33df..3b27660a 100644
--- a/src/game.h
+++ b/src/game.h
@@ -63,6 +63,7 @@ class Game : public ConfigListener
MessageHandlerPtr mBeingHandler;
MessageHandlerPtr mBuySellHandler;
MessageHandlerPtr mChatHandler;
+ MessageHandlerPtr mGuildHandler;
MessageHandlerPtr mInventoryHandler;
MessageHandlerPtr mItemHandler;
MessageHandlerPtr mNpcHandler;
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 8f5ffd50..2ef7aba3 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -26,7 +26,11 @@
#include <guichan/exception.hpp>
#include <guichan/image.hpp>
#include <guichan/imagefont.hpp>
+#ifdef __APPLE__
+#include <SDL_ttf/SDL_ttf.h>
+#else
#include <SDL/SDL_ttf.h>
+#endif
#include "focushandler.h"
#include "sdlinput.h"
diff --git a/src/gui/guildlistbox.cpp b/src/gui/guildlistbox.cpp
new file mode 100644
index 00000000..1a392d2d
--- /dev/null
+++ b/src/gui/guildlistbox.cpp
@@ -0,0 +1,98 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#include "guildlistbox.h"
+
+#include "../graphics.h"
+
+#include <guichan/font.hpp>
+
+GuildListBox::GuildListBox():
+ ListBox(NULL)
+{
+
+}
+
+void GuildListBox::draw(gcn::Graphics *graphics)
+{
+ if (!mListModel)
+ return;
+
+ graphics->setColor(gcn::Color(110, 160, 255));
+ graphics->setFont(getFont());
+
+ int fontHeight = getFont()->getHeight();
+
+ // Draw rectangle below the selected list element
+ if (mSelected >= 0) {
+ graphics->fillRectangle(gcn::Rectangle(0, fontHeight * mSelected,
+ 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);
+ }
+}
+
+void GuildListBox::setSelected(int selected)
+{
+ if (!mListModel)
+ {
+ mSelected = -1;
+ }
+ else
+ {
+ // Update mSelected with bounds checking
+ mSelected = std::min(mListModel->getNumberOfElements() - 1,
+ std::max(-1, selected));
+
+ gcn::Widget *parent;
+ parent = (gcn::Widget*)getParent();
+ if (parent)
+ {
+ gcn::Rectangle scroll;
+ scroll.y = (mSelected < 0) ? 0 : getFont()->getHeight() * mSelected;
+ scroll.height = getFont()->getHeight();
+ parent->showWidgetPart(this, scroll);
+ }
+ }
+
+ fireSelectionChangedEvent();
+}
+
+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());
+ generateAction();
+ }
+}
diff --git a/src/gui/guildlistbox.h b/src/gui/guildlistbox.h
new file mode 100644
index 00000000..befaef1f
--- /dev/null
+++ b/src/gui/guildlistbox.h
@@ -0,0 +1,76 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMW_GUI_GUILDLISTBOX_H
+#define _TMW_GUI_GUILDLISTBOX_H
+
+#include <string>
+#include <vector>
+
+#include "listbox.h"
+
+class GuildListBox : public ListBox
+{
+public:
+ /**
+ * Constructor
+ */
+ GuildListBox();
+
+ /**
+ * Set ListModel
+ */
+ void setList(gcn::ListModel *listModel);
+
+ /**
+ * Draws the list box.
+ */
+ void draw(gcn::Graphics *graphics);
+
+ void mousePressed(gcn::MouseEvent &event);
+
+ /**
+ * Adds a listener to the list that's notified each time a change to
+ * the selection occurs.
+ */
+ void addSelectionListener(SelectionListener *listener)
+ {
+ mListeners.push_back(listener);
+ }
+
+ /**
+ * Removes a listener from the list that's notified each time a change
+ * to the selection occurs.
+ */
+ void removeSelectionListener(SelectionListener *listener)
+ {
+ mListeners.remove(listener);
+ }
+
+ /**
+ * Sets the index of the selected element.
+ */
+ void setSelected(int selected);
+};
+
+#endif
diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp
new file mode 100644
index 00000000..a3d46ff5
--- /dev/null
+++ b/src/gui/guildwindow.cpp
@@ -0,0 +1,223 @@
+/*
+ * guildwindow.cpp
+ * A file part of The Mana World
+ *
+ * Created by David Athay on 06/03/2007.
+ *
+ * Copyright (c) 2007, David Athay
+ * 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.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * 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 "guildwindow.h"
+
+#include "button.h"
+#include "chat.h"
+#include "confirm_dialog.h"
+#include "gccontainer.h"
+#include "guildlistbox.h"
+#include "scrollarea.h"
+#include "tabbedcontainer.h"
+#include "textdialog.h"
+#include "windowcontainer.h"
+
+#include "../guild.h"
+#include "../log.h"
+#include "../localplayer.h"
+
+#include "../net/chatserver/guild.h"
+#include "../utils/dtor.h"
+
+GuildWindow::GuildWindow(LocalPlayer *player):
+ Window(player->getName()),
+ mPlayer(player),
+ mFocus(false)
+{
+ setCaption("Guild");
+ setResizable(true);
+ setCloseButton(true);
+ setMinWidth(200);
+ setMinHeight(280);
+ 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[1]->setEnabled(false);
+
+ mGuildsContainer = new TabbedContainer();
+
+ mGuildsContainer->setOpaque(false);
+
+ add(mGuildButton[0]);
+ add(mGuildButton[1]);
+ add(mGuildsContainer);
+
+ loadWindowState(player->getName());
+}
+
+GuildWindow::~GuildWindow()
+{
+ for_each(mTabs.begin(), mTabs.end(), make_dtor(mTabs));
+}
+
+void GuildWindow::update()
+{
+
+}
+
+void GuildWindow::draw(gcn::Graphics *g)
+{
+ update();
+
+ Window::draw(g);
+}
+
+void GuildWindow::action(const gcn::ActionEvent &event)
+{
+ const std::string &eventId = event.getId();
+
+ // Stats Part
+ if (eventId == "CREATE_GUILD")
+ {
+ // 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);
+ guildDialog->setOKButtonActionId("CREATE_GUILD_OK");
+ guildDialog->addActionListener(this);
+ }
+ else if (eventId == "INVITE_USER")
+ {
+ // TODO - Process Invite User button clicked
+ mFocus = true;
+ inviteDialog = new TextDialog("Member Invite", "Who would you like to invite?", this);
+ inviteDialog->setOKButtonActionId("INVITE_USER_OK");
+ inviteDialog->addActionListener(this);
+ }
+ else if (eventId == "CREATE_GUILD_OK")
+ {
+ std::string name = guildDialog->getText();
+ if(name.size() > 16)
+ {
+ // TODO : State too many characters in input.
+ return;
+ }
+ // Process guild name to be created, and unfocus.
+ Net::ChatServer::Guild::createGuild(name);
+
+ // Defocus dialog
+ mFocus = false;
+ chatWindow->chatLog("Creating Guild called " + name, BY_SERVER);
+ guildDialog->scheduleDelete();
+ }
+ else if (eventId == "INVITE_USER_OK")
+ {
+ std::string name = inviteDialog->getText();
+ short selectedGuild = getSelectedGuild();
+
+ // Process invited user to be created and unfocus.
+ Net::ChatServer::Guild::invitePlayer(name, selectedGuild);
+
+ // Defocus dialog
+ mFocus = false;
+ chatWindow->chatLog("Invited user " + name, BY_SERVER);
+ inviteDialog->scheduleDelete();
+ }
+ else if (eventId == "yes")
+ {
+ logger->log("Sending invitation acceptance.");
+ Net::ChatServer::Guild::acceptInvite(invitedGuild);
+ }
+}
+
+void GuildWindow::newGuildTab(const std::string &guildName)
+{
+
+ // Create new tab
+ GCContainer *tab = new GCContainer();
+ tab->setWidth(getWidth() - 2 * tab->getBorderSize());
+ tab->setHeight(getHeight() - 2 * tab->getBorderSize());
+ tab->setOpaque(false);
+ ListBox *list = new ListBox();
+ list->setListModel(player_node->findGuildByName(guildName));
+ ScrollArea *sa = new ScrollArea(list);
+ sa->setDimension(gcn::Rectangle(5, 5, 135, 250));
+ tab->add(sa);
+
+ mGuildsContainer->addTab(tab, guildName);
+ mGuildsContainer->setDimension(gcn::Rectangle(28,35,280,250));
+
+ mTabs.push_back(tab);
+
+ updateTab();
+}
+
+void GuildWindow::updateTab()
+{
+ setTab(mGuildsContainer->getActiveWidget());
+}
+
+void GuildWindow::setTab(const std::string &guildName)
+{
+
+ // Only enable invite button if user has rights
+ if(mPlayer->checkInviteRights(guildName))
+ {
+ mGuildButton[1]->setEnabled(true);
+ }
+ else
+ {
+ mGuildButton[1]->setEnabled(false);
+ }
+}
+
+bool GuildWindow::isFocused()
+{
+ return mFocus;
+}
+
+short GuildWindow::getSelectedGuild()
+{
+ return mPlayer->findGuildByName(mGuildsContainer->getActiveWidget())->getId();
+}
+
+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);
+
+ acceptDialog = new ConfirmDialog("Accept Guild Invite", msg, this);
+ acceptDialog->addActionListener(this);
+
+ invitedGuild = guildName;
+}
+
+void GuildWindow::requestMemberList(short guildId)
+{
+ // Get the list of members for displaying in the guild window.
+ Net::ChatServer::Guild::getGuildMembers(guildId);
+}
diff --git a/src/gui/guildwindow.h b/src/gui/guildwindow.h
new file mode 100644
index 00000000..2f494a9a
--- /dev/null
+++ b/src/gui/guildwindow.h
@@ -0,0 +1,133 @@
+/*
+ * guildwindow.h
+ * 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.
+ *
+ * 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$
+ */
+
+#ifndef _TMW_GUI_GUILDWINDOW_H
+#define _TMW_GUI_GUILDWINDOW_H
+
+#include <iosfwd>
+#include <vector>
+
+#include <guichan/actionlistener.hpp>
+#include <guichan/widgets/listbox.hpp>
+
+#include "window.h"
+
+#include "../guichanfwd.h"
+
+class LocalPlayer;
+class TextDialog;
+class ConfirmDialog;
+class GuildListBox;
+class TabbedContainer;
+class ScrollArea;
+class GCContainer;
+
+class GuildWindow : public Window, public gcn::ActionListener
+{
+public:
+ /**
+ * Constructor.
+ */
+ GuildWindow(LocalPlayer *player);
+
+ /**
+ * Destructor.
+ */
+ ~GuildWindow();
+
+ /**
+ * Called when receiving actions from widget.
+ */
+ void action(const gcn::ActionEvent &event);
+
+ /**
+ * Draw this window.
+ */
+ void draw(gcn::Graphics *graphics);
+
+ /**
+ * 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);
+
+protected:
+ /**
+ * Get selected guild tab
+ * @return Returns selected guild
+ */
+ short getSelectedGuild();
+
+private:
+ LocalPlayer *mPlayer;
+ gcn::Button *mGuildButton[2];
+ TextDialog *guildDialog;
+ TextDialog *inviteDialog;
+ ConfirmDialog *acceptDialog;
+ TabbedContainer *mGuildsContainer;
+ GuildListBox *mGuildMembersList;
+ ScrollArea *mScrollArea;
+ std::vector<GCContainer*> mTabs;
+ bool mFocus;
+ std::string invitedGuild;
+};
+
+extern GuildWindow *guildWindow;
+
+#endif
diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp
index 94e8b38c..61c7e078 100644
--- a/src/gui/listbox.cpp
+++ b/src/gui/listbox.cpp
@@ -35,6 +35,12 @@ ListBox::ListBox(gcn::ListModel *listModel):
{
}
+ListBox::ListBox():
+ gcn::ListBox()
+{
+
+}
+
void ListBox::draw(gcn::Graphics *graphics)
{
if (!mListModel)
diff --git a/src/gui/listbox.h b/src/gui/listbox.h
index 1d480eb1..21172a22 100644
--- a/src/gui/listbox.h
+++ b/src/gui/listbox.h
@@ -42,6 +42,7 @@ class ListBox : public gcn::ListBox
* Constructor.
*/
ListBox(gcn::ListModel *listModel);
+ ListBox();
/**
* Draws the list box.
diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp
index 560ec40a..84340fc4 100644
--- a/src/gui/menuwindow.cpp
+++ b/src/gui/menuwindow.cpp
@@ -37,6 +37,7 @@ extern Window *inventoryWindow;
extern Window *equipmentWindow;
extern Window *skillDialog;
extern Window *statusWindow;
+extern Window *guildWindow;
extern Window *itemShortcutWindow;
namespace {
@@ -63,6 +64,7 @@ MenuWindow::MenuWindow():
N_("Equipment"),
N_("Inventory"),
N_("Skills"),
+ N_("Guilds"),
N_("Shortcut"),
N_("Setup"),
0
@@ -108,6 +110,10 @@ void MenuWindowListener::action(const gcn::ActionEvent &event)
{
window = skillDialog;
}
+ else if (event.getId() == "Guilds")
+ {
+ window = guildWindow;
+ }
else if (event.getId() == "Shortcut")
{
window = itemShortcutWindow;
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index 821e9da6..b69cb9f1 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -42,6 +42,7 @@ extern Window *inventoryWindow;
extern Window *equipmentWindow;
extern Window *helpWindow;
extern Window *skillDialog;
+extern Window *guildWindow;
Setup::Setup():
Window(_("Setup"))
@@ -115,5 +116,6 @@ void Setup::action(const gcn::ActionEvent &event)
equipmentWindow->resetToDefaultSize();
helpWindow->resetToDefaultSize();
skillDialog->resetToDefaultSize();
+ guildWindow->resetToDefaultSize();
}
}
diff --git a/src/gui/textdialog.cpp b/src/gui/textdialog.cpp
new file mode 100644
index 00000000..202838f0
--- /dev/null
+++ b/src/gui/textdialog.cpp
@@ -0,0 +1,93 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#include "textdialog.h"
+
+#include <guichan/widgets/label.hpp>
+#include <guichan/widgets/textfield.hpp>
+
+#include "button.h"
+
+TextDialog::TextDialog(const std::string &title, const std::string &msg,
+ Window *parent):
+ Window(title, true, parent),
+ textField(new gcn::TextField(""))
+{
+ gcn::Label *textLabel = new gcn::Label(msg);
+ okButton = new Button("OK", "OK", this);
+ gcn::Button *cancelButton = new Button("Cancel", "CANCEL", this);
+
+ int w = textLabel->getWidth() + 20;
+ int inWidth = okButton->getWidth() + cancelButton->getWidth() + 5;
+ int h = textLabel->getHeight() + 25 + okButton->getHeight() + textField->getHeight();
+
+ if (w < inWidth + 10) {
+ w = inWidth + 10;
+ }
+
+ setContentSize(w, h);
+ textLabel->setPosition(10, 10);
+ textField->setWidth(85);
+ textField->setPosition(10,20 + textLabel->getHeight());
+ okButton->setPosition((w - inWidth) / 2,
+ h - 5 - cancelButton->getHeight());
+ cancelButton->setPosition(okButton->getX() + okButton->getWidth() + 5,
+ h - 5 - cancelButton->getHeight());
+
+ add(textLabel);
+ add(textField);
+ add(okButton);
+ add(cancelButton);
+
+ if (getParent()) {
+ setLocationRelativeTo(getParent());
+ getParent()->moveToTop(this);
+ }
+ setVisible(true);
+ textField->requestFocus();
+}
+
+void TextDialog::action(const gcn::ActionEvent &event)
+{
+ // Proxy button events to our listeners
+ ActionListenerIterator i;
+ for (i = mActionListeners.begin(); i != mActionListeners.end(); ++i)
+ {
+ (*i)->action(event);
+ }
+
+ if(event.getId() == "CANCEL" || event.getId() == "OK")
+ {
+ scheduleDelete();
+ }
+}
+
+const std::string& TextDialog::getText() const
+{
+ return textField->getText();
+}
+
+void TextDialog::setOKButtonActionId(const std::string &name)
+{
+ okButton->setActionEventId(name);
+}
diff --git a/src/gui/textdialog.h b/src/gui/textdialog.h
new file mode 100644
index 00000000..f8ec0172
--- /dev/null
+++ b/src/gui/textdialog.h
@@ -0,0 +1,67 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMW_GUI_GUILD_DIALOG_H
+#define _TMW_GUI_GUILD_DIALOG_H
+
+#include <guichan/actionlistener.hpp>
+
+#include "window.h"
+
+
+/**
+* An option dialog.
+ *
+ * \ingroup GUI
+ */
+class TextDialog : public Window, public gcn::ActionListener {
+public:
+ /**
+ * Constructor.
+ *
+ * @see Window::Window
+ */
+ TextDialog(const std::string &title, const std::string &msg,
+ Window *parent = NULL);
+
+ /**
+ * Called when receiving actions from the widgets.
+ */
+ void action(const gcn::ActionEvent &event);
+
+ /**
+ * Get the text in the textfield
+ */
+ const std::string& getText() const;
+
+ /**
+ * Set the OK button action id
+ */
+ void setOKButtonActionId(const std::string &name);
+
+private:
+ gcn::TextField *textField;
+ gcn::Button *okButton;
+};
+
+#endif
diff --git a/src/gui/truetypefont.h b/src/gui/truetypefont.h
index 7a4ee9ac..6dbc6634 100644
--- a/src/gui/truetypefont.h
+++ b/src/gui/truetypefont.h
@@ -28,7 +28,11 @@
#include <guichan/font.hpp>
#include <guichan/graphics.hpp>
+#ifdef __APPLE__
+#include <SDL_ttf/SDL_ttf.h>
+#else
#include <SDL/SDL_ttf.h>
+#endif
/**
* A wrapper around SDL_ttf for allowing the use of TrueType fonts.
diff --git a/src/guild.cpp b/src/guild.cpp
new file mode 100644
index 00000000..e2f9d097
--- /dev/null
+++ b/src/guild.cpp
@@ -0,0 +1,52 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+
+#include "guild.h"
+
+Guild::Guild(short id, bool inviteRights) :
+mId(id),
+mCanInviteUsers(inviteRights)
+{
+
+}
+
+void Guild::addMember(const std::string &name)
+{
+ mMembers.push_back(name);
+}
+
+void Guild::removeMember(const std::string &name)
+{
+ for(std::vector<std::string>::iterator itr = mMembers.begin();
+ itr != mMembers.end();
+ ++itr)
+ {
+ std::string member = (*itr);
+ if(member == name)
+ {
+ mMembers.erase(itr);
+ }
+ }
+
+}
diff --git a/src/guild.h b/src/guild.h
new file mode 100644
index 00000000..19cfd99c
--- /dev/null
+++ b/src/guild.h
@@ -0,0 +1,85 @@
+#ifndef TMW_GUILD_H
+#define TMW_GUILD_H
+
+#include <string>
+#include <guichan/listmodel.hpp>
+
+#include "player.h"
+
+class Guild : public gcn::ListModel
+{
+public:
+ /**
+ * Constructor with guild id passed to it
+ */
+ Guild(short id, bool inviteRights);
+
+ /**
+ * Set the guild's name
+ */
+ void setName(const std::string &name)
+ {
+ mName = name;
+ }
+
+ /**
+ * Add member to the list
+ */
+ void addMember(const std::string &name);
+
+ /**
+ * Get the name of the guild
+ * @return returns name of the guild
+ */
+ const std::string& getName() const
+ {
+ return mName;
+ }
+
+ /**
+ * Get the id of the guild
+ * @return Returns the id of the guild
+ */
+ short getId() const
+ {
+ return mId;
+ }
+
+ /**
+ * Remove member from the guild
+ */
+ void removeMember(const std::string &name);
+
+ /**
+ * Get size of members list
+ * @return Returns the number of members in the guild.
+ */
+ int getNumberOfElements() {
+ return mMembers.size();
+ }
+
+ /**
+ * Get member at i
+ * @return Returns the name of member.
+ */
+ std::string getElementAt(int i) {
+ return mMembers[i];
+ }
+
+ /**
+ * Get whether user can invite users to this guild
+ * @return Returns true if user can invite users
+ */
+ bool getInviteRights()
+ {
+ return mCanInviteUsers;
+ }
+
+private:
+ std::string mName;
+ short mId;
+ std::vector<std::string> mMembers;
+ bool mCanInviteUsers;
+};
+
+#endif
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 5a6457a4..3c70c228 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -115,6 +115,68 @@ 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<Guild*>::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)
+{
+ for (unsigned int i = 0; i < mGuilds.size(); ++i)
+ {
+ if(mGuilds[i]->getName() == guildName)
+ {
+ return mGuilds[i];
+ }
+ }
+
+ // 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;
+}
+
void LocalPlayer::clearInventory()
{
mEquipment->clear();
diff --git a/src/localplayer.h b/src/localplayer.h
index fc528171..d850ed5f 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -24,6 +24,7 @@
#ifndef _TMW_LOCALPLAYER_H
#define _TMW_LOCALPLAYER_H
+#include "guild.h"
#include "player.h"
// TODO move into some sane place...
@@ -149,6 +150,38 @@ 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
+ */
+ bool checkInviteRights(const std::string &guildName);
void clearInventory();
void setInvItem(int index, int id, int amount);
@@ -334,6 +367,9 @@ class LocalPlayer : public Player
protected:
void walk(unsigned char dir);
+
+ // Character guild information
+ std::vector<Guild*> mGuilds;
// Character status:
std::vector<int> mAttributeBase;
diff --git a/src/net/chatserver/guild.cpp b/src/net/chatserver/guild.cpp
new file mode 100644
index 00000000..441a52c2
--- /dev/null
+++ b/src/net/chatserver/guild.cpp
@@ -0,0 +1,74 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+
+#include "guild.h"
+
+#include "internal.h"
+
+#include "../connection.h"
+#include "../messageout.h"
+#include "../protocol.h"
+
+#include "../../log.h"
+
+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);
+}
+
+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);
+}
+
+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);
+}
+
+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);
+}
diff --git a/src/net/chatserver/guild.h b/src/net/chatserver/guild.h
new file mode 100644
index 00000000..849cd0a4
--- /dev/null
+++ b/src/net/chatserver/guild.h
@@ -0,0 +1,60 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+
+#ifndef _TMW_NET_CHATSERVER_GUILD_H
+#define _TMW_NET_CHATSERVER_GUILD_H
+
+#include <iosfwd>
+
+namespace Net
+{
+ namespace ChatServer
+ {
+ namespace Guild
+ {
+ /**
+ * 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);
+ }
+ }
+}
+
+#endif
+
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);
+}
diff --git a/src/net/guildhandler.h b/src/net/guildhandler.h
new file mode 100644
index 00000000..c76682b2
--- /dev/null
+++ b/src/net/guildhandler.h
@@ -0,0 +1,49 @@
+/*
+ * guildhandler.h
+ * 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$
+ */
+
+#ifndef _TMW_NET_GUILDHANDLER_H
+#define _TMW_NET_GUILDHANDLER_H
+
+#include "messagehandler.h"
+
+#include <string>
+
+class GuildHandler : public MessageHandler
+{
+public:
+ GuildHandler();
+
+ void handleMessage(MessageIn &msg);
+
+protected:
+ void joinedGuild(short guildId, const std::string &guildName, bool leader);
+};
+
+#endif
diff --git a/src/net/protocol.h b/src/net/protocol.h
index eb65febe..b255ae59 100644
--- a/src/net/protocol.h
+++ b/src/net/protocol.h
@@ -131,6 +131,21 @@ enum {
GPMSG_USE_RESPONSE = 0x0301, // B error
GPMSG_BEINGS_DAMAGE = 0x0310, // { W being id, W amount }*
+ // Guild
+ PCMSG_GUILD_CREATE = 0x0350, // S name
+ CPMSG_GUILD_CREATE_RESPONSE = 0x0351, // B error, W id, S name
+ 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
+ PCMSG_GUILD_GET_MEMBERS = 0x0356, // W id
+ CPMSG_GUILD_GET_MEMBERS_RESPONSE = 0x0357, // S names
+ 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
+
// Chat
CPMSG_ERROR = 0x0401, // B error
CPMSG_ANNOUNCEMENT = 0x0402, // S text
@@ -140,17 +155,22 @@ enum {
PCMSG_ANNOUNCE = 0x0411, // S text
PCMSG_PRIVMSG = 0x0412, // S user, S text
// -- Channeling
- PCMSG_REGISTER_CHANNEL = 0x0413, // B pub/priv, S name, S announcement, S password
- CPMSG_REGISTER_CHANNEL_RESPONSE = 0x0414, // B error, W channel, S channel
- PCMSG_UNREGISTER_CHANNEL = 0x0415, // W channel
- CPMSG_UNREGISTER_CHANNEL_RESPONSE = 0x0416, // B error
- CPMSG_CHANNEL_EVENT = 0x0418, // W channel, B event, S user
- PCMSG_ENTER_CHANNEL = 0x0419, // W channel, S password
- CPMSG_ENTER_CHANNEL_RESPONSE = 0x0420, // B error, W channel, S channel
- PCMSG_QUIT_CHANNEL = 0x0421, // W channel
- CPMSG_QUIT_CHANNEL_RESPONSE = 0x0422, // B error
- PCMSG_LIST_CHANNELS = 0x0423, // -
- CPMSG_LIST_CHANNELS_RESPONSE = 0x0424, // W number of channels, S channels
+ PCMSG_REGISTER_CHANNEL = 0x0420, // B pub/priv, S name, S announcement, S password
+ CPMSG_REGISTER_CHANNEL_RESPONSE = 0x0421, // B error, W channel, S channel
+ PCMSG_UNREGISTER_CHANNEL = 0x0422, // W channel
+ CPMSG_UNREGISTER_CHANNEL_RESPONSE = 0x0423, // B error
+ CPMSG_CHANNEL_EVENT = 0x0430, // W channel, B event, S user
+ PCMSG_ENTER_CHANNEL = 0x0440, // W channel, S password
+ CPMSG_ENTER_CHANNEL_RESPONSE = 0x0441, // B error, W channel, S channel
+ CPMSG_JOINED_CHANNEL = 0x0442, // S channel, W channel id
+ PCMSG_QUIT_CHANNEL = 0x0443, // W channel
+ CPMSG_QUIT_CHANNEL_RESPONSE = 0x0444, // B error
+ PCMSG_LIST_CHANNELS = 0x0445, // -
+ CPMSG_LIST_CHANNELS_RESPONSE = 0x0446, // W number of channels, S channels
+ 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
XXMSG_INVALID = 0x7FFF
};
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp
index 76eff9f5..92ce2fe9 100644
--- a/src/openglgraphics.cpp
+++ b/src/openglgraphics.cpp
@@ -76,7 +76,7 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel)
}
#ifdef __APPLE__
- long VBL = 1;
+ const GLint VBL = 1;
CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL);
#endif