From 2e2055c4693d4cefc514eb58a696a28291bb6df8 Mon Sep 17 00:00:00 2001 From: hunuza Date: Wed, 10 Dec 2008 16:41:46 +0100 Subject: [PATCH] [6892] Some small code clean ups and optimisations. Signed-off-by: hunuza --- src/game/Channel.cpp | 4 ++-- src/game/Channel.h | 12 +++------- src/game/CharacterHandler.cpp | 29 +++++++++--------------- src/game/Creature.cpp | 42 +++-------------------------------- src/shared/revision_nr.h | 2 +- 5 files changed, 19 insertions(+), 70 deletions(-) diff --git a/src/game/Channel.cpp b/src/game/Channel.cpp index ca7c8ff3e..2fb8b5d09 100644 --- a/src/game/Channel.cpp +++ b/src/game/Channel.cpp @@ -209,7 +209,7 @@ void Channel::KickOrBan(uint64 good, const char *badname, bool ban) if(ban && !IsBanned(bad->GetGUID())) { - banned.push_back(bad->GetGUID()); + banned.insert(bad->GetGUID()); MakePlayerBanned(&data, bad->GetGUID(), good); } else @@ -258,7 +258,7 @@ void Channel::UnBan(uint64 good, const char *badname) } else { - banned.remove(bad->GetGUID()); + banned.erase(bad->GetGUID()); WorldPacket data; MakePlayerUnbanned(&data, bad->GetGUID(), good); diff --git a/src/game/Channel.h b/src/game/Channel.h index 31e196948..fc87efdd0 100644 --- a/src/game/Channel.h +++ b/src/game/Channel.h @@ -147,7 +147,7 @@ class Channel typedef std::map PlayerList; PlayerList players; - typedef std::list BannedList; + typedef std::set BannedList; BannedList banned; bool m_announce; bool m_moderate; @@ -202,15 +202,9 @@ class Channel void SendToAllButOne(WorldPacket *data, uint64 who); void SendToOne(WorldPacket *data, uint64 who); - bool IsOn(uint64 who) const { return players.count(who) > 0; } + bool IsOn(uint64 who) const { return players.count(who) != 0; } - bool IsBanned(const uint64 guid) const - { - for(BannedList::const_iterator i = banned.begin(); i != banned.end(); ++i) - if(*i == guid) - return true; - return false; - } + bool IsBanned(const uint64 guid) const {return banned.count(guid) != 0; } bool IsFirst() const { return !(players.size() > 1); } diff --git a/src/game/CharacterHandler.cpp b/src/game/CharacterHandler.cpp index a09436590..8880a7b2e 100644 --- a/src/game/CharacterHandler.cpp +++ b/src/game/CharacterHandler.cpp @@ -904,23 +904,8 @@ void WorldSession::HandleChangePlayerNameOpcode(WorldPacket& recv_data) recv_data >> guid; recv_data >> newname; - QueryResult *result = CharacterDatabase.PQuery("SELECT at_login FROM characters WHERE guid ='%u'", GUID_LOPART(guid)); - if (result) - { - uint32 at_loginFlags; - Field *fields = result->Fetch(); - at_loginFlags = fields[0].GetUInt32(); - delete result; - - if (!(at_loginFlags & AT_LOGIN_RENAME)) - { - WorldPacket data(SMSG_CHAR_RENAME, 1); - data << (uint8)CHAR_CREATE_ERROR; - SendPacket( &data ); - return; - } - } - else + QueryResult *result = CharacterDatabase.PQuery("SELECT at_login, name FROM characters WHERE guid ='%u'", GUID_LOPART(guid)); + if (!result) { WorldPacket data(SMSG_CHAR_RENAME, 1); data << (uint8)CHAR_CREATE_ERROR; @@ -928,10 +913,16 @@ void WorldSession::HandleChangePlayerNameOpcode(WorldPacket& recv_data) return; } - if(!objmgr.GetPlayerNameByGUID(guid, oldname)) // character not exist, because we have no name for this guid + uint32 at_loginFlags; + Field *fields = result->Fetch(); + at_loginFlags = fields[0].GetUInt32(); + oldname = fields[1].GetCppString(); + delete result; + + if (!(at_loginFlags & AT_LOGIN_RENAME)) { WorldPacket data(SMSG_CHAR_RENAME, 1); - data << (uint8)CHAR_LOGIN_NO_CHARACTER; + data << (uint8)CHAR_CREATE_ERROR; SendPacket( &data ); return; } diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 880427b81..8ab1b3258 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -926,44 +926,7 @@ void Creature::OnPoiSelect(Player* player, GossipOption const *gossip) { if(gossip->GossipId==GOSSIP_GUARD_SPELLTRAINER || gossip->GossipId==GOSSIP_GUARD_SKILLTRAINER) { - //float x,y; - //bool findnpc=false; Poi_Icon icon = ICON_POI_0; - //QueryResult *result; - //Field *fields; - uint32 mapid=GetMapId(); - Map const* map=MapManager::Instance().GetBaseMap( mapid ); - uint16 areaflag=map->GetAreaFlag(GetPositionX(),GetPositionY()); - uint32 zoneid=Map::GetZoneId(areaflag,mapid); - std::string areaname= gossip->OptionText; - /* - uint16 pflag; - - // use the action relate to creaturetemplate.trainer_type ? - result= WorldDatabase.PQuery("SELECT creature.position_x,creature.position_y FROM creature,creature_template WHERE creature.map = '%u' AND creature.id = creature_template.entry AND creature_template.trainer_type = '%u'", mapid, gossip->Action ); - if(!result) - return; - do - { - fields = result->Fetch(); - x=fields[0].GetFloat(); - y=fields[1].GetFloat(); - pflag=map->GetAreaFlag(GetPositionX(),GetPositionY()); - if(pflag==areaflag) - { - findnpc=true; - break; - } - }while(result->NextRow()); - - delete result; - - if(!findnpc) - { - player->PlayerTalkClass->SendTalking( "$NSorry", "Here no this person."); - return; - }*/ - //need add more case. switch(gossip->Action) { @@ -980,8 +943,9 @@ void Creature::OnPoiSelect(Player* player, GossipOption const *gossip) icon=ICON_POI_TOWER; break; } - uint32 textid=GetGossipTextId( gossip->Action, zoneid ); - player->PlayerTalkClass->SendTalking( textid ); + uint32 textid = GetGossipTextId( gossip->Action, GetZoneId() ); + player->PlayerTalkClass->SendTalking(textid); + // std::string areaname= gossip->OptionText; // how this could worked player->PlayerTalkClass->SendPointOfInterest( x, y, icon, 2, 15, areaname.c_str() ); } } diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 27a2b558c..ae4d0945a 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "6891" + #define REVISION_NR "6892" #endif // __REVISION_NR_H__