root/trunk/src/game/ArenaTeamHandler.cpp @ 28

Revision 28, 14.1 kB (checked in by yumileroy, 17 years ago)

[svn] * Updated to 6743 and 685

Moved language id used by Arena to a higher place to solve conflicts
Added the empty script folders

Original author: Neo2003
Date: 2008-10-09 08:42:22-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#include "WorldSession.h"
20#include "WorldPacket.h"
21#include "Log.h"
22#include "Database/DatabaseEnv.h"
23#include "Player.h"
24#include "ObjectMgr.h"
25#include "ArenaTeam.h"
26#include "World.h"
27#include "SocialMgr.h"
28#include "Language.h"
29
30void WorldSession::HandleInspectArenaStatsOpcode(WorldPacket & recv_data)
31{
32    sLog.outDebug("MSG_INSPECT_ARENA_TEAMS");
33    //recv_data.hexlike();
34
35    CHECK_PACKET_SIZE(recv_data, 8);
36
37    uint64 guid;
38    recv_data >> guid;
39    sLog.outDebug("Inspect Arena stats " I64FMTD, guid);
40
41    if(Player *plr = objmgr.GetPlayer(guid))
42    {
43        for (uint8 i = 0; i < MAX_ARENA_SLOT; i++)
44        {
45            if(uint32 a_id = plr->GetArenaTeamId(i))
46            {
47                if(ArenaTeam *at = objmgr.GetArenaTeamById(a_id))
48                    at->InspectStats(this, plr->GetGUID());
49            }
50        }
51    }
52}
53
54void WorldSession::HandleArenaTeamQueryOpcode(WorldPacket & recv_data)
55{
56    sLog.outDebug( "WORLD: Received CMSG_ARENA_TEAM_QUERY" );
57    //recv_data.hexlike();
58
59    CHECK_PACKET_SIZE(recv_data, 4);
60
61    uint32 ArenaTeamId;
62    recv_data >> ArenaTeamId;
63
64    ArenaTeam *arenateam = objmgr.GetArenaTeamById(ArenaTeamId);
65    if(!arenateam)                                          // arena team not found
66        return;
67
68    arenateam->Query(this);
69    arenateam->Stats(this);
70}
71
72void WorldSession::HandleArenaTeamRosterOpcode(WorldPacket & recv_data)
73{
74    sLog.outDebug( "WORLD: Received CMSG_ARENA_TEAM_ROSTER" );
75    //recv_data.hexlike();
76
77    CHECK_PACKET_SIZE(recv_data, 4);
78
79    uint32 ArenaTeamId;                                     // arena team id
80    recv_data >> ArenaTeamId;
81
82    ArenaTeam *arenateam = objmgr.GetArenaTeamById(ArenaTeamId);
83    if(!arenateam)
84        return;
85
86    arenateam->Roster(this);
87}
88
89void WorldSession::HandleArenaTeamAddMemberOpcode(WorldPacket & recv_data)
90{
91    sLog.outDebug("CMSG_ARENA_TEAM_ADD_MEMBER");
92    //recv_data.hexlike();
93
94    CHECK_PACKET_SIZE(recv_data, 4+1);
95
96    uint32 ArenaTeamId;                                     // arena team id
97    std::string Invitedname;
98
99    Player * player = NULL;
100
101    recv_data >> ArenaTeamId >> Invitedname;
102
103    if(!Invitedname.empty())
104    {
105        if(!normalizePlayerName(Invitedname))
106            return;
107
108        player = ObjectAccessor::Instance().FindPlayerByName(Invitedname.c_str());
109    }
110
111    if(!player)
112    {
113        SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", Invitedname, ERR_ARENA_TEAM_PLAYER_NOT_FOUND_S);
114        return;
115    }
116
117    if(player->getLevel() < sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL))
118    {
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());
122        return;
123    }
124
125    ArenaTeam *arenateam = objmgr.GetArenaTeamById(ArenaTeamId);
126    if(!arenateam)
127    {
128        SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, "", "", ERR_ARENA_TEAM_PLAYER_NOT_IN_TEAM);
129        return;
130    }
131
132    // OK result but not send invite
133    if(player->GetSocial()->HasIgnore(GetPlayer()->GetGUIDLow()))
134        return;
135
136    if (!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && player->GetTeam() != GetPlayer()->GetTeam())
137    {
138        SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", "", ERR_ARENA_TEAM_NOT_ALLIED);
139        return;
140    }
141
142    if(player->GetArenaTeamId(arenateam->GetSlot()))
143    {
144        SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, player->GetName(), "", ERR_ALREADY_IN_ARENA_TEAM_S);
145        return;
146    }
147
148    if(player->GetArenaTeamIdInvited())
149    {
150        SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, player->GetName(), "", ERR_ALREADY_INVITED_TO_ARENA_TEAM_S);
151        return;
152    }
153
154    if(arenateam->GetMembersSize() >= arenateam->GetType() * 2)
155    {
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());
159        return;
160    }
161
162    sLog.outDebug("Player %s Invited %s to Join his ArenaTeam", GetPlayer()->GetName(), Invitedname.c_str());
163
164    player->SetArenaTeamIdInvited(arenateam->GetId());
165
166    WorldPacket data(SMSG_ARENA_TEAM_INVITE, (8+10));
167    data << GetPlayer()->GetName();
168    data << arenateam->GetName();
169    player->GetSession()->SendPacket(&data);
170
171    sLog.outDebug("WORLD: Sent SMSG_ARENA_TEAM_INVITE");
172}
173
174void WorldSession::HandleArenaTeamInviteAcceptOpcode(WorldPacket & /*recv_data*/)
175{
176    sLog.outDebug("CMSG_ARENA_TEAM_INVITE_ACCEPT");         // empty opcode
177
178    ArenaTeam *at = objmgr.GetArenaTeamById(_player->GetArenaTeamIdInvited());
179    if(!at)
180    {
181        // arena team not exist
182        return;
183    }
184
185    if(_player->GetArenaTeamId(at->GetSlot()))
186    {
187        // already in arena team that size
188        return;
189    }
190
191    // not let enemies sign petition
192    if (!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && _player->GetTeam() != objmgr.GetPlayerTeamByGUID(at->GetCaptain()))
193        return;
194
195    if(!at->AddMember(_player->GetGUID()))
196        return;
197
198    // event
199    WorldPacket data;
200    BuildArenaTeamEventPacket(&data, ERR_ARENA_TEAM_JOIN_SS, 2, _player->GetName(), at->GetName(), "");
201    at->BroadcastPacket(&data);
202}
203
204void WorldSession::HandleArenaTeamInviteDeclineOpcode(WorldPacket & /*recv_data*/)
205{
206    sLog.outDebug("CMSG_ARENA_TEAM_INVITE_DECLINE");        // empty opcode
207
208    _player->SetArenaTeamIdInvited(0);                      // no more invited
209}
210
211void WorldSession::HandleArenaTeamLeaveOpcode(WorldPacket & recv_data)
212{
213    sLog.outDebug("CMSG_ARENA_TEAM_LEAVE");
214    //recv_data.hexlike();
215
216    CHECK_PACKET_SIZE(recv_data, 4);
217
218    uint32 ArenaTeamId;                                     // arena team id
219    recv_data >> ArenaTeamId;
220
221    ArenaTeam *at = objmgr.GetArenaTeamById(ArenaTeamId);
222    if(!at)
223    {
224        // send command result
225        return;
226    }
227    if(_player->GetGUID() == at->GetCaptain() && at->GetMembersSize() > 1)
228    {
229        // check for correctness
230        SendArenaTeamCommandResult(ERR_ARENA_TEAM_QUIT_S, "", "", ERR_ARENA_TEAM_LEADER_LEAVE_S);
231        return;
232    }
233    // arena team has only one member (=captain)
234    if(_player->GetGUID() == at->GetCaptain())
235    {
236        at->Disband(this);
237        delete at;
238        return;
239    }
240
241    at->DelMember(_player->GetGUID());
242
243    // event
244    WorldPacket data;
245    BuildArenaTeamEventPacket(&data, ERR_ARENA_TEAM_LEAVE_SS, 2, _player->GetName(), at->GetName(), "");
246    at->BroadcastPacket(&data);
247
248    //SendArenaTeamCommandResult(ERR_ARENA_TEAM_QUIT_S, at->GetName(), "", 0);
249}
250
251void WorldSession::HandleArenaTeamDisbandOpcode(WorldPacket & recv_data)
252{
253    sLog.outDebug("CMSG_ARENA_TEAM_DISBAND");
254    //recv_data.hexlike();
255
256    CHECK_PACKET_SIZE(recv_data, 4);
257
258    uint32 ArenaTeamId;                                     // arena team id
259    recv_data >> ArenaTeamId;
260
261    ArenaTeam *at = objmgr.GetArenaTeamById(ArenaTeamId);
262    if(!at)
263    {
264        // arena team not found
265        return;
266    }
267
268    if(at->GetCaptain() != _player->GetGUID())
269    {
270        SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, "", "", ERR_ARENA_TEAM_PERMISSIONS);
271        return;
272    }
273
274    at->Disband(this);
275    delete at;
276}
277
278void WorldSession::HandleArenaTeamRemoveFromTeamOpcode(WorldPacket & recv_data)
279{
280    sLog.outDebug("CMSG_ARENA_TEAM_REMOVE_FROM_TEAM");
281    //recv_data.hexlike();
282
283    CHECK_PACKET_SIZE(recv_data, 4+1);
284
285    uint32 ArenaTeamId;
286    std::string name;
287
288    recv_data >> ArenaTeamId;
289    recv_data >> name;
290
291    ArenaTeam *at = objmgr.GetArenaTeamById(ArenaTeamId);
292    if(!at)
293    {
294        // arena team not found
295        return;
296    }
297
298    uint64 guid = objmgr.GetPlayerGUIDByName(name);
299    if(!guid)
300    {
301        // player guid not found
302        return;
303    }
304
305    if(at->GetCaptain() == guid)
306    {
307        // unsure
308        SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, "", "", ERR_ARENA_TEAM_PERMISSIONS);
309        return;
310    }
311
312    if(at->GetCaptain() != _player->GetGUID())
313    {
314        SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, "", "", ERR_ARENA_TEAM_PERMISSIONS);
315        return;
316    }
317
318    if(at->GetCaptain() == guid)
319    {
320        SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, "", "", ERR_ARENA_TEAM_LEADER_LEAVE_S);
321        return;
322    }
323
324    at->DelMember(guid);
325
326    // event
327    WorldPacket data;
328    BuildArenaTeamEventPacket(&data, ERR_ARENA_TEAM_REMOVE_SSS, 3, name, at->GetName(), _player->GetName());
329    at->BroadcastPacket(&data);
330}
331
332void WorldSession::HandleArenaTeamPromoteToCaptainOpcode(WorldPacket & recv_data)
333{
334    sLog.outDebug("CMSG_ARENA_TEAM_PROMOTE_TO_CAPTAIN");
335    //recv_data.hexlike();
336
337    CHECK_PACKET_SIZE(recv_data, 4+1);
338
339    uint32 ArenaTeamId;
340    std::string name;
341
342    recv_data >> ArenaTeamId;
343    recv_data >> name;
344
345    ArenaTeam *at = objmgr.GetArenaTeamById(ArenaTeamId);
346    if(!at)
347    {
348        // arena team not found
349        return;
350    }
351
352    uint64 guid = objmgr.GetPlayerGUIDByName(name);
353    if(!guid)
354    {
355        // player guid not found
356        return;
357    }
358
359    if(at->GetCaptain() == guid)
360    {
361        // target player already captain
362        return;
363    }
364
365    if(at->GetCaptain() != _player->GetGUID())
366    {
367        SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, "", "", ERR_ARENA_TEAM_PERMISSIONS);
368        return;
369    }
370
371    at->SetCaptain(guid);
372
373    // event
374    WorldPacket data;
375    BuildArenaTeamEventPacket(&data, ERR_ARENA_TEAM_LEADER_CHANGED_SSS, 3, _player->GetName(), name, at->GetName());
376    at->BroadcastPacket(&data);
377}
378
379void WorldSession::SendArenaTeamCommandResult(uint32 unk1, std::string str1, std::string str2, uint32 unk3)
380{
381    WorldPacket data(SMSG_ARENA_TEAM_COMMAND_RESULT, 4+str1.length()+1+str2.length()+1+4);
382    data << unk1;
383    data << str1;
384    data << str2;
385    data << unk3;
386    SendPacket(&data);
387}
388
389void WorldSession::BuildArenaTeamEventPacket(WorldPacket *data, uint8 eventid, uint8 str_count, std::string str1, std::string str2, std::string str3)
390{
391    data->Initialize(SMSG_ARENA_TEAM_EVENT, 1+1+1);
392    *data << eventid;
393    *data << str_count;
394    switch(str_count)
395    {
396        case 1:
397            *data << str1;
398            break;
399        case 2:
400            *data << str1;
401            *data << str2;
402            break;
403        case 3:
404            *data << str1;
405            *data << str2;
406            *data << str3;
407            break;
408        default:
409            sLog.outError("Unhandled str_count %u in SendArenaTeamEvent()", str_count);
410            return;
411    }
412}
413
414void WorldSession::SendNotInArenaTeamPacket(uint8 type)
415{
416    WorldPacket data(SMSG_ARENA_ERROR, 4+1);                // 886 - You are not in a %uv%u arena team
417    uint32 unk = 0;
418    data << uint32(unk);                                    // unk(0)
419    if(!unk)
420        data << uint8(type);                                // team type (2=2v2,3=3v3,5=5v5), can be used for custom types...
421    SendPacket(&data);
422}
423
424/*
425+ERR_ARENA_NO_TEAM_II "You are not in a %dv%d arena team"
426
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"
430ERR_ARENA_TEAM_FOUNDER_S "Congratulations, you are a founding member of %s!  To leave, use /teamquit [2v2, 3v3, 5v5]."
431
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"
445
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]."
448
449+ERR_ARENA_TEAM_LEAVE_SS "%s has left %s"
450
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"
453
454+ERR_ARENA_TEAM_REMOVE_SSS "%s has been kicked out of %s by %s"
455
456+ERR_ARENA_TEAM_DISBANDED_S "%s has disbanded %s"
457
458ERR_ARENA_TEAM_TARGET_TOO_LOW_S "%s is not high enough level to join your team"
459
460ERR_ARENA_TEAM_TOO_MANY_MEMBERS_S "%s is full"
461
462ERR_ARENA_TEAM_LEVEL_TOO_LOW_I "You must be level %d to form an arena team"
463*/
Note: See TracBrowser for help on using the browser.