summaryrefslogtreecommitdiff
path: root/src/net/manaserv/partyhandler.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-01-02 01:48:38 +0200
committerAndrei Karas <akaras@inbox.ru>2011-01-02 02:41:24 +0200
commit3eeae12c498d1a4dbe969462d2ba841f77ee3ccb (patch)
treeff8eab35e732bc0749fc11677c8873a7b3a58704 /src/net/manaserv/partyhandler.cpp
downloadmv-3eeae12c498d1a4dbe969462d2ba841f77ee3ccb.tar.gz
mv-3eeae12c498d1a4dbe969462d2ba841f77ee3ccb.tar.bz2
mv-3eeae12c498d1a4dbe969462d2ba841f77ee3ccb.tar.xz
mv-3eeae12c498d1a4dbe969462d2ba841f77ee3ccb.zip
Initial commit.
This code based on mana client http://www.gitorious.org/mana/mana and my private repository.
Diffstat (limited to 'src/net/manaserv/partyhandler.cpp')
-rw-r--r--src/net/manaserv/partyhandler.cpp197
1 files changed, 197 insertions, 0 deletions
diff --git a/src/net/manaserv/partyhandler.cpp b/src/net/manaserv/partyhandler.cpp
new file mode 100644
index 000000000..3aec20b6b
--- /dev/null
+++ b/src/net/manaserv/partyhandler.cpp
@@ -0,0 +1,197 @@
+/*
+ * The Mana Client
+ * Copyright (C) 2008-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ *
+ * This file is part of The Mana Client.
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "net/manaserv/partyhandler.h"
+
+#include "event.h"
+#include "log.h"
+#include "localplayer.h"
+
+#include "gui/socialwindow.h"
+
+#include "net/manaserv/connection.h"
+#include "net/manaserv/messagein.h"
+#include "net/manaserv/messageout.h"
+#include "net/manaserv/protocol.h"
+
+#include "utils/gettext.h"
+#include "utils/stringutils.h"
+
+#include <iostream>
+
+#define PARTY_ID 1
+
+extern Net::PartyHandler *partyHandler;
+
+namespace ManaServ
+{
+
+extern Connection *chatServerConnection;
+
+PartyHandler::PartyHandler():
+ mParty(Party::getParty(PARTY_ID))
+{
+ static const Uint16 _messages[] =
+ {
+ CPMSG_PARTY_INVITE_RESPONSE,
+ CPMSG_PARTY_INVITED,
+ CPMSG_PARTY_ACCEPT_INVITE_RESPONSE,
+ CPMSG_PARTY_QUIT_RESPONSE,
+ CPMSG_PARTY_NEW_MEMBER,
+ CPMSG_PARTY_MEMBER_LEFT,
+ CPMSG_PARTY_REJECTED,
+ 0
+ };
+ handledMessages = _messages;
+ partyHandler = this;
+}
+
+void PartyHandler::handleMessage(Net::MessageIn &msg)
+{
+ switch (msg.getId())
+ {
+ case CPMSG_PARTY_INVITE_RESPONSE:
+ {
+ if (msg.readInt8() == ERRMSG_OK)
+ {
+
+ }
+ } break;
+
+ case CPMSG_PARTY_INVITED:
+ {
+ socialWindow->showPartyInvite(msg.readString());
+ } break;
+
+ case CPMSG_PARTY_ACCEPT_INVITE_RESPONSE:
+ {
+ if (msg.readInt8() == ERRMSG_OK)
+ {
+ //
+ SERVER_NOTICE(_("Joined party."));
+ }
+ }
+
+ case CPMSG_PARTY_QUIT_RESPONSE:
+ {
+ if (msg.readInt8() == ERRMSG_OK)
+ {
+ mParty->clearMembers();
+ player_node->setParty(NULL);
+ }
+ } break;
+
+ case CPMSG_PARTY_NEW_MEMBER:
+ {
+ int id = msg.readInt16(); // being id
+ std::string name = msg.readString();
+
+ SERVER_NOTICE(strprintf(_("%s joined the party."),
+ name.c_str()));
+
+ if (id == player_node->getId())
+ player_node->setParty(mParty);
+
+ mParty->addMember(id, name);
+ } break;
+
+ case CPMSG_PARTY_MEMBER_LEFT:
+ {
+ mParty->removeMember(msg.readString());
+ } break;
+
+ case CPMSG_PARTY_REJECTED:
+ {
+ std::string name = msg.readString();
+ SERVER_NOTICE(strprintf(
+ _("%s rejected your invite."), name.c_str()));
+ } break;
+ default:
+ break;
+ }
+}
+
+void PartyHandler::create(const std::string &name _UNUSED_)
+{
+ // TODO
+}
+
+void PartyHandler::join(int partyId _UNUSED_)
+{
+ // TODO
+}
+
+void PartyHandler::invite(Being *being)
+{
+ invite(being->getName());
+}
+
+void PartyHandler::invite(const std::string &name)
+{
+ MessageOut msg(PCMSG_PARTY_INVITE);
+
+ msg.writeString(name);
+
+ chatServerConnection->send(msg);
+}
+
+void PartyHandler::inviteResponse(const std::string &inviter, bool accept)
+{
+ MessageOut msg = MessageOut(accept ? PCMSG_PARTY_ACCEPT_INVITE :
+ PCMSG_PARTY_REJECT_INVITE);
+
+ msg.writeString(inviter);
+
+ chatServerConnection->send(msg);
+}
+
+void PartyHandler::leave()
+{
+ MessageOut msg(PCMSG_PARTY_QUIT);
+
+ chatServerConnection->send(msg);
+}
+
+void PartyHandler::kick(Being *being _UNUSED_)
+{
+ // TODO
+}
+
+void PartyHandler::kick(const std::string &name _UNUSED_)
+{
+ // TODO
+}
+
+void PartyHandler::chat(const std::string &text _UNUSED_)
+{
+ // TODO
+}
+
+void PartyHandler::requestPartyMembers()
+{
+ //MessageOut msg(PCMSG_GUILD_GET_MEMBERS);
+
+ //msg.writeInt16(guildId);
+
+ //chatServerConnection->send(msg);
+}
+
+} // namespace ManaServ