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"
29 void WorldSession::HandleInspectArenaStatsOpcode(WorldPacket
& recv_data
)
31 sLog
.outDebug("MSG_INSPECT_ARENA_TEAMS");
33 CHECK_PACKET_SIZE(recv_data
, 8);
37 sLog
.outDebug("Inspect Arena stats " I64FMTD
, guid
);
39 if(Player
*plr
= objmgr
.GetPlayer(guid
))
41 for (uint8 i
= 0; i
< MAX_ARENA_SLOT
; i
++)
43 if(uint32 a_id
= plr
->GetArenaTeamId(i
))
45 if(ArenaTeam
*at
= objmgr
.GetArenaTeamById(a_id
))
46 at
->InspectStats(this, plr
->GetGUID());
52 void WorldSession::HandleArenaTeamQueryOpcode(WorldPacket
& recv_data
)
54 sLog
.outDebug( "WORLD: Received CMSG_ARENA_TEAM_QUERY" );
56 CHECK_PACKET_SIZE(recv_data
, 4);
59 recv_data
>> ArenaTeamId
;
61 ArenaTeam
*arenateam
= objmgr
.GetArenaTeamById(ArenaTeamId
);
62 if(!arenateam
) // arena team not found
65 arenateam
->Query(this);
66 arenateam
->Stats(this);
69 void WorldSession::HandleArenaTeamRosterOpcode(WorldPacket
& recv_data
)
71 sLog
.outDebug( "WORLD: Received CMSG_ARENA_TEAM_ROSTER" );
73 CHECK_PACKET_SIZE(recv_data
, 4);
75 uint32 ArenaTeamId
; // arena team id
76 recv_data
>> ArenaTeamId
;
78 ArenaTeam
*arenateam
= objmgr
.GetArenaTeamById(ArenaTeamId
);
82 arenateam
->Roster(this);
85 void WorldSession::HandleArenaTeamAddMemberOpcode(WorldPacket
& recv_data
)
87 sLog
.outDebug("CMSG_ARENA_TEAM_ADD_MEMBER");
89 CHECK_PACKET_SIZE(recv_data
, 4+1);
91 uint32 ArenaTeamId
; // arena team id
92 std::string Invitedname
;
94 Player
* player
= NULL
;
96 recv_data
>> ArenaTeamId
>> Invitedname
;
98 if(!Invitedname
.empty())
100 if(!normalizePlayerName(Invitedname
))
103 player
= ObjectAccessor::Instance().FindPlayerByName(Invitedname
.c_str());
108 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", Invitedname
, ERR_ARENA_TEAM_PLAYER_NOT_FOUND_S
);
112 if(player
->getLevel() < sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
114 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", player
->GetName(), ERR_ARENA_TEAM_PLAYER_TO_LOW
);
118 ArenaTeam
*arenateam
= objmgr
.GetArenaTeamById(ArenaTeamId
);
121 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", "", ERR_ARENA_TEAM_PLAYER_NOT_IN_TEAM
);
125 // OK result but not send invite
126 if(player
->GetSocial()->HasIgnore(GetPlayer()->GetGUIDLow()))
129 if (!sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD
) && player
->GetTeam() != GetPlayer()->GetTeam())
131 SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS
, "", "", ERR_ARENA_TEAM_NOT_ALLIED
);
135 if(player
->GetArenaTeamId(arenateam
->GetSlot()))
137 SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS
, "", player
->GetName(), ERR_ALREADY_IN_ARENA_TEAM_S
);
141 if(player
->GetArenaTeamIdInvited())
143 SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS
, "", player
->GetName(), ERR_ALREADY_INVITED_TO_ARENA_TEAM_S
);
147 if(arenateam
->GetMembersSize() >= arenateam
->GetType() * 2)
149 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
,arenateam
->GetName(),"",ERR_ARENA_TEAM_FULL
);
153 sLog
.outDebug("Player %s Invited %s to Join his ArenaTeam", GetPlayer()->GetName(), Invitedname
.c_str());
155 player
->SetArenaTeamIdInvited(arenateam
->GetId());
157 WorldPacket
data(SMSG_ARENA_TEAM_INVITE
, (8+10));
158 data
<< GetPlayer()->GetName();
159 data
<< arenateam
->GetName();
160 player
->GetSession()->SendPacket(&data
);
162 sLog
.outDebug("WORLD: Sent SMSG_ARENA_TEAM_INVITE");
165 void WorldSession::HandleArenaTeamInviteAcceptOpcode(WorldPacket
& /*recv_data*/)
167 sLog
.outDebug("CMSG_ARENA_TEAM_INVITE_ACCEPT"); // empty opcode
169 ArenaTeam
*at
= objmgr
.GetArenaTeamById(_player
->GetArenaTeamIdInvited());
173 if(_player
->GetArenaTeamId(at
->GetSlot()))
175 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
,"","",ERR_ALREADY_IN_ARENA_TEAM
); // already in arena team that size
179 if (!sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD
) && _player
->GetTeam() != objmgr
.GetPlayerTeamByGUID(at
->GetCaptain()))
181 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
,"","",ERR_ARENA_TEAM_NOT_ALLIED
);// not let enemies sign petition
185 if(!at
->AddMember(_player
->GetGUID()))
187 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
,"","",ERR_ARENA_TEAM_INTERNAL
);// arena team not found
193 BuildArenaTeamEventPacket(&data
, ERR_ARENA_TEAM_JOIN_SS
, 2, _player
->GetName(), at
->GetName(), "");
194 at
->BroadcastPacket(&data
);
197 void WorldSession::HandleArenaTeamInviteDeclineOpcode(WorldPacket
& /*recv_data*/)
199 sLog
.outDebug("CMSG_ARENA_TEAM_INVITE_DECLINE"); // empty opcode
201 _player
->SetArenaTeamIdInvited(0); // no more invited
204 void WorldSession::HandleArenaTeamLeaveOpcode(WorldPacket
& recv_data
)
206 sLog
.outDebug("CMSG_ARENA_TEAM_LEAVE");
208 CHECK_PACKET_SIZE(recv_data
, 4);
210 uint32 ArenaTeamId
; // arena team id
211 recv_data
>> ArenaTeamId
;
213 ArenaTeam
*at
= objmgr
.GetArenaTeamById(ArenaTeamId
);
216 if(_player
->GetGUID() == at
->GetCaptain() && at
->GetMembersSize() > 1)
218 // check for correctness
219 SendArenaTeamCommandResult(ERR_ARENA_TEAM_QUIT_S
, "", "", ERR_ARENA_TEAM_LEADER_LEAVE_S
);
222 // arena team has only one member (=captain)
223 if(_player
->GetGUID() == at
->GetCaptain())
230 at
->DelMember(_player
->GetGUID());
234 BuildArenaTeamEventPacket(&data
, ERR_ARENA_TEAM_LEAVE_SS
, 2, _player
->GetName(), at
->GetName(), "");
235 at
->BroadcastPacket(&data
);
237 //send you are no longer member of team
238 SendArenaTeamCommandResult(ERR_ARENA_TEAM_QUIT_S
, at
->GetName(), "", 0);
241 void WorldSession::HandleArenaTeamDisbandOpcode(WorldPacket
& recv_data
)
243 sLog
.outDebug("CMSG_ARENA_TEAM_DISBAND");
245 CHECK_PACKET_SIZE(recv_data
, 4);
247 uint32 ArenaTeamId
; // arena team id
248 recv_data
>> ArenaTeamId
;
250 ArenaTeam
*at
= objmgr
.GetArenaTeamById(ArenaTeamId
);
254 if(at
->GetCaptain() != _player
->GetGUID())
257 if (at
->IsFighting())
264 void WorldSession::HandleArenaTeamRemoveFromTeamOpcode(WorldPacket
& recv_data
)
266 sLog
.outDebug("CMSG_ARENA_TEAM_REMOVE_FROM_TEAM");
268 CHECK_PACKET_SIZE(recv_data
, 4+1);
273 recv_data
>> ArenaTeamId
;
276 ArenaTeam
*at
= objmgr
.GetArenaTeamById(ArenaTeamId
);
277 if(!at
) // arena team not found
280 if(at
->GetCaptain() != _player
->GetGUID())
282 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", "", ERR_ARENA_TEAM_PERMISSIONS
);
286 if(!normalizePlayerName(name
))
289 ArenaTeamMember
* member
= at
->GetMember(name
);
290 if(!member
) // member not found
292 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", name
, ERR_ARENA_TEAM_PLAYER_NOT_FOUND_S
);
296 if(at
->GetCaptain() == member
->guid
)
298 SendArenaTeamCommandResult(ERR_ARENA_TEAM_QUIT_S
, "", "", ERR_ARENA_TEAM_LEADER_LEAVE_S
);
302 at
->DelMember(member
->guid
);
306 BuildArenaTeamEventPacket(&data
, ERR_ARENA_TEAM_REMOVE_SSS
, 3, name
, at
->GetName(), _player
->GetName());
307 at
->BroadcastPacket(&data
);
310 void WorldSession::HandleArenaTeamPromoteToCaptainOpcode(WorldPacket
& recv_data
)
312 sLog
.outDebug("CMSG_ARENA_TEAM_PROMOTE_TO_CAPTAIN");
314 CHECK_PACKET_SIZE(recv_data
, 4+1);
319 recv_data
>> ArenaTeamId
;
322 ArenaTeam
*at
= objmgr
.GetArenaTeamById(ArenaTeamId
);
323 if(!at
) // arena team not found
326 if(at
->GetCaptain() != _player
->GetGUID())
328 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", "", ERR_ARENA_TEAM_PERMISSIONS
);
332 if(!normalizePlayerName(name
))
335 ArenaTeamMember
* member
= at
->GetMember(name
);
336 if(!member
) // member not found
338 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", name
, ERR_ARENA_TEAM_PLAYER_NOT_FOUND_S
);
342 if(at
->GetCaptain() == member
->guid
) // target player already captain
345 at
->SetCaptain(member
->guid
);
349 BuildArenaTeamEventPacket(&data
, ERR_ARENA_TEAM_LEADER_CHANGED_SSS
, 3, _player
->GetName(), name
, at
->GetName());
350 at
->BroadcastPacket(&data
);
353 void WorldSession::SendArenaTeamCommandResult(uint32 team_action
, const std::string
& team
, const std::string
& player
, uint32 error_id
)
355 WorldPacket
data(SMSG_ARENA_TEAM_COMMAND_RESULT
, 4+team
.length()+1+player
.length()+1+4);
363 void WorldSession::BuildArenaTeamEventPacket(WorldPacket
*data
, uint8 eventid
, uint8 str_count
, const std::string
& str1
, const std::string
& str2
, const std::string
& str3
)
365 data
->Initialize(SMSG_ARENA_TEAM_EVENT
, 1+1+1);
383 sLog
.outError("Unhandled str_count %u in SendArenaTeamEvent()", str_count
);
388 void WorldSession::SendNotInArenaTeamPacket(uint8 type
)
390 WorldPacket
data(SMSG_ARENA_ERROR
, 4+1); // 886 - You are not in a %uv%u arena team
392 data
<< uint32(unk
); // unk(0)
394 data
<< uint8(type
); // team type (2=2v2,3=3v3,5=5v5), can be used for custom types...
399 +ERR_ARENA_NO_TEAM_II "You are not in a %dv%d arena team"
401 +ERR_ARENA_TEAM_CREATE_S "%s created. To disband, use /teamdisband [2v2, 3v3, 5v5]."
402 +ERR_ARENA_TEAM_INVITE_SS "You have invited %s to join %s"
403 +ERR_ARENA_TEAM_QUIT_S "You are no longer a member of %s"
404 ERR_ARENA_TEAM_FOUNDER_S "Congratulations, you are a founding member of %s! To leave, use /teamquit [2v2, 3v3, 5v5]."
406 +ERR_ARENA_TEAM_INTERNAL "Internal arena team error"
407 +ERR_ALREADY_IN_ARENA_TEAM "You are already in an arena team of that size"
408 +ERR_ALREADY_IN_ARENA_TEAM_S "%s is already in an arena team of that size"
409 +ERR_INVITED_TO_ARENA_TEAM "You have already been invited into an arena team"
410 +ERR_ALREADY_INVITED_TO_ARENA_TEAM_S "%s has already been invited to an arena team"
411 +ERR_ARENA_TEAM_NAME_INVALID "That name contains invalid characters, please enter a new name"
412 +ERR_ARENA_TEAM_NAME_EXISTS_S "There is already an arena team named \"%s\""
413 +ERR_ARENA_TEAM_LEADER_LEAVE_S "You must promote a new team captain using /teamcaptain before leaving the team"
414 +ERR_ARENA_TEAM_PERMISSIONS "You don't have permission to do that"
415 +ERR_ARENA_TEAM_PLAYER_NOT_IN_TEAM "You are not in an arena team of that size"
416 +ERR_ARENA_TEAM_PLAYER_NOT_IN_TEAM_SS "%s is not in %s"
417 +ERR_ARENA_TEAM_PLAYER_NOT_FOUND_S "\"%s\" not found"
418 +ERR_ARENA_TEAM_NOT_ALLIED "You cannot invite players from the opposing alliance"
420 +ERR_ARENA_TEAM_JOIN_SS "%s has joined %s"
421 +ERR_ARENA_TEAM_YOU_JOIN_S "You have joined %s. To leave, use /teamquit [2v2, 3v3, 5v5]."
423 +ERR_ARENA_TEAM_LEAVE_SS "%s has left %s"
425 +ERR_ARENA_TEAM_LEADER_IS_SS "%s is the captain of %s"
426 +ERR_ARENA_TEAM_LEADER_CHANGED_SSS "%s has made %s the new captain of %s"
428 +ERR_ARENA_TEAM_REMOVE_SSS "%s has been kicked out of %s by %s"
430 +ERR_ARENA_TEAM_DISBANDED_S "%s has disbanded %s"
432 ERR_ARENA_TEAM_TARGET_TOO_LOW_S "%s is not high enough level to join your team"
434 ERR_ARENA_TEAM_TOO_MANY_MEMBERS_S "%s is full"
436 ERR_ARENA_TEAM_LEVEL_TOO_LOW_I "You must be level %d to form an arena team"