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::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
= objmgr
.GetPlayer(guid
))
39 for (uint8 i
= 0; i
< MAX_ARENA_SLOT
; ++i
)
41 if(uint32 a_id
= plr
->GetArenaTeamId(i
))
43 if(ArenaTeam
*at
= objmgr
.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 ArenaTeam
*arenateam
= objmgr
.GetArenaTeamById(ArenaTeamId
);
58 if(!arenateam
) // arena team not found
61 arenateam
->Query(this);
62 arenateam
->Stats(this);
65 void WorldSession::HandleArenaTeamRosterOpcode(WorldPacket
& recv_data
)
67 sLog
.outDebug( "WORLD: Received CMSG_ARENA_TEAM_ROSTER" );
69 uint32 ArenaTeamId
; // arena team id
70 recv_data
>> ArenaTeamId
;
72 ArenaTeam
*arenateam
= objmgr
.GetArenaTeamById(ArenaTeamId
);
76 arenateam
->Roster(this);
79 void WorldSession::HandleArenaTeamInviteOpcode(WorldPacket
& recv_data
)
81 sLog
.outDebug("CMSG_ARENA_TEAM_INVITE");
83 uint32 ArenaTeamId
; // arena team id
84 std::string Invitedname
;
86 Player
* player
= NULL
;
88 recv_data
>> ArenaTeamId
>> Invitedname
;
90 if(!Invitedname
.empty())
92 if(!normalizePlayerName(Invitedname
))
95 player
= ObjectAccessor::Instance().FindPlayerByName(Invitedname
.c_str());
100 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", Invitedname
, ERR_ARENA_TEAM_PLAYER_NOT_FOUND_S
);
104 if(player
->getLevel() < sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
106 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", player
->GetName(), ERR_ARENA_TEAM_PLAYER_TO_LOW
);
110 ArenaTeam
*arenateam
= objmgr
.GetArenaTeamById(ArenaTeamId
);
113 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", "", ERR_ARENA_TEAM_PLAYER_NOT_IN_TEAM
);
117 // OK result but not send invite
118 if(player
->GetSocial()->HasIgnore(GetPlayer()->GetGUIDLow()))
121 if (!sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD
) && player
->GetTeam() != GetPlayer()->GetTeam())
123 SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS
, "", "", ERR_ARENA_TEAM_NOT_ALLIED
);
127 if(player
->GetArenaTeamId(arenateam
->GetSlot()))
129 SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS
, "", player
->GetName(), ERR_ALREADY_IN_ARENA_TEAM_S
);
133 if(player
->GetArenaTeamIdInvited())
135 SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS
, "", player
->GetName(), ERR_ALREADY_INVITED_TO_ARENA_TEAM_S
);
139 if(arenateam
->GetMembersSize() >= arenateam
->GetType() * 2)
141 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
,arenateam
->GetName(),"",ERR_ARENA_TEAM_FULL
);
145 sLog
.outDebug("Player %s Invited %s to Join his ArenaTeam", GetPlayer()->GetName(), Invitedname
.c_str());
147 player
->SetArenaTeamIdInvited(arenateam
->GetId());
149 WorldPacket
data(SMSG_ARENA_TEAM_INVITE
, (8+10));
150 data
<< GetPlayer()->GetName();
151 data
<< arenateam
->GetName();
152 player
->GetSession()->SendPacket(&data
);
154 sLog
.outDebug("WORLD: Sent SMSG_ARENA_TEAM_INVITE");
157 void WorldSession::HandleArenaTeamAcceptOpcode(WorldPacket
& /*recv_data*/)
159 sLog
.outDebug("CMSG_ARENA_TEAM_ACCEPT"); // empty opcode
161 ArenaTeam
*at
= objmgr
.GetArenaTeamById(_player
->GetArenaTeamIdInvited());
165 if(_player
->GetArenaTeamId(at
->GetSlot()))
167 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
,"","",ERR_ALREADY_IN_ARENA_TEAM
); // already in arena team that size
171 if (!sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD
) && _player
->GetTeam() != objmgr
.GetPlayerTeamByGUID(at
->GetCaptain()))
173 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
,"","",ERR_ARENA_TEAM_NOT_ALLIED
);// not let enemies sign petition
177 if(!at
->AddMember(_player
->GetGUID()))
179 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
,"","",ERR_ARENA_TEAM_INTERNAL
);// arena team not found
185 BuildArenaTeamEventPacket(&data
, ERR_ARENA_TEAM_JOIN_SS
, 2, _player
->GetName(), at
->GetName(), "");
186 at
->BroadcastPacket(&data
);
189 void WorldSession::HandleArenaTeamDeclineOpcode(WorldPacket
& /*recv_data*/)
191 sLog
.outDebug("CMSG_ARENA_TEAM_DECLINE"); // empty opcode
193 _player
->SetArenaTeamIdInvited(0); // no more invited
196 void WorldSession::HandleArenaTeamLeaveOpcode(WorldPacket
& recv_data
)
198 sLog
.outDebug("CMSG_ARENA_TEAM_LEAVE");
200 uint32 ArenaTeamId
; // arena team id
201 recv_data
>> ArenaTeamId
;
203 ArenaTeam
*at
= objmgr
.GetArenaTeamById(ArenaTeamId
);
206 if(_player
->GetGUID() == at
->GetCaptain() && at
->GetMembersSize() > 1)
208 // check for correctness
209 SendArenaTeamCommandResult(ERR_ARENA_TEAM_QUIT_S
, "", "", ERR_ARENA_TEAM_LEADER_LEAVE_S
);
212 // arena team has only one member (=captain)
213 if(_player
->GetGUID() == at
->GetCaptain())
220 at
->DelMember(_player
->GetGUID());
224 BuildArenaTeamEventPacket(&data
, ERR_ARENA_TEAM_LEAVE_SS
, 2, _player
->GetName(), at
->GetName(), "");
225 at
->BroadcastPacket(&data
);
227 //send you are no longer member of team
228 SendArenaTeamCommandResult(ERR_ARENA_TEAM_QUIT_S
, at
->GetName(), "", 0);
231 void WorldSession::HandleArenaTeamDisbandOpcode(WorldPacket
& recv_data
)
233 sLog
.outDebug("CMSG_ARENA_TEAM_DISBAND");
235 uint32 ArenaTeamId
; // arena team id
236 recv_data
>> ArenaTeamId
;
238 ArenaTeam
*at
= objmgr
.GetArenaTeamById(ArenaTeamId
);
242 if(at
->GetCaptain() != _player
->GetGUID())
245 if (at
->IsFighting())
252 void WorldSession::HandleArenaTeamRemoveOpcode(WorldPacket
& recv_data
)
254 sLog
.outDebug("CMSG_ARENA_TEAM_REMOVE");
259 recv_data
>> ArenaTeamId
;
262 ArenaTeam
*at
= objmgr
.GetArenaTeamById(ArenaTeamId
);
263 if(!at
) // arena team not found
266 if(at
->GetCaptain() != _player
->GetGUID())
268 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", "", ERR_ARENA_TEAM_PERMISSIONS
);
272 if(!normalizePlayerName(name
))
275 ArenaTeamMember
* member
= at
->GetMember(name
);
276 if(!member
) // member not found
278 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", name
, ERR_ARENA_TEAM_PLAYER_NOT_FOUND_S
);
282 if(at
->GetCaptain() == member
->guid
)
284 SendArenaTeamCommandResult(ERR_ARENA_TEAM_QUIT_S
, "", "", ERR_ARENA_TEAM_LEADER_LEAVE_S
);
288 at
->DelMember(member
->guid
);
292 BuildArenaTeamEventPacket(&data
, ERR_ARENA_TEAM_REMOVE_SSS
, 3, name
, at
->GetName(), _player
->GetName());
293 at
->BroadcastPacket(&data
);
296 void WorldSession::HandleArenaTeamLeaderOpcode(WorldPacket
& recv_data
)
298 sLog
.outDebug("CMSG_ARENA_TEAM_LEADER");
303 recv_data
>> ArenaTeamId
;
306 ArenaTeam
*at
= objmgr
.GetArenaTeamById(ArenaTeamId
);
307 if(!at
) // arena team not found
310 if(at
->GetCaptain() != _player
->GetGUID())
312 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", "", ERR_ARENA_TEAM_PERMISSIONS
);
316 if(!normalizePlayerName(name
))
319 ArenaTeamMember
* member
= at
->GetMember(name
);
320 if(!member
) // member not found
322 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, "", name
, ERR_ARENA_TEAM_PLAYER_NOT_FOUND_S
);
326 if(at
->GetCaptain() == member
->guid
) // target player already captain
329 at
->SetCaptain(member
->guid
);
333 BuildArenaTeamEventPacket(&data
, ERR_ARENA_TEAM_LEADER_CHANGED_SSS
, 3, _player
->GetName(), name
, at
->GetName());
334 at
->BroadcastPacket(&data
);
337 void WorldSession::SendArenaTeamCommandResult(uint32 team_action
, const std::string
& team
, const std::string
& player
, uint32 error_id
)
339 WorldPacket
data(SMSG_ARENA_TEAM_COMMAND_RESULT
, 4+team
.length()+1+player
.length()+1+4);
347 void WorldSession::BuildArenaTeamEventPacket(WorldPacket
*data
, uint8 eventid
, uint8 str_count
, const std::string
& str1
, const std::string
& str2
, const std::string
& str3
)
349 data
->Initialize(SMSG_ARENA_TEAM_EVENT
, 1+1+1);
367 sLog
.outError("Unhandled str_count %u in SendArenaTeamEvent()", str_count
);
372 void WorldSession::SendNotInArenaTeamPacket(uint8 type
)
374 WorldPacket
data(SMSG_ARENA_ERROR
, 4+1); // 886 - You are not in a %uv%u arena team
376 data
<< uint32(unk
); // unk(0)
378 data
<< uint8(type
); // team type (2=2v2,3=3v3,5=5v5), can be used for custom types...
383 +ERR_ARENA_NO_TEAM_II "You are not in a %dv%d arena team"
385 +ERR_ARENA_TEAM_CREATE_S "%s created. To disband, use /teamdisband [2v2, 3v3, 5v5]."
386 +ERR_ARENA_TEAM_INVITE_SS "You have invited %s to join %s"
387 +ERR_ARENA_TEAM_QUIT_S "You are no longer a member of %s"
388 ERR_ARENA_TEAM_FOUNDER_S "Congratulations, you are a founding member of %s! To leave, use /teamquit [2v2, 3v3, 5v5]."
390 +ERR_ARENA_TEAM_INTERNAL "Internal arena team error"
391 +ERR_ALREADY_IN_ARENA_TEAM "You are already in an arena team of that size"
392 +ERR_ALREADY_IN_ARENA_TEAM_S "%s is already in an arena team of that size"
393 +ERR_INVITED_TO_ARENA_TEAM "You have already been invited into an arena team"
394 +ERR_ALREADY_INVITED_TO_ARENA_TEAM_S "%s has already been invited to an arena team"
395 +ERR_ARENA_TEAM_NAME_INVALID "That name contains invalid characters, please enter a new name"
396 +ERR_ARENA_TEAM_NAME_EXISTS_S "There is already an arena team named \"%s\""
397 +ERR_ARENA_TEAM_LEADER_LEAVE_S "You must promote a new team captain using /teamcaptain before leaving the team"
398 +ERR_ARENA_TEAM_PERMISSIONS "You don't have permission to do that"
399 +ERR_ARENA_TEAM_PLAYER_NOT_IN_TEAM "You are not in an arena team of that size"
400 +ERR_ARENA_TEAM_PLAYER_NOT_IN_TEAM_SS "%s is not in %s"
401 +ERR_ARENA_TEAM_PLAYER_NOT_FOUND_S "\"%s\" not found"
402 +ERR_ARENA_TEAM_NOT_ALLIED "You cannot invite players from the opposing alliance"
404 +ERR_ARENA_TEAM_JOIN_SS "%s has joined %s"
405 +ERR_ARENA_TEAM_YOU_JOIN_S "You have joined %s. To leave, use /teamquit [2v2, 3v3, 5v5]."
407 +ERR_ARENA_TEAM_LEAVE_SS "%s has left %s"
409 +ERR_ARENA_TEAM_LEADER_IS_SS "%s is the captain of %s"
410 +ERR_ARENA_TEAM_LEADER_CHANGED_SSS "%s has made %s the new captain of %s"
412 +ERR_ARENA_TEAM_REMOVE_SSS "%s has been kicked out of %s by %s"
414 +ERR_ARENA_TEAM_DISBANDED_S "%s has disbanded %s"
416 ERR_ARENA_TEAM_TARGET_TOO_LOW_S "%s is not high enough level to join your team"
418 ERR_ARENA_TEAM_TOO_MANY_MEMBERS_S "%s is full"
420 ERR_ARENA_TEAM_LEVEL_TOO_LOW_I "You must be level %d to form an arena team"