2 * Copyright (C) 2005-2008 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
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
24 #include "ObjectMgr.h"
28 #include "ArenaTeam.h"
29 #include "MapManager.h"
30 #include "GossipDef.h"
31 #include "SocialMgr.h"
33 /*enum PetitionType // dbc data
35 PETITION_TYPE_GUILD = 1,
36 PETITION_TYPE_ARENA_TEAM = 3
39 // Charters ID in item_template
40 #define GUILD_CHARTER 5863
41 #define GUILD_CHARTER_COST 1000 // 10 S
42 #define ARENA_TEAM_CHARTER_2v2 23560
43 #define ARENA_TEAM_CHARTER_2v2_COST 800000 // 80 G
44 #define ARENA_TEAM_CHARTER_3v3 23561
45 #define ARENA_TEAM_CHARTER_3v3_COST 1200000 // 120 G
46 #define ARENA_TEAM_CHARTER_5v5 23562
47 #define ARENA_TEAM_CHARTER_5v5_COST 2000000 // 200 G
49 void WorldSession::HandlePetitionBuyOpcode(WorldPacket
& recv_data
)
51 CHECK_PACKET_SIZE(recv_data
, 8+8+4+1+5*8+2+1+4+4);
53 sLog
.outDebug("Received opcode CMSG_PETITION_BUY");
54 //recv_data.hexlike();
57 uint64 unk1
, unk3
, unk4
, unk5
, unk6
, unk7
;
62 uint32 unk10
; // selected index
64 recv_data
>> guidNPC
; // NPC GUID
65 recv_data
>> unk1
; // 0
66 recv_data
>> unk2
; // 0
67 recv_data
>> name
; // name
70 CHECK_PACKET_SIZE(recv_data
, 8+8+4+(name
.size()+1)+5*8+2+1+4+4);
72 recv_data
>> unk3
; // 0
73 recv_data
>> unk4
; // 0
74 recv_data
>> unk5
; // 0
75 recv_data
>> unk6
; // 0
76 recv_data
>> unk7
; // 0
77 recv_data
>> unk8
; // 0
78 recv_data
>> unk9
; // 0
79 recv_data
>> unk10
; // index
80 recv_data
>> unk11
; // 0
81 sLog
.outDebug("Petitioner with GUID %u tried sell petition: name %s", GUID_LOPART(guidNPC
), name
.c_str());
84 Creature
*pCreature
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, guidNPC
,UNIT_NPC_FLAG_PETITIONER
);
87 sLog
.outDebug("WORLD: HandlePetitionBuyOpcode - Unit (GUID: %u) not found or you can't interact with him.", GUID_LOPART(guidNPC
));
92 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
93 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
98 if(pCreature
->isTabardDesigner())
100 // if tabard designer, then trying to buy a guild charter.
101 // do not let if already in guild.
102 if(_player
->GetGuildId())
105 charterid
= GUILD_CHARTER
;
106 cost
= GUILD_CHARTER_COST
;
111 // TODO: find correct opcode
112 if(_player
->getLevel() < sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
114 SendNotification(LANG_ARENA_ONE_TOOLOW
, 70);
118 for(uint8 i
= 0; i
< MAX_ARENA_SLOT
; i
++)
120 if(_player
->GetArenaTeamId(i
) && (i
== (unk10
-1)))
122 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, name
, "", ERR_ALREADY_IN_ARENA_TEAM
);
129 charterid
= ARENA_TEAM_CHARTER_2v2
;
130 cost
= ARENA_TEAM_CHARTER_2v2_COST
;
134 charterid
= ARENA_TEAM_CHARTER_3v3
;
135 cost
= ARENA_TEAM_CHARTER_3v3_COST
;
139 charterid
= ARENA_TEAM_CHARTER_5v5
;
140 cost
= ARENA_TEAM_CHARTER_5v5_COST
;
144 sLog
.outDebug("unknown selection at buy petition: %u", unk10
);
151 if(objmgr
.GetGuildByName(name
))
153 SendGuildCommandResult(GUILD_CREATE_S
, name
, GUILD_NAME_EXISTS
);
156 if(objmgr
.IsReservedName(name
))
158 SendGuildCommandResult(GUILD_CREATE_S
, name
, GUILD_NAME_INVALID
);
161 if(!ObjectMgr::IsValidCharterName(name
))
163 SendGuildCommandResult(GUILD_CREATE_S
, name
, GUILD_NAME_INVALID
);
169 if(objmgr
.GetArenaTeamByName(name
))
171 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, name
, "", ERR_ARENA_TEAM_NAME_EXISTS_S
);
174 if(objmgr
.IsReservedName(name
))
176 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, name
, "", ERR_ARENA_TEAM_NAME_INVALID
);
179 if(!ObjectMgr::IsValidCharterName(name
))
181 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, name
, "", ERR_ARENA_TEAM_NAME_INVALID
);
186 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(charterid
);
189 _player
->SendBuyError(BUY_ERR_CANT_FIND_ITEM
, NULL
, charterid
, 0);
193 if(_player
->GetMoney() < cost
)
194 { //player hasn't got enough money
195 _player
->SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY
, pCreature
, charterid
, 0);
199 ItemPosCountVec dest
;
200 uint8 msg
= _player
->CanStoreNewItem(NULL_BAG
, NULL_SLOT
, dest
, charterid
, pProto
->BuyCount
);
201 if(msg
!= EQUIP_ERR_OK
)
203 _player
->SendBuyError(msg
, pCreature
, charterid
, 0);
207 _player
->ModifyMoney(-(int32
)cost
);
208 Item
*charter
= _player
->StoreNewItem(dest
, charterid
, true);
212 charter
->SetUInt32Value(ITEM_FIELD_ENCHANTMENT
, charter
->GetGUIDLow());
213 // ITEM_FIELD_ENCHANTMENT is guild/arenateam id
214 // ITEM_FIELD_ENCHANTMENT+1 is current signatures count (showed on item)
215 charter
->SetState(ITEM_CHANGED
, _player
);
216 _player
->SendNewItem(charter
, 1, true, false);
218 // a petition is invalid, if both the owner and the type matches
219 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT petitionguid FROM petition WHERE ownerguid = '%u' AND type = '%u'", _player
->GetGUIDLow(), type
);
221 std::ostringstream ssInvalidPetitionGUIDs
;
228 Field
*fields
= result
->Fetch();
229 ssInvalidPetitionGUIDs
<< "'" << fields
[0].GetUInt32() << "' , ";
230 } while (result
->NextRow());
235 // delete petitions with the same guid as this one
236 ssInvalidPetitionGUIDs
<< "'" << charter
->GetGUIDLow() << "'";
238 sLog
.outDebug("Invalid petition GUIDs: %s", ssInvalidPetitionGUIDs
.str().c_str());
239 CharacterDatabase
.escape_string(name
);
240 CharacterDatabase
.BeginTransaction();
241 CharacterDatabase
.PExecute("DELETE FROM petition WHERE petitionguid IN ( %s )", ssInvalidPetitionGUIDs
.str().c_str());
242 CharacterDatabase
.PExecute("DELETE FROM petition_sign WHERE petitionguid IN ( %s )", ssInvalidPetitionGUIDs
.str().c_str());
243 CharacterDatabase
.PExecute("INSERT INTO petition (ownerguid, petitionguid, name, type) VALUES ('%u', '%u', '%s', '%u')",
244 _player
->GetGUIDLow(), charter
->GetGUIDLow(), name
.c_str(), type
);
245 CharacterDatabase
.CommitTransaction();
248 void WorldSession::HandlePetitionShowSignOpcode(WorldPacket
& recv_data
)
250 CHECK_PACKET_SIZE(recv_data
, 8);
253 sLog
.outDebug("Received opcode CMSG_PETITION_SHOW_SIGNATURES");
254 //recv_data.hexlike();
258 recv_data
>> petitionguid
; // petition guid
260 // solve (possible) some strange compile problems with explicit use GUID_LOPART(petitionguid) at some GCC versions (wrong code optimization in compiler?)
261 uint32 petitionguid_low
= GUID_LOPART(petitionguid
);
263 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT petitionguid, type FROM petition WHERE petitionguid = '%u'", petitionguid_low
);
266 sLog
.outError("any petition on server...");
269 Field
*fields
= result
->Fetch();
270 uint32 type
= fields
[1].GetUInt32();
272 // if guild petition and has guild => error, return;
273 if(type
==9 && _player
->GetGuildId())
276 result
= CharacterDatabase
.PQuery("SELECT playerguid FROM petition_sign WHERE petitionguid = '%u'", petitionguid_low
);
278 // result==NULL also correct in case no sign yet
280 signs
= result
->GetRowCount();
282 sLog
.outDebug("CMSG_PETITION_SHOW_SIGNATURES petition entry: '%u'", petitionguid_low
);
284 WorldPacket
data(SMSG_PETITION_SHOW_SIGNATURES
, (8+8+4+1+signs
*12));
285 data
<< petitionguid
; // petition guid
286 data
<< _player
->GetGUID(); // owner guid
287 data
<< petitionguid_low
; // guild guid (in mangos always same as GUID_LOPART(petitionguid)
288 data
<< signs
; // sign's count
290 for(uint8 i
= 1; i
<= signs
; i
++)
292 Field
*fields
= result
->Fetch();
293 uint64 plguid
= fields
[0].GetUInt64();
295 data
<< plguid
; // Player GUID
296 data
<< (uint32
)0; // there 0 ...
304 void WorldSession::HandlePetitionQueryOpcode(WorldPacket
& recv_data
)
306 CHECK_PACKET_SIZE(recv_data
, 4+8);
308 sLog
.outDebug("Received opcode CMSG_PETITION_QUERY"); // ok
309 //recv_data.hexlike();
313 recv_data
>> guildguid
; // in mangos always same as GUID_LOPART(petitionguid)
314 recv_data
>> petitionguid
; // petition guid
315 sLog
.outDebug("CMSG_PETITION_QUERY Petition GUID %u Guild GUID %u", GUID_LOPART(petitionguid
), guildguid
);
317 SendPetitionQueryOpcode(petitionguid
);
320 void WorldSession::SendPetitionQueryOpcode(uint64 petitionguid
)
322 uint64 ownerguid
= 0;
324 std::string name
= "NO_NAME_FOR_GUID";
327 QueryResult
*result
= CharacterDatabase
.PQuery(
328 "SELECT ownerguid, name, "
329 " (SELECT COUNT(playerguid) FROM petition_sign WHERE petition_sign.petitionguid = '%u') AS signs "
330 "FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid
), GUID_LOPART(petitionguid
));
334 Field
* fields
= result
->Fetch();
335 ownerguid
= MAKE_NEW_GUID(fields
[0].GetUInt32(), 0, HIGHGUID_PLAYER
);
336 name
= fields
[1].GetCppString();
337 signs
= fields
[2].GetUInt8();
342 sLog
.outDebug("CMSG_PETITION_QUERY failed for petition (GUID: %u)", GUID_LOPART(petitionguid
));
346 QueryResult
*result2
= CharacterDatabase
.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid
));
350 Field
* fields
= result2
->Fetch();
351 type
= fields
[0].GetUInt32();
356 sLog
.outDebug("CMSG_PETITION_QUERY failed for petition (GUID: %u)", GUID_LOPART(petitionguid
));
360 WorldPacket
data(SMSG_PETITION_QUERY_RESPONSE
, (4+8+name
.size()+1+1+4*13));
361 data
<< GUID_LOPART(petitionguid
); // guild/team guid (in mangos always same as GUID_LOPART(petition guid)
362 data
<< ownerguid
; // charter owner guid
363 data
<< name
; // name (guild/arena team)
364 data
<< uint8(0); // 1
369 data
<< uint32(0); // bypass client - side limitation, a different value is needed here for each petition
375 data
<< type
; // bypass client - side limitation, a different value is needed here for each petition
377 data
<< uint32(0); // 5
378 data
<< uint32(0); // 6
379 data
<< uint32(0); // 7
380 data
<< uint32(0); // 8
381 data
<< uint16(0); // 9 2 bytes field
382 data
<< uint32(0); // 10
383 data
<< uint32(0); // 11
384 data
<< uint32(0); // 13 count of next strings?
385 data
<< uint32(0); // 14
387 data
<< uint32(0); // 15 0 - guild, 1 - arena team
393 void WorldSession::HandlePetitionRenameOpcode(WorldPacket
& recv_data
)
395 CHECK_PACKET_SIZE(recv_data
, 8+1);
397 sLog
.outDebug("Received opcode MSG_PETITION_RENAME"); // ok
398 //recv_data.hexlike();
404 recv_data
>> petitionguid
; // guid
405 recv_data
>> newname
; // new name
407 Item
*item
= _player
->GetItemByGuid(petitionguid
);
411 QueryResult
*result2
= CharacterDatabase
.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid
));
415 Field
* fields
= result2
->Fetch();
416 type
= fields
[0].GetUInt32();
421 sLog
.outDebug("CMSG_PETITION_QUERY failed for petition (GUID: %u)", GUID_LOPART(petitionguid
));
427 if(objmgr
.GetGuildByName(newname
))
429 SendGuildCommandResult(GUILD_CREATE_S
, newname
, GUILD_NAME_EXISTS
);
432 if(objmgr
.IsReservedName(newname
))
434 SendGuildCommandResult(GUILD_CREATE_S
, newname
, GUILD_NAME_INVALID
);
437 if(!ObjectMgr::IsValidCharterName(newname
))
439 SendGuildCommandResult(GUILD_CREATE_S
, newname
, GUILD_NAME_INVALID
);
445 if(objmgr
.GetArenaTeamByName(newname
))
447 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, newname
, "", ERR_ARENA_TEAM_NAME_EXISTS_S
);
450 if(objmgr
.IsReservedName(newname
))
452 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, newname
, "", ERR_ARENA_TEAM_NAME_INVALID
);
455 if(!ObjectMgr::IsValidCharterName(newname
))
457 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, newname
, "", ERR_ARENA_TEAM_NAME_INVALID
);
462 std::string db_newname
= newname
;
463 CharacterDatabase
.escape_string(db_newname
);
464 CharacterDatabase
.PExecute("UPDATE petition SET name = '%s' WHERE petitionguid = '%u'",
465 db_newname
.c_str(), GUID_LOPART(petitionguid
));
467 sLog
.outDebug("Petition (GUID: %u) renamed to '%s'", GUID_LOPART(petitionguid
), newname
.c_str());
468 WorldPacket
data(MSG_PETITION_RENAME
, (8+newname
.size()+1));
469 data
<< petitionguid
;
474 void WorldSession::HandlePetitionSignOpcode(WorldPacket
& recv_data
)
476 CHECK_PACKET_SIZE(recv_data
, 8+1);
478 sLog
.outDebug("Received opcode CMSG_PETITION_SIGN"); // ok
479 //recv_data.hexlike();
486 recv_data
>> petitionguid
; // petition guid
491 QueryResult
*result
= CharacterDatabase
.PQuery(
493 " (SELECT COUNT(playerguid) FROM petition_sign WHERE petition_sign.petitionguid = '%u') AS signs "
494 "FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid
), GUID_LOPART(petitionguid
));
498 sLog
.outError("any petition on server...");
502 fields
= result
->Fetch();
503 ownerguid
= MAKE_NEW_GUID(fields
[0].GetUInt32(), 0, HIGHGUID_PLAYER
);
504 signs
= fields
[1].GetUInt8();
508 uint32 plguidlo
= _player
->GetGUIDLow();
509 if(GUID_LOPART(ownerguid
) == plguidlo
)
512 // not let enemies sign guild charter
513 if(!sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD
) && GetPlayer()->GetTeam() != objmgr
.GetPlayerTeamByGUID(ownerguid
))
516 QueryResult
*result2
= CharacterDatabase
.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid
));
520 Field
* fields
= result2
->Fetch();
521 type
= fields
[0].GetUInt32();
526 sLog
.outDebug("CMSG_PETITION_QUERY failed for petition (GUID: %u)", GUID_LOPART(petitionguid
));
530 if(type
!= 9 && _player
->getLevel() < sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
532 // player is too low level to join an arena team
533 SendNotification(LANG_YOUR_ARENA_LEVEL_REQ_ERROR
,sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
));
538 if(signs
> type
) // client signs maximum
541 //client doesn't allow to sign petition two times by one character, but not check sign by another character from same account
542 //not allow sign another player from already sign player account
543 result
= CharacterDatabase
.PQuery("SELECT playerguid FROM petition_sign WHERE player_account = '%u' AND petitionguid = '%u'", GetAccountId(), GUID_LOPART(petitionguid
));
548 WorldPacket
data(SMSG_PETITION_SIGN_RESULTS
, (8+8+4));
549 data
<< petitionguid
;
550 data
<< _player
->GetGUID();
551 data
<< (uint32
)PETITION_SIGN_ALREADY_SIGNED
;
553 // close at signer side
556 // update for owner if online
557 if(Player
*owner
= objmgr
.GetPlayer(ownerguid
))
558 owner
->GetSession()->SendPacket(&data
);
562 CharacterDatabase
.PExecute("INSERT INTO petition_sign (ownerguid,petitionguid, playerguid, player_account) VALUES ('%u', '%u', '%u','%u')", GUID_LOPART(ownerguid
),GUID_LOPART(petitionguid
), plguidlo
,GetAccountId());
564 sLog
.outDebug("PETITION SIGN: GUID %u by player: %s (GUID: %u Account: %u)", GUID_LOPART(petitionguid
), _player
->GetName(),plguidlo
,GetAccountId());
566 WorldPacket
data(SMSG_PETITION_SIGN_RESULTS
, (8+8+4));
567 data
<< petitionguid
;
568 data
<< _player
->GetGUID();
569 data
<< (uint32
)PETITION_SIGN_OK
;
571 // close at signer side
574 // update signs count on charter, required testing...
575 //Item *item = _player->GetItemByGuid(petitionguid));
577 // item->SetUInt32Value(ITEM_FIELD_ENCHANTMENT+1, signs);
579 // update for owner if online
580 if(Player
*owner
= objmgr
.GetPlayer(ownerguid
))
581 owner
->GetSession()->SendPacket(&data
);
584 void WorldSession::HandlePetitionDeclineOpcode(WorldPacket
& recv_data
)
586 CHECK_PACKET_SIZE(recv_data
, 8);
588 sLog
.outDebug("Received opcode MSG_PETITION_DECLINE"); // ok
589 //recv_data.hexlike();
593 recv_data
>> petitionguid
; // petition guid
594 sLog
.outDebug("Petition %u declined by %u", GUID_LOPART(petitionguid
), _player
->GetGUIDLow());
596 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT ownerguid FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid
));
600 Field
*fields
= result
->Fetch();
601 ownerguid
= MAKE_NEW_GUID(fields
[0].GetUInt32(), 0, HIGHGUID_PLAYER
);
604 Player
*owner
= objmgr
.GetPlayer(ownerguid
);
605 if(owner
) // petition owner online
607 WorldPacket
data(MSG_PETITION_DECLINE
, 8);
608 data
<< _player
->GetGUID();
609 owner
->GetSession()->SendPacket(&data
);
613 void WorldSession::HandleOfferPetitionOpcode(WorldPacket
& recv_data
)
615 CHECK_PACKET_SIZE(recv_data
, 4+8+8);
617 sLog
.outDebug("Received opcode CMSG_OFFER_PETITION"); // ok
618 //recv_data.hexlike();
621 uint64 petitionguid
, plguid
;
624 recv_data
>> petitiontype
; // 2.0.8 - petition type?
625 recv_data
>> petitionguid
; // petition guid
626 recv_data
>> plguid
; // player guid
627 sLog
.outDebug("OFFER PETITION: type %u, GUID1 %u, to player id: %u", petitiontype
, GUID_LOPART(petitionguid
), GUID_LOPART(plguid
));
629 player
= ObjectAccessor::FindPlayer(plguid
);
630 if(!player
|| player
->GetSocial()->HasIgnore(GetPlayer()->GetGUIDLow()))
633 // not let offer to enemies
634 if (!sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD
) && GetPlayer()->GetTeam() != player
->GetTeam() )
637 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT petitionguid FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid
));
640 sLog
.outError("any petition on server...");
646 result
= CharacterDatabase
.PQuery("SELECT playerguid FROM petition_sign WHERE petitionguid = '%u'", GUID_LOPART(petitionguid
));
647 // result==NULL also correct charter without signs
649 signs
= result
->GetRowCount();
651 WorldPacket
data(SMSG_PETITION_SHOW_SIGNATURES
, (8+8+4+signs
+signs
*12));
652 data
<< petitionguid
; // petition guid
653 data
<< _player
->GetGUID(); // owner guid
654 data
<< GUID_LOPART(petitionguid
); // guild guid (in mangos always same as GUID_LOPART(petition guid)
655 data
<< signs
; // sign's count
657 for(uint8 i
= 1; i
<= signs
; i
++)
659 Field
*fields
= result
->Fetch();
660 uint64 plguid
= fields
[0].GetUInt64();
662 data
<< plguid
; // Player GUID
663 data
<< (uint32
)0; // there 0 ...
669 player
->GetSession()->SendPacket(&data
);
672 void WorldSession::HandleTurnInPetitionOpcode(WorldPacket
& recv_data
)
674 CHECK_PACKET_SIZE(recv_data
, 8);
676 sLog
.outDebug("Received opcode CMSG_TURN_IN_PETITION"); // ok
677 //recv_data.hexlike();
686 recv_data
>> petitionguid
;
688 sLog
.outDebug("Petition %u turned in by %u", GUID_LOPART(petitionguid
), _player
->GetGUIDLow());
691 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT ownerguid, name, type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid
));
694 Field
*fields
= result
->Fetch();
695 ownerguidlo
= fields
[0].GetUInt32();
696 name
= fields
[1].GetCppString();
697 type
= fields
[2].GetUInt32();
702 sLog
.outError("petition table has broken data!");
708 if(_player
->GetGuildId())
710 data
.Initialize(SMSG_TURN_IN_PETITION_RESULTS
, 4);
711 data
<< (uint32
)PETITION_TURN_ALREADY_IN_GUILD
; // already in guild
712 _player
->GetSession()->SendPacket(&data
);
718 uint8 slot
= ArenaTeam::GetSlotByType(type
);
719 if(slot
>= MAX_ARENA_SLOT
)
722 if(_player
->GetArenaTeamId(slot
))
724 //data.Initialize(SMSG_TURN_IN_PETITION_RESULTS, 4);
725 //data << (uint32)PETITION_TURN_ALREADY_IN_GUILD; // already in guild
726 //_player->GetSession()->SendPacket(&data);
727 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, name
, "", ERR_ALREADY_IN_ARENA_TEAM
);
732 if(_player
->GetGUIDLow() != ownerguidlo
)
737 result
= CharacterDatabase
.PQuery("SELECT playerguid FROM petition_sign WHERE petitionguid = '%u'", GUID_LOPART(petitionguid
));
739 signs
= result
->GetRowCount();
744 //if(signs < sWorld.getConfig(CONFIG_MIN_PETITION_SIGNS))
746 count
= sWorld
.getConfig(CONFIG_MIN_PETITION_SIGNS
);
751 data
.Initialize(SMSG_TURN_IN_PETITION_RESULTS
, 4);
752 data
<< (uint32
)PETITION_TURN_NEED_MORE_SIGNATURES
; // need more signatures...
760 if(objmgr
.GetGuildByName(name
))
762 SendGuildCommandResult(GUILD_CREATE_S
, name
, GUILD_NAME_EXISTS
);
769 if(objmgr
.GetArenaTeamByName(name
))
771 SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S
, name
, "", ERR_ARENA_TEAM_NAME_EXISTS_S
);
777 // and at last charter item check
778 Item
*item
= _player
->GetItemByGuid(petitionguid
);
787 // delete charter item
788 _player
->DestroyItem(item
->GetBagSlot(),item
->GetSlot(), true);
790 if(type
== 9) // create guild
792 Guild
* guild
= new Guild
;
793 if(!guild
->create(_player
->GetGUID(), name
))
800 // register guild and add guildmaster
801 objmgr
.AddGuild(guild
);
804 for(uint8 i
= 0; i
< signs
; ++i
)
806 Field
* fields
= result
->Fetch();
807 guild
->AddMember(fields
[0].GetUInt64(), guild
->GetLowestRank());
811 else // or arena team
813 ArenaTeam
* at
= new ArenaTeam
;
814 if(!at
->create(_player
->GetGUID(), type
, name
))
816 sLog
.outError("PetitionsHandler: arena team create failed.");
822 CHECK_PACKET_SIZE(recv_data
, 8+5*4);
823 uint32 icon
, iconcolor
, border
, bordercolor
, backgroud
;
824 recv_data
>> backgroud
>> icon
>> iconcolor
>> border
>> bordercolor
;
826 at
->SetEmblem(backgroud
, icon
, iconcolor
, border
, bordercolor
);
828 // register team and add captain
829 objmgr
.AddArenaTeam(at
);
830 sLog
.outDebug("PetitonsHandler: arena team added to objmrg");
833 for(uint8 i
= 0; i
< signs
; ++i
)
835 Field
* fields
= result
->Fetch();
836 uint64 memberGUID
= fields
[0].GetUInt64();
837 sLog
.outDebug("PetitionsHandler: adding arena member %u", GUID_LOPART(memberGUID
));
838 at
->AddMember(memberGUID
);
845 CharacterDatabase
.BeginTransaction();
846 CharacterDatabase
.PExecute("DELETE FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid
));
847 CharacterDatabase
.PExecute("DELETE FROM petition_sign WHERE petitionguid = '%u'", GUID_LOPART(petitionguid
));
848 CharacterDatabase
.CommitTransaction();
851 sLog
.outDebug("TURN IN PETITION GUID %u", GUID_LOPART(petitionguid
));
853 data
.Initialize(SMSG_TURN_IN_PETITION_RESULTS
, 4);
854 data
<< (uint32
)PETITION_TURN_OK
;
858 void WorldSession::HandlePetitionShowListOpcode(WorldPacket
& recv_data
)
860 CHECK_PACKET_SIZE(recv_data
, 8);
862 sLog
.outDebug("Received CMSG_PETITION_SHOWLIST"); // ok
863 //recv_data.hexlike();
868 SendPetitionShowList(guid
);
871 void WorldSession::SendPetitionShowList(uint64 guid
)
873 Creature
*pCreature
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, guid
, UNIT_NPC_FLAG_PETITIONER
);
876 sLog
.outDebug("WORLD: HandlePetitionShowListOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid
)));
881 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
882 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
885 if(pCreature
->isTabardDesigner())
890 WorldPacket
data(SMSG_PETITION_SHOWLIST
, 8+1+4*6);
891 data
<< guid
; // npc guid
892 data
<< count
; // count
895 data
<< uint32(1); // index
896 data
<< uint32(GUILD_CHARTER
); // charter entry
897 data
<< uint32(16161); // charter display id
898 data
<< uint32(GUILD_CHARTER_COST
); // charter cost
899 data
<< uint32(0); // unknown
900 data
<< uint32(9); // required signs?
905 data
<< uint32(1); // index
906 data
<< uint32(ARENA_TEAM_CHARTER_2v2
); // charter entry
907 data
<< uint32(16161); // charter display id
908 data
<< uint32(ARENA_TEAM_CHARTER_2v2_COST
); // charter cost
909 data
<< uint32(2); // unknown
910 data
<< uint32(2); // required signs?
912 data
<< uint32(2); // index
913 data
<< uint32(ARENA_TEAM_CHARTER_3v3
); // charter entry
914 data
<< uint32(16161); // charter display id
915 data
<< uint32(ARENA_TEAM_CHARTER_3v3_COST
); // charter cost
916 data
<< uint32(3); // unknown
917 data
<< uint32(3); // required signs?
919 data
<< uint32(3); // index
920 data
<< uint32(ARENA_TEAM_CHARTER_5v5
); // charter entry
921 data
<< uint32(16161); // charter display id
922 data
<< uint32(ARENA_TEAM_CHARTER_5v5_COST
); // charter cost
923 data
<< uint32(5); // unknown
924 data
<< uint32(5); // required signs?
926 //for(uint8 i = 0; i < count; i++)
928 // data << uint32(i); // index
929 // data << uint32(GUILD_CHARTER); // charter entry
930 // data << uint32(16161); // charter display id
931 // data << uint32(GUILD_CHARTER_COST+i); // charter cost
932 // data << uint32(0); // unknown
933 // data << uint32(9); // required signs?
936 sLog
.outDebug("Sent SMSG_PETITION_SHOWLIST");