From 19cb07cfef0179ac45bd1b39a82ae0bf952192e1 Mon Sep 17 00:00:00 2001 From: false_genesis Date: Wed, 30 Jan 2008 22:22:41 +0000 Subject: [PATCH] * fixed bbread DefScript func in strnz mode * optimized player name querying when recieving channel list (now all at once, not one by one) * cleanup: replaced valid player name lengths by #defines instead of hardcoded numbers --- src/Client/DefScript/DefScriptBBFunctions.cpp | 3 ++- src/Client/World/CacheHandler.cpp | 5 +++-- src/Client/World/Channel.cpp | 8 ++++++-- src/Client/World/SharedDefines.h | 3 +++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Client/DefScript/DefScriptBBFunctions.cpp b/src/Client/DefScript/DefScriptBBFunctions.cpp index 4ab006f..46d5cf4 100644 --- a/src/Client/DefScript/DefScriptBBFunctions.cpp +++ b/src/Client/DefScript/DefScriptBBFunctions.cpp @@ -88,7 +88,8 @@ DefReturnResult DefScriptPackage::func_bbread(CmdSet& Set) if(bytes) { std::string g; - char *buf = new char[bytes]; + char *buf = new char[bytes+1]; // +1 for \0 + buf[bytes] = 0; bb->read((uint8*)buf,bytes); g = buf; delete [] buf; diff --git a/src/Client/World/CacheHandler.cpp b/src/Client/World/CacheHandler.cpp index 326890c..ac80911 100644 --- a/src/Client/World/CacheHandler.cpp +++ b/src/Client/World/CacheHandler.cpp @@ -123,8 +123,9 @@ bool PlayerNameCache::ReadFromFile(void) PlayerNameCacheItem *cacheItem=new PlayerNameCacheItem; fh.read((char*)&(cacheItem->_guid),sizeof(uint64)); fh.read((char*)&len,sizeof(uint8)); - if(len>12 || len<2){ - logerror("PlayerNameCache data seem corrupt [namelength=%d, should be <=12]",len); + if(len > MAX_PLAYERNAME_LENGTH || len < MIN_PLAYERNAME_LENGTH) + { + logerror("PlayerNameCache data seem corrupt [namelength=%d, should be <=%u]",len,MAX_PLAYERNAME_LENGTH); log("-> Clearing cache, creating new."); _cache.clear(); success=false; diff --git a/src/Client/World/Channel.cpp b/src/Client/World/Channel.cpp index ffa541e..2c0be4f 100644 --- a/src/Client/World/Channel.cpp +++ b/src/Client/World/Channel.cpp @@ -222,6 +222,8 @@ void Channel::HandleListRequest(WorldPacket& recvPacket) uint64 guid; uint8 mode, flags; // mode: player flags; flags: channel flags std::string name; + bool must_delay = false; + recvPacket >> unk >> name >> flags >> size; for(uint32 i = 0; i < size; i++) @@ -231,10 +233,12 @@ void Channel::HandleListRequest(WorldPacket& recvPacket) if(_worldSession->GetOrRequestPlayerName(guid).empty()) { _worldSession->_DelayWorldPacket(recvPacket, _worldSession->GetLagMS() * 1.2f); - return; + must_delay = true; } cpl[guid] = mode; } + if(must_delay) + return; // store list of GUIDs in: @ChannelList - see below DefList *l = _worldSession->GetInstance()->GetScripts()->lists.Get("@ChannelList"); @@ -253,7 +257,7 @@ void Channel::HandleListRequest(WorldPacket& recvPacket) muted = mode & MEMBER_FLAG_MUTED; mod = mode & MEMBER_FLAG_MODERATOR; - while(pname.length()<12) + while(pname.length() < MAX_PLAYERNAME_LENGTH) pname += " "; // for better formatting logcustom(0,WHITE,"%s ["I64FMT"] %s %s",pname.c_str(),i->first,muted?"(muted)":"",mod?"(moderator)":""); diff --git a/src/Client/World/SharedDefines.h b/src/Client/World/SharedDefines.h index 74c4138..1b93bd5 100644 --- a/src/Client/World/SharedDefines.h +++ b/src/Client/World/SharedDefines.h @@ -1371,4 +1371,7 @@ enum SpellCastTargetFlags TARGET_FLAG_STRING = 0x2000 }; +#define MAX_PLAYERNAME_LENGTH 12 +#define MIN_PLAYERNAME_LENGTH 2 + #endif