diff --git a/src/Client/DefScript/VarSet.cpp b/src/Client/DefScript/VarSet.cpp index 1736653..be978b7 100644 --- a/src/Client/DefScript/VarSet.cpp +++ b/src/Client/DefScript/VarSet.cpp @@ -17,7 +17,7 @@ VarSet::~VarSet() std::string VarSet::Get(std::string varname) { - for(std::list::iterator i=buffer.begin();i!=buffer.end();i++) + for(std::deque::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::iterator i = buffer.begin();i!=buffer.end();i++) + for(std::deque::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::iterator i = buffer.begin();i!=buffer.end();i++) + for(std::deque::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::iterator i = buffer.begin();i!=buffer.end();i++) + for(std::deque::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) { diff --git a/src/Client/DefScript/VarSet.h b/src/Client/DefScript/VarSet.h index 7c1bf16..3067840 100644 --- a/src/Client/DefScript/VarSet.h +++ b/src/Client/DefScript/VarSet.h @@ -2,7 +2,7 @@ #define __VARSET_H #include -#include +#include 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 buffer; + std::deque buffer; std::string toLower(std::string); std::string toUpper(std::string); diff --git a/src/Client/PseuWoW.cpp b/src/Client/PseuWoW.cpp index 7fd9e1e..a99c492 100644 --- a/src/Client/PseuWoW.cpp +++ b/src/Client/PseuWoW.cpp @@ -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); +} + /* diff --git a/src/Client/PseuWoW.h b/src/Client/PseuWoW.h index 0b8025f..1f69e45 100644 --- a/src/Client/PseuWoW.h +++ b/src/Client/PseuWoW.h @@ -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 \ No newline at end of file diff --git a/src/Client/Realm/RealmSocket.cpp b/src/Client/Realm/RealmSocket.cpp index 2560a4f..bf606db 100644 --- a/src/Client/Realm/RealmSocket.cpp +++ b/src/Client/Realm/RealmSocket.cpp @@ -115,7 +115,7 @@ void RealmSocket::Start(void) void RealmSocket::Stop(void) { _valid=false; - this->SetCloseAndDelete(); + this->Close(); memset(_m2,0,20); _key=0; } diff --git a/src/Client/World/WorldSession.cpp b/src/Client/World/WorldSession.cpp index 6406d5b..9d09110 100644 --- a/src/Client/World/WorldSession.cpp +++ b/src/Client/World/WorldSession.cpp @@ -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) diff --git a/src/Client/main.cpp b/src/Client/main.cpp index 0aec6f4..f860c14 100644 --- a/src/Client/main.cpp +++ b/src/Client/main.cpp @@ -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 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::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::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(); diff --git a/src/Client/main.h b/src/Client/main.h index e10d3eb..6d4d8b8 100644 --- a/src/Client/main.h +++ b/src/Client/main.h @@ -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 \ No newline at end of file diff --git a/src/PseuWoW.vcproj b/src/PseuWoW.vcproj index 8549c88..f2adaad 100644 --- a/src/PseuWoW.vcproj +++ b/src/PseuWoW.vcproj @@ -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" diff --git a/src/shared/SysDefs.h b/src/shared/SysDefs.h index dec3cdd..f0889e1 100644 --- a/src/shared/SysDefs.h +++ b/src/shared/SysDefs.h @@ -83,4 +83,9 @@ typedef uint32 DWORD; #endif +#ifndef SIGQUIT +#define SIGQUIT 3 +#endif + + #endif \ No newline at end of file diff --git a/src/shared/common.h b/src/shared/common.h index 3dbee03..7e38017 100644 --- a/src/shared/common.h +++ b/src/shared/common.h @@ -12,6 +12,9 @@ #include #include #include +#include +#include +#include #include #include "zthread/FastMutex.h"