mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-20 17:27:36 +01:00
804 lines
29 KiB
C++
804 lines
29 KiB
C++
/*
|
|
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
|
|
*
|
|
* 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 MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the 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, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "WorldSession.h"
|
|
#include "ArenaTeam.h"
|
|
#include "ArenaTeamMgr.h"
|
|
#include "CharacterCache.h"
|
|
#include "Common.h"
|
|
#include "Creature.h"
|
|
#include "DatabaseEnv.h"
|
|
#include "Guild.h"
|
|
#include "GuildMgr.h"
|
|
#include "Item.h"
|
|
#include "Log.h"
|
|
#include "ObjectAccessor.h"
|
|
#include "ObjectMgr.h"
|
|
#include "Opcodes.h"
|
|
#include "Player.h"
|
|
#include "PetitionMgr.h"
|
|
#include "WorldPacket.h"
|
|
#include "World.h"
|
|
|
|
#define CHARTER_DISPLAY_ID 16161
|
|
|
|
// Charters ID in item_template
|
|
enum CharterItemIDs
|
|
{
|
|
GUILD_CHARTER = 5863,
|
|
ARENA_TEAM_CHARTER_2v2 = 23560,
|
|
ARENA_TEAM_CHARTER_3v3 = 23561,
|
|
ARENA_TEAM_CHARTER_5v5 = 23562
|
|
};
|
|
|
|
void WorldSession::HandlePetitionBuyOpcode(WorldPacket& recvData)
|
|
{
|
|
TC_LOG_DEBUG("network", "Received opcode CMSG_PETITION_BUY");
|
|
|
|
ObjectGuid guidNPC;
|
|
uint32 clientIndex; // 1 for guild and arenaslot+1 for arenas in client
|
|
std::string name;
|
|
|
|
recvData >> guidNPC; // NPC GUID
|
|
recvData.read_skip<uint32>(); // 0
|
|
recvData.read_skip<uint64>(); // 0
|
|
recvData >> name; // name
|
|
recvData.read_skip<std::string>(); // some string
|
|
recvData.read_skip<uint32>(); // 0
|
|
recvData.read_skip<uint32>(); // 0
|
|
recvData.read_skip<uint32>(); // 0
|
|
recvData.read_skip<uint32>(); // 0
|
|
recvData.read_skip<uint32>(); // 0
|
|
recvData.read_skip<uint32>(); // 0
|
|
recvData.read_skip<uint32>(); // 0
|
|
recvData.read_skip<uint16>(); // 0
|
|
recvData.read_skip<uint32>(); // 0
|
|
recvData.read_skip<uint32>(); // 0
|
|
recvData.read_skip<uint32>(); // 0
|
|
|
|
for (int i = 0; i < 10; ++i)
|
|
recvData.read_skip<std::string>();
|
|
|
|
recvData >> clientIndex; // index
|
|
recvData.read_skip<uint32>(); // 0
|
|
|
|
TC_LOG_DEBUG("network", "Petitioner {} tried sell petition: name {}", guidNPC.ToString(), name);
|
|
|
|
// prevent cheating
|
|
Creature* creature = GetPlayer()->GetNPCIfCanInteractWith(guidNPC, UNIT_NPC_FLAG_PETITIONER);
|
|
if (!creature)
|
|
{
|
|
TC_LOG_DEBUG("network", "WORLD: HandlePetitionBuyOpcode - {} not found or you can't interact with him.", guidNPC.ToString());
|
|
return;
|
|
}
|
|
|
|
// remove fake death
|
|
if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
|
|
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
|
|
|
|
uint32 charterid = 0;
|
|
uint32 cost = 0;
|
|
CharterTypes type = CHARTER_TYPE_NONE;
|
|
if (creature->IsTabardDesigner())
|
|
{
|
|
// if tabard designer, then trying to buy a guild charter.
|
|
// do not let if already in guild.
|
|
if (_player->GetGuildId())
|
|
return;
|
|
|
|
charterid = GUILD_CHARTER;
|
|
cost = sWorld->getIntConfig(CONFIG_CHARTER_COST_GUILD);
|
|
type = GUILD_CHARTER_TYPE;
|
|
}
|
|
else
|
|
{
|
|
/// @todo find correct opcode
|
|
if (!_player->IsMaxLevel())
|
|
{
|
|
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, "", _player->GetName(), ERR_ARENA_TEAM_TARGET_TOO_LOW_S);
|
|
return;
|
|
}
|
|
|
|
switch (clientIndex) // arenaSlot+1 as received from client (1 from 3 case)
|
|
{
|
|
case 1:
|
|
charterid = ARENA_TEAM_CHARTER_2v2;
|
|
cost = sWorld->getIntConfig(CONFIG_CHARTER_COST_ARENA_2v2);
|
|
type = ARENA_TEAM_CHARTER_2v2_TYPE;
|
|
break;
|
|
case 2:
|
|
charterid = ARENA_TEAM_CHARTER_3v3;
|
|
cost = sWorld->getIntConfig(CONFIG_CHARTER_COST_ARENA_3v3);
|
|
type = ARENA_TEAM_CHARTER_3v3_TYPE;
|
|
break;
|
|
case 3:
|
|
charterid = ARENA_TEAM_CHARTER_5v5;
|
|
cost = sWorld->getIntConfig(CONFIG_CHARTER_COST_ARENA_5v5);
|
|
type = ARENA_TEAM_CHARTER_5v5_TYPE;
|
|
break;
|
|
default:
|
|
TC_LOG_DEBUG("network", "unknown selection at buy arena petition: {}", clientIndex);
|
|
return;
|
|
}
|
|
|
|
if (_player->GetArenaTeamId(clientIndex - 1)) // arenaSlot+1 as received from client
|
|
{
|
|
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ALREADY_IN_ARENA_TEAM);
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (type == GUILD_CHARTER_TYPE)
|
|
{
|
|
if (sGuildMgr->GetGuildByName(name))
|
|
{
|
|
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_EXISTS_S, name);
|
|
return;
|
|
}
|
|
|
|
if (sObjectMgr->IsReservedName(name) || !ObjectMgr::IsValidCharterName(name))
|
|
{
|
|
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_INVALID, name);
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (sArenaTeamMgr->GetArenaTeamByName(name))
|
|
{
|
|
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_EXISTS_S);
|
|
return;
|
|
}
|
|
if (sObjectMgr->IsReservedName(name) || !ObjectMgr::IsValidCharterName(name))
|
|
{
|
|
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_INVALID);
|
|
return;
|
|
}
|
|
}
|
|
|
|
ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(charterid);
|
|
if (!pProto)
|
|
{
|
|
_player->SendBuyError(BUY_ERR_CANT_FIND_ITEM, nullptr, charterid, 0);
|
|
return;
|
|
}
|
|
|
|
if (!_player->HasEnoughMoney(cost))
|
|
{ //player hasn't got enough money
|
|
_player->SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY, creature, charterid, 0);
|
|
return;
|
|
}
|
|
|
|
ItemPosCountVec dest;
|
|
InventoryResult msg = _player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, charterid, pProto->BuyCount);
|
|
if (msg != EQUIP_ERR_OK)
|
|
{
|
|
_player->SendEquipError(msg, nullptr, nullptr, charterid);
|
|
return;
|
|
}
|
|
|
|
_player->ModifyMoney(-(int32)cost);
|
|
Item* charter = _player->StoreNewItem(dest, charterid, true);
|
|
if (!charter)
|
|
return;
|
|
|
|
charter->SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1, charter->GetGUID().GetCounter());
|
|
// ITEM_FIELD_ENCHANTMENT_1_1 is guild/arenateam id
|
|
// ITEM_FIELD_ENCHANTMENT_1_1+1 is current signatures count (showed on item)
|
|
charter->SetState(ITEM_CHANGED, _player);
|
|
_player->SendNewItem(charter, 1, true, false);
|
|
|
|
// a petition is invalid, if both the owner and the type matches
|
|
// we checked above, if this player is in an arenateam, so this must be
|
|
// datacorruption
|
|
CharacterDatabase.EscapeString(name);
|
|
if (Petition const* petition = sPetitionMgr->GetPetitionByOwnerWithType(_player->GetGUID(), type))
|
|
{
|
|
// clear from petition store
|
|
sPetitionMgr->RemovePetition(petition->PetitionGuid);
|
|
TC_LOG_DEBUG("network", "Invalid petition {}", petition->PetitionGuid.ToString());
|
|
}
|
|
|
|
// fill petition store
|
|
sPetitionMgr->AddPetition(charter->GetGUID(), _player->GetGUID(), name, type, false);
|
|
}
|
|
|
|
void WorldSession::HandlePetitionShowSignatures(WorldPacket& recvData)
|
|
{
|
|
TC_LOG_DEBUG("network", "Received opcode CMSG_PETITION_SHOW_SIGNATURES");
|
|
|
|
ObjectGuid petitionGuid;
|
|
recvData >> petitionGuid; // petition guid
|
|
|
|
Petition const* petition = sPetitionMgr->GetPetition(petitionGuid);
|
|
if (!petition)
|
|
{
|
|
TC_LOG_DEBUG("entities.player.items", "Petition {} is not found for player {} {}", petitionGuid.ToString(), GetPlayer()->GetGUID().ToString(), GetPlayer()->GetName());
|
|
return;
|
|
}
|
|
|
|
// if guild petition and has guild => error, return;
|
|
if (petition->PetitionType == GUILD_CHARTER_TYPE && _player->GetGuildId())
|
|
return;
|
|
|
|
TC_LOG_DEBUG("network", "CMSG_PETITION_SHOW_SIGNATURES petition {}", petitionGuid.ToString());
|
|
|
|
SendPetitionSigns(petition, _player);
|
|
}
|
|
|
|
void WorldSession::SendPetitionSigns(Petition const* petition, Player* sendTo)
|
|
{
|
|
SignaturesVector const& signatures = petition->Signatures;
|
|
WorldPacket data(SMSG_PETITION_SHOW_SIGNATURES, (8 + 8 + 4 + 1 + signatures.size() * 12));
|
|
data << uint64(petition->PetitionGuid); // petition guid
|
|
data << uint64(petition->OwnerGuid); // owner guid
|
|
data << uint32(petition->PetitionGuid.GetCounter()); // guild guid
|
|
data << uint8(signatures.size()); // sign's count
|
|
|
|
for (Signature const& signature : signatures)
|
|
{
|
|
data << signature.second; // Player GUID
|
|
data << uint32(0); // there 0 ...
|
|
}
|
|
|
|
sendTo->SendDirectMessage(&data);
|
|
}
|
|
|
|
void WorldSession::HandleQueryPetition(WorldPacket& recvData)
|
|
{
|
|
TC_LOG_DEBUG("network", "Received opcode CMSG_PETITION_QUERY"); // ok
|
|
|
|
ObjectGuid::LowType guildguid;
|
|
ObjectGuid petitionguid;
|
|
recvData >> guildguid; // in Trinity always same as GUID_LOPART(petitionguid)
|
|
recvData >> petitionguid; // petition guid
|
|
TC_LOG_DEBUG("network", "CMSG_PETITION_QUERY Petition {} Guild GUID {}", petitionguid.ToString(), guildguid);
|
|
|
|
SendPetitionQueryOpcode(petitionguid);
|
|
}
|
|
|
|
void WorldSession::SendPetitionQueryOpcode(ObjectGuid petitionguid)
|
|
{
|
|
Petition const* petition = sPetitionMgr->GetPetition(petitionguid);
|
|
if (!petition)
|
|
{
|
|
TC_LOG_DEBUG("network", "CMSG_PETITION_QUERY failed for petition ({})", petitionguid.ToString());
|
|
return;
|
|
}
|
|
|
|
WorldPacket data(SMSG_PETITION_QUERY_RESPONSE, (4+8+petition->PetitionName.size()+1+1+4*12+2+10));
|
|
data << uint32(petitionguid.GetCounter()); // guild/team guid (in Trinity always same as GUID_LOPART(petition guid)
|
|
data << uint64(petition->OwnerGuid); // charter owner guid
|
|
data << petition->PetitionName; // name (guild/arena team)
|
|
data << uint8(0); // some string
|
|
|
|
CharterTypes type = petition->PetitionType;
|
|
if (type == GUILD_CHARTER_TYPE)
|
|
{
|
|
uint32 needed = sWorld->getIntConfig(CONFIG_MIN_PETITION_SIGNS);
|
|
data << uint32(needed);
|
|
data << uint32(needed);
|
|
data << uint32(0); // bypass client - side limitation, a different value is needed here for each petition
|
|
}
|
|
else
|
|
{
|
|
data << uint32(type-1);
|
|
data << uint32(type-1);
|
|
data << uint32(type); // bypass client - side limitation, a different value is needed here for each petition
|
|
}
|
|
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?
|
|
|
|
for (int i = 0; i < 10; ++i)
|
|
data << uint8(0); // some string
|
|
|
|
data << uint32(0); // 14
|
|
|
|
data << uint32(type != GUILD_CHARTER_TYPE); // 15 0 - guild, 1 - arena team
|
|
|
|
SendPacket(&data);
|
|
}
|
|
|
|
void WorldSession::HandlePetitionRenameGuild(WorldPacket& recvData)
|
|
{
|
|
TC_LOG_DEBUG("network", "Received opcode MSG_PETITION_RENAME");
|
|
|
|
ObjectGuid petitionGuid;
|
|
std::string newName;
|
|
|
|
recvData >> petitionGuid; // guid
|
|
recvData >> newName; // new name
|
|
|
|
Item* item = _player->GetItemByGuid(petitionGuid);
|
|
if (!item)
|
|
return;
|
|
|
|
Petition* petition = sPetitionMgr->GetPetition(petitionGuid);
|
|
if (!petition)
|
|
{
|
|
TC_LOG_DEBUG("network", "CMSG_PETITION_QUERY failed for petition {}", petitionGuid.ToString());
|
|
return;
|
|
}
|
|
|
|
CharterTypes type = petition->PetitionType;
|
|
if (type == GUILD_CHARTER_TYPE)
|
|
{
|
|
if (sGuildMgr->GetGuildByName(newName))
|
|
{
|
|
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_EXISTS_S, newName);
|
|
return;
|
|
}
|
|
if (sObjectMgr->IsReservedName(newName) || !ObjectMgr::IsValidCharterName(newName))
|
|
{
|
|
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_INVALID, newName);
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (sArenaTeamMgr->GetArenaTeamByName(newName))
|
|
{
|
|
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, newName, "", ERR_ARENA_TEAM_NAME_EXISTS_S);
|
|
return;
|
|
}
|
|
if (sObjectMgr->IsReservedName(newName) || !ObjectMgr::IsValidCharterName(newName))
|
|
{
|
|
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, newName, "", ERR_ARENA_TEAM_NAME_INVALID);
|
|
return;
|
|
}
|
|
}
|
|
|
|
CharacterDatabase.EscapeString(newName);
|
|
|
|
// update petition storage
|
|
petition->UpdateName(newName);
|
|
|
|
TC_LOG_DEBUG("network", "Petition {} renamed to '{}'", petitionGuid.ToString(), newName);
|
|
WorldPacket data(MSG_PETITION_RENAME, (8+newName.size()+1));
|
|
data << uint64(petitionGuid);
|
|
data << newName;
|
|
SendPacket(&data);
|
|
}
|
|
|
|
void WorldSession::HandleSignPetition(WorldPacket& recvData)
|
|
{
|
|
TC_LOG_DEBUG("network", "Received opcode CMSG_PETITION_SIGN"); // ok
|
|
|
|
ObjectGuid petitionGuid;
|
|
uint8 unk;
|
|
recvData >> petitionGuid; // petition guid
|
|
recvData >> unk;
|
|
|
|
Petition* petition = sPetitionMgr->GetPetition(petitionGuid);
|
|
if (!petition)
|
|
{
|
|
TC_LOG_ERROR("network", "Petition {} is not found for player {} {}", petitionGuid.ToString(), GetPlayer()->GetGUID().ToString(), GetPlayer()->GetName());
|
|
return;
|
|
}
|
|
|
|
ObjectGuid ownerGuid = petition->OwnerGuid;
|
|
CharterTypes type = petition->PetitionType;
|
|
uint8 signs = uint8(petition->Signatures.size());
|
|
|
|
ObjectGuid playerGuid = _player->GetGUID();
|
|
if (ownerGuid == playerGuid)
|
|
return;
|
|
|
|
// not let enemies sign guild charter
|
|
if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && GetPlayer()->GetTeam() != sCharacterCache->GetCharacterTeamByGuid(ownerGuid))
|
|
{
|
|
if (type != GUILD_CHARTER_TYPE)
|
|
SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", "", ERR_ARENA_TEAM_NOT_ALLIED);
|
|
else
|
|
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NOT_ALLIED);
|
|
return;
|
|
}
|
|
|
|
if (type != GUILD_CHARTER_TYPE)
|
|
{
|
|
if (!_player->IsMaxLevel())
|
|
{
|
|
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, "", _player->GetName(), ERR_ARENA_TEAM_TARGET_TOO_LOW_S);
|
|
return;
|
|
}
|
|
|
|
uint8 slot = ArenaTeam::GetSlotByType(static_cast<uint32>(type));
|
|
if (slot >= MAX_ARENA_SLOT)
|
|
return;
|
|
|
|
if (_player->GetArenaTeamId(slot))
|
|
{
|
|
SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", _player->GetName(), ERR_ALREADY_IN_ARENA_TEAM_S);
|
|
return;
|
|
}
|
|
|
|
if (_player->GetArenaTeamIdInvited())
|
|
{
|
|
SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", _player->GetName(), ERR_ALREADY_INVITED_TO_ARENA_TEAM_S);
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (_player->GetGuildId())
|
|
{
|
|
Guild::SendCommandResult(this, GUILD_COMMAND_INVITE, ERR_ALREADY_IN_GUILD_S, _player->GetName());
|
|
return;
|
|
}
|
|
if (_player->GetGuildIdInvited())
|
|
{
|
|
Guild::SendCommandResult(this, GUILD_COMMAND_INVITE, ERR_ALREADY_INVITED_TO_GUILD_S, _player->GetName());
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (++signs > static_cast<uint8>(type)) // client signs maximum
|
|
return;
|
|
|
|
// 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
|
|
bool isSigned = petition->IsPetitionSignedByAccount(GetAccountId());
|
|
if (isSigned)
|
|
{
|
|
WorldPacket data(SMSG_PETITION_SIGN_RESULTS, (8+8+4));
|
|
data << uint64(petitionGuid);
|
|
data << uint64(_player->GetGUID());
|
|
data << uint32(PETITION_SIGN_ALREADY_SIGNED);
|
|
|
|
// close at signer side
|
|
SendPacket(&data);
|
|
|
|
// update for owner if online
|
|
if (Player* owner = ObjectAccessor::FindConnectedPlayer(ownerGuid))
|
|
owner->SendDirectMessage(&data);
|
|
return;
|
|
}
|
|
|
|
// fill petition store
|
|
petition->AddSignature(GetAccountId(), playerGuid, false);
|
|
|
|
TC_LOG_DEBUG("network", "PETITION SIGN: {} by player: {} ({} Account: {})", petitionGuid.ToString(), _player->GetName(), playerGuid.ToString(), GetAccountId());
|
|
|
|
WorldPacket data(SMSG_PETITION_SIGN_RESULTS, (8+8+4));
|
|
data << uint64(petitionGuid);
|
|
data << uint64(_player->GetGUID());
|
|
data << uint32(PETITION_SIGN_OK);
|
|
SendPacket(&data);
|
|
|
|
// update for owner if online
|
|
if (Player* owner = ObjectAccessor::FindConnectedPlayer(ownerGuid))
|
|
owner->SendDirectMessage(&data);
|
|
}
|
|
|
|
void WorldSession::HandleDeclinePetition(WorldPacket& recvData)
|
|
{
|
|
TC_LOG_DEBUG("network", "Received opcode MSG_PETITION_DECLINE"); // ok
|
|
|
|
ObjectGuid petitionguid;
|
|
recvData >> petitionguid; // petition guid
|
|
TC_LOG_DEBUG("network", "Petition {} declined by {}", petitionguid.ToString(), _player->GetGUID().ToString());
|
|
|
|
Petition const* petition = sPetitionMgr->GetPetition(petitionguid);
|
|
if (!petition)
|
|
return;
|
|
|
|
// petition owner online
|
|
if (Player* owner = ObjectAccessor::FindConnectedPlayer(petition->OwnerGuid))
|
|
{
|
|
WorldPacket data(MSG_PETITION_DECLINE, 8);
|
|
data << uint64(_player->GetGUID());
|
|
owner->SendDirectMessage(&data);
|
|
}
|
|
}
|
|
|
|
void WorldSession::HandleOfferPetitionOpcode(WorldPacket& recvData)
|
|
{
|
|
TC_LOG_DEBUG("network", "Received opcode CMSG_OFFER_PETITION"); // ok
|
|
|
|
ObjectGuid petitionGuid, offererGuid;
|
|
uint32 junk;
|
|
recvData >> junk; // this is not petition type!
|
|
recvData >> petitionGuid; // petition guid
|
|
recvData >> offererGuid; // player guid
|
|
|
|
Player* player = ObjectAccessor::FindConnectedPlayer(offererGuid);
|
|
if (!player)
|
|
return;
|
|
|
|
Petition const* petition = sPetitionMgr->GetPetition(petitionGuid);
|
|
if (!petition)
|
|
return;
|
|
|
|
CharterTypes type = petition->PetitionType;
|
|
|
|
TC_LOG_DEBUG("network", "OFFER PETITION: type {}, {}, to {}", static_cast<uint32>(type), petitionGuid.ToString(), offererGuid.ToString());
|
|
|
|
if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && GetPlayer()->GetTeam() != player->GetTeam())
|
|
{
|
|
if (type != GUILD_CHARTER_TYPE)
|
|
SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", "", ERR_ARENA_TEAM_NOT_ALLIED);
|
|
else
|
|
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NOT_ALLIED);
|
|
return;
|
|
}
|
|
|
|
if (type != GUILD_CHARTER_TYPE)
|
|
{
|
|
if (!player->IsMaxLevel())
|
|
{
|
|
// player is too low level to join an arena team
|
|
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, player->GetName(), "", ERR_ARENA_TEAM_TARGET_TOO_LOW_S);
|
|
return;
|
|
}
|
|
|
|
uint8 slot = ArenaTeam::GetSlotByType(static_cast<uint32>(type));
|
|
if (slot >= MAX_ARENA_SLOT)
|
|
return;
|
|
|
|
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;
|
|
}
|
|
|
|
if (player->GetArenaTeamIdInvited())
|
|
{
|
|
SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", _player->GetName(), ERR_ALREADY_INVITED_TO_ARENA_TEAM_S);
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (player->GetGuildId())
|
|
{
|
|
Guild::SendCommandResult(this, GUILD_COMMAND_INVITE, ERR_ALREADY_IN_GUILD_S, _player->GetName());
|
|
return;
|
|
}
|
|
|
|
if (player->GetGuildIdInvited())
|
|
{
|
|
Guild::SendCommandResult(this, GUILD_COMMAND_INVITE, ERR_ALREADY_INVITED_TO_GUILD_S, _player->GetName());
|
|
return;
|
|
}
|
|
}
|
|
|
|
SendPetitionSigns(petition, player);
|
|
}
|
|
|
|
void WorldSession::HandleTurnInPetitionOpcode(WorldPacket& recvData)
|
|
{
|
|
TC_LOG_DEBUG("network", "Received opcode CMSG_TURN_IN_PETITION");
|
|
|
|
// Get petition guid from packet
|
|
WorldPacket data;
|
|
ObjectGuid petitionGuid;
|
|
|
|
recvData >> petitionGuid;
|
|
|
|
// Check if player really has the required petition charter
|
|
Item* item = _player->GetItemByGuid(petitionGuid);
|
|
if (!item)
|
|
return;
|
|
|
|
TC_LOG_DEBUG("network", "Petition {} turned in by {}", petitionGuid.ToString(), _player->GetGUID().ToString());
|
|
|
|
Petition const* petition = sPetitionMgr->GetPetition(petitionGuid);
|
|
if (!petition)
|
|
{
|
|
TC_LOG_ERROR("entities.player.cheat", "Player {} {} tried to turn in petition ({}) that is not present in the database", _player->GetName(), _player->GetGUID().ToString(), petitionGuid.ToString());
|
|
return;
|
|
}
|
|
|
|
CharterTypes type = petition->PetitionType;
|
|
std::string const name = petition->PetitionName; // we need a copy, it will be removed on guild/arena remove
|
|
|
|
// Only the petition owner can turn in the petition
|
|
if (_player->GetGUID() != petition->OwnerGuid)
|
|
return;
|
|
|
|
// Petition type (guild/arena) specific checks
|
|
if (type == GUILD_CHARTER_TYPE)
|
|
{
|
|
// Check if player is already in a guild
|
|
if (_player->GetGuildId())
|
|
{
|
|
data.Initialize(SMSG_TURN_IN_PETITION_RESULTS, 4);
|
|
data << uint32(PETITION_TURN_ALREADY_IN_GUILD);
|
|
_player->SendDirectMessage(&data);
|
|
return;
|
|
}
|
|
|
|
// Check if guild name is already taken
|
|
if (sGuildMgr->GetGuildByName(name))
|
|
{
|
|
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_EXISTS_S, name);
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Check for valid arena bracket (2v2, 3v3, 5v5)
|
|
uint8 slot = ArenaTeam::GetSlotByType(static_cast<uint32>(type));
|
|
if (slot >= MAX_ARENA_SLOT)
|
|
return;
|
|
|
|
// Check if player is already in an arena team
|
|
if (_player->GetArenaTeamId(slot))
|
|
{
|
|
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ALREADY_IN_ARENA_TEAM);
|
|
return;
|
|
}
|
|
|
|
// Check if arena team name is already taken
|
|
if (sArenaTeamMgr->GetArenaTeamByName(name))
|
|
{
|
|
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_EXISTS_S);
|
|
return;
|
|
}
|
|
}
|
|
|
|
SignaturesVector const signatures = petition->Signatures; // we need a copy, it will be removed on guild/arena remove
|
|
uint32 requiredSignatures = static_cast<uint32>(type) - 1;
|
|
if (type == GUILD_CHARTER_TYPE)
|
|
requiredSignatures = sWorld->getIntConfig(CONFIG_MIN_PETITION_SIGNS);
|
|
|
|
// Notify player if signatures are missing
|
|
if (signatures.size() < requiredSignatures)
|
|
{
|
|
data.Initialize(SMSG_TURN_IN_PETITION_RESULTS, 4);
|
|
data << (uint32)PETITION_TURN_NEED_MORE_SIGNATURES;
|
|
SendPacket(&data);
|
|
return;
|
|
}
|
|
|
|
// Proceed with guild/arena team creation
|
|
|
|
// Delete charter item
|
|
_player->DestroyItem(item->GetBagSlot(), item->GetSlot(), true);
|
|
|
|
if (type == GUILD_CHARTER_TYPE)
|
|
{
|
|
// Create guild
|
|
Guild* guild = new Guild;
|
|
|
|
if (!guild->Create(_player, name))
|
|
{
|
|
delete guild;
|
|
return;
|
|
}
|
|
|
|
// Register guild and add guild master
|
|
sGuildMgr->AddGuild(guild);
|
|
|
|
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_COMMAND_SUCCESS, name);
|
|
|
|
{
|
|
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
|
|
|
// Add members from signatures
|
|
for (Signature const& signature : signatures)
|
|
guild->AddMember(trans, signature.second);
|
|
|
|
CharacterDatabase.CommitTransaction(trans);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Receive the rest of the packet in arena team creation case
|
|
uint32 background, icon, iconcolor, border, bordercolor;
|
|
recvData >> background >> icon >> iconcolor >> border >> bordercolor;
|
|
|
|
// Create arena team
|
|
ArenaTeam* arenaTeam = new ArenaTeam();
|
|
|
|
if (!arenaTeam->Create(_player->GetGUID(), type, name, background, icon, iconcolor, border, bordercolor))
|
|
{
|
|
delete arenaTeam;
|
|
return;
|
|
}
|
|
|
|
// Register arena team
|
|
sArenaTeamMgr->AddArenaTeam(arenaTeam);
|
|
TC_LOG_DEBUG("network", "PetitonsHandler: Arena team (guid: {}) added to ObjectMgr", arenaTeam->GetId());
|
|
|
|
// Add members
|
|
for (Signature const& signature : signatures)
|
|
{
|
|
TC_LOG_DEBUG("network", "PetitionsHandler: Adding arena team (guid: {}) member {}", arenaTeam->GetId(), signature.second.ToString());
|
|
arenaTeam->AddMember(signature.second);
|
|
}
|
|
}
|
|
|
|
sPetitionMgr->RemovePetition(petitionGuid);
|
|
|
|
// created
|
|
TC_LOG_DEBUG("network", "Player {} ({}) turning in petition {}", _player->GetName(), _player->GetGUID().ToString(), petitionGuid.ToString());
|
|
|
|
data.Initialize(SMSG_TURN_IN_PETITION_RESULTS, 4);
|
|
data << (uint32)PETITION_TURN_OK;
|
|
SendPacket(&data);
|
|
}
|
|
|
|
void WorldSession::HandlePetitionShowListOpcode(WorldPacket& recvData)
|
|
{
|
|
TC_LOG_DEBUG("network", "Received CMSG_PETITION_SHOWLIST");
|
|
|
|
ObjectGuid guid;
|
|
recvData >> guid;
|
|
|
|
SendPetitionShowList(guid);
|
|
}
|
|
|
|
void WorldSession::SendPetitionShowList(ObjectGuid guid)
|
|
{
|
|
Creature* creature = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_PETITIONER);
|
|
if (!creature)
|
|
{
|
|
TC_LOG_DEBUG("network", "WORLD: HandlePetitionShowListOpcode - {} not found or you can't interact with him.", guid.ToString());
|
|
return;
|
|
}
|
|
|
|
WorldPacket data(SMSG_PETITION_SHOWLIST, 8+1+4*6);
|
|
data << guid; // npc guid
|
|
|
|
if (creature->IsTabardDesigner())
|
|
{
|
|
data << uint8(1); // count
|
|
data << uint32(1); // index
|
|
data << uint32(GUILD_CHARTER); // charter entry
|
|
data << uint32(CHARTER_DISPLAY_ID); // charter display id
|
|
data << uint32(sWorld->getIntConfig(CONFIG_CHARTER_COST_GUILD)); // charter cost
|
|
data << uint32(0); // unknown
|
|
data << uint32(sWorld->getIntConfig(CONFIG_MIN_PETITION_SIGNS)); // required signs
|
|
}
|
|
else
|
|
{
|
|
data << uint8(3); // count
|
|
// 2v2
|
|
data << uint32(1); // index
|
|
data << uint32(ARENA_TEAM_CHARTER_2v2); // charter entry
|
|
data << uint32(CHARTER_DISPLAY_ID); // charter display id
|
|
data << uint32(sWorld->getIntConfig(CONFIG_CHARTER_COST_ARENA_2v2)); // 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(CHARTER_DISPLAY_ID); // charter display id
|
|
data << uint32(sWorld->getIntConfig(CONFIG_CHARTER_COST_ARENA_3v3)); // 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(CHARTER_DISPLAY_ID); // charter display id
|
|
data << uint32(sWorld->getIntConfig(CONFIG_CHARTER_COST_ARENA_5v5)); // charter cost
|
|
data << uint32(5); // unknown
|
|
data << uint32(5); // required signs?
|
|
}
|
|
|
|
SendPacket(&data);
|
|
TC_LOG_DEBUG("network", "Sent SMSG_PETITION_SHOWLIST");
|
|
}
|