From 1cfddad5b6680a4b32b47b5ddd5f3c9caf15d303 Mon Sep 17 00:00:00 2001 From: "False.Genesis" Date: Sat, 6 Jan 2007 16:08:02 +0000 Subject: [PATCH] temp commit, WorldSocket update --- src/Client/PseuWoW.cpp | 16 ++++++++++++++-- src/Client/PseuWoW.h | 3 ++- src/Client/Realm/RealmSocket.cpp | 4 ++++ src/Client/World/WorldSession.cpp | 13 ++++++++++++- src/Client/World/WorldSession.h | 2 ++ src/Client/World/WorldSocket.cpp | 6 ++++++ src/Client/World/WorldSocket.h | 1 + 7 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/Client/PseuWoW.cpp b/src/Client/PseuWoW.cpp index a99c492..ae5c2df 100644 --- a/src/Client/PseuWoW.cpp +++ b/src/Client/PseuWoW.cpp @@ -52,6 +52,7 @@ PseuInstance::PseuInstance(PseuInstanceRunnable *run) _conf=NULL; _stop=false; _fastquit=false; + createWorldSession=false; } @@ -83,7 +84,6 @@ bool PseuInstance::Init(void) { _scp->SetParentMethod((void*)this); _conf=new PseuInstanceConf(); _rsession=new RealmSocket(_sh); - _wsession=new WorldSession(this); if(!_scp->variables.ReadVarsFromFile(_confdir + "PseuWoW.conf")) { @@ -171,8 +171,20 @@ void PseuInstance::Update() _sh.Select(0,0); // update the realmsocket //else // socket invalid? + if(createWorldSession) + { + createWorldSession=false; + _wsession=new WorldSession(this); + } + if(_wsession && !_wsession->IsValid()) + { + _wsession->Start(); // update the worldSESSION, which will update the worldsocket itself + } + if(_wsession && _wsession->IsValid()) + { + _wsession->Update(); // update the worldSESSION, which will update the worldsocket itself + } - _wsession->Update(); // update the worldSESSION, which will update the worldsocket itself this->Sleep(GetConf()->networksleeptime); } diff --git a/src/Client/PseuWoW.h b/src/Client/PseuWoW.h index 1f69e45..b4f148a 100644 --- a/src/Client/PseuWoW.h +++ b/src/Client/PseuWoW.h @@ -72,7 +72,8 @@ class PseuInstance void Sleep(uint32 msecs); - + bool createWorldSession; + private: PseuInstanceRunnable *_runnable; diff --git a/src/Client/Realm/RealmSocket.cpp b/src/Client/Realm/RealmSocket.cpp index bf606db..8634f66 100644 --- a/src/Client/Realm/RealmSocket.cpp +++ b/src/Client/Realm/RealmSocket.cpp @@ -4,6 +4,7 @@ #include "Auth/Sha1.h" #include "Auth/BigNumber.h" #include "RealmSocket.h" +#include "WorldSession.h" @@ -185,6 +186,9 @@ void RealmSocket::_HandleRealmList(void) // set vars GetInstance()->GetScripts()->variables.Set("WORLDHOST",GetInstance()->GetConf()->worldhost); GetInstance()->GetScripts()->variables.Set("WORLDPORT",toString((uint64)(GetInstance()->GetConf()->worldport))); + + // now we have the correct addr/port, time to create the WorldSession + GetInstance()->createWorldSession=true; } diff --git a/src/Client/World/WorldSession.cpp b/src/Client/World/WorldSession.cpp index 9d09110..86027e1 100644 --- a/src/Client/World/WorldSession.cpp +++ b/src/Client/World/WorldSession.cpp @@ -8,6 +8,7 @@ #include "WorldSocket.h" #include "WorldSession.h" #include "NameTables.h" +#include "RealmSocket.h" struct ClientPktHeader @@ -33,6 +34,7 @@ WorldSession::WorldSession(PseuInstance *in) _sh.Add(_socket); _targetGUID=0; // no target _followGUID=0; // dont follow anything + _myGUID=0; // i dont have a guid yet plrNameCache.ReadFromFile(); // load names/guids of known players //... } @@ -42,6 +44,13 @@ WorldSession::~WorldSession() //delete _socket; the socket will be deleted by its handler!! } +void WorldSession::Start(void) +{ + _socket->Open(GetInstance()->GetConf()->worldhost,GetInstance()->GetConf()->worldport); + GetInstance()->GetRSession()->SetCloseAndDelete(); // realm socket is no longer needed + _valid=true; +} + void WorldSession::AddToDataQueue(uint8 *data, uint32 len) { for (uint32 i=0;iGetConf()->worldhost.empty() || GetInstance()->GetConf()->worldport==0) + if (!IsValid()) return; + if(_sh.GetCount()) + _sh.Select(0,0); WorldPacket packet; OpcodeHandler *table = _GetOpcodeHandlerTable(); while(pktQueue.size()>5) diff --git a/src/Client/World/WorldSession.h b/src/Client/World/WorldSession.h index 6d2ca1b..18172b0 100644 --- a/src/Client/World/WorldSession.h +++ b/src/Client/World/WorldSession.h @@ -34,6 +34,8 @@ public: void Connect(std::string addr,uint16 port); WorldPacket BuildWorldPacket(void); void Update(void); + void Start(void); + bool IsValid(void) { return _valid; } void SendWorldPacket(WorldPacket&); void SetTarget(uint64 guid); diff --git a/src/Client/World/WorldSocket.cpp b/src/Client/World/WorldSocket.cpp index b0b2230..b4ab0ed 100644 --- a/src/Client/World/WorldSocket.cpp +++ b/src/Client/World/WorldSocket.cpp @@ -14,9 +14,15 @@ void WorldSocket::OnConnect() printf("Connected to world server.\r\n"); } +void WorldSocket::OnConnectFailed() +{ + printf("WorldSocket::OnConnectFailed()\n"); +} + void WorldSocket::OnRead() { TcpSocket::OnRead(); + printf("WorldSocket::OnRead() %u bytes\n",ibuf.GetLength()); if(!ibuf.GetLength()) return; uint8 *buf=new uint8[ibuf.GetLength()]; diff --git a/src/Client/World/WorldSocket.h b/src/Client/World/WorldSocket.h index 87c5a41..45e2ce4 100644 --- a/src/Client/World/WorldSocket.h +++ b/src/Client/World/WorldSocket.h @@ -14,6 +14,7 @@ public: void OnRead(); void OnConnect(); + void OnConnectFailed(); private: WorldSession *_session;