+ proper shutdown

+ better thread pausing
+ misc stuff
This commit is contained in:
False.Genesis 2007-01-06 15:29:00 +00:00
parent b701810b15
commit 0962bec886
11 changed files with 106 additions and 85 deletions

View File

@ -17,7 +17,7 @@ VarSet::~VarSet()
std::string VarSet::Get(std::string varname)
{
for(std::list<Var>::iterator i=buffer.begin();i!=buffer.end();i++)
for(std::deque<Var>::iterator i=buffer.begin();i!=buffer.end();i++)
if( i->name==varname )
return i->value;
return ""; // if var has not been set return empty string
@ -27,7 +27,7 @@ void VarSet::Set(std::string varname, std::string varvalue)
{
if(varname.empty())
return;
for(std::list<Var>::iterator i = buffer.begin();i!=buffer.end();i++)
for(std::deque<Var>::iterator i = buffer.begin();i!=buffer.end();i++)
{
if( i->name==varname )
{
@ -49,7 +49,7 @@ unsigned int VarSet::Size(void)
bool VarSet::Exists(std::string varname)
{
for(std::list<Var>::iterator i = buffer.begin();i!=buffer.end();i++)
for(std::deque<Var>::iterator i = buffer.begin();i!=buffer.end();i++)
if(i->name==varname)
return true;
return false;
@ -59,7 +59,7 @@ void VarSet::Unset(std::string varname)
{
if ( varname.empty() )
return;
for(std::list<Var>::iterator i = buffer.begin();i!=buffer.end();i++)
for(std::deque<Var>::iterator i = buffer.begin();i!=buffer.end();i++)
{
if(i->name==varname)
{
@ -73,6 +73,11 @@ void VarSet::Clear(void)
{
buffer.clear();
}
Var VarSet::operator[](unsigned int id)
{
return buffer.at(id);
}
bool VarSet::ReadVarsFromFile(std::string fn)
{

View File

@ -2,7 +2,7 @@
#define __VARSET_H
#include <string>
#include <list>
#include <deque>
struct Var {
@ -19,12 +19,13 @@ public:
unsigned int Size(void);
bool Exists(std::string);
bool ReadVarsFromFile(std::string fn);
Var operator[](unsigned int id);
VarSet();
~VarSet();
// far future: MergeWith(VarSet,bool overwrite);
private:
std::list<Var> buffer;
std::deque<Var> buffer;
std::string toLower(std::string);
std::string toUpper(std::string);

View File

@ -21,9 +21,13 @@ opcode handler table vervollst
//###### Start of program code #######
PseuInstanceRunnable::PseuInstanceRunnable()
{
}
void PseuInstanceRunnable::run(void)
{
PseuInstance *_i = new PseuInstance();
_i = new PseuInstance(this);
_i->SetConfDir("./conf/");
_i->SetScpDir("./scripts/");
_i->Init();
@ -32,13 +36,22 @@ void PseuInstanceRunnable::run(void)
delete _i;
}
PseuInstance::PseuInstance()
void PseuInstanceRunnable::sleep(uint32 msecs)
{
ZThread::Thread::sleep(msecs);
}
PseuInstance::PseuInstance(PseuInstanceRunnable *run)
{
_runnable=run;
_ver="PseuWoW Alpha Build 12 dev 2" DEBUG_APPENDIX;
_ver_short="A12-dev1" DEBUG_APPENDIX;
_wsession=NULL;
_rsession=NULL;
_scp=NULL;
_conf=NULL;
_stop=false;
_fastquit=false;
}
@ -47,7 +60,7 @@ PseuInstance::~PseuInstance()
{
delete _scp;
delete _conf;
delete _rsession;
//delete _rsession; // deleted by SocketHandler!!!!!
delete _wsession;
}
@ -138,6 +151,16 @@ void PseuInstance::Run(void)
{
Update();
}
if(_fastquit)
{
printf("Aborting Instance...\n");
return;
}
printf("Shutting down instance...\n");
// save all data here
}
@ -145,12 +168,12 @@ void PseuInstance::Run(void)
void PseuInstance::Update()
{
if(_sh.GetCount())
_sh.Select(1,0); // update the realmsocket
_sh.Select(0,0); // update the realmsocket
//else
// socket invalid?
_wsession->Update();
_wsession->Update(); // update the worldSESSION, which will update the worldsocket itself
this->Sleep(GetConf()->networksleeptime);
}
void PseuInstance::SaveAllCache(void)
@ -159,6 +182,11 @@ void PseuInstance::SaveAllCache(void)
//...
}
void PseuInstance::Sleep(uint32 msecs)
{
GetRunnable()->sleep(msecs);
}
/*

View File

@ -2,15 +2,15 @@
#ifndef _PSEUWOW_H
#define _PSEUWOW_H
#include "../shared/common.h"
#include "common.h"
#include "Auth/BigNumber.h"
#include "DefScript/DefScript.h"
#include "../shared/Network/SocketHandler.h"
#include "Network/SocketHandler.h"
class RealmSocket;
class WorldSession;
class Sockethandler;
class PseuInstanceRunnable;
class PseuInstanceConf
{
@ -45,7 +45,7 @@ class PseuInstance
{
public:
PseuInstance();
PseuInstance(PseuInstanceRunnable *run);
~PseuInstance();
@ -53,6 +53,7 @@ class PseuInstance
RealmSocket *GetRSession(void) { return _rsession; }
PseuInstanceConf *GetConf(void) { return _conf; }
DefScriptPackage *GetScripts(void) { return _scp; }
PseuInstanceRunnable *GetRunnable(void) { return _runnable; }
void SetConfDir(std::string dir) { _confdir = dir; }
void SetScpDir(std::string dir) { _scpdir = dir; }
void SetSessionKey(BigNumber key) { _sessionkey = key; }
@ -64,21 +65,24 @@ class PseuInstance
bool Init();
void SaveAllCache(void);
void Stop(void) { _stop = true; }
void SetFastQuit(bool q=true) { _fastquit=true; }
void Quit(void);
void Run(void);
void Update(void);
void Sleep(uint32 msecs);
private:
PseuInstanceRunnable *_runnable;
RealmSocket *_rsession;
WorldSession *_wsession;
PseuInstanceConf *_conf;
DefScriptPackage *_scp;
std::string _confdir,_scpdir;
bool _initialized;
bool _stop;
bool _stop,_fastquit;
BigNumber _sessionkey;
char *_ver,*_ver_short;
SocketHandler _sh;
@ -89,60 +93,14 @@ class PseuInstance
class PseuInstanceRunnable : public ZThread::Runnable
{
public:
void run();
PseuInstanceRunnable::PseuInstanceRunnable();
void run(void);
void sleep(uint32);
PseuInstance *GetInstance(void) { return _i; }
private:
PseuInstance *_i;
};
// OBOELETE
/*
class SDLTCPConnection;
class DefScriptPackage;
class PlayerNameCache;
class VarSet;
extern char DEBUG;
extern char *ver;
extern char *realmlist,*accname,*accpass,*realmname;
extern bool quit,quitted,exitonerror;
extern unsigned char error;
extern unsigned char clientversion[3];
extern unsigned short clientbuild;
extern char clientlang[4];
extern bool something_went_wrong;
extern unsigned int c_port;
extern bool allowcontroller;
extern char *c_password;
extern unsigned int rs_port;
extern unsigned short clientbuild;
extern char clientlang[4];
extern unsigned int ws_port;
extern std::string worldhost, charname;
extern SDLTCPConnection worldCon,realmCon,ctrlCon;
extern bool inworld;
extern unsigned short idleSleepTime;
extern DefScriptPackage defScp;
extern std::string defScpPath;
extern PlayerNameCache plrNameCache;
extern VarSet playerPermissions;
extern uint64 _myGUID, _targetGUID, _followGUID;
// --- Some Functions ---
void quitproc_error(void);
void quitproc(void);
void _SaveAllCache(void);
*/
#endif

View File

@ -115,7 +115,7 @@ void RealmSocket::Start(void)
void RealmSocket::Stop(void)
{
_valid=false;
this->SetCloseAndDelete();
this->Close();
memset(_m2,0,20);
_key=0;
}

View File

@ -29,6 +29,7 @@ WorldSession::WorldSession(PseuInstance *in)
_instance = in;
_valid=_authed=_logged=false;
_socket=new WorldSocket(_sh,this);
_socket->SetDeleteByHandler();
_sh.Add(_socket);
_targetGUID=0; // no target
_followGUID=0; // dont follow anything
@ -38,7 +39,7 @@ WorldSession::WorldSession(PseuInstance *in)
WorldSession::~WorldSession()
{
delete _socket;
//delete _socket; the socket will be deleted by its handler!!
}
void WorldSession::AddToDataQueue(uint8 *data, uint32 len)

View File

@ -1,10 +1,9 @@
#include "../shared/common.h"
#include "common.h"
#include "main.h"
#include "PseuWoW.h"
#ifndef SIGQUIT
#define SIGQUIT 3
#endif
std::list<PseuInstanceRunnable*> instanceList; // TODO: move this to a "Master" class later
void _HookSignals(void)
{
@ -24,28 +23,50 @@ void _OnSignal(int s)
case SIGINT:
case SIGQUIT:
case SIGTERM:
case SIGABRT:
quitproc();
break;
case SIGABRT:
#ifndef _DEBUG
case SIGSEGV:
#endif
#ifdef _WIN32
case SIGBREAK:
exit(0);
break;
#endif
abortproc();
break;
}
signal(s, _OnSignal);
}
void quitproc(void){
exit(0);
void quitproc(void)
{
printf("Waiting for all instances to finish... [%u]\n",instanceList.size());
for(std::list<PseuInstanceRunnable*>::iterator i=instanceList.begin();i!=instanceList.end();i++)
{
(*i)->GetInstance()->Stop();
}
}
void abortproc(void)
{
printf("Terminating all instances... [%u]\n",instanceList.size());
for(std::list<PseuInstanceRunnable*>::iterator i=instanceList.begin();i!=instanceList.end();i++)
{
(*i)->GetInstance()->SetFastQuit(true);
(*i)->GetInstance()->Stop();
}
}
int main(int argc, char* argv[]) {
try
{
_HookSignals();
ZThread::Thread t(new PseuInstanceRunnable);
// 1 instance is enough for now
PseuInstanceRunnable *r=new PseuInstanceRunnable();
ZThread::Thread t(r);
instanceList.push_back(r);
t.setPriority((ZThread::Priority)2);
//...
t.wait();

View File

@ -4,8 +4,7 @@
void _HookSignals(void);
void _OnSignal(int);
void quitproc(void);
void abortproc(void);
int main(int,char**);
// TODO: ZTHread additional includes machen, dass #include <...> möglich ist
#endif

View File

@ -106,7 +106,7 @@
Name="VCLinkerTool"
AdditionalDependencies="odbc32.lib odbccp32.lib sdl.lib sdl_net.lib sdlmain.lib libeay32MT.lib ssleay32MT.lib WS2_32.LIB"
OutputFile="$(OutDir)/$(InputName).exe"
LinkIncremental="1"
LinkIncremental="2"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories=""
GenerateDebugInformation="TRUE"

View File

@ -83,4 +83,9 @@
typedef uint32 DWORD;
#endif
#ifndef SIGQUIT
#define SIGQUIT 3
#endif
#endif

View File

@ -12,6 +12,9 @@
#include <string>
#include <string.h>
#include <sstream>
#include <list>
#include <deque>
#include <vector>
#include <SDL/SDL.h>
#include "zthread/FastMutex.h"