Core/Guilds: guild code was completely refactored and rewritten.

* OOP desing and implementation;
* all the queries are moved to prepared statements;
* guild loading is optimized;
* all the possible interaction with guild's data is done inside the guild class;
* added more hooks to GuildScript class;

WARNING: Make sure you backup your characters database before applying this change (just in case).

Known problems with guilds:
* when new member is added to the guild, MOTD is not displayed for him in guild tab of social window;
* if you add item with random property to guild bank visual representation of item below it becomes wrong (it displays wrong stack number);
* packets order differs from official: currently guild bank packet traffic is twice as more than on offy.

--HG--
branch : trunk
This commit is contained in:
azazel
2010-10-17 19:54:13 +06:00
parent f5911917b4
commit c0faed2251
27 changed files with 3892 additions and 3538 deletions
@@ -751,24 +751,12 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder * holder)
if (pCurrChar->GetGuildId() != 0)
{
Guild* guild = sObjectMgr.GetGuildById(pCurrChar->GetGuildId());
if (guild)
{
data.Initialize(SMSG_GUILD_EVENT, (1+1+guild->GetMOTD().size()+1));
data << uint8(GE_MOTD);
data << uint8(1);
data << guild->GetMOTD();
SendPacket(&data);
sLog.outStaticDebug("WORLD: Sent guild-motd (SMSG_GUILD_EVENT)");
guild->DisplayGuildBankTabsInfo(this);
guild->BroadcastEvent(GE_SIGNED_ON, pCurrChar->GetGUID(), 1, pCurrChar->GetName(), "", "");
}
if (Guild* pGuild = sObjectMgr.GetGuildById(pCurrChar->GetGuildId()))
pGuild->SendLoginInfo(this);
else
{
// remove wrong guild data
sLog.outError("Player %s (GUID: %u) marked as member not existed guild (id: %u), removing guild membership for player.",pCurrChar->GetName(),pCurrChar->GetGUIDLow(),pCurrChar->GetGuildId());
sLog.outError("Player %s (GUID: %u) marked as member of not existing guild (id: %u), removing guild membership for player.",pCurrChar->GetName(),pCurrChar->GetGUIDLow(),pCurrChar->GetGuildId());
pCurrChar->SetInGuild(0);
}
}
@@ -331,7 +331,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket & recv_data)
{
sScriptMgr.OnPlayerChat(GetPlayer(), type, lang, msg, guild);
guild->BroadcastToGuild(this, msg, lang == LANG_ADDON ? LANG_ADDON : LANG_UNIVERSAL);
guild->BroadcastToGuild(this, false, msg, lang == LANG_ADDON ? LANG_ADDON : LANG_UNIVERSAL);
}
}
@@ -360,7 +360,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket & recv_data)
{
sScriptMgr.OnPlayerChat(GetPlayer(), type, lang, msg, guild);
guild->BroadcastToOfficers(this, msg, lang == LANG_ADDON ? LANG_ADDON : LANG_UNIVERSAL);
guild->BroadcastToGuild(this, true, msg, lang == LANG_ADDON ? LANG_ADDON : LANG_UNIVERSAL);
}
}
break;
File diff suppressed because it is too large Load Diff
@@ -33,7 +33,6 @@
#include "Pet.h"
#include "BattlegroundMgr.h"
#include "Battleground.h"
#include "Guild.h"
#include "ScriptMgr.h"
enum StableResultCode
@@ -880,31 +879,13 @@ void WorldSession::HandleRepairItemOpcode(WorldPacket & recv_data)
sLog.outDebug("ITEM: Repair item, itemGUID = %u, npcGUID = %u", GUID_LOPART(itemGUID), GUID_LOPART(npcGUID));
Item* item = _player->GetItemByGuid(itemGUID);
if (item)
TotalCost= _player->DurabilityRepair(item->GetPos(),true,discountMod,guildBank>0?true:false);
TotalCost = _player->DurabilityRepair(item->GetPos(), true, discountMod, guildBank);
}
else
{
sLog.outDebug("ITEM: Repair all items, npcGUID = %u", GUID_LOPART(npcGUID));
TotalCost = _player->DurabilityRepairAll(true,discountMod,guildBank>0?true:false);
}
if (guildBank)
{
uint32 GuildId = _player->GetGuildId();
if (!GuildId)
return;
Guild *pGuild = sObjectMgr.GetGuildById(GuildId);
if (!pGuild)
return;
//- TODO: Fix poor function call design
SQLTransaction trans = CharacterDatabase.BeginTransaction();
pGuild->LogBankEvent(trans, GUILD_BANK_LOG_REPAIR_MONEY, 0, _player->GetGUIDLow(), TotalCost);
CharacterDatabase.CommitTransaction(trans);
pGuild->SendMoneyInfo(this, _player->GetGUIDLow());
TotalCost = _player->DurabilityRepairAll(true, discountMod, guildBank);
}
}
@@ -46,14 +46,6 @@ enum CharterItemIDs
ARENA_TEAM_CHARTER_5v5 = 23562
};
enum CharterTypes
{
GUILD_CHARTER_TYPE = 9,
ARENA_TEAM_CHARTER_2v2_TYPE = 2,
ARENA_TEAM_CHARTER_3v3_TYPE = 3,
ARENA_TEAM_CHARTER_5v5_TYPE = 5
};
enum CharterCosts
{
GUILD_CHARTER_COST = 1000,
@@ -164,12 +156,12 @@ void WorldSession::HandlePetitionBuyOpcode(WorldPacket & recv_data)
{
if (sObjectMgr.GetGuildByName(name))
{
SendGuildCommandResult(GUILD_CREATE_S, name, ERR_GUILD_NAME_EXISTS_S);
Guild::SendCommandResult(this, GUILD_CREATE_S, ERR_GUILD_NAME_EXISTS_S, name);
return;
}
if (sObjectMgr.IsReservedName(name) || !ObjectMgr::IsValidCharterName(name))
{
SendGuildCommandResult(GUILD_CREATE_S, name, ERR_GUILD_NAME_INVALID);
Guild::SendCommandResult(this, GUILD_CREATE_S, ERR_GUILD_NAME_INVALID, name);
return;
}
}
@@ -414,12 +406,12 @@ void WorldSession::HandlePetitionRenameOpcode(WorldPacket & recv_data)
{
if (sObjectMgr.GetGuildByName(newname))
{
SendGuildCommandResult(GUILD_CREATE_S, newname, ERR_GUILD_NAME_EXISTS_S);
Guild::SendCommandResult(this, GUILD_CREATE_S, ERR_GUILD_NAME_EXISTS_S, newname);
return;
}
if (sObjectMgr.IsReservedName(newname) || !ObjectMgr::IsValidCharterName(newname))
{
SendGuildCommandResult(GUILD_CREATE_S, newname, ERR_GUILD_NAME_INVALID);
Guild::SendCommandResult(this, GUILD_CREATE_S, ERR_GUILD_NAME_INVALID, newname);
return;
}
}
@@ -484,14 +476,14 @@ void WorldSession::HandlePetitionSignOpcode(WorldPacket & recv_data)
// not let enemies sign guild charter
if (!sWorld.getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && GetPlayer()->GetTeam() != sObjectMgr.GetPlayerTeamByGUID(ownerguid))
{
if (type != 9)
if (type != GUILD_CHARTER_TYPE)
SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", "", ERR_ARENA_TEAM_NOT_ALLIED);
else
SendGuildCommandResult(GUILD_CREATE_S, "", ERR_GUILD_NOT_ALLIED);
Guild::SendCommandResult(this, GUILD_CREATE_S, ERR_GUILD_NOT_ALLIED);
return;
}
if (type != 9)
if (type != GUILD_CHARTER_TYPE)
{
if (_player->getLevel() < sWorld.getIntConfig(CONFIG_MAX_PLAYER_LEVEL))
{
@@ -519,12 +511,12 @@ void WorldSession::HandlePetitionSignOpcode(WorldPacket & recv_data)
{
if (_player->GetGuildId())
{
SendGuildCommandResult(GUILD_INVITE_S, _player->GetName(), ERR_ALREADY_IN_GUILD_S);
Guild::SendCommandResult(this, GUILD_INVITE_S, ERR_ALREADY_IN_GUILD_S, _player->GetName());
return;
}
if (_player->GetGuildIdInvited())
{
SendGuildCommandResult(GUILD_INVITE_S, _player->GetName(), ERR_ALREADY_INVITED_TO_GUILD_S);
Guild::SendCommandResult(this, GUILD_INVITE_S, ERR_ALREADY_INVITED_TO_GUILD_S, _player->GetName());
return;
}
}
@@ -628,14 +620,14 @@ void WorldSession::HandleOfferPetitionOpcode(WorldPacket & recv_data)
if (!sWorld.getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && GetPlayer()->GetTeam() != player->GetTeam())
{
if (type != 9)
if (type != GUILD_CHARTER_TYPE)
SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", "", ERR_ARENA_TEAM_NOT_ALLIED);
else
SendGuildCommandResult(GUILD_CREATE_S, "", ERR_GUILD_NOT_ALLIED);
Guild::SendCommandResult(this, GUILD_CREATE_S, ERR_GUILD_NOT_ALLIED);
return;
}
if (type != 9)
if (type != GUILD_CHARTER_TYPE)
{
if (player->getLevel() < sWorld.getIntConfig(CONFIG_MAX_PLAYER_LEVEL))
{
@@ -665,13 +657,13 @@ void WorldSession::HandleOfferPetitionOpcode(WorldPacket & recv_data)
{
if (player->GetGuildId())
{
SendGuildCommandResult(GUILD_INVITE_S, _player->GetName(), ERR_ALREADY_IN_GUILD_S);
Guild::SendCommandResult(this, GUILD_INVITE_S, ERR_ALREADY_IN_GUILD_S, _player->GetName());
return;
}
if (player->GetGuildIdInvited())
{
SendGuildCommandResult(GUILD_INVITE_S, _player->GetName(), ERR_ALREADY_INVITED_TO_GUILD_S);
Guild::SendCommandResult(this, GUILD_INVITE_S, ERR_ALREADY_INVITED_TO_GUILD_S, _player->GetName());
return;
}
}
@@ -787,7 +779,7 @@ void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data)
{
if (sObjectMgr.GetGuildByName(name))
{
SendGuildCommandResult(GUILD_CREATE_S, name, ERR_GUILD_NAME_EXISTS_S);
Guild::SendCommandResult(this, GUILD_CREATE_S, ERR_GUILD_NAME_EXISTS_S, name);
return;
}
}
@@ -826,7 +818,7 @@ void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data)
for (uint8 i = 0; i < signs; ++i)
{
Field* fields = result->Fetch();
guild->AddMember(fields[0].GetUInt64(), guild->GetLowestRank());
guild->AddMember(fields[0].GetUInt64());
result->NextRow();
}
}