implemented CLI. New conf option: "enablecli".

This commit is contained in:
False.Genesis 2007-01-11 21:29:27 +00:00
parent 2ffade365c
commit ddfb91d677
8 changed files with 61 additions and 9 deletions

View File

@ -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

View File

@ -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;

View File

@ -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)

View File

@ -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;
};

View File

@ -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<<type<<lang;

View File

@ -16,6 +16,17 @@ void _HookSignals(void)
#endif
}
void _UnhookSignals(void)
{
signal(SIGINT, 0);
signal(SIGQUIT, 0);
signal(SIGTERM, 0);
signal(SIGABRT, 0);
#ifdef _WIN32
signal(SIGBREAK, 0);
#endif
}
void _OnSignal(int s)
{
switch (s)
@ -71,7 +82,8 @@ int main(int argc, char* argv[]) {
//...
t.wait();
//...
return 0;
_UnhookSignals();
raise(SIGQUIT);
}
catch (...)
{

View File

@ -2,6 +2,7 @@
#define _MAIN_H
void _HookSignals(void);
void _UnhookSignals(void);
void _OnSignal(int);
void quitproc(void);
void abortproc(void);

View File

@ -150,6 +150,12 @@
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
<File
RelativePath=".\Client\Cli.cpp">
</File>
<File
RelativePath=".\Client\Cli.h">
</File>
<File
RelativePath=".\Client\DefScriptInterface.cpp">
</File>