temp commit, WorldSocket update

This commit is contained in:
False.Genesis 2007-01-06 16:08:02 +00:00
parent 0962bec886
commit 1cfddad5b6
7 changed files with 41 additions and 4 deletions

View File

@ -52,6 +52,7 @@ PseuInstance::PseuInstance(PseuInstanceRunnable *run)
_conf=NULL; _conf=NULL;
_stop=false; _stop=false;
_fastquit=false; _fastquit=false;
createWorldSession=false;
} }
@ -83,7 +84,6 @@ bool PseuInstance::Init(void) {
_scp->SetParentMethod((void*)this); _scp->SetParentMethod((void*)this);
_conf=new PseuInstanceConf(); _conf=new PseuInstanceConf();
_rsession=new RealmSocket(_sh); _rsession=new RealmSocket(_sh);
_wsession=new WorldSession(this);
if(!_scp->variables.ReadVarsFromFile(_confdir + "PseuWoW.conf")) if(!_scp->variables.ReadVarsFromFile(_confdir + "PseuWoW.conf"))
{ {
@ -171,8 +171,20 @@ void PseuInstance::Update()
_sh.Select(0,0); // update the realmsocket _sh.Select(0,0); // update the realmsocket
//else //else
// socket invalid? // 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); this->Sleep(GetConf()->networksleeptime);
} }

View File

@ -72,6 +72,7 @@ class PseuInstance
void Sleep(uint32 msecs); void Sleep(uint32 msecs);
bool createWorldSession;
private: private:

View File

@ -4,6 +4,7 @@
#include "Auth/Sha1.h" #include "Auth/Sha1.h"
#include "Auth/BigNumber.h" #include "Auth/BigNumber.h"
#include "RealmSocket.h" #include "RealmSocket.h"
#include "WorldSession.h"
@ -185,6 +186,9 @@ void RealmSocket::_HandleRealmList(void)
// set vars // set vars
GetInstance()->GetScripts()->variables.Set("WORLDHOST",GetInstance()->GetConf()->worldhost); GetInstance()->GetScripts()->variables.Set("WORLDHOST",GetInstance()->GetConf()->worldhost);
GetInstance()->GetScripts()->variables.Set("WORLDPORT",toString((uint64)(GetInstance()->GetConf()->worldport))); 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;
} }

View File

@ -8,6 +8,7 @@
#include "WorldSocket.h" #include "WorldSocket.h"
#include "WorldSession.h" #include "WorldSession.h"
#include "NameTables.h" #include "NameTables.h"
#include "RealmSocket.h"
struct ClientPktHeader struct ClientPktHeader
@ -33,6 +34,7 @@ WorldSession::WorldSession(PseuInstance *in)
_sh.Add(_socket); _sh.Add(_socket);
_targetGUID=0; // no target _targetGUID=0; // no target
_followGUID=0; // dont follow anything _followGUID=0; // dont follow anything
_myGUID=0; // i dont have a guid yet
plrNameCache.ReadFromFile(); // load names/guids of known players plrNameCache.ReadFromFile(); // load names/guids of known players
//... //...
} }
@ -42,6 +44,13 @@ WorldSession::~WorldSession()
//delete _socket; the socket will be deleted by its handler!! //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) void WorldSession::AddToDataQueue(uint8 *data, uint32 len)
{ {
for (uint32 i=0;i<len;i++) for (uint32 i=0;i<len;i++)
@ -63,8 +72,10 @@ void WorldSession::SendWorldPacket(WorldPacket &pkt)
void WorldSession::Update(void) void WorldSession::Update(void)
{ {
if (GetInstance()->GetConf()->worldhost.empty() || GetInstance()->GetConf()->worldport==0) if (!IsValid())
return; return;
if(_sh.GetCount())
_sh.Select(0,0);
WorldPacket packet; WorldPacket packet;
OpcodeHandler *table = _GetOpcodeHandlerTable(); OpcodeHandler *table = _GetOpcodeHandlerTable();
while(pktQueue.size()>5) while(pktQueue.size()>5)

View File

@ -34,6 +34,8 @@ public:
void Connect(std::string addr,uint16 port); void Connect(std::string addr,uint16 port);
WorldPacket BuildWorldPacket(void); WorldPacket BuildWorldPacket(void);
void Update(void); void Update(void);
void Start(void);
bool IsValid(void) { return _valid; }
void SendWorldPacket(WorldPacket&); void SendWorldPacket(WorldPacket&);
void SetTarget(uint64 guid); void SetTarget(uint64 guid);

View File

@ -14,9 +14,15 @@ void WorldSocket::OnConnect()
printf("Connected to world server.\r\n"); printf("Connected to world server.\r\n");
} }
void WorldSocket::OnConnectFailed()
{
printf("WorldSocket::OnConnectFailed()\n");
}
void WorldSocket::OnRead() void WorldSocket::OnRead()
{ {
TcpSocket::OnRead(); TcpSocket::OnRead();
printf("WorldSocket::OnRead() %u bytes\n",ibuf.GetLength());
if(!ibuf.GetLength()) if(!ibuf.GetLength())
return; return;
uint8 *buf=new uint8[ibuf.GetLength()]; uint8 *buf=new uint8[ibuf.GetLength()];

View File

@ -14,6 +14,7 @@ public:
void OnRead(); void OnRead();
void OnConnect(); void OnConnect();
void OnConnectFailed();
private: private:
WorldSession *_session; WorldSession *_session;