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