summaryrefslogtreecommitdiff
path: root/src/net
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/net
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/net')
-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
5 files changed, 364 insertions, 11 deletions
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
};