2008-10-11 14:16:25 -05:00
/*
2009-02-04 12:42:26 +01:00
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
2008-10-14 11:57:03 -05:00
*
2010-01-16 20:19:18 +03:00
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
2008-10-11 14:16:25 -05:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2008-10-14 11:57:03 -05:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2008-10-11 14:16:25 -05:00
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2008-10-14 11:57:03 -05:00
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2008-10-11 14:16:25 -05:00
*/
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
#include "Common.h"
#include "Language.h"
#include "WorldPacket.h"
#include "WorldSession.h"
#include "World.h"
#include "ObjectMgr.h"
#include "Log.h"
#include "Opcodes.h"
#include "Guild.h"
#include "ArenaTeam.h"
#include "GossipDef.h"
#include "SocialMgr.h"
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
/*enum PetitionType // dbc data
{
PETITION_TYPE_GUILD = 1,
PETITION_TYPE_ARENA_TEAM = 3
};*/
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// Charters ID in item_template
#define GUILD_CHARTER 5863
#define GUILD_CHARTER_COST 1000 // 10 S
#define ARENA_TEAM_CHARTER_2v2 23560
#define ARENA_TEAM_CHARTER_2v2_COST 800000 // 80 G
#define ARENA_TEAM_CHARTER_3v3 23561
#define ARENA_TEAM_CHARTER_3v3_COST 1200000 // 120 G
#define ARENA_TEAM_CHARTER_5v5 23562
#define ARENA_TEAM_CHARTER_5v5_COST 2000000 // 200 G
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
void WorldSession :: HandlePetitionBuyOpcode ( WorldPacket & recv_data )
{
sLog . outDebug ( "Received opcode CMSG_PETITION_BUY" );
2009-12-17 11:46:00 +01:00
recv_data . hexlike ();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint64 guidNPC ;
2009-12-17 11:46:00 +01:00
uint32 clientIndex ; // 1 for guild and arenaslot+1 for arenas in client
2008-10-11 14:16:25 -05:00
std :: string name ;
2009-12-17 11:46:00 +01:00
2008-10-11 14:16:25 -05:00
recv_data >> guidNPC ; // NPC GUID
2009-12-17 11:46:00 +01:00
recv_data . read_skip < uint32 > (); // 0
recv_data . read_skip < uint64 > (); // 0
2008-10-11 14:16:25 -05:00
recv_data >> name ; // name
2009-12-17 11:46:00 +01:00
recv_data . read_skip < std :: string > (); // some string
recv_data . read_skip < uint32 > (); // 0
recv_data . read_skip < uint32 > (); // 0
recv_data . read_skip < uint32 > (); // 0
recv_data . read_skip < uint32 > (); // 0
recv_data . read_skip < uint32 > (); // 0
recv_data . read_skip < uint32 > (); // 0
recv_data . read_skip < uint32 > (); // 0
recv_data . read_skip < uint16 > (); // 0
recv_data . read_skip < uint32 > (); // 0
recv_data . read_skip < uint32 > (); // 0
recv_data . read_skip < uint32 > (); // 0
for ( int i = 0 ; i < 10 ; ++ i )
recv_data . read_skip < std :: string > ();
recv_data >> clientIndex ; // index
recv_data . read_skip < uint32 > (); // 0
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
sLog . outDebug ( "Petitioner with GUID %u tried sell petition: name %s" , GUID_LOPART ( guidNPC ), name . c_str ());
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// prevent cheating
2009-04-19 18:23:10 -05:00
Creature * pCreature = GetPlayer () -> GetNPCIfCanInteractWith ( guidNPC , UNIT_NPC_FLAG_PETITIONER );
2008-10-11 14:16:25 -05:00
if ( ! pCreature )
{
sLog . outDebug ( "WORLD: HandlePetitionBuyOpcode - Unit (GUID: %u) not found or you can't interact with him." , GUID_LOPART ( guidNPC ));
return ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// remove fake death
if ( GetPlayer () -> hasUnitState ( UNIT_STAT_DIED ))
2009-04-06 13:31:14 +02:00
GetPlayer () -> RemoveAurasByType ( SPELL_AURA_FEIGN_DEATH );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint32 charterid = 0 ;
uint32 cost = 0 ;
uint32 type = 0 ;
if ( pCreature -> isTabardDesigner ())
{
// if tabard designer, then trying to buy a guild charter.
// do not let if already in guild.
if ( _player -> GetGuildId ())
return ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
charterid = GUILD_CHARTER ;
cost = GUILD_CHARTER_COST ;
type = 9 ;
}
else
{
// TODO: find correct opcode
if ( _player -> getLevel () < sWorld . getConfig ( CONFIG_MAX_PLAYER_LEVEL ))
{
2008-12-22 10:59:38 -06:00
SendNotification ( LANG_ARENA_ONE_TOOLOW , sWorld . getConfig ( CONFIG_MAX_PLAYER_LEVEL ));
2008-10-11 14:16:25 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2009-12-17 11:46:00 +01:00
switch ( clientIndex ) // arenaSlot+1 as received from client (1 from 3 case)
2008-10-11 14:16:25 -05:00
{
case 1 :
charterid = ARENA_TEAM_CHARTER_2v2 ;
cost = ARENA_TEAM_CHARTER_2v2_COST ;
type = 2 ; // 2v2
break ;
case 2 :
charterid = ARENA_TEAM_CHARTER_3v3 ;
cost = ARENA_TEAM_CHARTER_3v3_COST ;
type = 3 ; // 3v3
break ;
case 3 :
charterid = ARENA_TEAM_CHARTER_5v5 ;
cost = ARENA_TEAM_CHARTER_5v5_COST ;
type = 5 ; // 5v5
break ;
default :
2009-12-17 11:46:00 +01:00
sLog . outDebug ( "unknown selection at buy arena petition: %u" , clientIndex );
2008-10-11 14:16:25 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2009-12-17 11:46:00 +01:00
if ( _player -> GetArenaTeamId ( clientIndex - 1 )) // arenaSlot+1 as received from client
2008-12-19 16:05:13 -06:00
{
SendArenaTeamCommandResult ( ERR_ARENA_TEAM_CREATE_S , name , "" , ERR_ALREADY_IN_ARENA_TEAM );
return ;
}
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
if ( type == 9 )
{
if ( objmgr . GetGuildByName ( name ))
{
SendGuildCommandResult ( GUILD_CREATE_S , name , GUILD_NAME_EXISTS );
return ;
}
2008-12-19 16:05:13 -06:00
if ( objmgr . IsReservedName ( name ) || ! ObjectMgr :: IsValidCharterName ( name ))
2008-10-11 14:16:25 -05:00
{
SendGuildCommandResult ( GUILD_CREATE_S , name , GUILD_NAME_INVALID );
return ;
}
}
else
{
if ( objmgr . GetArenaTeamByName ( name ))
{
SendArenaTeamCommandResult ( ERR_ARENA_TEAM_CREATE_S , name , "" , ERR_ARENA_TEAM_NAME_EXISTS_S );
return ;
}
2008-12-19 16:05:13 -06:00
if ( objmgr . IsReservedName ( name ) || ! ObjectMgr :: IsValidCharterName ( name ))
2008-10-11 14:16:25 -05:00
{
SendArenaTeamCommandResult ( ERR_ARENA_TEAM_CREATE_S , name , "" , ERR_ARENA_TEAM_NAME_INVALID );
return ;
}
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
ItemPrototype const * pProto = objmgr . GetItemPrototype ( charterid );
if ( ! pProto )
{
_player -> SendBuyError ( BUY_ERR_CANT_FIND_ITEM , NULL , charterid , 0 );
return ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
if ( _player -> GetMoney () < cost )
{ //player hasn't got enough money
_player -> SendBuyError ( BUY_ERR_NOT_ENOUGHT_MONEY , pCreature , charterid , 0 );
return ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
ItemPosCountVec dest ;
uint8 msg = _player -> CanStoreNewItem ( NULL_BAG , NULL_SLOT , dest , charterid , pProto -> BuyCount );
if ( msg != EQUIP_ERR_OK )
{
_player -> SendBuyError ( msg , pCreature , charterid , 0 );
return ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
_player -> ModifyMoney ( - ( int32 ) cost );
Item * charter = _player -> StoreNewItem ( dest , charterid , true );
if ( ! charter )
return ;
2009-10-17 15:51:44 -07:00
2008-12-24 09:58:26 -06:00
charter -> SetUInt32Value ( ITEM_FIELD_ENCHANTMENT_1_1 , charter -> GetGUIDLow ());
// ITEM_FIELD_ENCHANTMENT_1_1 is guild/arenateam id
// ITEM_FIELD_ENCHANTMENT_1_1+1 is current signatures count (showed on item)
2008-10-11 14:16:25 -05:00
charter -> SetState ( ITEM_CHANGED , _player );
_player -> SendNewItem ( charter , 1 , true , false );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// a petition is invalid, if both the owner and the type matches
2008-12-19 16:05:13 -06:00
// we checked above, if this player is in an arenateam, so this must be
// datacorruption
2010-01-23 14:45:58 +01:00
QueryResult_AutoPtr result = CharacterDatabase . PQuery ( "SELECT petitionguid FROM petition WHERE ownerguid = '%u' AND type = '%u'" , _player -> GetGUIDLow (), type );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
std :: ostringstream ssInvalidPetitionGUIDs ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
if ( result )
{
do
{
Field * fields = result -> Fetch ();
ssInvalidPetitionGUIDs << "'" << fields [ 0 ]. GetUInt32 () << "' , " ;
} while ( result -> NextRow ());
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// delete petitions with the same guid as this one
ssInvalidPetitionGUIDs << "'" << charter -> GetGUIDLow () << "'" ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
sLog . outDebug ( "Invalid petition GUIDs: %s" , ssInvalidPetitionGUIDs . str (). c_str ());
CharacterDatabase . escape_string ( name );
CharacterDatabase . BeginTransaction ();
CharacterDatabase . PExecute ( "DELETE FROM petition WHERE petitionguid IN ( %s )" , ssInvalidPetitionGUIDs . str (). c_str ());
CharacterDatabase . PExecute ( "DELETE FROM petition_sign WHERE petitionguid IN ( %s )" , ssInvalidPetitionGUIDs . str (). c_str ());
CharacterDatabase . PExecute ( "INSERT INTO petition (ownerguid, petitionguid, name, type) VALUES ('%u', '%u', '%s', '%u')" ,
_player -> GetGUIDLow (), charter -> GetGUIDLow (), name . c_str (), type );
CharacterDatabase . CommitTransaction ();
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
void WorldSession :: HandlePetitionShowSignOpcode ( WorldPacket & recv_data )
{
// ok
sLog . outDebug ( "Received opcode CMSG_PETITION_SHOW_SIGNATURES" );
//recv_data.hexlike();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint8 signs = 0 ;
uint64 petitionguid ;
recv_data >> petitionguid ; // petition guid
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// solve (possible) some strange compile problems with explicit use GUID_LOPART(petitionguid) at some GCC versions (wrong code optimization in compiler?)
uint32 petitionguid_low = GUID_LOPART ( petitionguid );
2009-10-17 15:51:44 -07:00
2010-01-23 14:45:58 +01:00
QueryResult_AutoPtr result = CharacterDatabase . PQuery ( "SELECT type FROM petition WHERE petitionguid = '%u'" , petitionguid_low );
2008-10-11 14:16:25 -05:00
if ( ! result )
{
2009-04-07 21:13:21 -05:00
sLog . outError ( "Petition %u is not found for player %u %s" , GUID_LOPART ( petitionguid ), GetPlayer () -> GetGUIDLow (), GetPlayer () -> GetName ());
2008-10-11 14:16:25 -05:00
return ;
}
Field * fields = result -> Fetch ();
2008-12-19 16:05:13 -06:00
uint32 type = fields [ 0 ]. GetUInt32 ();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// if guild petition and has guild => error, return;
if ( type == 9 && _player -> GetGuildId ())
return ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
result = CharacterDatabase . PQuery ( "SELECT playerguid FROM petition_sign WHERE petitionguid = '%u'" , petitionguid_low );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// result==NULL also correct in case no sign yet
if ( result )
signs = result -> GetRowCount ();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
sLog . outDebug ( "CMSG_PETITION_SHOW_SIGNATURES petition entry: '%u'" , petitionguid_low );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
WorldPacket data ( SMSG_PETITION_SHOW_SIGNATURES , ( 8 + 8 + 4 + 1 + signs * 12 ));
data << petitionguid ; // petition guid
data << _player -> GetGUID (); // owner guid
2008-10-14 11:57:03 -05:00
data << petitionguid_low ; // guild guid (in Trinity always same as GUID_LOPART(petitionguid)
2008-10-11 14:16:25 -05:00
data << signs ; // sign's count
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for ( uint8 i = 1 ; i <= signs ; ++ i )
2008-10-11 14:16:25 -05:00
{
2009-04-27 18:42:35 -05:00
Field * fields2 = result -> Fetch ();
uint64 plguid = fields2 [ 0 ]. GetUInt64 ();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
data << plguid ; // Player GUID
data << ( uint32 ) 0 ; // there 0 ...
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
result -> NextRow ();
}
SendPacket ( & data );
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
void WorldSession :: HandlePetitionQueryOpcode ( WorldPacket & recv_data )
{
sLog . outDebug ( "Received opcode CMSG_PETITION_QUERY" ); // ok
//recv_data.hexlike();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint32 guildguid ;
uint64 petitionguid ;
2008-10-14 11:57:03 -05:00
recv_data >> guildguid ; // in Trinity always same as GUID_LOPART(petitionguid)
2008-10-11 14:16:25 -05:00
recv_data >> petitionguid ; // petition guid
sLog . outDebug ( "CMSG_PETITION_QUERY Petition GUID %u Guild GUID %u" , GUID_LOPART ( petitionguid ), guildguid );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
SendPetitionQueryOpcode ( petitionguid );
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
void WorldSession :: SendPetitionQueryOpcode ( uint64 petitionguid )
{
uint64 ownerguid = 0 ;
uint32 type ;
std :: string name = "NO_NAME_FOR_GUID" ;
uint8 signs = 0 ;
2009-10-17 15:51:44 -07:00
2010-01-23 14:45:58 +01:00
QueryResult_AutoPtr result = CharacterDatabase . PQuery (
2008-10-11 14:16:25 -05:00
"SELECT ownerguid, name, "
2008-12-19 16:05:13 -06:00
" (SELECT COUNT(playerguid) FROM petition_sign WHERE petition_sign.petitionguid = '%u') AS signs, "
" type "
2008-10-11 14:16:25 -05:00
"FROM petition WHERE petitionguid = '%u'" , GUID_LOPART ( petitionguid ), GUID_LOPART ( petitionguid ));
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
if ( result )
{
Field * fields = result -> Fetch ();
ownerguid = MAKE_NEW_GUID ( fields [ 0 ]. GetUInt32 (), 0 , HIGHGUID_PLAYER );
name = fields [ 1 ]. GetCppString ();
signs = fields [ 2 ]. GetUInt8 ();
2008-12-19 16:05:13 -06:00
type = fields [ 3 ]. GetUInt32 ();
2008-10-11 14:16:25 -05:00
}
else
{
sLog . outDebug ( "CMSG_PETITION_QUERY failed for petition (GUID: %u)" , GUID_LOPART ( petitionguid ));
return ;
}
2009-10-17 15:51:44 -07:00
2009-12-17 11:46:00 +01:00
WorldPacket data ( SMSG_PETITION_QUERY_RESPONSE , ( 4 + 8 + name . size () + 1 + 1 + 4 * 12 + 2 + 10 ));
data << uint32 ( GUID_LOPART ( petitionguid )); // guild/team guid (in Trinity always same as GUID_LOPART(petition guid)
data << uint64 ( ownerguid ); // charter owner guid
2008-10-11 14:16:25 -05:00
data << name ; // name (guild/arena team)
2009-12-17 11:46:00 +01:00
data << uint8 ( 0 ); // some string
2008-10-11 14:16:25 -05:00
if ( type == 9 )
{
data << uint32 ( 9 );
data << uint32 ( 9 );
data << uint32 ( 0 ); // bypass client - side limitation, a different value is needed here for each petition
}
else
{
2009-12-17 11:46:00 +01:00
data << uint32 ( type - 1 );
data << uint32 ( type - 1 );
data << uint32 ( type ); // bypass client - side limitation, a different value is needed here for each petition
2008-10-11 14:16:25 -05:00
}
data << uint32 ( 0 ); // 5
data << uint32 ( 0 ); // 6
data << uint32 ( 0 ); // 7
data << uint32 ( 0 ); // 8
data << uint16 ( 0 ); // 9 2 bytes field
data << uint32 ( 0 ); // 10
data << uint32 ( 0 ); // 11
data << uint32 ( 0 ); // 13 count of next strings?
2009-12-17 11:46:00 +01:00
for ( int i = 0 ; i < 10 ; ++ i )
data << uint8 ( 0 ); // some string
2008-10-11 14:16:25 -05:00
data << uint32 ( 0 ); // 14
2009-12-17 11:46:00 +01:00
2008-10-11 14:16:25 -05:00
if ( type == 9 )
data << uint32 ( 0 ); // 15 0 - guild, 1 - arena team
else
data << uint32 ( 1 );
2009-12-17 11:46:00 +01:00
2008-10-11 14:16:25 -05:00
SendPacket ( & data );
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
void WorldSession :: HandlePetitionRenameOpcode ( WorldPacket & recv_data )
{
sLog . outDebug ( "Received opcode MSG_PETITION_RENAME" ); // ok
//recv_data.hexlike();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint64 petitionguid ;
uint32 type ;
std :: string newname ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
recv_data >> petitionguid ; // guid
recv_data >> newname ; // new name
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
Item * item = _player -> GetItemByGuid ( petitionguid );
if ( ! item )
return ;
2009-10-17 15:51:44 -07:00
2010-01-23 14:45:58 +01:00
QueryResult_AutoPtr result = CharacterDatabase . PQuery ( "SELECT type FROM petition WHERE petitionguid = '%u'" , GUID_LOPART ( petitionguid ));
2009-10-17 15:51:44 -07:00
2008-12-19 16:05:13 -06:00
if ( result )
2008-10-11 14:16:25 -05:00
{
2008-12-19 16:05:13 -06:00
Field * fields = result -> Fetch ();
2008-10-11 14:16:25 -05:00
type = fields [ 0 ]. GetUInt32 ();
}
else
{
sLog . outDebug ( "CMSG_PETITION_QUERY failed for petition (GUID: %u)" , GUID_LOPART ( petitionguid ));
return ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
if ( type == 9 )
{
if ( objmgr . GetGuildByName ( newname ))
{
SendGuildCommandResult ( GUILD_CREATE_S , newname , GUILD_NAME_EXISTS );
return ;
}
2008-12-19 16:05:13 -06:00
if ( objmgr . IsReservedName ( newname ) || ! ObjectMgr :: IsValidCharterName ( newname ))
2008-10-11 14:16:25 -05:00
{
SendGuildCommandResult ( GUILD_CREATE_S , newname , GUILD_NAME_INVALID );
return ;
}
}
else
{
if ( objmgr . GetArenaTeamByName ( newname ))
{
SendArenaTeamCommandResult ( ERR_ARENA_TEAM_CREATE_S , newname , "" , ERR_ARENA_TEAM_NAME_EXISTS_S );
return ;
}
2008-12-19 16:05:13 -06:00
if ( objmgr . IsReservedName ( newname ) || ! ObjectMgr :: IsValidCharterName ( newname ))
2008-10-11 14:16:25 -05:00
{
SendArenaTeamCommandResult ( ERR_ARENA_TEAM_CREATE_S , newname , "" , ERR_ARENA_TEAM_NAME_INVALID );
return ;
}
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
std :: string db_newname = newname ;
CharacterDatabase . escape_string ( db_newname );
CharacterDatabase . PExecute ( "UPDATE petition SET name = '%s' WHERE petitionguid = '%u'" ,
db_newname . c_str (), GUID_LOPART ( petitionguid ));
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
sLog . outDebug ( "Petition (GUID: %u) renamed to '%s'" , GUID_LOPART ( petitionguid ), newname . c_str ());
WorldPacket data ( MSG_PETITION_RENAME , ( 8 + newname . size () + 1 ));
data << petitionguid ;
data << newname ;
SendPacket ( & data );
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
void WorldSession :: HandlePetitionSignOpcode ( WorldPacket & recv_data )
{
sLog . outDebug ( "Received opcode CMSG_PETITION_SIGN" ); // ok
//recv_data.hexlike();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
Field * fields ;
uint64 petitionguid ;
uint8 unk ;
recv_data >> petitionguid ; // petition guid
recv_data >> unk ;
2009-10-17 15:51:44 -07:00
2010-01-23 14:45:58 +01:00
QueryResult_AutoPtr result = CharacterDatabase . PQuery (
2008-10-11 14:16:25 -05:00
"SELECT ownerguid, "
2008-12-19 16:05:13 -06:00
" (SELECT COUNT(playerguid) FROM petition_sign WHERE petition_sign.petitionguid = '%u') AS signs, "
" type "
2008-10-11 14:16:25 -05:00
"FROM petition WHERE petitionguid = '%u'" , GUID_LOPART ( petitionguid ), GUID_LOPART ( petitionguid ));
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
if ( ! result )
{
2009-04-07 21:13:21 -05:00
sLog . outError ( "Petition %u is not found for player %u %s" , GUID_LOPART ( petitionguid ), GetPlayer () -> GetGUIDLow (), GetPlayer () -> GetName ());
2008-10-11 14:16:25 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
fields = result -> Fetch ();
2008-12-19 16:05:13 -06:00
uint64 ownerguid = MAKE_NEW_GUID ( fields [ 0 ]. GetUInt32 (), 0 , HIGHGUID_PLAYER );
uint8 signs = fields [ 1 ]. GetUInt8 ();
uint32 type = fields [ 2 ]. GetUInt32 ();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint32 plguidlo = _player -> GetGUIDLow ();
if ( GUID_LOPART ( ownerguid ) == plguidlo )
return ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// not let enemies sign guild charter
if ( ! sWorld . getConfig ( CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD ) && GetPlayer () -> GetTeam () != objmgr . GetPlayerTeamByGUID ( ownerguid ))
2008-12-19 16:05:13 -06:00
{
if ( type != 9 )
SendArenaTeamCommandResult ( ERR_ARENA_TEAM_INVITE_SS , "" , "" , ERR_ARENA_TEAM_NOT_ALLIED );
else
SendGuildCommandResult ( GUILD_CREATE_S , "" , GUILD_NOT_ALLIED );
2008-10-11 14:16:25 -05:00
return ;
2008-12-19 16:05:13 -06:00
}
2009-10-17 15:51:44 -07:00
2008-12-19 16:05:13 -06:00
if ( type != 9 )
2008-10-11 14:16:25 -05:00
{
2008-12-19 16:05:13 -06:00
if ( _player -> getLevel () < sWorld . getConfig ( CONFIG_MAX_PLAYER_LEVEL ))
{
SendArenaTeamCommandResult ( ERR_ARENA_TEAM_CREATE_S , "" , _player -> GetName (), ERR_ARENA_TEAM_PLAYER_TO_LOW );
return ;
}
2009-10-17 15:51:44 -07:00
2008-12-19 16:05:13 -06:00
uint8 slot = ArenaTeam :: GetSlotByType ( type );
if ( slot >= MAX_ARENA_SLOT )
return ;
2009-10-17 15:51:44 -07:00
2008-12-19 16:05:13 -06:00
if ( _player -> GetArenaTeamId ( slot ))
{
SendArenaTeamCommandResult ( ERR_ARENA_TEAM_INVITE_SS , "" , _player -> GetName (), ERR_ALREADY_IN_ARENA_TEAM_S );
return ;
}
2009-10-17 15:51:44 -07:00
2008-12-19 16:05:13 -06:00
if ( _player -> GetArenaTeamIdInvited ())
{
SendArenaTeamCommandResult ( ERR_ARENA_TEAM_INVITE_SS , "" , _player -> GetName (), ERR_ALREADY_INVITED_TO_ARENA_TEAM_S );
return ;
}
2008-10-11 14:16:25 -05:00
}
else
{
2008-12-19 16:05:13 -06:00
if ( _player -> GetGuildId ())
{
SendGuildCommandResult ( GUILD_INVITE_S , _player -> GetName (), ALREADY_IN_GUILD );
return ;
}
if ( _player -> GetGuildIdInvited ())
{
SendGuildCommandResult ( GUILD_INVITE_S , _player -> GetName (), ALREADY_INVITED_TO_GUILD );
return ;
}
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2008-12-19 16:05:13 -06:00
if ( ++ signs > type ) // client signs maximum
2008-10-11 14:16:25 -05:00
return ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
//client doesn't allow to sign petition two times by one character, but not check sign by another character from same account
//not allow sign another player from already sign player account
result = CharacterDatabase . PQuery ( "SELECT playerguid FROM petition_sign WHERE player_account = '%u' AND petitionguid = '%u'" , GetAccountId (), GUID_LOPART ( petitionguid ));
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
if ( result )
{
WorldPacket data ( SMSG_PETITION_SIGN_RESULTS , ( 8 + 8 + 4 ));
data << petitionguid ;
data << _player -> GetGUID ();
data << ( uint32 ) PETITION_SIGN_ALREADY_SIGNED ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// close at signer side
SendPacket ( & data );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// update for owner if online
if ( Player * owner = objmgr . GetPlayer ( ownerguid ))
owner -> GetSession () -> SendPacket ( & data );
return ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
CharacterDatabase . PExecute ( "INSERT INTO petition_sign (ownerguid,petitionguid, playerguid, player_account) VALUES ('%u', '%u', '%u','%u')" , GUID_LOPART ( ownerguid ), GUID_LOPART ( petitionguid ), plguidlo , GetAccountId ());
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
sLog . outDebug ( "PETITION SIGN: GUID %u by player: %s (GUID: %u Account: %u)" , GUID_LOPART ( petitionguid ), _player -> GetName (), plguidlo , GetAccountId ());
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
WorldPacket data ( SMSG_PETITION_SIGN_RESULTS , ( 8 + 8 + 4 ));
data << petitionguid ;
data << _player -> GetGUID ();
data << ( uint32 ) PETITION_SIGN_OK ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// close at signer side
SendPacket ( & data );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// update signs count on charter, required testing...
//Item *item = _player->GetItemByGuid(petitionguid));
//if(item)
2008-12-24 09:58:26 -06:00
// item->SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1+1, signs);
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// update for owner if online
if ( Player * owner = objmgr . GetPlayer ( ownerguid ))
owner -> GetSession () -> SendPacket ( & data );
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
void WorldSession :: HandlePetitionDeclineOpcode ( WorldPacket & recv_data )
{
sLog . outDebug ( "Received opcode MSG_PETITION_DECLINE" ); // ok
//recv_data.hexlike();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint64 petitionguid ;
uint64 ownerguid ;
recv_data >> petitionguid ; // petition guid
sLog . outDebug ( "Petition %u declined by %u" , GUID_LOPART ( petitionguid ), _player -> GetGUIDLow ());
2009-10-17 15:51:44 -07:00
2010-01-23 14:45:58 +01:00
QueryResult_AutoPtr result = CharacterDatabase . PQuery ( "SELECT ownerguid FROM petition WHERE petitionguid = '%u'" , GUID_LOPART ( petitionguid ));
2008-10-11 14:16:25 -05:00
if ( ! result )
return ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
Field * fields = result -> Fetch ();
ownerguid = MAKE_NEW_GUID ( fields [ 0 ]. GetUInt32 (), 0 , HIGHGUID_PLAYER );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
Player * owner = objmgr . GetPlayer ( ownerguid );
if ( owner ) // petition owner online
{
WorldPacket data ( MSG_PETITION_DECLINE , 8 );
data << _player -> GetGUID ();
owner -> GetSession () -> SendPacket ( & data );
}
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
void WorldSession :: HandleOfferPetitionOpcode ( WorldPacket & recv_data )
{
sLog . outDebug ( "Received opcode CMSG_OFFER_PETITION" ); // ok
//recv_data.hexlike();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint8 signs = 0 ;
uint64 petitionguid , plguid ;
2008-12-19 16:05:13 -06:00
uint32 type , junk ;
2008-10-11 14:16:25 -05:00
Player * player ;
2008-12-19 16:05:13 -06:00
recv_data >> junk ; // this is not petition type!
2008-10-11 14:16:25 -05:00
recv_data >> petitionguid ; // petition guid
recv_data >> plguid ; // player guid
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
player = ObjectAccessor :: FindPlayer ( plguid );
2008-12-19 16:05:13 -06:00
if ( ! player )
2008-10-11 14:16:25 -05:00
return ;
2009-10-17 15:51:44 -07:00
2010-01-23 14:45:58 +01:00
QueryResult_AutoPtr result = CharacterDatabase . PQuery ( "SELECT type FROM petition WHERE petitionguid = '%u'" , GUID_LOPART ( petitionguid ));
2008-12-19 16:05:13 -06:00
if ( ! result )
2008-10-11 14:16:25 -05:00
return ;
2009-10-17 15:51:44 -07:00
2008-12-19 16:05:13 -06:00
Field * fields = result -> Fetch ();
type = fields [ 0 ]. GetUInt32 ();
2009-10-17 15:51:44 -07:00
2008-12-19 16:05:13 -06:00
sLog . outDebug ( "OFFER PETITION: type %u, GUID1 %u, to player id: %u" , type , GUID_LOPART ( petitionguid ), GUID_LOPART ( plguid ));
2009-10-17 15:51:44 -07:00
2008-12-19 16:05:13 -06:00
if ( ! sWorld . getConfig ( CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD ) && GetPlayer () -> GetTeam () != player -> GetTeam () )
2008-10-11 14:16:25 -05:00
{
2008-12-19 16:05:13 -06:00
if ( type != 9 )
SendArenaTeamCommandResult ( ERR_ARENA_TEAM_INVITE_SS , "" , "" , ERR_ARENA_TEAM_NOT_ALLIED );
else
SendGuildCommandResult ( GUILD_CREATE_S , "" , GUILD_NOT_ALLIED );
2008-10-11 14:16:25 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2008-12-19 16:05:13 -06:00
if ( type != 9 )
{
if ( player -> getLevel () < sWorld . getConfig ( CONFIG_MAX_PLAYER_LEVEL ))
{
// player is too low level to join an arena team
SendArenaTeamCommandResult ( ERR_ARENA_TEAM_CREATE_S , player -> GetName (), "" , ERR_ARENA_TEAM_PLAYER_TO_LOW );
return ;
}
2009-10-17 15:51:44 -07:00
2008-12-19 16:05:13 -06:00
uint8 slot = ArenaTeam :: GetSlotByType ( type );
if ( slot >= MAX_ARENA_SLOT )
return ;
2009-10-17 15:51:44 -07:00
2008-12-19 16:05:13 -06:00
if ( player -> GetArenaTeamId ( slot ))
{
// player is already in an arena team
SendArenaTeamCommandResult ( ERR_ARENA_TEAM_CREATE_S , player -> GetName (), "" , ERR_ALREADY_IN_ARENA_TEAM_S );
return ;
}
2009-10-17 15:51:44 -07:00
2008-12-19 16:05:13 -06:00
if ( player -> GetArenaTeamIdInvited ())
{
SendArenaTeamCommandResult ( ERR_ARENA_TEAM_INVITE_SS , "" , _player -> GetName (), ERR_ALREADY_INVITED_TO_ARENA_TEAM_S );
return ;
}
}
else
{
if ( player -> GetGuildId ())
{
SendGuildCommandResult ( GUILD_INVITE_S , _player -> GetName (), ALREADY_IN_GUILD );
return ;
}
2009-10-17 15:51:44 -07:00
2008-12-19 16:05:13 -06:00
if ( player -> GetGuildIdInvited ())
{
SendGuildCommandResult ( GUILD_INVITE_S , _player -> GetName (), ALREADY_INVITED_TO_GUILD );
return ;
}
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
result = CharacterDatabase . PQuery ( "SELECT playerguid FROM petition_sign WHERE petitionguid = '%u'" , GUID_LOPART ( petitionguid ));
// result==NULL also correct charter without signs
if ( result )
signs = result -> GetRowCount ();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
WorldPacket data ( SMSG_PETITION_SHOW_SIGNATURES , ( 8 + 8 + 4 + signs + signs * 12 ));
data << petitionguid ; // petition guid
data << _player -> GetGUID (); // owner guid
2008-10-14 11:57:03 -05:00
data << GUID_LOPART ( petitionguid ); // guild guid (in Trinity always same as GUID_LOPART(petition guid)
2008-10-11 14:16:25 -05:00
data << signs ; // sign's count
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for ( uint8 i = 1 ; i <= signs ; ++ i )
2008-10-11 14:16:25 -05:00
{
2009-04-27 18:42:35 -05:00
Field * fields2 = result -> Fetch ();
plguid = fields2 [ 0 ]. GetUInt64 ();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
data << plguid ; // Player GUID
data << ( uint32 ) 0 ; // there 0 ...
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
result -> NextRow ();
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
player -> GetSession () -> SendPacket ( & data );
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
void WorldSession :: HandleTurnInPetitionOpcode ( WorldPacket & recv_data )
{
sLog . outDebug ( "Received opcode CMSG_TURN_IN_PETITION" ); // ok
//recv_data.hexlike();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
WorldPacket data ;
uint64 petitionguid ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint32 ownerguidlo ;
uint32 type ;
std :: string name ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
recv_data >> petitionguid ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
sLog . outDebug ( "Petition %u turned in by %u" , GUID_LOPART ( petitionguid ), _player -> GetGUIDLow ());
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// data
2010-01-23 14:45:58 +01:00
QueryResult_AutoPtr result = CharacterDatabase . PQuery ( "SELECT ownerguid, name, type FROM petition WHERE petitionguid = '%u'" , GUID_LOPART ( petitionguid ));
2008-10-11 14:16:25 -05:00
if ( result )
{
Field * fields = result -> Fetch ();
ownerguidlo = fields [ 0 ]. GetUInt32 ();
name = fields [ 1 ]. GetCppString ();
type = fields [ 2 ]. GetUInt32 ();
}
else
{
sLog . outError ( "petition table has broken data!" );
return ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
if ( type == 9 )
{
if ( _player -> GetGuildId ())
{
data . Initialize ( SMSG_TURN_IN_PETITION_RESULTS , 4 );
data << ( uint32 ) PETITION_TURN_ALREADY_IN_GUILD ; // already in guild
_player -> GetSession () -> SendPacket ( & data );
return ;
}
}
else
{
uint8 slot = ArenaTeam :: GetSlotByType ( type );
if ( slot >= MAX_ARENA_SLOT )
return ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
if ( _player -> GetArenaTeamId ( slot ))
{
//data.Initialize(SMSG_TURN_IN_PETITION_RESULTS, 4);
//data << (uint32)PETITION_TURN_ALREADY_IN_GUILD; // already in guild
//_player->GetSession()->SendPacket(&data);
SendArenaTeamCommandResult ( ERR_ARENA_TEAM_CREATE_S , name , "" , ERR_ALREADY_IN_ARENA_TEAM );
return ;
}
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
if ( _player -> GetGUIDLow () != ownerguidlo )
return ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// signs
uint8 signs ;
result = CharacterDatabase . PQuery ( "SELECT playerguid FROM petition_sign WHERE petitionguid = '%u'" , GUID_LOPART ( petitionguid ));
if ( result )
signs = result -> GetRowCount ();
else
signs = 0 ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint32 count ;
//if(signs < sWorld.getConfig(CONFIG_MIN_PETITION_SIGNS))
if ( type == 9 )
count = sWorld . getConfig ( CONFIG_MIN_PETITION_SIGNS );
else
count = type - 1 ;
if ( signs < count )
{
data . Initialize ( SMSG_TURN_IN_PETITION_RESULTS , 4 );
data << ( uint32 ) PETITION_TURN_NEED_MORE_SIGNATURES ; // need more signatures...
SendPacket ( & data );
return ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
if ( type == 9 )
{
if ( objmgr . GetGuildByName ( name ))
{
SendGuildCommandResult ( GUILD_CREATE_S , name , GUILD_NAME_EXISTS );
return ;
}
}
else
{
if ( objmgr . GetArenaTeamByName ( name ))
{
SendArenaTeamCommandResult ( ERR_ARENA_TEAM_CREATE_S , name , "" , ERR_ARENA_TEAM_NAME_EXISTS_S );
return ;
}
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// and at last charter item check
Item * item = _player -> GetItemByGuid ( petitionguid );
if ( ! item )
return ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// OK!
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// delete charter item
_player -> DestroyItem ( item -> GetBagSlot (), item -> GetSlot (), true );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
if ( type == 9 ) // create guild
{
Guild * guild = new Guild ;
2009-08-24 19:23:31 -05:00
if ( ! guild -> Create ( _player , name ))
2008-10-11 14:16:25 -05:00
{
delete guild ;
return ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// register guild and add guildmaster
objmgr . AddGuild ( guild );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// add members
2009-10-17 16:20:24 -07:00
for ( uint8 i = 0 ; i < signs ; ++ i )
2008-10-11 14:16:25 -05:00
{
Field * fields = result -> Fetch ();
guild -> AddMember ( fields [ 0 ]. GetUInt64 (), guild -> GetLowestRank ());
result -> NextRow ();
}
}
else // or arena team
{
ArenaTeam * at = new ArenaTeam ;
2008-12-19 16:05:13 -06:00
if ( ! at -> Create ( _player -> GetGUID (), type , name ))
2008-10-11 14:16:25 -05:00
{
sLog . outError ( "PetitionsHandler: arena team create failed." );
delete at ;
return ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint32 icon , iconcolor , border , bordercolor , backgroud ;
recv_data >> backgroud >> icon >> iconcolor >> border >> bordercolor ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
at -> SetEmblem ( backgroud , icon , iconcolor , border , bordercolor );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// register team and add captain
objmgr . AddArenaTeam ( at );
sLog . outDebug ( "PetitonsHandler: arena team added to objmrg" );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// add members
2009-10-17 16:20:24 -07:00
for ( uint8 i = 0 ; i < signs ; ++ i )
2008-10-11 14:16:25 -05:00
{
Field * fields = result -> Fetch ();
2008-11-10 09:04:23 -06:00
uint64 memberGUID = fields [ 0 ]. GetUInt64 ();
sLog . outDebug ( "PetitionsHandler: adding arena member %u" , GUID_LOPART ( memberGUID ));
at -> AddMember ( memberGUID );
2008-10-11 14:16:25 -05:00
result -> NextRow ();
}
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
CharacterDatabase . BeginTransaction ();
CharacterDatabase . PExecute ( "DELETE FROM petition WHERE petitionguid = '%u'" , GUID_LOPART ( petitionguid ));
CharacterDatabase . PExecute ( "DELETE FROM petition_sign WHERE petitionguid = '%u'" , GUID_LOPART ( petitionguid ));
CharacterDatabase . CommitTransaction ();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// created
sLog . outDebug ( "TURN IN PETITION GUID %u" , GUID_LOPART ( petitionguid ));
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
data . Initialize ( SMSG_TURN_IN_PETITION_RESULTS , 4 );
data << ( uint32 ) PETITION_TURN_OK ;
SendPacket ( & data );
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
void WorldSession :: HandlePetitionShowListOpcode ( WorldPacket & recv_data )
{
sLog . outDebug ( "Received CMSG_PETITION_SHOWLIST" ); // ok
//recv_data.hexlike();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint64 guid ;
recv_data >> guid ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
SendPetitionShowList ( guid );
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
void WorldSession :: SendPetitionShowList ( uint64 guid )
{
2009-04-19 18:23:10 -05:00
Creature * pCreature = GetPlayer () -> GetNPCIfCanInteractWith ( guid , UNIT_NPC_FLAG_PETITIONER );
2008-10-11 14:16:25 -05:00
if ( ! pCreature )
{
sLog . outDebug ( "WORLD: HandlePetitionShowListOpcode - Unit (GUID: %u) not found or you can't interact with him." , uint32 ( GUID_LOPART ( guid )));
return ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// remove fake death
if ( GetPlayer () -> hasUnitState ( UNIT_STAT_DIED ))
2009-04-06 13:31:14 +02:00
GetPlayer () -> RemoveAurasByType ( SPELL_AURA_FEIGN_DEATH );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint8 count = 0 ;
if ( pCreature -> isTabardDesigner ())
count = 1 ;
else
count = 3 ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
WorldPacket data ( SMSG_PETITION_SHOWLIST , 8 + 1 + 4 * 6 );
data << guid ; // npc guid
data << count ; // count
if ( count == 1 )
{
data << uint32 ( 1 ); // index
data << uint32 ( GUILD_CHARTER ); // charter entry
data << uint32 ( 16161 ); // charter display id
data << uint32 ( GUILD_CHARTER_COST ); // charter cost
data << uint32 ( 0 ); // unknown
data << uint32 ( 9 ); // required signs?
}
else
{
// 2v2
data << uint32 ( 1 ); // index
data << uint32 ( ARENA_TEAM_CHARTER_2v2 ); // charter entry
data << uint32 ( 16161 ); // charter display id
data << uint32 ( ARENA_TEAM_CHARTER_2v2_COST ); // charter cost
data << uint32 ( 2 ); // unknown
data << uint32 ( 2 ); // required signs?
// 3v3
data << uint32 ( 2 ); // index
data << uint32 ( ARENA_TEAM_CHARTER_3v3 ); // charter entry
data << uint32 ( 16161 ); // charter display id
data << uint32 ( ARENA_TEAM_CHARTER_3v3_COST ); // charter cost
data << uint32 ( 3 ); // unknown
data << uint32 ( 3 ); // required signs?
// 5v5
data << uint32 ( 3 ); // index
data << uint32 ( ARENA_TEAM_CHARTER_5v5 ); // charter entry
data << uint32 ( 16161 ); // charter display id
data << uint32 ( ARENA_TEAM_CHARTER_5v5_COST ); // charter cost
data << uint32 ( 5 ); // unknown
data << uint32 ( 5 ); // required signs?
}
2009-10-17 16:20:24 -07:00
//for (uint8 i = 0; i < count; ++i)
2008-10-11 14:16:25 -05:00
//{
// data << uint32(i); // index
// data << uint32(GUILD_CHARTER); // charter entry
// data << uint32(16161); // charter display id
// data << uint32(GUILD_CHARTER_COST+i); // charter cost
// data << uint32(0); // unknown
// data << uint32(9); // required signs?
//}
SendPacket ( & data );
sLog . outDebug ( "Sent SMSG_PETITION_SHOWLIST" );
}