From bc74818daacd21bb432b3f000871f37800d8a947 Mon Sep 17 00:00:00 2001 From: "False.Genesis" Date: Wed, 28 Feb 2007 21:17:01 +0000 Subject: [PATCH] * added: auto-query player name on UPDATETYPE_CREATE_OBJECT * added Object::_name to store object names faster & easier accessable. only players & items are added yet. * added a small check for headers < 4 bytes (this can MAYBE fix some problems/errors with crypt) --- src/Client/World/Object.h | 3 +++ src/Client/World/UpdateData.cpp | 18 +++++++++++++++--- src/Client/World/WorldSession.cpp | 3 +++ src/Client/World/WorldSession.h | 2 +- src/Client/World/WorldSocket.cpp | 8 +++++++- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/Client/World/Object.h b/src/Client/World/Object.h index ed55e85..2f83e78 100644 --- a/src/Client/World/Object.h +++ b/src/Client/World/Object.h @@ -96,10 +96,13 @@ public: inline float GetY(void) { return _y; } inline float GetZ(void) { return _z; } inline float GetO(void) { return _o; } + inline void SetName(std::string name) { _name = name; } + inline std::string GetName(void) { return _name; } protected: WorldObject(); float _x,_y,_z,_o; // coords, orientation uint16 _m; // map + std::string _name; }; diff --git a/src/Client/World/UpdateData.cpp b/src/Client/World/UpdateData.cpp index b7b4f20..4902101 100644 --- a/src/Client/World/UpdateData.cpp +++ b/src/Client/World/UpdateData.cpp @@ -134,7 +134,7 @@ void WorldSession::_HandleUpdateObjectOpcode(WorldPacket& recvPacket) this->_MovementUpdate(objtypeid, uguid, recvPacket); this->_ValuesUpdate(uguid, recvPacket); - _QueryObjectProto(uguid); + _QueryObjectInfo(uguid); } break; @@ -282,7 +282,7 @@ void WorldSession::_ValuesUpdate(uint64 uguid, WorldPacket& recvPacket) } -void WorldSession::_QueryObjectProto(uint64 guid) +void WorldSession::_QueryObjectInfo(uint64 guid) { Object *obj = objmgr.GetObj(guid); if(obj) @@ -299,7 +299,19 @@ void WorldSession::_QueryObjectProto(uint64 guid) SendQueryItem(obj->GetEntry(),obj->GetGUID()); // not sure if sending GUID is correct } } - // case ... + case TYPEID_PLAYER: + { + std::string name = plrNameCache.GetName(guid); + if(name.empty()) + { + SendQueryPlayerName(guid); + } + else + { + ((WorldObject*)obj)->SetName(name); + } + } + //case... } } } \ No newline at end of file diff --git a/src/Client/World/WorldSession.cpp b/src/Client/World/WorldSession.cpp index e4acec3..485a6c5 100644 --- a/src/Client/World/WorldSession.cpp +++ b/src/Client/World/WorldSession.cpp @@ -546,6 +546,9 @@ void WorldSession::_HandleNameQueryResponseOpcode(WorldPacket& recvPacket) if(GetInstance()->GetConf()->debug > 1) SendChatMessage(CHAT_MSG_SAY,0,"Player "+pname+" added to cache.",""); } + WorldObject *wo = (WorldObject*)objmgr.GetObj(pguid); + if(wo) + wo->SetName(pname); } void WorldSession::_HandlePongOpcode(WorldPacket& recvPacket) diff --git a/src/Client/World/WorldSession.h b/src/Client/World/WorldSession.h index 9c58f0f..8d88787 100644 --- a/src/Client/World/WorldSession.h +++ b/src/Client/World/WorldSession.h @@ -95,7 +95,7 @@ private: void _MovementUpdate(uint8 objtypeid, uint64 guid, WorldPacket& recvPacket); // Helper for _HandleUpdateObjectOpcode void _ValuesUpdate(uint64 uguid, WorldPacket& recvPacket); // ... - void _QueryObjectProto(uint64 guid); + void _QueryObjectInfo(uint64 guid); PseuInstance *_instance; WorldSocket *_socket; diff --git a/src/Client/World/WorldSocket.cpp b/src/Client/World/WorldSocket.cpp index fc5abaf..0b581c2 100644 --- a/src/Client/World/WorldSocket.cpp +++ b/src/Client/World/WorldSocket.cpp @@ -42,6 +42,12 @@ void WorldSocket::OnRead() this->CloseAndDelete(); return; } + // a valid header needs to have at least 4 bytes + if(len < 4 && (!_gothdr)) + { + logerror("WorldSocket::OnRead(): Got %u bytes (header too small) - waiting for more data",len); + return; + } uint8 *buf=new uint8[len]; ibuf.Read((char*)buf,len); @@ -76,7 +82,7 @@ void WorldSocket::OnRead() // if the crypt gets messy its hardly possible to recover it, especially if we dont know // the lentgh of the following data part // TODO: invent some way how to recover the crypt (reconnect?) - delete [] buf; // drop the current queue content + delete buf; // drop the current queue content return; }