00001 /* 00002 * The Mana World 00003 * Copyright (C) 2008 The Mana World Development Team 00004 * 00005 * This file is part of The Mana World. 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 */ 00021 00022 #include "net/tmwserv/partyhandler.h" 00023 00024 #include "net/tmwserv/protocol.h" 00025 00026 #include "net/tmwserv/chatserver/chatserver.h" 00027 #include "net/tmwserv/chatserver/party.h" 00028 00029 #include "net/messagein.h" 00030 00031 #include "gui/partywindow.h" 00032 00033 #include "gui/widgets/chattab.h" 00034 00035 #include "log.h" 00036 #include "localplayer.h" 00037 00038 #include <iostream> 00039 00040 Net::PartyHandler *partyHandler; 00041 00042 namespace TmwServ { 00043 00044 PartyHandler::PartyHandler() 00045 { 00046 static const Uint16 _messages[] = { 00047 CPMSG_PARTY_INVITE_RESPONSE, 00048 CPMSG_PARTY_INVITED, 00049 CPMSG_PARTY_ACCEPT_INVITE_RESPONSE, 00050 CPMSG_PARTY_QUIT_RESPONSE, 00051 CPMSG_PARTY_NEW_MEMBER, 00052 CPMSG_PARTY_MEMBER_LEFT, 00053 CPMSG_PARTY_REJECTED, 00054 0 00055 }; 00056 handledMessages = _messages; 00057 partyHandler = this; 00058 } 00059 00060 void PartyHandler::handleMessage(MessageIn &msg) 00061 { 00062 switch (msg.getId()) 00063 { 00064 case CPMSG_PARTY_INVITE_RESPONSE: 00065 { 00066 if (msg.readInt8() == ERRMSG_OK) 00067 { 00068 00069 } 00070 } break; 00071 00072 case CPMSG_PARTY_INVITED: 00073 { 00074 std::string inviter = msg.readString(); 00075 partyWindow->showPartyInvite(inviter); 00076 } break; 00077 00078 case CPMSG_PARTY_ACCEPT_INVITE_RESPONSE: 00079 { 00080 if (msg.readInt8() == ERRMSG_OK) 00081 { 00082 player_node->setInParty(true); 00083 localChatTab->chatLog("Joined party"); 00084 } 00085 } 00086 00087 case CPMSG_PARTY_QUIT_RESPONSE: 00088 { 00089 if (msg.readInt8() == ERRMSG_OK) 00090 { 00091 player_node->setInParty(false); 00092 } 00093 } break; 00094 00095 case CPMSG_PARTY_NEW_MEMBER: 00096 { 00097 int id = msg.readInt16(); // being id 00098 std::string name = msg.readString(); 00099 00100 localChatTab->chatLog(name + " joined the party"); 00101 00102 if (!player_node->getInParty()) 00103 player_node->setInParty(true); 00104 00105 partyWindow->updateMember(id, name); 00106 } break; 00107 00108 case CPMSG_PARTY_MEMBER_LEFT: 00109 { 00110 partyWindow->removeMember(msg.readString()); 00111 } break; 00112 00113 case CPMSG_PARTY_REJECTED: 00114 { 00115 std::string name = msg.readString(); 00116 localChatTab->chatLog(name + "rejected your invite."); 00117 } break; 00118 } 00119 } 00120 00121 void PartyHandler::create(const std::string &name) 00122 { 00123 // TODO 00124 } 00125 00126 void PartyHandler::join(int partyId) 00127 { 00128 // TODO 00129 } 00130 00131 void PartyHandler::invite(Player *player) 00132 { 00133 invite(player->getName()); 00134 } 00135 00136 void PartyHandler::invite(const std::string &name) 00137 { 00138 Net::ChatServer::Party::invitePlayer(name); 00139 } 00140 00141 void PartyHandler::inviteResponse(const std::string &inviter, bool accept) 00142 { 00143 if (accept) 00144 Net::ChatServer::Party::acceptInvite(inviter); 00145 else 00146 Net::ChatServer::Party::rejectInvite(inviter); 00147 } 00148 00149 void PartyHandler::leave() 00150 { 00151 Net::ChatServer::Party::quitParty(); 00152 } 00153 00154 void PartyHandler::kick(Player *player) 00155 { 00156 // TODO 00157 } 00158 00159 void PartyHandler::kick(const std::string &name) 00160 { 00161 // TODO 00162 } 00163 00164 void PartyHandler::chat(const std::string &text) 00165 { 00166 // TODO 00167 } 00168 00169 void PartyHandler::requestPartyMembers() 00170 { 00171 // TODO 00172 } 00173 00174 } // namespace TmwServ