implemented CLI. New conf option: "enablecli".
This commit is contained in:
parent
2ffade365c
commit
ddfb91d677
@ -61,4 +61,6 @@ NetworkSleepTime=50
|
|||||||
// set this to 0 and PseuWoW will not react to given commands
|
// set this to 0 and PseuWoW will not react to given commands
|
||||||
allowgamecmd=1
|
allowgamecmd=1
|
||||||
|
|
||||||
|
// enable this if you plan to enter commands on the console
|
||||||
|
enablecli=1
|
||||||
|
|
||||||
|
|||||||
@ -20,6 +20,11 @@ bool DefScriptPackage::SCpause(CmdSet Set){
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool DefScriptPackage::SCSendChatMessage(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;
|
std::stringstream ss;
|
||||||
uint32 type=atoi(Set.arg[0].c_str());
|
uint32 type=atoi(Set.arg[0].c_str());
|
||||||
uint32 lang=atoi(Set.arg[1].c_str());
|
uint32 lang=atoi(Set.arg[1].c_str());
|
||||||
@ -45,17 +50,23 @@ bool DefScriptPackage::SCsavecache(CmdSet Set){
|
|||||||
((PseuInstance*)parentMethod)->SaveAllCache();
|
((PseuInstance*)parentMethod)->SaveAllCache();
|
||||||
std::stringstream tmp;
|
std::stringstream tmp;
|
||||||
std::string str;
|
std::string str;
|
||||||
|
if(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid())
|
||||||
|
{
|
||||||
tmp << ((PseuInstance*)parentMethod)->GetWSession()->plrNameCache.GetSize();
|
tmp << ((PseuInstance*)parentMethod)->GetWSession()->plrNameCache.GetSize();
|
||||||
str+="Cache saved. [ "+tmp.str()+ " Playernames ]";
|
str+="Cache saved. [ "+tmp.str()+ " Playernames ]";
|
||||||
((PseuInstance*)parentMethod)->GetWSession()->SendChatMessage(CHAT_MSG_SAY,0,str,"");
|
((PseuInstance*)parentMethod)->GetWSession()->SendChatMessage(CHAT_MSG_SAY,0,str,"");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DefScriptPackage::SCemote(CmdSet Set){
|
bool DefScriptPackage::SCemote(CmdSet Set){
|
||||||
if(Set.defaultarg.empty())
|
if(Set.defaultarg.empty())
|
||||||
return true;
|
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());
|
uint32 id=atoi(Set.defaultarg.c_str());
|
||||||
((PseuInstance*)parentMethod)->GetWSession()->SendEmote(id);
|
((PseuInstance*)parentMethod)->GetWSession()->SendEmote(id);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
#include "DefScript/DefScript.h"
|
#include "DefScript/DefScript.h"
|
||||||
#include "Realm/RealmSocket.h"
|
#include "Realm/RealmSocket.h"
|
||||||
#include "World/WorldSession.h"
|
#include "World/WorldSession.h"
|
||||||
|
#include "Cli.h"
|
||||||
|
|
||||||
|
|
||||||
//###### Start of program code #######
|
//###### Start of program code #######
|
||||||
@ -44,6 +45,7 @@ PseuInstance::PseuInstance(PseuInstanceRunnable *run)
|
|||||||
_rsession=NULL;
|
_rsession=NULL;
|
||||||
_scp=NULL;
|
_scp=NULL;
|
||||||
_conf=NULL;
|
_conf=NULL;
|
||||||
|
_cli=NULL;
|
||||||
_stop=false;
|
_stop=false;
|
||||||
_fastquit=false;
|
_fastquit=false;
|
||||||
_startrealm=true;
|
_startrealm=true;
|
||||||
@ -54,10 +56,15 @@ PseuInstance::PseuInstance(PseuInstanceRunnable *run)
|
|||||||
|
|
||||||
PseuInstance::~PseuInstance()
|
PseuInstance::~PseuInstance()
|
||||||
{
|
{
|
||||||
|
if(GetConf()->enablecli && _cli)
|
||||||
|
{
|
||||||
|
_cli->stop();
|
||||||
|
}
|
||||||
delete _scp;
|
delete _scp;
|
||||||
delete _conf;
|
delete _conf;
|
||||||
//delete _rsession; // deleted by SocketHandler!!!!!
|
//delete _rsession; // deleted by SocketHandler!!!!!
|
||||||
delete _wsession;
|
delete _wsession;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PseuInstance::Init(void) {
|
bool PseuInstance::Init(void) {
|
||||||
@ -112,6 +119,12 @@ bool PseuInstance::Init(void) {
|
|||||||
printf("Main_Init: Error executing '_startup.def'\n");
|
printf("Main_Init: Error executing '_startup.def'\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(GetConf()->enablecli)
|
||||||
|
{
|
||||||
|
_cli = new CliRunnable(this);
|
||||||
|
ZThread::Thread t(_cli);
|
||||||
|
}
|
||||||
|
|
||||||
if(_stop){
|
if(_stop){
|
||||||
printf("Errors while initializing, proc halted!!\n");
|
printf("Errors while initializing, proc halted!!\n");
|
||||||
if(GetConf()->exitonerror)
|
if(GetConf()->exitonerror)
|
||||||
@ -147,7 +160,7 @@ void PseuInstance::Run(void)
|
|||||||
|
|
||||||
while((!_stop) && (!_startrealm))
|
while((!_stop) && (!_startrealm))
|
||||||
{
|
{
|
||||||
Update();
|
//Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while(GetConf()->reconnect && (!_stop));
|
while(GetConf()->reconnect && (!_stop));
|
||||||
@ -195,8 +208,12 @@ void PseuInstance::Update()
|
|||||||
|
|
||||||
void PseuInstance::SaveAllCache(void)
|
void PseuInstance::SaveAllCache(void)
|
||||||
{
|
{
|
||||||
|
//...
|
||||||
|
if(GetWSession() && GetWSession()->IsValid())
|
||||||
|
{
|
||||||
GetWSession()->plrNameCache.SaveToFile();
|
GetWSession()->plrNameCache.SaveToFile();
|
||||||
//...
|
//...
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PseuInstance::Sleep(uint32 msecs)
|
void PseuInstance::Sleep(uint32 msecs)
|
||||||
|
|||||||
@ -11,6 +11,7 @@ class RealmSocket;
|
|||||||
class WorldSession;
|
class WorldSession;
|
||||||
class Sockethandler;
|
class Sockethandler;
|
||||||
class PseuInstanceRunnable;
|
class PseuInstanceRunnable;
|
||||||
|
class CliRunnable;
|
||||||
|
|
||||||
class PseuInstanceConf
|
class PseuInstanceConf
|
||||||
{
|
{
|
||||||
@ -92,6 +93,8 @@ class PseuInstance
|
|||||||
BigNumber _sessionkey;
|
BigNumber _sessionkey;
|
||||||
char *_ver,*_ver_short;
|
char *_ver,*_ver_short;
|
||||||
SocketHandler _sh;
|
SocketHandler _sh;
|
||||||
|
CliRunnable *_cli;
|
||||||
|
ZThread::Thread _clithread;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
#include "WorldSession.h"
|
#include "WorldSession.h"
|
||||||
|
|
||||||
void WorldSession::SendChatMessage(uint32 type, uint32 lang, std::string msg, std::string to){
|
void WorldSession::SendChatMessage(uint32 type, uint32 lang, std::string msg, std::string to){
|
||||||
if((!_logged) || msg.empty())
|
if((!_valid) || (!_logged) || msg.empty())
|
||||||
return;
|
return;
|
||||||
WorldPacket packet;
|
WorldPacket packet;
|
||||||
packet<<type<<lang;
|
packet<<type<<lang;
|
||||||
|
|||||||
@ -16,6 +16,17 @@ void _HookSignals(void)
|
|||||||
#endif
|
#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)
|
void _OnSignal(int s)
|
||||||
{
|
{
|
||||||
switch (s)
|
switch (s)
|
||||||
@ -71,7 +82,8 @@ int main(int argc, char* argv[]) {
|
|||||||
//...
|
//...
|
||||||
t.wait();
|
t.wait();
|
||||||
//...
|
//...
|
||||||
return 0;
|
_UnhookSignals();
|
||||||
|
raise(SIGQUIT);
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
#define _MAIN_H
|
#define _MAIN_H
|
||||||
|
|
||||||
void _HookSignals(void);
|
void _HookSignals(void);
|
||||||
|
void _UnhookSignals(void);
|
||||||
void _OnSignal(int);
|
void _OnSignal(int);
|
||||||
void quitproc(void);
|
void quitproc(void);
|
||||||
void abortproc(void);
|
void abortproc(void);
|
||||||
|
|||||||
@ -150,6 +150,12 @@
|
|||||||
<Filter
|
<Filter
|
||||||
Name="Source Files"
|
Name="Source Files"
|
||||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
|
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
|
||||||
|
<File
|
||||||
|
RelativePath=".\Client\Cli.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\Client\Cli.h">
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\Client\DefScriptInterface.cpp">
|
RelativePath=".\Client\DefScriptInterface.cpp">
|
||||||
</File>
|
</File>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user