2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "WorldSession.h"
20 #include "WorldPacket.h"
22 #include "Database/DatabaseEnv.h"
24 #include "ObjectMgr.h"
25 #include "ArenaTeam.h"
27 #include "SocialMgr.h"
30 void WorldSession::HandleInspectArenaStatsOpcode(WorldPacket
& recv_data
)
32 sLog
.outDebug("MSG_INSPECT_ARENA_TEAMS");
33 //recv_data.hexlike();
35 CHECK_PACKET_SIZE(recv_data
, 8);
39 sLog
.outDebug("Inspect Arena stats " I64FMTD
, guid
);
41 if(Player
*plr
= objmgr
.GetPlayer(guid
))
43 for (uint8 i
= 0; i
< MAX_ARENA_SLOT
; i
++)
45 if(uint32 a_id
= plr
->GetArenaTeamId(i
))
47 if(ArenaTeam
*at
= objmgr
.GetArenaTeamById(a_id
))
48 at
->InspectStats(this, plr
->GetGUID());
54 void WorldSession::HandleArenaTeamQueryOpcode(WorldPacket
& recv_data
)
56 sLog
.outDebug( "WORLD: Received CMSG_ARENA_TEAM_QUERY" );
57 //recv_data.hexlike();
59 CHECK_PACKET_SIZE(recv_data
, 4);
62 recv_data
>> ArenaTeamId
;
64 ArenaTeam
*arenateam
= objmgr
.GetArenaTeamById(ArenaTeamId
);
65 if(!arenateam
) // arena team not found
68 arenateam
->Query(this);
69 arenateam
->Stats(this);
72 void WorldSession::HandleArenaTeamRosterOpcode(WorldPacket
& recv_data
)
74 sLog
.outDebug( "WORLD: Received CMSG_ARENA_TEAM_ROSTER" );
75 //recv_data.hexlike();
77 CHECK_PACKET_SIZE(recv_data
, 4);
79 uint32 ArenaTeamId
; // arena team id
80 recv_data
>> ArenaTeamId
;
82 ArenaTeam
*arenateam
= objmgr
.GetArenaTeamById(ArenaTeamId
);
86 arenateam
->Roster(this);
89 void WorldSession::HandleArenaTeamAddMemberOpcode(WorldPacket
& recv_data
)
91 sLog
.outDebug("CMSG_ARENA_TEAM_ADD_MEMBER");
92 //recv_data.hexlike();
94 CHECK_PACKET_SIZE(recv_data
, 4+1);
96 uint32 ArenaTeamId
; // arena team id
97 std::string Invitedname
;
99 Player
* player
= NULL
;
101 recv_data
>> ArenaTeamId
>> Invitedname
;
103 if(!Invitedname
.empty())
105 if(!normalizePlayerName(Invitedname
))
108 player
= ObjectAccessor::Instance().FindPlayerByName(Invitedname
.c_str());
113 SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS
, "", Invitedname
, ERR_ARENA_TEAM_PLAYER_NOT_FOUND_S
);
117 if(player
->getLevel() < sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
119 //SendArenaTeamCommandResult(ARENA_TEAM_INVITE_SS,"",Invitedname,ARENA_TEAM_PLAYER_NOT_FOUND_S);
120 // can't find related opcode
121 SendNotification(LANG_HIS_ARENA_LEVEL_REQ_ERROR
, player
->GetName());
125 ArenaTeam
*arenateam
= objmgr
.GetArenaTeamById(ArenaTeamId
);
128 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", "", ERR_ARENA_TEAM_PLAYER_NOT_IN_TEAM
);
132 // OK result but not send invite
133 if(player
->GetSocial()->HasIgnore(GetPlayer()->GetGUIDLow()))
136 if (!sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD
) && player
->GetTeam() != GetPlayer()->GetTeam())
138 SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS
, "", "", ERR_ARENA_TEAM_NOT_ALLIED
);
142 if(player
->GetArenaTeamId(arenateam
->GetSlot()))
144 SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS
, player
->GetName(), "", ERR_ALREADY_IN_ARENA_TEAM_S
);
148 if(player
->GetArenaTeamIdInvited())
150 SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS
, player
->GetName(), "", ERR_ALREADY_INVITED_TO_ARENA_TEAM_S
);
154 if(arenateam
->GetMembersSize() >= arenateam
->GetType() * 2)
156 // should send an "arena team is full" or the likes message, I just don't know the proper values so... ERR_INTERNAL
157 // SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", "", ERR_ARENA_TEAM_INTERNAL);
158 SendNotification(LANG_YOUR_ARENA_TEAM_FULL
, player
->GetName());
162 sLog
.outDebug("Player %s Invited %s to Join his ArenaTeam", GetPlayer()->GetName(), Invitedname
.c_str());
164 player
->SetArenaTeamIdInvited(arenateam
->GetId());
166 WorldPacket
data(SMSG_ARENA_TEAM_INVITE
, (8+10));
167 data
<< GetPlayer()->GetName();
168 data
<< arenateam
->GetName();
169 player
->GetSession()->SendPacket(&data
);
171 sLog
.outDebug("WORLD: Sent SMSG_ARENA_TEAM_INVITE");
174 void WorldSession::HandleArenaTeamInviteAcceptOpcode(WorldPacket
& /*recv_data*/)
176 sLog
.outDebug("CMSG_ARENA_TEAM_INVITE_ACCEPT"); // empty opcode
178 ArenaTeam
*at
= objmgr
.GetArenaTeamById(_player
->GetArenaTeamIdInvited());
181 // arena team not exist
185 if(_player
->GetArenaTeamId(at
->GetSlot()))
187 // already in arena team that size
191 // not let enemies sign petition
192 if (!sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD
) && _player
->GetTeam() != objmgr
.GetPlayerTeamByGUID(at
->GetCaptain()))
195 if(!at
->AddMember(_player
->GetGUID()))
200 BuildArenaTeamEventPacket(&data
, ERR_ARENA_TEAM_JOIN_SS
, 2, _player
->GetName(), at
->GetName(), "");
201 at
->BroadcastPacket(&data
);
204 void WorldSession::HandleArenaTeamInviteDeclineOpcode(WorldPacket
& /*recv_data*/)
206 sLog
.outDebug("CMSG_ARENA_TEAM_INVITE_DECLINE"); // empty opcode
208 _player
->SetArenaTeamIdInvited(0); // no more invited
211 void WorldSession::HandleArenaTeamLeaveOpcode(WorldPacket
& recv_data
)
213 sLog
.outDebug("CMSG_ARENA_TEAM_LEAVE");
214 //recv_data.hexlike();
216 CHECK_PACKET_SIZE(recv_data
, 4);
218 uint32 ArenaTeamId
; // arena team id
219 recv_data
>> ArenaTeamId
;
221 ArenaTeam
*at
= objmgr
.GetArenaTeamById(ArenaTeamId
);
224 // send command result
227 if(_player
->GetGUID() == at
->GetCaptain() && at
->GetMembersSize() > 1)
229 // check for correctness
230 SendArenaTeamCommandResult(ERR_ARENA_TEAM_QUIT_S
, "", "", ERR_ARENA_TEAM_LEADER_LEAVE_S
);
233 // arena team has only one member (=captain)
234 if(_player
->GetGUID() == at
->GetCaptain())
241 at
->DelMember(_player
->GetGUID());
245 BuildArenaTeamEventPacket(&data
, ERR_ARENA_TEAM_LEAVE_SS
, 2, _player
->GetName(), at
->GetName(), "");
246 at
->BroadcastPacket(&data
);
248 //SendArenaTeamCommandResult(ERR_ARENA_TEAM_QUIT_S, at->GetName(), "", 0);
251 void WorldSession::HandleArenaTeamDisbandOpcode(WorldPacket
& recv_data
)
253 sLog
.outDebug("CMSG_ARENA_TEAM_DISBAND");
254 //recv_data.hexlike();
256 CHECK_PACKET_SIZE(recv_data
, 4);
258 uint32 ArenaTeamId
; // arena team id
259 recv_data
>> ArenaTeamId
;
261 ArenaTeam
*at
= objmgr
.GetArenaTeamById(ArenaTeamId
);
264 // arena team not found
268 if(at
->GetCaptain() != _player
->GetGUID())
270 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", "", ERR_ARENA_TEAM_PERMISSIONS
);
278 void WorldSession::HandleArenaTeamRemoveFromTeamOpcode(WorldPacket
& recv_data
)
280 sLog
.outDebug("CMSG_ARENA_TEAM_REMOVE_FROM_TEAM");
281 //recv_data.hexlike();
283 CHECK_PACKET_SIZE(recv_data
, 4+1);
288 recv_data
>> ArenaTeamId
;
291 ArenaTeam
*at
= objmgr
.GetArenaTeamById(ArenaTeamId
);
294 // arena team not found
298 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
301 // player guid not found
305 if(at
->GetCaptain() == guid
)
308 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", "", ERR_ARENA_TEAM_PERMISSIONS
);
312 if(at
->GetCaptain() != _player
->GetGUID())
314 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", "", ERR_ARENA_TEAM_PERMISSIONS
);
318 if(at
->GetCaptain() == guid
)
320 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", "", ERR_ARENA_TEAM_LEADER_LEAVE_S
);
328 BuildArenaTeamEventPacket(&data
, ERR_ARENA_TEAM_REMOVE_SSS
, 3, name
, at
->GetName(), _player
->GetName());
329 at
->BroadcastPacket(&data
);
332 void WorldSession::HandleArenaTeamPromoteToCaptainOpcode(WorldPacket
& recv_data
)
334 sLog
.outDebug("CMSG_ARENA_TEAM_PROMOTE_TO_CAPTAIN");
335 //recv_data.hexlike();
337 CHECK_PACKET_SIZE(recv_data
, 4+1);
342 recv_data
>> ArenaTeamId
;
345 ArenaTeam
*at
= objmgr
.GetArenaTeamById(ArenaTeamId
);
348 // arena team not found
352 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
355 // player guid not found
359 if(at
->GetCaptain() == guid
)
361 // target player already captain
365 if(at
->GetCaptain() != _player
->GetGUID())
367 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", "", ERR_ARENA_TEAM_PERMISSIONS
);
371 at
->SetCaptain(guid
);
375 BuildArenaTeamEventPacket(&data
, ERR_ARENA_TEAM_LEADER_CHANGED_SSS
, 3, _player
->GetName(), name
, at
->GetName());
376 at
->BroadcastPacket(&data
);
379 void WorldSession::SendArenaTeamCommandResult(uint32 unk1
, std::string str1
, std::string str2
, uint32 unk3
)
381 WorldPacket
data(SMSG_ARENA_TEAM_COMMAND_RESULT
, 4+str1
.length()+1+str2
.length()+1+4);
389 void WorldSession::BuildArenaTeamEventPacket(WorldPacket
*data
, uint8 eventid
, uint8 str_count
, std::string str1
, std::string str2
, std::string str3
)
391 data
->Initialize(SMSG_ARENA_TEAM_EVENT
, 1+1+1);
409 sLog
.outError("Unhandled str_count %u in SendArenaTeamEvent()", str_count
);
414 void WorldSession::SendNotInArenaTeamPacket(uint8 type
)
416 WorldPacket
data(SMSG_ARENA_ERROR
, 4+1); // 886 - You are not in a %uv%u arena team
418 data
<< uint32(unk
); // unk(0)
420 data
<< uint8(type
); // team type (2=2v2,3=3v3,5=5v5), can be used for custom types...
425 +ERR_ARENA_NO_TEAM_II "You are not in a %dv%d arena team"
427 +ERR_ARENA_TEAM_CREATE_S "%s created. To disband, use /teamdisband [2v2, 3v3, 5v5]."
428 +ERR_ARENA_TEAM_INVITE_SS "You have invited %s to join %s"
429 +ERR_ARENA_TEAM_QUIT_S "You are no longer a member of %s"
430 ERR_ARENA_TEAM_FOUNDER_S "Congratulations, you are a founding member of %s! To leave, use /teamquit [2v2, 3v3, 5v5]."
432 +ERR_ARENA_TEAM_INTERNAL "Internal arena team error"
433 +ERR_ALREADY_IN_ARENA_TEAM "You are already in an arena team of that size"
434 +ERR_ALREADY_IN_ARENA_TEAM_S "%s is already in an arena team of that size"
435 +ERR_INVITED_TO_ARENA_TEAM "You have already been invited into an arena team"
436 +ERR_ALREADY_INVITED_TO_ARENA_TEAM_S "%s has already been invited to an arena team"
437 +ERR_ARENA_TEAM_NAME_INVALID "That name contains invalid characters, please enter a new name"
438 +ERR_ARENA_TEAM_NAME_EXISTS_S "There is already an arena team named \"%s\""
439 +ERR_ARENA_TEAM_LEADER_LEAVE_S "You must promote a new team captain using /teamcaptain before leaving the team"
440 +ERR_ARENA_TEAM_PERMISSIONS "You don't have permission to do that"
441 +ERR_ARENA_TEAM_PLAYER_NOT_IN_TEAM "You are not in an arena team of that size"
442 +ERR_ARENA_TEAM_PLAYER_NOT_IN_TEAM_SS "%s is not in %s"
443 +ERR_ARENA_TEAM_PLAYER_NOT_FOUND_S "\"%s\" not found"
444 +ERR_ARENA_TEAM_NOT_ALLIED "You cannot invite players from the opposing alliance"
446 +ERR_ARENA_TEAM_JOIN_SS "%s has joined %s"
447 +ERR_ARENA_TEAM_YOU_JOIN_S "You have joined %s. To leave, use /teamquit [2v2, 3v3, 5v5]."
449 +ERR_ARENA_TEAM_LEAVE_SS "%s has left %s"
451 +ERR_ARENA_TEAM_LEADER_IS_SS "%s is the captain of %s"
452 +ERR_ARENA_TEAM_LEADER_CHANGED_SSS "%s has made %s the new captain of %s"
454 +ERR_ARENA_TEAM_REMOVE_SSS "%s has been kicked out of %s by %s"
456 +ERR_ARENA_TEAM_DISBANDED_S "%s has disbanded %s"
458 ERR_ARENA_TEAM_TARGET_TOO_LOW_S "%s is not high enough level to join your team"
460 ERR_ARENA_TEAM_TOO_MANY_MEMBERS_S "%s is full"
462 ERR_ARENA_TEAM_LEVEL_TOO_LOW_I "You must be level %d to form an arena team"