* updated the ControlSocket to be telnet-compatible. original idea by klip, thx.
* added optional password to the ContolSocket * fixed possible exception/crash in the DefScript variable handler (occurred when typing "getvar" into the console or telnet). maybe a very slight code speedup, too. * minor chat script updates (more telnet-friendly) * note: if you use PHP or anything that is NOT telnet/netcat to send commands to the ControlSocket, you have to terminate each line with '\n' !
This commit is contained in:
parent
860b1ef7cd
commit
32248f0880
@ -117,6 +117,9 @@ enablegui=0
|
|||||||
rmcontrolport=8101
|
rmcontrolport=8101
|
||||||
// IP or hostname that is allowed to connect. leave blank to allow connections from everywhere (dangerous!)
|
// IP or hostname that is allowed to connect. leave blank to allow connections from everywhere (dangerous!)
|
||||||
rmcontrolhost=localhost
|
rmcontrolhost=localhost
|
||||||
|
// password required to gain access. leave blank for no password.
|
||||||
|
// to authenticate, type "pw your_pass_word" into telnet or send it somehow else if not using telnet.
|
||||||
|
rmcontrolpass=
|
||||||
|
|
||||||
// if you have exported and copied data from your original client,
|
// if you have exported and copied data from your original client,
|
||||||
// set this to 1 to enable movement and everything map related.
|
// set this to 1 to enable movement and everything map related.
|
||||||
|
|||||||
@ -12,8 +12,9 @@
|
|||||||
#permission=10
|
#permission=10
|
||||||
SET,lang ${@1}
|
SET,lang ${@1}
|
||||||
DEFAULT,lang 0
|
DEFAULT,lang 0
|
||||||
SENDCHATMESSAGE,17,{${lang}},{${@def}},{${@0}}
|
SET,r ?{SENDCHATMESSAGE,17,{${lang}},{${@def}},{${@0}}}
|
||||||
UNSET lang
|
UNSET lang
|
||||||
|
RETURN ${r}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
@ -24,7 +25,7 @@ UNSET lang
|
|||||||
// args:
|
// args:
|
||||||
// @def: command to send
|
// @def: command to send
|
||||||
|
|
||||||
SAY ${#CMDCHAR}${@def}
|
RETURN ?{SAY ${#CMDCHAR}${@def}}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
@ -56,8 +57,7 @@ IF ?{AND,?{string_is_command ${@def}} ?{SMALLER,?{GETPLAYERPERM ${@thiscmd_name}
|
|||||||
RETURN false
|
RETURN false
|
||||||
ELSE
|
ELSE
|
||||||
// no: say the text as usual.
|
// no: say the text as usual.
|
||||||
SAY,{${@0}} ${@def}
|
RETURN ?{SAY,{${@0}} ${@def}}
|
||||||
RETURN true
|
|
||||||
ENDIF
|
ENDIF
|
||||||
|
|
||||||
|
|
||||||
@ -75,9 +75,10 @@ DEFAULT,lang ${#DEFAULTLANG}
|
|||||||
|
|
||||||
LOGDEBUG * Saying '${msg}' in lang ${lang}
|
LOGDEBUG * Saying '${msg}' in lang ${lang}
|
||||||
|
|
||||||
SENDCHATMESSAGE,1,${lang},{${msg}}
|
SET,r ?{SENDCHATMESSAGE,1,${lang},{${msg}}}
|
||||||
UNSET lang
|
UNSET lang
|
||||||
UNSET msg
|
UNSET msg
|
||||||
|
RETURN ${r}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
@ -93,16 +94,17 @@ default,lang 0
|
|||||||
|
|
||||||
LOGDEBUG * Saying '${msg}' in lang ${lang} to guild
|
LOGDEBUG * Saying '${msg}' in lang ${lang} to guild
|
||||||
|
|
||||||
SENDCHATMESSAGE,4,${lang},{${msg}}
|
SET,r ?{SENDCHATMESSAGE,4,${lang},{${msg}}}
|
||||||
UNSET lang
|
UNSET lang
|
||||||
UNSET msg
|
UNSET msg
|
||||||
|
RETURN ${r}
|
||||||
|
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
#script=sayitem
|
#script=sayitem
|
||||||
#permission=0
|
#permission=0
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
// example script to "say" a clickable item
|
// example script to "say" a clickable item
|
||||||
SAY ?{getchatitem ${@def}}
|
RETURN ?{SAY ?{getchatitem ${@def}}}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
@ -118,16 +120,17 @@ default,lang 0
|
|||||||
|
|
||||||
LOGDEBUG * Saying '${msg}' in lang ${lang} to party
|
LOGDEBUG * Saying '${msg}' in lang ${lang} to party
|
||||||
|
|
||||||
SENDCHATMESSAGE,2,${lang},{${msg}}
|
SET,r ?{SENDCHATMESSAGE,2,${lang},{${msg}}}
|
||||||
UNSET lang
|
UNSET lang
|
||||||
UNSET msg
|
UNSET msg
|
||||||
|
RETURN ${r}
|
||||||
|
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
#script=sayred
|
#script=sayred
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
// example script how to output colored text
|
// example script how to output colored text
|
||||||
#permission=0
|
#permission=0
|
||||||
SAY,{${@0}} |cffFF0000${@def}
|
RETURN ?{SAY,{${@0}} |cffFF0000${@def}}
|
||||||
|
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
#script=sayv
|
#script=sayv
|
||||||
@ -140,16 +143,16 @@ SET,vl ${@0}
|
|||||||
DEFAULT,vl 0
|
DEFAULT,vl 0
|
||||||
|
|
||||||
IF ?{NOT ?{ISSET ${vn}}}
|
IF ?{NOT ?{ISSET ${vn}}}
|
||||||
SAY,{${vl}} * Var '${@def}' not defined.
|
SET,r ?{SAY,{${vl}} * Var '${@def}' not defined.}
|
||||||
ELSE
|
ELSE
|
||||||
SET,vv ${${vn}}
|
SET,vv ${${vn}}
|
||||||
SAY,{${vl}} * Var '${@def}' = '${vv}'
|
SET,r ?{SAY,{${vl}} * Var '${@def}' = '${vv}'}
|
||||||
ENDIF
|
ENDIF
|
||||||
|
|
||||||
UNSET vv
|
UNSET vv
|
||||||
UNSET vn
|
UNSET vn
|
||||||
UNSET vl
|
UNSET vl
|
||||||
|
RETURN ${r}
|
||||||
|
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
#script=whisper
|
#script=whisper
|
||||||
@ -168,10 +171,11 @@ DEFAULT,lang ${#DEFAULTLANG}
|
|||||||
|
|
||||||
LOGDEBUG * Whisp to '{${player}}' '{${msg}}' in lang '${lang}'
|
LOGDEBUG * Whisp to '{${player}}' '{${msg}}' in lang '${lang}'
|
||||||
|
|
||||||
SENDCHATMESSAGE,7,{${lang}},{${msg}},{${player}}
|
SET,r ?{SENDCHATMESSAGE,7,{${lang}},{${msg}},{${player}}}
|
||||||
UNSET lang
|
UNSET lang
|
||||||
UNSET msg
|
UNSET msg
|
||||||
UNSET player
|
UNSET player
|
||||||
|
RETURN ${r}
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------
|
//-------------------------------------------------------------
|
||||||
@ -189,9 +193,10 @@ DEFAULT,lang ${#DEFAULTLANG}
|
|||||||
|
|
||||||
LOGDEBUG * Yelling '${msg}' in lang ${lang}
|
LOGDEBUG * Yelling '${msg}' in lang ${lang}
|
||||||
|
|
||||||
SENDCHATMESSAGE,6,${lang},{${msg}}
|
SET,r ?{SENDCHATMESSAGE,6,${lang},{${msg}}}
|
||||||
UNSET lang
|
UNSET lang
|
||||||
UNSET msg
|
UNSET msg
|
||||||
|
RETURN ${r}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
@ -205,8 +210,7 @@ IF ?{AND,?{string_is_command ${@def}} ?{SMALLER,?{GETPLAYERPERM ${@thiscmd_name}
|
|||||||
RETURN false
|
RETURN false
|
||||||
ELSE
|
ELSE
|
||||||
// no: say the text as usual.
|
// no: say the text as usual.
|
||||||
YELL,{${@0}} ${@def}
|
RETURN ?{YELL,{${@0}} ${@def}}
|
||||||
RETURN true
|
|
||||||
ENDIF
|
ENDIF
|
||||||
|
|
||||||
|
|
||||||
@ -223,7 +227,8 @@ DEFAULT,lang ${#DEFAULTLANG}
|
|||||||
|
|
||||||
LOGDEBUG * Me ${msg} (in lang ${lang})
|
LOGDEBUG * Me ${msg} (in lang ${lang})
|
||||||
|
|
||||||
SENDCHATMESSAGE,10,${lang},{${msg}}
|
SET,r ?{SENDCHATMESSAGE,10,${lang},{${msg}}}
|
||||||
UNSET lang
|
UNSET lang
|
||||||
UNSET msg
|
UNSET msg
|
||||||
|
RETURN ${r}
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
ControlSocket::ControlSocket(SocketHandler& h) : TcpSocket(h)
|
ControlSocket::ControlSocket(SocketHandler& h) : TcpSocket(h)
|
||||||
{
|
{
|
||||||
_ok = false;
|
_ok = false;
|
||||||
|
_authed = false;
|
||||||
DEBUG(logdebug("ControlSocket created"));
|
DEBUG(logdebug("ControlSocket created"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,6 +29,12 @@ void ControlSocket::OnAccept(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SendTelnetText(_instance->GetScripts()->variables.Get("@version"));
|
||||||
|
if(_instance->GetConf()->rmcontrolpass.size())
|
||||||
|
{
|
||||||
|
SendTelnetText("Authentication?");
|
||||||
|
}
|
||||||
|
|
||||||
_ok = true;
|
_ok = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,15 +52,94 @@ void ControlSocket::OnRead(void)
|
|||||||
|
|
||||||
char *buf = new char[len];
|
char *buf = new char[len];
|
||||||
ibuf.Read(buf,len);
|
ibuf.Read(buf,len);
|
||||||
if(buf[0]==0)
|
|
||||||
|
if(buf[0]==0 && len > 1)
|
||||||
{
|
{
|
||||||
// reserved for future applications
|
// reserved for future applications
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(_instance && _instance->GetScripts())
|
uint32 i = 0;
|
||||||
_instance->GetScripts()->RunSingleLine(&buf[0]);
|
while(i < len)
|
||||||
|
{
|
||||||
|
if(buf[i] == 127) // ignore del key for now
|
||||||
|
continue;
|
||||||
|
if(buf[i] == 27) // escape sequence, drop whole buf (sent on direction key press for example)
|
||||||
|
break;
|
||||||
|
if(buf[i] == 8) // backspace
|
||||||
|
{
|
||||||
|
if(_str.length())
|
||||||
|
_str.erase(_str.length() - 1);
|
||||||
|
}
|
||||||
|
else if(buf[i] == 10 || buf[i] == 13 || buf[i] == 0) // newline or \0 char
|
||||||
|
{
|
||||||
|
if(_str.length() && _instance && _instance->GetScripts())
|
||||||
|
{
|
||||||
|
HandleString(_str);
|
||||||
|
}
|
||||||
|
_str.clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_str += buf[i];
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete [] buf;
|
delete [] buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ControlSocket::SendTelnetText(std::string s)
|
||||||
|
{
|
||||||
|
s += "\n\r";
|
||||||
|
SendBuf(s.c_str(),s.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ControlSocket::_Execute(std::string s)
|
||||||
|
{
|
||||||
|
DefReturnResult& r = _instance->GetScripts()->RunSingleLine(s);
|
||||||
|
if(r.ok)
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "+OK";
|
||||||
|
if(r.ret.size())
|
||||||
|
ss << ". r: [" << r.ret << "]";
|
||||||
|
SendTelnetText(ss.str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
SendTelnetText("+ERR");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ControlSocket::HandleString(std::string s)
|
||||||
|
{
|
||||||
|
if(_instance->GetConf()->rmcontrolpass.size())
|
||||||
|
{
|
||||||
|
if(_authed)
|
||||||
|
{
|
||||||
|
_Execute(s);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(s.size() > 3 && !memicmp(s.c_str(),"pw ",3)) // string format: "pw secret12345"
|
||||||
|
{
|
||||||
|
if(_instance->GetConf()->rmcontrolpass == s.c_str() + 3)
|
||||||
|
{
|
||||||
|
logdetail("ControlSocket: Authenticated successfully with: \"%s\"",s.c_str());
|
||||||
|
SendTelnetText("+accepted");
|
||||||
|
_authed = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SendTelnetText("+wrong password");
|
||||||
|
SetCloseAndDelete(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_Execute(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,9 +14,15 @@ public:
|
|||||||
void OnAccept();
|
void OnAccept();
|
||||||
void OnRead();
|
void OnRead();
|
||||||
|
|
||||||
|
void HandleString(std::string);
|
||||||
|
void SendTelnetText(std::string);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void _Execute(std::string);
|
||||||
PseuInstance *_instance;
|
PseuInstance *_instance;
|
||||||
bool _ok;
|
bool _ok;
|
||||||
|
std::string _str;
|
||||||
|
bool _authed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1055,24 +1055,24 @@ DefXChgResult DefScriptPackage::ReplaceVars(std::string str, CmdSet *pSet, unsig
|
|||||||
return xchg;
|
return xchg;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DefScriptPackage::_NormalizeVarName(std::string vn_in, std::string sn){
|
std::string DefScriptPackage::_NormalizeVarName(std::string vn, std::string sn)
|
||||||
if(vn_in.empty())
|
{
|
||||||
return vn_in;
|
|
||||||
std::string vn=vn_in;
|
|
||||||
bool global=false;
|
bool global=false;
|
||||||
if(sn.empty())
|
if(sn.empty())
|
||||||
global = true;
|
global = true;
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
if(vn.at(0)=='#')
|
if(vn.empty())
|
||||||
|
break;
|
||||||
|
if(vn[0]=='#')
|
||||||
global = true;
|
global = true;
|
||||||
if(vn.at(0)=='#' || vn.at(0)==':')
|
if(vn[0]=='#' || vn[0]==':')
|
||||||
vn.erase(0,1);
|
vn.erase(0,1);
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (!global) && (vn.at(0)!='@') )
|
if( (!global) && (vn[0]!='@') )
|
||||||
vn=sn+"::"+vn;
|
vn=sn+"::"+vn;
|
||||||
|
|
||||||
return vn;
|
return vn;
|
||||||
|
|||||||
@ -352,7 +352,7 @@ void PseuInstance::Update()
|
|||||||
{
|
{
|
||||||
logdetail("Disconnected, switching GUI back to Loginscreen.");
|
logdetail("Disconnected, switching GUI back to Loginscreen.");
|
||||||
_gui->SetSceneState(SCENESTATE_LOGINSCREEN);
|
_gui->SetSceneState(SCENESTATE_LOGINSCREEN);
|
||||||
while(_gui->GetSceneState() != SCENESTATE_LOGINSCREEN) // .. and wait until scenestate is set
|
while(_gui && _gui->GetSceneState() != SCENESTATE_LOGINSCREEN) // .. and wait until scenestate is set
|
||||||
Sleep(1);
|
Sleep(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -485,6 +485,7 @@ void PseuInstanceConf::ApplyFromVarSet(VarSet &v)
|
|||||||
enablegui=(bool)atoi(v.Get("ENABLEGUI").c_str());
|
enablegui=(bool)atoi(v.Get("ENABLEGUI").c_str());
|
||||||
rmcontrolport=atoi(v.Get("RMCONTROLPORT").c_str());
|
rmcontrolport=atoi(v.Get("RMCONTROLPORT").c_str());
|
||||||
rmcontrolhost=v.Get("RMCONTROLHOST");
|
rmcontrolhost=v.Get("RMCONTROLHOST");
|
||||||
|
rmcontrolpass=v.Get("RMCONTROLPASS");
|
||||||
useMaps=(bool)atoi(v.Get("USEMAPS").c_str());
|
useMaps=(bool)atoi(v.Get("USEMAPS").c_str());
|
||||||
skipaddonchat=(bool)atoi(v.Get("SKIPADDONCHAT").c_str());
|
skipaddonchat=(bool)atoi(v.Get("SKIPADDONCHAT").c_str());
|
||||||
dumpPackets=(uint8)atoi(v.Get("DUMPPACKETS").c_str());
|
dumpPackets=(uint8)atoi(v.Get("DUMPPACKETS").c_str());
|
||||||
|
|||||||
@ -54,6 +54,7 @@ class PseuInstanceConf
|
|||||||
bool disablespellcheck;
|
bool disablespellcheck;
|
||||||
uint32 rmcontrolport;
|
uint32 rmcontrolport;
|
||||||
std::string rmcontrolhost;
|
std::string rmcontrolhost;
|
||||||
|
std::string rmcontrolpass;
|
||||||
bool useMaps;
|
bool useMaps;
|
||||||
bool skipaddonchat;
|
bool skipaddonchat;
|
||||||
uint8 dumpPackets;
|
uint8 dumpPackets;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user