00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "net/ea/partyhandler.h"
00023
00024 #include "beingmanager.h"
00025 #include "localplayer.h"
00026 #include "log.h"
00027
00028 #include "gui/chat.h"
00029 #include "gui/partywindow.h"
00030
00031 #include "net/messagein.h"
00032 #include "net/messageout.h"
00033
00034 #include "net/ea/protocol.h"
00035 #include "net/ea/gui/partytab.h"
00036
00037 #include "utils/gettext.h"
00038 #include "utils/strprintf.h"
00039
00040 PartyTab *partyTab = 0;
00041 Net::PartyHandler *partyHandler = 0;
00042
00043 namespace EAthena {
00044
00045 PartyHandler::PartyHandler()
00046 {
00047 static const Uint16 _messages[] = {
00048 SMSG_PARTY_CREATE,
00049 SMSG_PARTY_INFO,
00050 SMSG_PARTY_INVITE_RESPONSE,
00051 SMSG_PARTY_INVITED,
00052 SMSG_PARTY_SETTINGS,
00053 SMSG_PARTY_MOVE,
00054 SMSG_PARTY_LEAVE,
00055 SMSG_PARTY_UPDATE_HP,
00056 SMSG_PARTY_UPDATE_COORDS,
00057 SMSG_PARTY_MESSAGE,
00058 0
00059 };
00060 handledMessages = _messages;
00061 partyHandler = this;
00062
00063
00064 }
00065
00066 PartyHandler::~PartyHandler()
00067 {
00068
00069 }
00070
00071 void PartyHandler::handleMessage(MessageIn &msg)
00072 {
00073 switch (msg.getId())
00074 {
00075 case SMSG_PARTY_CREATE:
00076 if (msg.readInt8())
00077 {
00078 partyTab->chatLog(_("Party successfully created."), BY_SERVER);
00079 player_node->setInParty(true);
00080 }
00081 else
00082 partyTab->chatLog(_("Could not create party."), BY_SERVER);
00083 break;
00084 case SMSG_PARTY_INFO:
00085 {
00086 if (!partyWindow)
00087 break;
00088
00089 partyWindow->clear();
00090
00091 int length = msg.readInt16();
00092 std::string party = msg.readString(24);
00093 int count = (length - 28) / 46;
00094
00095 for (int i = 0; i < count; i++)
00096 {
00097 int id = msg.readInt32();
00098 std::string nick = msg.readString(24);
00099 std::string map = msg.readString(16);
00100 bool leader = msg.readInt8() == 0;
00101 bool online = msg.readInt8() == 0;
00102
00103 partyWindow->updateMember(id, nick, leader, online);
00104 }
00105
00106 partyWindow->setVisible(true);
00107 }
00108 break;
00109 case SMSG_PARTY_INVITE_RESPONSE:
00110 {
00111 std::string nick = msg.readString(24);
00112 switch (msg.readInt8())
00113 {
00114 case 0:
00115 partyTab->chatLog(strprintf(_("%s is already a member of a party."),
00116 nick.c_str()), BY_SERVER);
00117 break;
00118 case 1:
00119 partyTab->chatLog(strprintf(_("%s refused your invitation."),
00120 nick.c_str()), BY_SERVER);
00121 break;
00122 case 2:
00123 partyTab->chatLog(strprintf(_("%s is now a member of your party."),
00124 nick.c_str()), BY_SERVER);
00125 break;
00126 default:
00127 partyTab->chatLog(strprintf(_("Unknown invite response for %s."),
00128 nick.c_str()), BY_SERVER);
00129 break;
00130 }
00131 break;
00132 }
00133 case SMSG_PARTY_INVITED:
00134 {
00135 int id = msg.readInt32();
00136 Being *being = beingManager->findBeing(id);
00137 if (!being)
00138 {
00139 break;
00140 }
00141 std::string nick;
00142 int gender = 0;
00143 std::string partyName = "";
00144 if (being->getType() != Being::PLAYER)
00145 {
00146 nick = "";
00147 }
00148 else
00149 {
00150 nick = being->getName();
00151 gender = being->getGender();
00152 partyName = msg.readString(24);
00153 }
00154 partyWindow->showPartyInvite(nick, partyName);
00155 break;
00156 }
00157 case SMSG_PARTY_SETTINGS:
00158 {
00159
00160 short exp = msg.readInt16();
00161 short item = msg.readInt16();
00162
00163 switch (exp) {
00164 case PARTY_SHARE:
00165 if (mShareExp == PARTY_SHARE)
00166 break;
00167 mShareExp = PARTY_SHARE;
00168 partyTab->chatLog(_("Experience sharing enabled."), BY_SERVER);
00169 break;
00170 case PARTY_SHARE_NO:
00171 if (mShareExp == PARTY_SHARE_NO)
00172 break;
00173 mShareExp =PARTY_SHARE_NO;
00174 partyTab->chatLog(_("Experience sharing disabled."), BY_SERVER);
00175 break;
00176 case PARTY_SHARE_NOT_POSSIBLE:
00177 if (mShareExp == PARTY_SHARE_NOT_POSSIBLE)
00178 break;
00179 mShareExp = PARTY_SHARE_NOT_POSSIBLE;
00180 partyTab->chatLog(_("Experience sharing not possible."), BY_SERVER);
00181 break;
00182 default:
00183 logger->log("Unknown party exp option: %d\n", exp);
00184 }
00185
00186 switch (item) {
00187 case PARTY_SHARE:
00188 if (mShareItems == PARTY_SHARE)
00189 break;
00190 mShareItems = PARTY_SHARE;
00191 partyTab->chatLog(_("Item sharing enabled."), BY_SERVER);
00192 break;
00193 case PARTY_SHARE_NO:
00194 if (mShareItems == PARTY_SHARE_NO)
00195 break;
00196 mShareItems =PARTY_SHARE_NO;
00197 partyTab->chatLog(_("Item sharing disabled."), BY_SERVER);
00198 break;
00199 case PARTY_SHARE_NOT_POSSIBLE:
00200 if (mShareItems == PARTY_SHARE_NOT_POSSIBLE)
00201 break;
00202 mShareItems = PARTY_SHARE_NOT_POSSIBLE;
00203 partyTab->chatLog(_("Item sharing not possible."), BY_SERVER);
00204 break;
00205 default:
00206 logger->log("Unknown party item option: %d\n", exp);
00207 }
00208 break;
00209 }
00210 case SMSG_PARTY_MOVE:
00211 {
00212 msg.readInt32();
00213 msg.skip(4);
00214 msg.readInt16();
00215 msg.readInt16();
00216 msg.readInt8();
00217 msg.readString(24);
00218 msg.readString(24);
00219 msg.readString(16);
00220 }
00221 break;
00222 case SMSG_PARTY_LEAVE:
00223 {
00224 int id = msg.readInt32();
00225 std::string nick = msg.readString(24);
00226 msg.readInt8();
00227 if (id == player_node->getId())
00228 {
00229 player_node->setInParty(false);
00230 partyWindow->clear();
00231 partyWindow->setVisible(false);
00232 partyTab->chatLog(_("You have left the party."), BY_SERVER);
00233 }
00234 else
00235 partyTab->chatLog(strprintf(_("%s has left your party."),
00236 nick.c_str()), BY_SERVER);
00237 partyWindow->removeMember(id);
00238 break;
00239 }
00240 case SMSG_PARTY_UPDATE_HP:
00241 {
00242 msg.readInt32();
00243 msg.readInt16();
00244 msg.readInt16();
00245 }
00246 break;
00247 case SMSG_PARTY_UPDATE_COORDS:
00248 {
00249 msg.readInt32();
00250 msg.readInt16();
00251 msg.readInt16();
00252 }
00253 break;
00254 case SMSG_PARTY_MESSAGE:
00255 {
00256 int msgLength = msg.readInt16() - 8;
00257 if (msgLength <= 0)
00258 {
00259 return;
00260 }
00261 int id = msg.readInt32();
00262 std::string chatMsg = msg.readString(msgLength);
00263
00264 Being *being = beingManager->findBeing(id);
00265 if (being)
00266 being->setSpeech(chatMsg, SPEECH_TIME);
00267
00268 PartyMember *member = partyWindow->findMember(id);
00269 if (member)
00270 partyTab->chatLog(member->name, chatMsg);
00271 else
00272 partyTab->chatLog(strprintf(_("An unknown member tried to "
00273 "say: %s"), chatMsg.c_str()), BY_SERVER);
00274 }
00275 break;
00276 }
00277 }
00278
00279 void PartyHandler::create(const std::string &name)
00280 {
00281 MessageOut outMsg(CMSG_PARTY_CREATE);
00282 outMsg.writeString(name.substr(0, 23), 24);
00283 }
00284
00285 void PartyHandler::join(int partyId)
00286 {
00287
00288 }
00289
00290 void PartyHandler::invite(Player *player)
00291 {
00292 MessageOut outMsg(CMSG_PARTY_INVITE);
00293 outMsg.writeInt32(player->getId());
00294 }
00295
00296 void PartyHandler::invite(const std::string &name)
00297 {
00298
00299 }
00300
00301 void PartyHandler::inviteResponse(const std::string &inviter, bool accept)
00302 {
00303 MessageOut outMsg(CMSG_PARTY_INVITED);
00304 outMsg.writeInt32(player_node->getId());
00305 outMsg.writeInt32(accept ? 1 : 0);
00306 player_node->setInParty(player_node->getInParty() || accept);
00307 }
00308
00309 void PartyHandler::leave()
00310 {
00311 MessageOut outMsg(CMSG_PARTY_LEAVE);
00312 }
00313
00314 void PartyHandler::kick(Player *player)
00315 {
00316 MessageOut outMsg(CMSG_PARTY_KICK);
00317 outMsg.writeInt32(player->getId());
00318 outMsg.writeString("", 24);
00319 }
00320
00321 void PartyHandler::kick(const std::string &name)
00322 {
00323 int id = partyWindow->findMember(name);
00324 if (id == -1)
00325 {
00326 partyTab->chatLog(strprintf(_("%s is not in your party!"), name.c_str()),
00327 BY_SERVER);
00328 return;
00329 }
00330
00331 MessageOut outMsg(CMSG_PARTY_KICK);
00332 outMsg.writeInt32(id);
00333 outMsg.writeString(name, 24);
00334 }
00335
00336 void PartyHandler::chat(const std::string &text)
00337 {
00338 MessageOut outMsg(CMSG_PARTY_MESSAGE);
00339 outMsg.writeInt16(text.length() + 4);
00340 outMsg.writeString(text, text.length());
00341 }
00342
00343 void PartyHandler::requestPartyMembers()
00344 {
00345
00346
00347 }
00348
00349 void PartyHandler::setShareExperience(PartyShare share)
00350 {
00351 if (share == PARTY_SHARE_NOT_POSSIBLE)
00352 return;
00353
00354 MessageOut outMsg(CMSG_PARTY_SETTINGS);
00355 outMsg.writeInt16(share);
00356 outMsg.writeInt16(mShareItems);
00357 }
00358
00359 void PartyHandler::setShareItems(PartyShare share)
00360 {
00361 if (share == PARTY_SHARE_NOT_POSSIBLE)
00362 return;
00363
00364 MessageOut outMsg(CMSG_PARTY_SETTINGS);
00365 outMsg.writeInt16(mShareExp);
00366 outMsg.writeInt16(share);
00367 }
00368
00369 }