mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 13:37:05 +00:00
Improve some arena team related DB access.
Reduce number of queries for adding a new arena team member. Merge two queries in Player::GetArenaTeamIdFromDB() into one.
This commit is contained in:
parent
166007525e
commit
2cdd7dcfce
2 changed files with 34 additions and 50 deletions
|
|
@ -88,40 +88,45 @@ bool ArenaTeam::AddMember(uint64 PlayerGuid)
|
||||||
std::string plName;
|
std::string plName;
|
||||||
uint8 plClass;
|
uint8 plClass;
|
||||||
|
|
||||||
|
// arena team is full (can't have more than type * 2 players!)
|
||||||
if(GetMembersSize() >= GetType() * 2)
|
if(GetMembersSize() >= GetType() * 2)
|
||||||
{
|
|
||||||
// arena team is full (can't have more than type * 2 players!)
|
|
||||||
// return false
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if(!objmgr.GetPlayerNameByGUID(PlayerGuid, plName)) // player doesnt exist
|
Player *pl = objmgr.GetPlayer(PlayerGuid);
|
||||||
return false;
|
if(pl)
|
||||||
// player already in arenateam of that size
|
|
||||||
if(Player::GetArenaTeamIdFromDB(PlayerGuid, GetType()) != 0)
|
|
||||||
{
|
{
|
||||||
sLog.outError("Arena::AddMember() : player already in this sized team");
|
if(pl->GetArenaTeamId(GetType()))
|
||||||
return false;
|
{
|
||||||
|
sLog.outError("Arena::AddMember() : player already in this sized team");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
plClass = (uint8)pl->getClass();
|
||||||
|
plName = pl->GetName();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 0 1
|
||||||
|
QueryResult *result = CharacterDatabase.PQuery("SELECT name, class FROM characters WHERE guid='%u'", GUID_LOPART(PlayerGuid));
|
||||||
|
if(!result)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
plName = (*result)[0].GetCppString();
|
||||||
|
plClass = (*result)[1].GetUInt8();
|
||||||
|
delete result;
|
||||||
|
|
||||||
|
// check if player already in arenateam of that size
|
||||||
|
if(Player::GetArenaTeamIdFromDB(PlayerGuid, GetType()) != 0)
|
||||||
|
{
|
||||||
|
sLog.outError("Arena::AddMember() : player already in this sized team");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove all player signs from another petitions
|
// remove all player signs from another petitions
|
||||||
// this will be prevent attempt joining player to many arenateams and corrupt arena team data integrity
|
// this will be prevent attempt joining player to many arenateams and corrupt arena team data integrity
|
||||||
Player::RemovePetitionsAndSigns(PlayerGuid, GetType());
|
Player::RemovePetitionsAndSigns(PlayerGuid, GetType());
|
||||||
|
|
||||||
Player *pl = objmgr.GetPlayer(PlayerGuid);
|
|
||||||
if(pl)
|
|
||||||
{
|
|
||||||
plClass = (uint8)pl->getClass();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QueryResult *result = CharacterDatabase.PQuery("SELECT class FROM characters WHERE guid='%u'", GUID_LOPART(PlayerGuid));
|
|
||||||
if(!result)
|
|
||||||
return false;
|
|
||||||
plClass = (*result)[0].GetUInt8();
|
|
||||||
delete result;
|
|
||||||
}
|
|
||||||
|
|
||||||
ArenaTeamMember newmember;
|
ArenaTeamMember newmember;
|
||||||
newmember.name = plName;
|
newmember.name = plName;
|
||||||
newmember.guid = PlayerGuid;
|
newmember.guid = PlayerGuid;
|
||||||
|
|
|
||||||
|
|
@ -6012,32 +6012,11 @@ uint32 Player::GetRankFromDB(uint64 guid)
|
||||||
|
|
||||||
uint32 Player::GetArenaTeamIdFromDB(uint64 guid, uint8 type)
|
uint32 Player::GetArenaTeamIdFromDB(uint64 guid, uint8 type)
|
||||||
{
|
{
|
||||||
// need fix it!
|
QueryResult *result = CharacterDatabase.PQuery("SELECT arena_team_member.arenateamid FROM arena_team_member JOIN arena_team ON arena_team_member.arenateamid = arena_team.arenateamid WHERE guid='%u' AND type='%u' LIMIT 1", GUID_LOPART(guid), type);
|
||||||
QueryResult *result = CharacterDatabase.PQuery("SELECT arenateamid FROM arena_team_member WHERE guid='%u'", GUID_LOPART(guid));
|
if(!result)
|
||||||
if(result)
|
return 0;
|
||||||
{
|
|
||||||
// init id to 0, check the arena type before assigning a value to id
|
return (*result)[0].GetUInt32();
|
||||||
uint32 id = 0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
QueryResult *result2 = CharacterDatabase.PQuery("SELECT type FROM arena_team WHERE arenateamid='%u'", id);
|
|
||||||
if(result2)
|
|
||||||
{
|
|
||||||
uint8 dbtype = (*result2)[0].GetUInt32();
|
|
||||||
delete result2;
|
|
||||||
if(dbtype == type)
|
|
||||||
{
|
|
||||||
// if the type matches, we've found the id
|
|
||||||
id = (*result)[0].GetUInt32();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while(result->NextRow());
|
|
||||||
delete result;
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
// no arenateam for the specified guid, return 0
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 Player::GetZoneIdFromDB(uint64 guid)
|
uint32 Player::GetZoneIdFromDB(uint64 guid)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue