2 * Copyright (C) 2005-2009 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");
34 CHECK_PACKET_SIZE(recv_data
, 8);
38 sLog
.outDebug("Inspect Arena stats " I64FMTD
, guid
);
40 if(Player
*plr
= objmgr
.GetPlayer(guid
))
42 for (uint8 i
= 0; i
< MAX_ARENA_SLOT
; i
++)
44 if(uint32 a_id
= plr
->GetArenaTeamId(i
))
46 if(ArenaTeam
*at
= objmgr
.GetArenaTeamById(a_id
))
47 at
->InspectStats(this, plr
->GetGUID());
53 void WorldSession::HandleArenaTeamQueryOpcode(WorldPacket
& recv_data
)
55 sLog
.outDebug( "WORLD: Received CMSG_ARENA_TEAM_QUERY" );
57 CHECK_PACKET_SIZE(recv_data
, 4);
60 recv_data
>> ArenaTeamId
;
62 ArenaTeam
*arenateam
= objmgr
.GetArenaTeamById(ArenaTeamId
);
63 if(!arenateam
) // arena team not found
66 arenateam
->Query(this);
67 arenateam
->Stats(this);
70 void WorldSession::HandleArenaTeamRosterOpcode(WorldPacket
& recv_data
)
72 sLog
.outDebug( "WORLD: Received CMSG_ARENA_TEAM_ROSTER" );
74 CHECK_PACKET_SIZE(recv_data
, 4);
76 uint32 ArenaTeamId
; // arena team id
77 recv_data
>> ArenaTeamId
;
79 ArenaTeam
*arenateam
= objmgr
.GetArenaTeamById(ArenaTeamId
);
83 arenateam
->Roster(this);
86 void WorldSession::HandleArenaTeamAddMemberOpcode(WorldPacket
& recv_data
)
88 sLog
.outDebug("CMSG_ARENA_TEAM_ADD_MEMBER");
90 CHECK_PACKET_SIZE(recv_data
, 4+1);
92 uint32 ArenaTeamId
; // arena team id
93 std::string Invitedname
;
95 Player
* player
= NULL
;
97 recv_data
>> ArenaTeamId
>> Invitedname
;
99 if(!Invitedname
.empty())
101 if(!normalizePlayerName(Invitedname
))
104 player
= ObjectAccessor::Instance().FindPlayerByName(Invitedname
.c_str());
109 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", Invitedname
, ERR_ARENA_TEAM_PLAYER_NOT_FOUND_S
);
113 if(player
->getLevel() < sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
115 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", player
->GetName(), ERR_ARENA_TEAM_PLAYER_TO_LOW
);
119 ArenaTeam
*arenateam
= objmgr
.GetArenaTeamById(ArenaTeamId
);
122 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", "", ERR_ARENA_TEAM_PLAYER_NOT_IN_TEAM
);
126 // OK result but not send invite
127 if(player
->GetSocial()->HasIgnore(GetPlayer()->GetGUIDLow()))
130 if (!sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD
) && player
->GetTeam() != GetPlayer()->GetTeam())
132 SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS
, "", "", ERR_ARENA_TEAM_NOT_ALLIED
);
136 if(player
->GetArenaTeamId(arenateam
->GetSlot()))
138 SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS
, "", player
->GetName(), ERR_ALREADY_IN_ARENA_TEAM_S
);
142 if(player
->GetArenaTeamIdInvited())
144 SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS
, "", player
->GetName(), ERR_ALREADY_INVITED_TO_ARENA_TEAM_S
);
148 if(arenateam
->GetMembersSize() >= arenateam
->GetType() * 2)
150 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
,arenateam
->GetName(),"",ERR_ARENA_TEAM_FULL
);
154 sLog
.outDebug("Player %s Invited %s to Join his ArenaTeam", GetPlayer()->GetName(), Invitedname
.c_str());
156 player
->SetArenaTeamIdInvited(arenateam
->GetId());
158 WorldPacket
data(SMSG_ARENA_TEAM_INVITE
, (8+10));
159 data
<< GetPlayer()->GetName();
160 data
<< arenateam
->GetName();
161 player
->GetSession()->SendPacket(&data
);
163 sLog
.outDebug("WORLD: Sent SMSG_ARENA_TEAM_INVITE");
166 void WorldSession::HandleArenaTeamInviteAcceptOpcode(WorldPacket
& /*recv_data*/)
168 sLog
.outDebug("CMSG_ARENA_TEAM_INVITE_ACCEPT"); // empty opcode
170 ArenaTeam
*at
= objmgr
.GetArenaTeamById(_player
->GetArenaTeamIdInvited());
174 if(_player
->GetArenaTeamId(at
->GetType()))
176 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
,"","",ERR_ALREADY_IN_ARENA_TEAM
); // already in arena team that size
180 if (!sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD
) && _player
->GetTeam() != objmgr
.GetPlayerTeamByGUID(at
->GetCaptain()))
182 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
,"","",ERR_ARENA_TEAM_NOT_ALLIED
);// not let enemies sign petition
186 if(!at
->AddMember(_player
->GetGUID()))
188 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
,"","",ERR_ARENA_TEAM_INTERNAL
);// arena team not found
194 BuildArenaTeamEventPacket(&data
, ERR_ARENA_TEAM_JOIN_SS
, 2, _player
->GetName(), at
->GetName(), "");
195 at
->BroadcastPacket(&data
);
198 void WorldSession::HandleArenaTeamInviteDeclineOpcode(WorldPacket
& /*recv_data*/)
200 sLog
.outDebug("CMSG_ARENA_TEAM_INVITE_DECLINE"); // empty opcode
202 _player
->SetArenaTeamIdInvited(0); // no more invited
205 void WorldSession::HandleArenaTeamLeaveOpcode(WorldPacket
& recv_data
)
207 sLog
.outDebug("CMSG_ARENA_TEAM_LEAVE");
209 CHECK_PACKET_SIZE(recv_data
, 4);
211 uint32 ArenaTeamId
; // arena team id
212 recv_data
>> ArenaTeamId
;
214 ArenaTeam
*at
= objmgr
.GetArenaTeamById(ArenaTeamId
);
217 if(_player
->GetGUID() == at
->GetCaptain() && at
->GetMembersSize() > 1)
219 // check for correctness
220 SendArenaTeamCommandResult(ERR_ARENA_TEAM_QUIT_S
, "", "", ERR_ARENA_TEAM_LEADER_LEAVE_S
);
223 // arena team has only one member (=captain)
224 if(_player
->GetGUID() == at
->GetCaptain())
231 at
->DelMember(_player
->GetGUID());
235 BuildArenaTeamEventPacket(&data
, ERR_ARENA_TEAM_LEAVE_SS
, 2, _player
->GetName(), at
->GetName(), "");
236 at
->BroadcastPacket(&data
);
238 //send you are no longer member of team
239 SendArenaTeamCommandResult(ERR_ARENA_TEAM_QUIT_S
, at
->GetName(), "", 0);
242 void WorldSession::HandleArenaTeamDisbandOpcode(WorldPacket
& recv_data
)
244 sLog
.outDebug("CMSG_ARENA_TEAM_DISBAND");
246 CHECK_PACKET_SIZE(recv_data
, 4);
248 uint32 ArenaTeamId
; // arena team id
249 recv_data
>> ArenaTeamId
;
251 ArenaTeam
*at
= objmgr
.GetArenaTeamById(ArenaTeamId
);
255 if(at
->GetCaptain() != _player
->GetGUID())
258 if (at
->IsFighting())
265 void WorldSession::HandleArenaTeamRemoveFromTeamOpcode(WorldPacket
& recv_data
)
267 sLog
.outDebug("CMSG_ARENA_TEAM_REMOVE_FROM_TEAM");
269 CHECK_PACKET_SIZE(recv_data
, 4+1);
274 recv_data
>> ArenaTeamId
;
277 ArenaTeam
*at
= objmgr
.GetArenaTeamById(ArenaTeamId
);
278 if(!at
) // arena team not found
281 if(at
->GetCaptain() != _player
->GetGUID())
283 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", "", ERR_ARENA_TEAM_PERMISSIONS
);
287 if(!normalizePlayerName(name
))
290 ArenaTeamMember
* member
= at
->GetMember(name
);
291 if(!member
) // member not found
293 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", name
, ERR_ARENA_TEAM_PLAYER_NOT_FOUND_S
);
297 if(at
->GetCaptain() == member
->guid
)
299 SendArenaTeamCommandResult(ERR_ARENA_TEAM_QUIT_S
, "", "", ERR_ARENA_TEAM_LEADER_LEAVE_S
);
303 at
->DelMember(member
->guid
);
307 BuildArenaTeamEventPacket(&data
, ERR_ARENA_TEAM_REMOVE_SSS
, 3, name
, at
->GetName(), _player
->GetName());
308 at
->BroadcastPacket(&data
);
311 void WorldSession::HandleArenaTeamPromoteToCaptainOpcode(WorldPacket
& recv_data
)
313 sLog
.outDebug("CMSG_ARENA_TEAM_PROMOTE_TO_CAPTAIN");
315 CHECK_PACKET_SIZE(recv_data
, 4+1);
320 recv_data
>> ArenaTeamId
;
323 ArenaTeam
*at
= objmgr
.GetArenaTeamById(ArenaTeamId
);
324 if(!at
) // arena team not found
327 if(at
->GetCaptain() != _player
->GetGUID())
329 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", "", ERR_ARENA_TEAM_PERMISSIONS
);
333 if(!normalizePlayerName(name
))
336 ArenaTeamMember
* member
= at
->GetMember(name
);
337 if(!member
) // member not found
339 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", name
, ERR_ARENA_TEAM_PLAYER_NOT_FOUND_S
);
343 if(at
->GetCaptain() == member
->guid
) // target player already captain
346 at
->SetCaptain(member
->guid
);
350 BuildArenaTeamEventPacket(&data
, ERR_ARENA_TEAM_LEADER_CHANGED_SSS
, 3, _player
->GetName(), name
, at
->GetName());
351 at
->BroadcastPacket(&data
);
354 void WorldSession::SendArenaTeamCommandResult(uint32 team_action
, const std::string
& team
, const std::string
& player
, uint32 error_id
)
356 WorldPacket
data(SMSG_ARENA_TEAM_COMMAND_RESULT
, 4+team
.length()+1+player
.length()+1+4);
364 void WorldSession::BuildArenaTeamEventPacket(WorldPacket
*data
, uint8 eventid
, uint8 str_count
, const std::string
& str1
, const std::string
& str2
, const std::string
& str3
)
366 data
->Initialize(SMSG_ARENA_TEAM_EVENT
, 1+1+1);
384 sLog
.outError("Unhandled str_count %u in SendArenaTeamEvent()", str_count
);
389 void WorldSession::SendNotInArenaTeamPacket(uint8 type
)
391 WorldPacket
data(SMSG_ARENA_ERROR
, 4+1); // 886 - You are not in a %uv%u arena team
393 data
<< uint32(unk
); // unk(0)
395 data
<< uint8(type
); // team type (2=2v2,3=3v3,5=5v5), can be used for custom types...
400 +ERR_ARENA_NO_TEAM_II "You are not in a %dv%d arena team"
402 +ERR_ARENA_TEAM_CREATE_S "%s created. To disband, use /teamdisband [2v2, 3v3, 5v5]."
403 +ERR_ARENA_TEAM_INVITE_SS "You have invited %s to join %s"
404 +ERR_ARENA_TEAM_QUIT_S "You are no longer a member of %s"
405 ERR_ARENA_TEAM_FOUNDER_S "Congratulations, you are a founding member of %s! To leave, use /teamquit [2v2, 3v3, 5v5]."
407 +ERR_ARENA_TEAM_INTERNAL "Internal arena team error"
408 +ERR_ALREADY_IN_ARENA_TEAM "You are already in an arena team of that size"
409 +ERR_ALREADY_IN_ARENA_TEAM_S "%s is already in an arena team of that size"
410 +ERR_INVITED_TO_ARENA_TEAM "You have already been invited into an arena team"
411 +ERR_ALREADY_INVITED_TO_ARENA_TEAM_S "%s has already been invited to an arena team"
412 +ERR_ARENA_TEAM_NAME_INVALID "That name contains invalid characters, please enter a new name"
413 +ERR_ARENA_TEAM_NAME_EXISTS_S "There is already an arena team named \"%s\""
414 +ERR_ARENA_TEAM_LEADER_LEAVE_S "You must promote a new team captain using /teamcaptain before leaving the team"
415 +ERR_ARENA_TEAM_PERMISSIONS "You don't have permission to do that"
416 +ERR_ARENA_TEAM_PLAYER_NOT_IN_TEAM "You are not in an arena team of that size"
417 +ERR_ARENA_TEAM_PLAYER_NOT_IN_TEAM_SS "%s is not in %s"
418 +ERR_ARENA_TEAM_PLAYER_NOT_FOUND_S "\"%s\" not found"
419 +ERR_ARENA_TEAM_NOT_ALLIED "You cannot invite players from the opposing alliance"
421 +ERR_ARENA_TEAM_JOIN_SS "%s has joined %s"
422 +ERR_ARENA_TEAM_YOU_JOIN_S "You have joined %s. To leave, use /teamquit [2v2, 3v3, 5v5]."
424 +ERR_ARENA_TEAM_LEAVE_SS "%s has left %s"
426 +ERR_ARENA_TEAM_LEADER_IS_SS "%s is the captain of %s"
427 +ERR_ARENA_TEAM_LEADER_CHANGED_SSS "%s has made %s the new captain of %s"
429 +ERR_ARENA_TEAM_REMOVE_SSS "%s has been kicked out of %s by %s"
431 +ERR_ARENA_TEAM_DISBANDED_S "%s has disbanded %s"
433 ERR_ARENA_TEAM_TARGET_TOO_LOW_S "%s is not high enough level to join your team"
435 ERR_ARENA_TEAM_TOO_MANY_MEMBERS_S "%s is full"
437 ERR_ARENA_TEAM_LEVEL_TOO_LOW_I "You must be level %d to form an arena team"