diff --git a/bin/conf/PseuWoW.conf.default b/bin/conf/PseuWoW.conf.default index 4bb4f59..7ab3622 100644 --- a/bin/conf/PseuWoW.conf.default +++ b/bin/conf/PseuWoW.conf.default @@ -61,4 +61,6 @@ NetworkSleepTime=50 // set this to 0 and PseuWoW will not react to given commands allowgamecmd=1 +// enable this if you plan to enter commands on the console +enablecli=1 diff --git a/src/Client/DefScriptInterface.cpp b/src/Client/DefScriptInterface.cpp index 124d1e2..77c25eb 100644 --- a/src/Client/DefScriptInterface.cpp +++ b/src/Client/DefScriptInterface.cpp @@ -20,6 +20,11 @@ bool DefScriptPackage::SCpause(CmdSet Set){ } bool DefScriptPackage::SCSendChatMessage(CmdSet Set){ + if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid())) + { + printf("Invalid Script call: SCSendChatMessage: WorldSession not valid\n"); + return false; + } std::stringstream ss; uint32 type=atoi(Set.arg[0].c_str()); uint32 lang=atoi(Set.arg[1].c_str()); @@ -45,17 +50,23 @@ bool DefScriptPackage::SCsavecache(CmdSet Set){ ((PseuInstance*)parentMethod)->SaveAllCache(); std::stringstream tmp; std::string str; - tmp << ((PseuInstance*)parentMethod)->GetWSession()->plrNameCache.GetSize(); - str+="Cache saved. [ "+tmp.str()+ " Playernames ]"; - ((PseuInstance*)parentMethod)->GetWSession()->SendChatMessage(CHAT_MSG_SAY,0,str,""); + if(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()) + { + tmp << ((PseuInstance*)parentMethod)->GetWSession()->plrNameCache.GetSize(); + str+="Cache saved. [ "+tmp.str()+ " Playernames ]"; + ((PseuInstance*)parentMethod)->GetWSession()->SendChatMessage(CHAT_MSG_SAY,0,str,""); + } return true; - - } bool DefScriptPackage::SCemote(CmdSet Set){ if(Set.defaultarg.empty()) return true; + if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid())) + { + printf("Invalid Script call: SCEmote: WorldSession not valid\n"); + return false; + } uint32 id=atoi(Set.defaultarg.c_str()); ((PseuInstance*)parentMethod)->GetWSession()->SendEmote(id); return true; diff --git a/src/Client/PseuWoW.cpp b/src/Client/PseuWoW.cpp index 764dbe5..91dc8b2 100644 --- a/src/Client/PseuWoW.cpp +++ b/src/Client/PseuWoW.cpp @@ -11,6 +11,7 @@ #include "DefScript/DefScript.h" #include "Realm/RealmSocket.h" #include "World/WorldSession.h" +#include "Cli.h" //###### Start of program code ####### @@ -44,6 +45,7 @@ PseuInstance::PseuInstance(PseuInstanceRunnable *run) _rsession=NULL; _scp=NULL; _conf=NULL; + _cli=NULL; _stop=false; _fastquit=false; _startrealm=true; @@ -54,10 +56,15 @@ PseuInstance::PseuInstance(PseuInstanceRunnable *run) PseuInstance::~PseuInstance() { + if(GetConf()->enablecli && _cli) + { + _cli->stop(); + } delete _scp; delete _conf; //delete _rsession; // deleted by SocketHandler!!!!! delete _wsession; + } bool PseuInstance::Init(void) { @@ -112,6 +119,12 @@ bool PseuInstance::Init(void) { printf("Main_Init: Error executing '_startup.def'\n"); } + if(GetConf()->enablecli) + { + _cli = new CliRunnable(this); + ZThread::Thread t(_cli); + } + if(_stop){ printf("Errors while initializing, proc halted!!\n"); if(GetConf()->exitonerror) @@ -147,7 +160,7 @@ void PseuInstance::Run(void) while((!_stop) && (!_startrealm)) { - Update(); + //Update(); } } while(GetConf()->reconnect && (!_stop)); @@ -195,8 +208,12 @@ void PseuInstance::Update() void PseuInstance::SaveAllCache(void) { - GetWSession()->plrNameCache.SaveToFile(); //... + if(GetWSession() && GetWSession()->IsValid()) + { + GetWSession()->plrNameCache.SaveToFile(); + //... + } } void PseuInstance::Sleep(uint32 msecs) diff --git a/src/Client/PseuWoW.h b/src/Client/PseuWoW.h index feb7e03..7e26ed8 100644 --- a/src/Client/PseuWoW.h +++ b/src/Client/PseuWoW.h @@ -11,6 +11,7 @@ class RealmSocket; class WorldSession; class Sockethandler; class PseuInstanceRunnable; +class CliRunnable; class PseuInstanceConf { @@ -92,6 +93,8 @@ class PseuInstance BigNumber _sessionkey; char *_ver,*_ver_short; SocketHandler _sh; + CliRunnable *_cli; + ZThread::Thread _clithread; }; diff --git a/src/Client/World/CMSGConstructor.cpp b/src/Client/World/CMSGConstructor.cpp index b2d4601..9b411de 100644 --- a/src/Client/World/CMSGConstructor.cpp +++ b/src/Client/World/CMSGConstructor.cpp @@ -6,7 +6,7 @@ #include "WorldSession.h" void WorldSession::SendChatMessage(uint32 type, uint32 lang, std::string msg, std::string to){ - if((!_logged) || msg.empty()) + if((!_valid) || (!_logged) || msg.empty()) return; WorldPacket packet; packet< + + + +