2 * Copyright (C) 2005-2010 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::HandleInspectArenaTeamsOpcode(WorldPacket
& recv_data
)
31 sLog
.outDebug("MSG_INSPECT_ARENA_TEAMS");
35 sLog
.outDebug("Inspect Arena stats (GUID: %u TypeId: %u)", GUID_LOPART(guid
),GuidHigh2TypeId(GUID_HIPART(guid
)));
37 if(Player
*plr
= sObjectMgr
.GetPlayer(guid
))
39 for (uint8 i
= 0; i
< MAX_ARENA_SLOT
; ++i
)
41 if(uint32 a_id
= plr
->GetArenaTeamId(i
))
43 if(ArenaTeam
*at
= sObjectMgr
.GetArenaTeamById(a_id
))
44 at
->InspectStats(this, plr
->GetGUID());
50 void WorldSession::HandleArenaTeamQueryOpcode(WorldPacket
& recv_data
)
52 sLog
.outDebug( "WORLD: Received CMSG_ARENA_TEAM_QUERY" );
55 recv_data
>> ArenaTeamId
;
57 if(ArenaTeam
*arenateam
= sObjectMgr
.GetArenaTeamById(ArenaTeamId
))
59 arenateam
->Query(this);
60 arenateam
->Stats(this);
64 void WorldSession::HandleArenaTeamRosterOpcode(WorldPacket
& recv_data
)
66 sLog
.outDebug( "WORLD: Received CMSG_ARENA_TEAM_ROSTER" );
68 uint32 ArenaTeamId
; // arena team id
69 recv_data
>> ArenaTeamId
;
71 if(ArenaTeam
*arenateam
= sObjectMgr
.GetArenaTeamById(ArenaTeamId
))
72 arenateam
->Roster(this);
75 void WorldSession::HandleArenaTeamInviteOpcode(WorldPacket
& recv_data
)
77 sLog
.outDebug("CMSG_ARENA_TEAM_INVITE");
79 uint32 ArenaTeamId
; // arena team id
80 std::string Invitedname
;
82 Player
* player
= NULL
;
84 recv_data
>> ArenaTeamId
>> Invitedname
;
86 if(!Invitedname
.empty())
88 if(!normalizePlayerName(Invitedname
))
91 player
= ObjectAccessor::FindPlayerByName(Invitedname
.c_str());
96 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", Invitedname
, ERR_ARENA_TEAM_PLAYER_NOT_FOUND_S
);
100 if(player
->getLevel() < sWorld
.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL
))
102 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", player
->GetName(), ERR_ARENA_TEAM_TARGET_TOO_LOW_S
);
106 ArenaTeam
*arenateam
= sObjectMgr
.GetArenaTeamById(ArenaTeamId
);
109 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", "", ERR_ARENA_TEAM_PLAYER_NOT_IN_TEAM
);
113 // OK result but not send invite
114 if(player
->GetSocial()->HasIgnore(GetPlayer()->GetGUIDLow()))
117 if (!sWorld
.getConfig(CONFIG_BOOL_ALLOW_TWO_SIDE_INTERACTION_GUILD
) && player
->GetTeam() != GetPlayer()->GetTeam())
119 SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS
, "", "", ERR_ARENA_TEAM_NOT_ALLIED
);
123 if(player
->GetArenaTeamId(arenateam
->GetSlot()))
125 SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS
, "", player
->GetName(), ERR_ALREADY_IN_ARENA_TEAM_S
);
129 if(player
->GetArenaTeamIdInvited())
131 SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS
, "", player
->GetName(), ERR_ALREADY_INVITED_TO_ARENA_TEAM_S
);
135 if(arenateam
->GetMembersSize() >= arenateam
->GetType() * 2)
137 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, arenateam
->GetName(), "", ERR_ARENA_TEAM_TOO_MANY_MEMBERS_S
);
141 sLog
.outDebug("Player %s Invited %s to Join his ArenaTeam", GetPlayer()->GetName(), Invitedname
.c_str());
143 player
->SetArenaTeamIdInvited(arenateam
->GetId());
145 WorldPacket
data(SMSG_ARENA_TEAM_INVITE
, (8+10));
146 data
<< GetPlayer()->GetName();
147 data
<< arenateam
->GetName();
148 player
->GetSession()->SendPacket(&data
);
150 sLog
.outDebug("WORLD: Sent SMSG_ARENA_TEAM_INVITE");
153 void WorldSession::HandleArenaTeamAcceptOpcode(WorldPacket
& /*recv_data*/)
155 sLog
.outDebug("CMSG_ARENA_TEAM_ACCEPT"); // empty opcode
157 ArenaTeam
*at
= sObjectMgr
.GetArenaTeamById(_player
->GetArenaTeamIdInvited());
161 if(_player
->GetArenaTeamId(at
->GetSlot()))
163 // already in arena team that size
164 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", "", ERR_ALREADY_IN_ARENA_TEAM
);
168 if (!sWorld
.getConfig(CONFIG_BOOL_ALLOW_TWO_SIDE_INTERACTION_GUILD
) && _player
->GetTeam() != sObjectMgr
.GetPlayerTeamByGUID(at
->GetCaptain()))
170 // not let enemies sign petition
171 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", "", ERR_ARENA_TEAM_NOT_ALLIED
);
175 if(!at
->AddMember(_player
->GetGUID()))
177 // arena team not found
178 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
,"","",ERR_ARENA_TEAM_INTERNAL
);
183 at
->BroadcastEvent(ERR_ARENA_TEAM_JOIN_SS
, _player
->GetGUID(), 2, _player
->GetName(), at
->GetName(), "");
186 void WorldSession::HandleArenaTeamDeclineOpcode(WorldPacket
& /*recv_data*/)
188 sLog
.outDebug("CMSG_ARENA_TEAM_DECLINE"); // empty opcode
190 _player
->SetArenaTeamIdInvited(0); // no more invited
193 void WorldSession::HandleArenaTeamLeaveOpcode(WorldPacket
& recv_data
)
195 sLog
.outDebug("CMSG_ARENA_TEAM_LEAVE");
197 uint32 ArenaTeamId
; // arena team id
198 recv_data
>> ArenaTeamId
;
200 ArenaTeam
*at
= sObjectMgr
.GetArenaTeamById(ArenaTeamId
);
204 if(_player
->GetGUID() == at
->GetCaptain() && at
->GetMembersSize() > 1)
206 // check for correctness
207 SendArenaTeamCommandResult(ERR_ARENA_TEAM_QUIT_S
, "", "", ERR_ARENA_TEAM_LEADER_LEAVE_S
);
211 // arena team has only one member (=captain)
212 if(_player
->GetGUID() == at
->GetCaptain())
219 at
->DelMember(_player
->GetGUID());
222 at
->BroadcastEvent(ERR_ARENA_TEAM_LEAVE_SS
, _player
->GetGUID(), 2, _player
->GetName(), at
->GetName(), "");
224 // send you are no longer member of team
225 SendArenaTeamCommandResult(ERR_ARENA_TEAM_QUIT_S
, at
->GetName(), "", 0);
228 void WorldSession::HandleArenaTeamDisbandOpcode(WorldPacket
& recv_data
)
230 sLog
.outDebug("CMSG_ARENA_TEAM_DISBAND");
232 uint32 ArenaTeamId
; // arena team id
233 recv_data
>> ArenaTeamId
;
235 if(ArenaTeam
*at
= sObjectMgr
.GetArenaTeamById(ArenaTeamId
))
237 if(at
->GetCaptain() != _player
->GetGUID())
248 void WorldSession::HandleArenaTeamRemoveOpcode(WorldPacket
& recv_data
)
250 sLog
.outDebug("CMSG_ARENA_TEAM_REMOVE");
255 recv_data
>> ArenaTeamId
;
258 ArenaTeam
*at
= sObjectMgr
.GetArenaTeamById(ArenaTeamId
);
259 if(!at
) // arena team not found
262 if(at
->GetCaptain() != _player
->GetGUID())
264 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", "", ERR_ARENA_TEAM_PERMISSIONS
);
268 if(!normalizePlayerName(name
))
271 ArenaTeamMember
* member
= at
->GetMember(name
);
272 if(!member
) // member not found
274 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", name
, ERR_ARENA_TEAM_PLAYER_NOT_FOUND_S
);
278 if(at
->GetCaptain() == member
->guid
)
280 SendArenaTeamCommandResult(ERR_ARENA_TEAM_QUIT_S
, "", "", ERR_ARENA_TEAM_LEADER_LEAVE_S
);
284 at
->DelMember(member
->guid
);
287 at
->BroadcastEvent(ERR_ARENA_TEAM_REMOVE_SSS
, 0, 3, name
, at
->GetName(), _player
->GetName());
290 void WorldSession::HandleArenaTeamLeaderOpcode(WorldPacket
& recv_data
)
292 sLog
.outDebug("CMSG_ARENA_TEAM_LEADER");
297 recv_data
>> ArenaTeamId
;
300 ArenaTeam
*at
= sObjectMgr
.GetArenaTeamById(ArenaTeamId
);
301 if(!at
) // arena team not found
304 if(at
->GetCaptain() != _player
->GetGUID())
306 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", "", ERR_ARENA_TEAM_PERMISSIONS
);
310 if(!normalizePlayerName(name
))
313 ArenaTeamMember
* member
= at
->GetMember(name
);
314 if(!member
) // member not found
316 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", name
, ERR_ARENA_TEAM_PLAYER_NOT_FOUND_S
);
320 if(at
->GetCaptain() == member
->guid
) // target player already captain
323 at
->SetCaptain(member
->guid
);
326 at
->BroadcastEvent(ERR_ARENA_TEAM_LEADER_CHANGED_SSS
, 0, 3, _player
->GetName(), name
, at
->GetName());
329 void WorldSession::SendArenaTeamCommandResult(uint32 team_action
, const std::string
& team
, const std::string
& player
, uint32 error_id
)
331 WorldPacket
data(SMSG_ARENA_TEAM_COMMAND_RESULT
, 4+team
.length()+1+player
.length()+1+4);
332 data
<< uint32(team_action
);
335 data
<< uint32(error_id
);
339 void WorldSession::SendNotInArenaTeamPacket(uint8 type
)
341 WorldPacket
data(SMSG_ARENA_ERROR
, 4+1); // 886 - You are not in a %uv%u arena team
343 data
<< uint32(unk
); // unk(0)
345 data
<< uint8(type
); // team type (2=2v2,3=3v3,5=5v5), can be used for custom types...
350 +ERR_ARENA_NO_TEAM_II "You are not in a %dv%d arena team"
352 +ERR_ARENA_TEAM_CREATE_S "%s created. To disband, use /teamdisband [2v2, 3v3, 5v5]."
353 +ERR_ARENA_TEAM_INVITE_SS "You have invited %s to join %s"
354 +ERR_ARENA_TEAM_QUIT_S "You are no longer a member of %s"
355 ERR_ARENA_TEAM_FOUNDER_S "Congratulations, you are a founding member of %s! To leave, use /teamquit [2v2, 3v3, 5v5]."
357 +ERR_ARENA_TEAM_INTERNAL "Internal arena team error"
358 +ERR_ALREADY_IN_ARENA_TEAM "You are already in an arena team of that size"
359 +ERR_ALREADY_IN_ARENA_TEAM_S "%s is already in an arena team of that size"
360 +ERR_INVITED_TO_ARENA_TEAM "You have already been invited into an arena team"
361 +ERR_ALREADY_INVITED_TO_ARENA_TEAM_S "%s has already been invited to an arena team"
362 +ERR_ARENA_TEAM_NAME_INVALID "That name contains invalid characters, please enter a new name"
363 +ERR_ARENA_TEAM_NAME_EXISTS_S "There is already an arena team named \"%s\""
364 +ERR_ARENA_TEAM_LEADER_LEAVE_S "You must promote a new team captain using /teamcaptain before leaving the team"
365 +ERR_ARENA_TEAM_PERMISSIONS "You don't have permission to do that"
366 +ERR_ARENA_TEAM_PLAYER_NOT_IN_TEAM "You are not in an arena team of that size"
367 +ERR_ARENA_TEAM_PLAYER_NOT_IN_TEAM_SS "%s is not in %s"
368 +ERR_ARENA_TEAM_PLAYER_NOT_FOUND_S "\"%s\" not found"
369 +ERR_ARENA_TEAM_NOT_ALLIED "You cannot invite players from the opposing alliance"
371 +ERR_ARENA_TEAM_JOIN_SS "%s has joined %s"
372 +ERR_ARENA_TEAM_YOU_JOIN_S "You have joined %s. To leave, use /teamquit [2v2, 3v3, 5v5]."
374 +ERR_ARENA_TEAM_LEAVE_SS "%s has left %s"
376 +ERR_ARENA_TEAM_LEADER_IS_SS "%s is the captain of %s"
377 +ERR_ARENA_TEAM_LEADER_CHANGED_SSS "%s has made %s the new captain of %s"
379 +ERR_ARENA_TEAM_REMOVE_SSS "%s has been kicked out of %s by %s"
381 +ERR_ARENA_TEAM_DISBANDED_S "%s has disbanded %s"
383 ERR_ARENA_TEAM_TARGET_TOO_LOW_S "%s is not high enough level to join your team"
385 ERR_ARENA_TEAM_TOO_MANY_MEMBERS_S "%s is full"
387 ERR_ARENA_TEAM_LEVEL_TOO_LOW_I "You must be level %d to form an arena team"