* updated some DefScript stuff
* added some DefScript return values for SCP databases
This commit is contained in:
parent
6c2355b75c
commit
2f459f9d0f
@ -11,8 +11,11 @@
|
|||||||
// --- SECTION FOR SCRIPT PACKAGES ---
|
// --- SECTION FOR SCRIPT PACKAGES ---
|
||||||
DefScriptPackage::DefScriptPackage()
|
DefScriptPackage::DefScriptPackage()
|
||||||
{
|
{
|
||||||
functionTable=_GetFunctionTable();
|
|
||||||
_eventmgr=new DefScript_DynamicEventMgr(this);
|
_eventmgr=new DefScript_DynamicEventMgr(this);
|
||||||
|
_InitFunctions();
|
||||||
|
# ifdef USING_DEFSCRIPT_EXTENSIONS
|
||||||
|
_InitDefScriptInterface();
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
DefScriptPackage::~DefScriptPackage()
|
DefScriptPackage::~DefScriptPackage()
|
||||||
@ -36,63 +39,58 @@ void DefScriptPackage::Clear(void)
|
|||||||
Script.empty();
|
Script.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
DefScriptFunctionTable *DefScriptPackage::_GetFunctionTable(void) const
|
void DefScriptPackage::_InitFunctions(void)
|
||||||
{
|
{
|
||||||
static DefScriptFunctionTable table[] = {
|
AddFunc("out",&DefScriptPackage::func_out);
|
||||||
// basic functions:
|
AddFunc("set",&DefScriptPackage::func_set);
|
||||||
{"out",&DefScriptPackage::func_out},
|
AddFunc("default",&DefScriptPackage::func_default);
|
||||||
{"set",&DefScriptPackage::func_set},
|
AddFunc("unset",&DefScriptPackage::func_unset);
|
||||||
{"default",&DefScriptPackage::func_default},
|
AddFunc("shdn",&DefScriptPackage::func_shdn);
|
||||||
{"unset",&DefScriptPackage::func_unset},
|
AddFunc("loaddef",&DefScriptPackage::func_loaddef);
|
||||||
{"shdn",&DefScriptPackage::func_shdn},
|
AddFunc("reloaddef",&DefScriptPackage::func_reloaddef);
|
||||||
{"loaddef",&DefScriptPackage::func_loaddef},
|
AddFunc("setscriptpermission",&DefScriptPackage::func_setscriptpermission);
|
||||||
{"reloaddef",&DefScriptPackage::func_reloaddef},
|
AddFunc("toint",&DefScriptPackage::func_toint);
|
||||||
{"setscriptpermission",&DefScriptPackage::func_setscriptpermission},
|
AddFunc("add",&DefScriptPackage::func_add);
|
||||||
|
AddFunc("sub",&DefScriptPackage::func_sub);
|
||||||
// mathematical functions:
|
AddFunc("mul",&DefScriptPackage::func_mul);
|
||||||
{"toint",&DefScriptPackage::func_toint},
|
AddFunc("div",&DefScriptPackage::func_div);
|
||||||
{"add",&DefScriptPackage::func_add},
|
AddFunc("mod",&DefScriptPackage::func_mod);
|
||||||
{"sub",&DefScriptPackage::func_sub},
|
AddFunc("pow",&DefScriptPackage::func_pow);
|
||||||
{"mul",&DefScriptPackage::func_mul},
|
AddFunc("bitor",&DefScriptPackage::func_bitor);
|
||||||
{"div",&DefScriptPackage::func_div},
|
AddFunc("bitand",&DefScriptPackage::func_bitand);
|
||||||
{"mod",&DefScriptPackage::func_mod},
|
AddFunc("bitxor",&DefScriptPackage::func_bitxor);
|
||||||
{"pow",&DefScriptPackage::func_pow},
|
AddFunc("addevent",&DefScriptPackage::func_addevent);
|
||||||
{"bitor",&DefScriptPackage::func_bitor},
|
AddFunc("removeevent",&DefScriptPackage::func_removeevent);
|
||||||
{"bitand",&DefScriptPackage::func_bitand},
|
|
||||||
{"bitxor",&DefScriptPackage::func_bitxor},
|
|
||||||
{"addevent",&DefScriptPackage::func_addevent},
|
|
||||||
{"removeevent",&DefScriptPackage::func_removeevent},
|
|
||||||
|
|
||||||
// user functions:
|
|
||||||
{"pause",&DefScriptPackage::SCpause},
|
|
||||||
{"emote",&DefScriptPackage::SCemote},
|
|
||||||
//{"follow",&DefScriptPackage::SCfollow},
|
|
||||||
{"savecache",&DefScriptPackage::SCsavecache},
|
|
||||||
{"sendchatmessage",&DefScriptPackage::SCSendChatMessage},
|
|
||||||
{"joinchannel",&DefScriptPackage::SCjoinchannel},
|
|
||||||
{"leavechannel",&DefScriptPackage::SCleavechannel},
|
|
||||||
{"loadconf",&DefScriptPackage::SCloadconf},
|
|
||||||
{"applyconf",&DefScriptPackage::SCapplyconf},
|
|
||||||
{"applypermissions",&DefScriptPackage::SCapplypermissions},
|
|
||||||
{"log",&DefScriptPackage::SClog},
|
|
||||||
{"logdetail",&DefScriptPackage::SClogdetail},
|
|
||||||
{"logerror",&DefScriptPackage::SClogerror},
|
|
||||||
{"logdebug",&DefScriptPackage::SClogdebug},
|
|
||||||
{"castspell", &DefScriptPackage::SCcastspell},
|
|
||||||
{"queryitem", &DefScriptPackage::SCqueryitem},
|
|
||||||
{"target", &DefScriptPackage::SCtarget},
|
|
||||||
{"loadscp", &DefScriptPackage::SCloadscp},
|
|
||||||
|
|
||||||
// table termination
|
|
||||||
{NULL,NULL}
|
|
||||||
|
|
||||||
};
|
|
||||||
return table;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefScriptPackage::SetFunctionTable(DefScriptFunctionTable *tab)
|
void DefScriptPackage::AddFunc(std::string n,DefReturnResult (DefScriptPackage::*f)(CmdSet& Set))
|
||||||
{
|
{
|
||||||
functionTable=tab;
|
DefScriptFunctionEntry e(n,f);
|
||||||
|
AddFunc(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DefScriptPackage::AddFunc(DefScriptFunctionEntry e)
|
||||||
|
{
|
||||||
|
if( (!e.name.empty()) && (!HasFunc(e.name)) )
|
||||||
|
_functable.push_back(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DefScriptPackage::HasFunc(std::string n)
|
||||||
|
{
|
||||||
|
for(DefScriptFunctionTable::iterator i=_functable.begin();i!=_functable.end();i++)
|
||||||
|
if(i->name==n)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DefScriptPackage::DelFunc(std::string n)
|
||||||
|
{
|
||||||
|
for(DefScriptFunctionTable::iterator i=_functable.begin();i!=_functable.end();i++)
|
||||||
|
if(i->name==n)
|
||||||
|
{
|
||||||
|
_functable.erase(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefScriptPackage::SetPath(std::string p){
|
void DefScriptPackage::SetPath(std::string p){
|
||||||
@ -117,8 +115,8 @@ bool DefScriptPackage::ScriptExists(std::string name)
|
|||||||
for (std::map<std::string,DefScript*>::iterator i = Script.begin();i != Script.end();i++)
|
for (std::map<std::string,DefScript*>::iterator i = Script.begin();i != Script.end();i++)
|
||||||
if(i->first == name && i->second != NULL)
|
if(i->first == name && i->second != NULL)
|
||||||
return true;
|
return true;
|
||||||
for(unsigned int i=0;functionTable[i].func!=NULL;i++)
|
for(unsigned int i=0;i<_functable.size();i++)
|
||||||
if(name == functionTable[i].name)
|
if(name == _functable[i].name)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -647,15 +645,11 @@ DefReturnResult DefScriptPackage::Interpret(CmdSet& Set)
|
|||||||
DefReturnResult result;
|
DefReturnResult result;
|
||||||
|
|
||||||
// first search if the script is defined in the internal functions
|
// first search if the script is defined in the internal functions
|
||||||
for(unsigned int i=0;;i++)
|
for(unsigned int i=0;i<_functable.size();i++)
|
||||||
{
|
{
|
||||||
if(functionTable[i].func==NULL || functionTable[i].name==NULL) // reached the end of the table?
|
if(Set.cmd==_functable[i].name)
|
||||||
{
|
{
|
||||||
break;
|
result=(this->*(_functable[i].func))(Set);
|
||||||
}
|
|
||||||
if(Set.cmd==functionTable[i].name)
|
|
||||||
{
|
|
||||||
result=(this->*functionTable[i].func)(Set);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ class DefScript;
|
|||||||
struct DefReturnResult
|
struct DefReturnResult
|
||||||
{
|
{
|
||||||
DefReturnResult() { ok=true; mustreturn=false; ret="true"; }
|
DefReturnResult() { ok=true; mustreturn=false; ret="true"; }
|
||||||
DefReturnResult(bool b) { ok=b; mustreturn=false; ret=b?"true":"false"; }
|
DefReturnResult(bool b) { ok=true; mustreturn=false; ret=b?"true":"false"; }
|
||||||
bool ok; // true if the execution of the current statement was successful
|
bool ok; // true if the execution of the current statement was successful
|
||||||
bool mustreturn;
|
bool mustreturn;
|
||||||
std::string ret; // return value used by ?{..}
|
std::string ret; // return value used by ?{..}
|
||||||
@ -24,6 +24,8 @@ struct DefReturnResult
|
|||||||
//std::string err; // error string, including tracestack, etc.
|
//std::string err; // error string, including tracestack, etc.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define DEF_RETURN_ERROR { DefReturnResult __defreturnresult(false); __defreturnresult.ok=false; return __defreturnresult; }
|
||||||
|
|
||||||
struct DefXChgResult
|
struct DefXChgResult
|
||||||
{
|
{
|
||||||
DefXChgResult() { changed=false; }
|
DefXChgResult() { changed=false; }
|
||||||
@ -44,11 +46,18 @@ class CmdSet {
|
|||||||
std::string caller;
|
std::string caller;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DefScriptFunctionTable {
|
struct DefScriptFunctionEntry {
|
||||||
char *name;
|
DefScriptFunctionEntry(std::string n,DefReturnResult (DefScriptPackage::*f)(CmdSet& Set))
|
||||||
|
{
|
||||||
|
name=n;
|
||||||
|
func=f;
|
||||||
|
}
|
||||||
|
std::string name;
|
||||||
DefReturnResult (DefScriptPackage::*func)(CmdSet& Set);
|
DefReturnResult (DefScriptPackage::*func)(CmdSet& Set);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef std::deque<DefScriptFunctionEntry> DefScriptFunctionTable;
|
||||||
|
|
||||||
class DefScript {
|
class DefScript {
|
||||||
public:
|
public:
|
||||||
DefScript(DefScriptPackage *p);
|
DefScript(DefScriptPackage *p);
|
||||||
@ -94,10 +103,14 @@ public:
|
|||||||
VarSet variables;
|
VarSet variables;
|
||||||
void SetPath(std::string);
|
void SetPath(std::string);
|
||||||
bool LoadByName(std::string);
|
bool LoadByName(std::string);
|
||||||
void SetFunctionTable(DefScriptFunctionTable*);
|
|
||||||
std::string _NormalizeVarName(std::string, std::string);
|
std::string _NormalizeVarName(std::string, std::string);
|
||||||
DefReturnResult RunSingleLineFromScript(std::string line, DefScript *pScript);
|
DefReturnResult RunSingleLineFromScript(std::string line, DefScript *pScript);
|
||||||
DefScript_DynamicEventMgr *GetEventMgr(void);
|
DefScript_DynamicEventMgr *GetEventMgr(void);
|
||||||
|
void AddFunc(DefScriptFunctionEntry);
|
||||||
|
void AddFunc(std::string n,DefReturnResult (DefScriptPackage::*)(CmdSet& Set));
|
||||||
|
bool HasFunc(std::string);
|
||||||
|
void DelFunc(std::string);
|
||||||
|
|
||||||
|
|
||||||
std::string scPath;
|
std::string scPath;
|
||||||
|
|
||||||
@ -106,18 +119,18 @@ public:
|
|||||||
void My_Run(std::string line,std::string username);
|
void My_Run(std::string line,std::string username);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void _InitFunctions(void);
|
||||||
DefXChgResult ReplaceVars(std::string str, CmdSet* pSet, unsigned char VarType);
|
DefXChgResult ReplaceVars(std::string str, CmdSet* pSet, unsigned char VarType);
|
||||||
void SplitLine(CmdSet&,std::string);
|
void SplitLine(CmdSet&,std::string);
|
||||||
DefReturnResult Interpret(CmdSet&);
|
DefReturnResult Interpret(CmdSet&);
|
||||||
void RemoveBrackets(CmdSet&);
|
void RemoveBrackets(CmdSet&);
|
||||||
std::string RemoveBracketsFromString(std::string);
|
std::string RemoveBracketsFromString(std::string);
|
||||||
DefScriptFunctionTable *_GetFunctionTable(void) const;
|
|
||||||
DefScriptFunctionTable *functionTable;
|
|
||||||
unsigned int functions;
|
unsigned int functions;
|
||||||
void *parentMethod;
|
void *parentMethod;
|
||||||
DefScript_DynamicEventMgr *_eventmgr;
|
DefScript_DynamicEventMgr *_eventmgr;
|
||||||
std::map<std::string,DefScript*> Script;
|
std::map<std::string,DefScript*> Script;
|
||||||
std::map<std::string,unsigned char> scriptPermissionMap;
|
std::map<std::string,unsigned char> scriptPermissionMap;
|
||||||
|
DefScriptFunctionTable _functable;
|
||||||
|
|
||||||
// Usable internal basic functions:
|
// Usable internal basic functions:
|
||||||
DefReturnResult func_default(CmdSet&);
|
DefReturnResult func_default(CmdSet&);
|
||||||
@ -142,26 +155,8 @@ private:
|
|||||||
DefReturnResult func_addevent(CmdSet&);
|
DefReturnResult func_addevent(CmdSet&);
|
||||||
DefReturnResult func_removeevent(CmdSet&);
|
DefReturnResult func_removeevent(CmdSet&);
|
||||||
|
|
||||||
// Useable own internal functions:
|
// setup own function declarations here
|
||||||
DefReturnResult SCpause(CmdSet&);
|
# include "DefScriptInterfaceInclude.h"
|
||||||
DefReturnResult SCSendChatMessage(CmdSet&);
|
|
||||||
DefReturnResult SCsavecache(CmdSet&);
|
|
||||||
DefReturnResult SCemote(CmdSet&);
|
|
||||||
DefReturnResult SCfollow(CmdSet&);
|
|
||||||
DefReturnResult SCshdn(CmdSet&);
|
|
||||||
DefReturnResult SCjoinchannel(CmdSet&);
|
|
||||||
DefReturnResult SCleavechannel(CmdSet&);
|
|
||||||
DefReturnResult SCloadconf(CmdSet&);
|
|
||||||
DefReturnResult SCapplypermissions(CmdSet&);
|
|
||||||
DefReturnResult SCapplyconf(CmdSet&);
|
|
||||||
DefReturnResult SClog(CmdSet&);
|
|
||||||
DefReturnResult SClogdetail(CmdSet&);
|
|
||||||
DefReturnResult SClogdebug(CmdSet&);
|
|
||||||
DefReturnResult SClogerror(CmdSet&);
|
|
||||||
DefReturnResult SCcastspell(CmdSet&);
|
|
||||||
DefReturnResult SCqueryitem(CmdSet&);
|
|
||||||
DefReturnResult SCtarget(CmdSet&);
|
|
||||||
DefReturnResult SCloadscp(CmdSet&);
|
|
||||||
|
|
||||||
// Own variable declarations
|
// Own variable declarations
|
||||||
std::map<std::string, unsigned char> my_usrPermissionMap;
|
std::map<std::string, unsigned char> my_usrPermissionMap;
|
||||||
|
|||||||
@ -151,7 +151,7 @@ DefReturnResult DefScriptPackage::func_setscriptpermission(CmdSet& Set)
|
|||||||
DefReturnResult DefScriptPackage::func_toint(CmdSet& Set)
|
DefReturnResult DefScriptPackage::func_toint(CmdSet& Set)
|
||||||
{
|
{
|
||||||
DefReturnResult r;
|
DefReturnResult r;
|
||||||
std::string num=toString(floor(toNumber(Set.defaultarg.c_str())));
|
std::string num=toString(floor(toNumber(Set.defaultarg)));
|
||||||
if(!Set.arg[0].empty())
|
if(!Set.arg[0].empty())
|
||||||
{
|
{
|
||||||
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
||||||
@ -171,7 +171,7 @@ DefReturnResult DefScriptPackage::func_add(CmdSet& Set)
|
|||||||
|
|
||||||
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
||||||
double a=toNumber(variables.Get(vname));
|
double a=toNumber(variables.Get(vname));
|
||||||
double b=toNumber(Set.defaultarg.c_str());
|
double b=toNumber(Set.defaultarg);
|
||||||
a+=b;
|
a+=b;
|
||||||
variables.Set(vname,toString(a));
|
variables.Set(vname,toString(a));
|
||||||
r.ret=toString(a);
|
r.ret=toString(a);
|
||||||
@ -188,7 +188,7 @@ DefReturnResult DefScriptPackage::func_sub(CmdSet& Set)
|
|||||||
|
|
||||||
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
||||||
double a=toNumber(variables.Get(vname));
|
double a=toNumber(variables.Get(vname));
|
||||||
double b=toNumber(Set.defaultarg.c_str());
|
double b=toNumber(Set.defaultarg);
|
||||||
a-=b;
|
a-=b;
|
||||||
variables.Set(vname,toString(a));
|
variables.Set(vname,toString(a));
|
||||||
r.ret=toString(a);
|
r.ret=toString(a);
|
||||||
@ -205,7 +205,7 @@ DefReturnResult DefScriptPackage::func_mul(CmdSet& Set)
|
|||||||
|
|
||||||
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
||||||
double a=toNumber(variables.Get(vname));
|
double a=toNumber(variables.Get(vname));
|
||||||
double b=toNumber(Set.defaultarg.c_str());
|
double b=toNumber(Set.defaultarg);
|
||||||
a*=b;
|
a*=b;
|
||||||
variables.Set(vname,toString(a));
|
variables.Set(vname,toString(a));
|
||||||
r.ret=toString(a);
|
r.ret=toString(a);
|
||||||
@ -222,7 +222,7 @@ DefReturnResult DefScriptPackage::func_div(CmdSet& Set)
|
|||||||
|
|
||||||
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
||||||
double a=toNumber(variables.Get(vname));
|
double a=toNumber(variables.Get(vname));
|
||||||
double b=toNumber(Set.defaultarg.c_str());
|
double b=toNumber(Set.defaultarg);
|
||||||
if(b==0)
|
if(b==0)
|
||||||
a=0;
|
a=0;
|
||||||
else
|
else
|
||||||
@ -242,7 +242,7 @@ DefReturnResult DefScriptPackage::func_mod(CmdSet& Set)
|
|||||||
|
|
||||||
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
||||||
uint64 a=(uint64)toNumber(variables.Get(vname));
|
uint64 a=(uint64)toNumber(variables.Get(vname));
|
||||||
uint64 b=(uint64)toNumber(Set.defaultarg.c_str());
|
uint64 b=(uint64)toNumber(Set.defaultarg);
|
||||||
if(b==0)
|
if(b==0)
|
||||||
a=0;
|
a=0;
|
||||||
else
|
else
|
||||||
@ -262,7 +262,7 @@ DefReturnResult DefScriptPackage::func_pow(CmdSet& Set)
|
|||||||
|
|
||||||
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
||||||
double a=toNumber(variables.Get(vname));
|
double a=toNumber(variables.Get(vname));
|
||||||
double b=toNumber(Set.defaultarg.c_str());
|
double b=toNumber(Set.defaultarg);
|
||||||
a=pow(a,b);
|
a=pow(a,b);
|
||||||
variables.Set(vname,toString(a));
|
variables.Set(vname,toString(a));
|
||||||
r.ret=toString(a);
|
r.ret=toString(a);
|
||||||
@ -279,7 +279,7 @@ DefReturnResult DefScriptPackage::func_bitor(CmdSet& Set)
|
|||||||
|
|
||||||
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
||||||
uint64 a=(uint64)toNumber(variables.Get(vname));
|
uint64 a=(uint64)toNumber(variables.Get(vname));
|
||||||
uint64 b=(uint64)toNumber(Set.defaultarg.c_str());
|
uint64 b=(uint64)toNumber(Set.defaultarg);
|
||||||
a|=b;
|
a|=b;
|
||||||
variables.Set(vname,toString(a));
|
variables.Set(vname,toString(a));
|
||||||
r.ret=toString(a);
|
r.ret=toString(a);
|
||||||
@ -296,7 +296,7 @@ DefReturnResult DefScriptPackage::func_bitand(CmdSet& Set)
|
|||||||
|
|
||||||
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
||||||
uint64 a=(uint64)toNumber(variables.Get(vname));
|
uint64 a=(uint64)toNumber(variables.Get(vname));
|
||||||
uint64 b=(uint64)toNumber(Set.defaultarg.c_str());
|
uint64 b=(uint64)toNumber(Set.defaultarg);
|
||||||
a&=b;
|
a&=b;
|
||||||
variables.Set(vname,toString(a));
|
variables.Set(vname,toString(a));
|
||||||
r.ret=toString(a);
|
r.ret=toString(a);
|
||||||
@ -313,7 +313,7 @@ DefReturnResult DefScriptPackage::func_bitxor(CmdSet& Set)
|
|||||||
|
|
||||||
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
||||||
uint64 a=(uint64)toNumber(variables.Get(vname));
|
uint64 a=(uint64)toNumber(variables.Get(vname));
|
||||||
uint64 b=(uint64)toNumber(Set.defaultarg.c_str());
|
uint64 b=(uint64)toNumber(Set.defaultarg);
|
||||||
a^=b;
|
a^=b;
|
||||||
variables.Set(vname,toString(a));
|
variables.Set(vname,toString(a));
|
||||||
r.ret=toString(a);
|
r.ret=toString(a);
|
||||||
@ -323,7 +323,7 @@ DefReturnResult DefScriptPackage::func_bitxor(CmdSet& Set)
|
|||||||
DefReturnResult DefScriptPackage::func_addevent(CmdSet& Set)
|
DefReturnResult DefScriptPackage::func_addevent(CmdSet& Set)
|
||||||
{
|
{
|
||||||
DefReturnResult r;
|
DefReturnResult r;
|
||||||
GetEventMgr()->Add(Set.arg[0],Set.defaultarg,atoi(Set.arg[1].c_str()),Set.myname.c_str());
|
GetEventMgr()->Add(Set.arg[0],Set.defaultarg,(clock_t)toNumber(Set.arg[1]),Set.myname.c_str());
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
#include "PseuWoW.h"
|
#include "PseuWoW.h"
|
||||||
#include "NameTables.h"
|
#include "NameTables.h"
|
||||||
#include "DefScript/DefScript.h"
|
#include "DefScript/DefScript.h"
|
||||||
|
#include "DefScript/DefScriptTools.h"
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "Opcodes.h"
|
#include "Opcodes.h"
|
||||||
#include "SharedDefines.h"
|
#include "SharedDefines.h"
|
||||||
@ -11,6 +12,31 @@
|
|||||||
#include "CacheHandler.h"
|
#include "CacheHandler.h"
|
||||||
#include "SCPDatabase.h"
|
#include "SCPDatabase.h"
|
||||||
|
|
||||||
|
void DefScriptPackage::_InitDefScriptInterface(void)
|
||||||
|
{
|
||||||
|
AddFunc("pause",&DefScriptPackage::SCpause);
|
||||||
|
AddFunc("emote",&DefScriptPackage::SCemote);
|
||||||
|
AddFunc("follow",&DefScriptPackage::SCfollow);
|
||||||
|
AddFunc("savecache",&DefScriptPackage::SCsavecache);
|
||||||
|
AddFunc("sendchatmessage",&DefScriptPackage::SCSendChatMessage);
|
||||||
|
AddFunc("joinchannel",&DefScriptPackage::SCjoinchannel);
|
||||||
|
AddFunc("loadconf",&DefScriptPackage::SCloadconf);
|
||||||
|
AddFunc("applyconf",&DefScriptPackage::SCapplyconf);
|
||||||
|
AddFunc("applypermissions",&DefScriptPackage::SCapplypermissions);
|
||||||
|
AddFunc("log",&DefScriptPackage::SClog);
|
||||||
|
AddFunc("logdetail",&DefScriptPackage::SClogdetail);
|
||||||
|
AddFunc("logerror",&DefScriptPackage::SClogerror);
|
||||||
|
AddFunc("logdebug",&DefScriptPackage::SClogdebug);
|
||||||
|
AddFunc("castspell",&DefScriptPackage::SCcastspell);
|
||||||
|
AddFunc("queryitem",&DefScriptPackage::SCqueryitem);
|
||||||
|
AddFunc("target",&DefScriptPackage::SCtarget);
|
||||||
|
AddFunc("loadscp",&DefScriptPackage::SCloadscp);
|
||||||
|
AddFunc("scpexists",&DefScriptPackage::SCloadscp);
|
||||||
|
AddFunc("scpsectionexists",&DefScriptPackage::SCloadscp);
|
||||||
|
AddFunc("scpentryexists",&DefScriptPackage::SCloadscp);
|
||||||
|
AddFunc("getscpvalue",&DefScriptPackage::SCloadscp);
|
||||||
|
}
|
||||||
|
|
||||||
DefReturnResult DefScriptPackage::SCshdn(CmdSet& Set)
|
DefReturnResult DefScriptPackage::SCshdn(CmdSet& Set)
|
||||||
{
|
{
|
||||||
((PseuInstance*)parentMethod)->Stop();
|
((PseuInstance*)parentMethod)->Stop();
|
||||||
@ -26,7 +52,7 @@ DefReturnResult DefScriptPackage::SCSendChatMessage(CmdSet& Set){
|
|||||||
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
||||||
{
|
{
|
||||||
logerror("Invalid Script call: SCSendChatMessage: WorldSession not valid");
|
logerror("Invalid Script call: SCSendChatMessage: WorldSession not valid");
|
||||||
return false;
|
DEF_RETURN_ERROR;
|
||||||
}
|
}
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
uint32 type=atoi(Set.arg[0].c_str());
|
uint32 type=atoi(Set.arg[0].c_str());
|
||||||
@ -68,18 +94,20 @@ DefReturnResult DefScriptPackage::SCsavecache(CmdSet& Set){
|
|||||||
|
|
||||||
DefReturnResult DefScriptPackage::SCemote(CmdSet& Set){
|
DefReturnResult DefScriptPackage::SCemote(CmdSet& Set){
|
||||||
if(Set.defaultarg.empty())
|
if(Set.defaultarg.empty())
|
||||||
return true;
|
return false;
|
||||||
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
||||||
{
|
{
|
||||||
logerror("Invalid Script call: SCEmote: WorldSession not valid");
|
logerror("Invalid Script call: SCEmote: WorldSession not valid");
|
||||||
return false;
|
DEF_RETURN_ERROR;
|
||||||
}
|
}
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
DefReturnResult DefScriptPackage::SCfollow(CmdSet& Set){
|
DefReturnResult DefScriptPackage::SCfollow(CmdSet& Set)
|
||||||
|
{
|
||||||
|
DEF_RETURN_ERROR; // prevent execution for now
|
||||||
WorldSession *ws=((PseuInstance*)parentMethod)->GetWSession();
|
WorldSession *ws=((PseuInstance*)parentMethod)->GetWSession();
|
||||||
if(Set.defaultarg.empty()){
|
if(Set.defaultarg.empty()){
|
||||||
ws->SendChatMessage(CHAT_MSG_SAY,0,"Stopping! (Please give me a Playername to follow!)","");
|
ws->SendChatMessage(CHAT_MSG_SAY,0,"Stopping! (Please give me a Playername to follow!)","");
|
||||||
@ -99,11 +127,11 @@ DefReturnResult DefScriptPackage::SCfollow(CmdSet& Set){
|
|||||||
|
|
||||||
DefReturnResult DefScriptPackage::SCjoinchannel(CmdSet& Set){
|
DefReturnResult DefScriptPackage::SCjoinchannel(CmdSet& Set){
|
||||||
if(Set.defaultarg.empty())
|
if(Set.defaultarg.empty())
|
||||||
return true;
|
return false;
|
||||||
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
||||||
{
|
{
|
||||||
logerror("Invalid Script call: SCjoinchannel: WorldSession not valid");
|
logerror("Invalid Script call: SCjoinchannel: WorldSession not valid");
|
||||||
return false;
|
DEF_RETURN_ERROR;
|
||||||
}
|
}
|
||||||
((PseuInstance*)parentMethod)->GetWSession()->GetChannels()->Join(Set.defaultarg,Set.arg[0]);
|
((PseuInstance*)parentMethod)->GetWSession()->GetChannels()->Join(Set.defaultarg,Set.arg[0]);
|
||||||
return true;
|
return true;
|
||||||
@ -111,11 +139,11 @@ DefReturnResult DefScriptPackage::SCjoinchannel(CmdSet& Set){
|
|||||||
|
|
||||||
DefReturnResult DefScriptPackage::SCleavechannel(CmdSet& Set){
|
DefReturnResult DefScriptPackage::SCleavechannel(CmdSet& Set){
|
||||||
if(Set.defaultarg.empty())
|
if(Set.defaultarg.empty())
|
||||||
return true;
|
return false;
|
||||||
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
||||||
{
|
{
|
||||||
logerror("Invalid Script call: SCleavechannel: WorldSession not valid");
|
logerror("Invalid Script call: SCleavechannel: WorldSession not valid");
|
||||||
return false;
|
DEF_RETURN_ERROR;
|
||||||
}
|
}
|
||||||
((PseuInstance*)parentMethod)->GetWSession()->GetChannels()->Leave(Set.defaultarg);
|
((PseuInstance*)parentMethod)->GetWSession()->GetChannels()->Leave(Set.defaultarg);
|
||||||
return true;
|
return true;
|
||||||
@ -123,17 +151,20 @@ DefReturnResult DefScriptPackage::SCleavechannel(CmdSet& Set){
|
|||||||
|
|
||||||
DefReturnResult DefScriptPackage::SCloadconf(CmdSet& Set){
|
DefReturnResult DefScriptPackage::SCloadconf(CmdSet& Set){
|
||||||
if(Set.defaultarg.empty())
|
if(Set.defaultarg.empty())
|
||||||
return true;
|
return false;
|
||||||
std::string fn;
|
std::string fn;
|
||||||
if(Set.defaultarg.find('/')==std::string::npos && Set.defaultarg.find('\\')==std::string::npos)
|
if(Set.defaultarg.find('/')==std::string::npos && Set.defaultarg.find('\\')==std::string::npos)
|
||||||
fn += ((PseuInstance*)parentMethod)->GetConfDir();
|
fn += ((PseuInstance*)parentMethod)->GetConfDir();
|
||||||
fn += Set.defaultarg;
|
fn += Set.defaultarg;
|
||||||
|
|
||||||
if(variables.ReadVarsFromFile(fn))
|
if(variables.ReadVarsFromFile(fn))
|
||||||
|
{
|
||||||
log("Loaded conf file [%s]",fn.c_str());
|
log("Loaded conf file [%s]",fn.c_str());
|
||||||
else
|
return true;
|
||||||
log("Error loading conf file [%s]",fn.c_str());
|
}
|
||||||
return true;
|
|
||||||
|
log("Error loading conf file [%s]",fn.c_str());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DefReturnResult DefScriptPackage::SCapplypermissions(CmdSet& Set){
|
DefReturnResult DefScriptPackage::SCapplypermissions(CmdSet& Set){
|
||||||
@ -169,11 +200,11 @@ DefReturnResult DefScriptPackage::SClogerror(CmdSet& Set){
|
|||||||
DefReturnResult DefScriptPackage::SCcastspell(CmdSet& Set)
|
DefReturnResult DefScriptPackage::SCcastspell(CmdSet& Set)
|
||||||
{
|
{
|
||||||
if(Set.defaultarg.empty())
|
if(Set.defaultarg.empty())
|
||||||
return true;
|
return false;
|
||||||
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
||||||
{
|
{
|
||||||
logerror("Invalid Script call: SCcastspell: WorldSession not valid");
|
logerror("Invalid Script call: SCcastspell: WorldSession not valid");
|
||||||
return false;
|
DEF_RETURN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 spellId = atoi(Set.defaultarg.c_str());
|
uint32 spellId = atoi(Set.defaultarg.c_str());
|
||||||
@ -181,7 +212,7 @@ DefReturnResult DefScriptPackage::SCcastspell(CmdSet& Set)
|
|||||||
if (spellId <= 0)
|
if (spellId <= 0)
|
||||||
{
|
{
|
||||||
logerror("Invalid Script call: SCcastspell: SpellId not valid");
|
logerror("Invalid Script call: SCcastspell: SpellId not valid");
|
||||||
return false;
|
DEF_RETURN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
((PseuInstance*)parentMethod)->GetWSession()->SendCastSpell(spellId);
|
((PseuInstance*)parentMethod)->GetWSession()->SendCastSpell(spellId);
|
||||||
@ -191,12 +222,12 @@ DefReturnResult DefScriptPackage::SCcastspell(CmdSet& Set)
|
|||||||
DefReturnResult DefScriptPackage::SCqueryitem(CmdSet& Set){
|
DefReturnResult DefScriptPackage::SCqueryitem(CmdSet& Set){
|
||||||
uint32 id = atoi(Set.defaultarg.c_str());
|
uint32 id = atoi(Set.defaultarg.c_str());
|
||||||
if(!id)
|
if(!id)
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
||||||
{
|
{
|
||||||
logerror("Invalid Script call: SCqueryitem: WorldSession not valid");
|
logerror("Invalid Script call: SCqueryitem: WorldSession not valid");
|
||||||
return false;
|
DEF_RETURN_ERROR;
|
||||||
}
|
}
|
||||||
((PseuInstance*)parentMethod)->GetWSession()->SendQueryItem(id,0);
|
((PseuInstance*)parentMethod)->GetWSession()->SendQueryItem(id,0);
|
||||||
return true;
|
return true;
|
||||||
@ -209,7 +240,7 @@ DefReturnResult DefScriptPackage::SCtarget(CmdSet& Set)
|
|||||||
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
||||||
{
|
{
|
||||||
logerror("Invalid Script call: SCtarget: WorldSession not valid");
|
logerror("Invalid Script call: SCtarget: WorldSession not valid");
|
||||||
return false;
|
DEF_RETURN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Set.defaultarg.empty())
|
if(Set.defaultarg.empty())
|
||||||
@ -231,9 +262,11 @@ DefReturnResult DefScriptPackage::SCtarget(CmdSet& Set)
|
|||||||
|
|
||||||
DefReturnResult DefScriptPackage::SCloadscp(CmdSet& Set)
|
DefReturnResult DefScriptPackage::SCloadscp(CmdSet& Set)
|
||||||
{
|
{
|
||||||
|
DefReturnResult r;
|
||||||
if(Set.arg[0].empty() || Set.defaultarg.empty())
|
if(Set.arg[0].empty() || Set.defaultarg.empty())
|
||||||
return true;
|
return false;
|
||||||
std::string dbname = stringToLower(Set.arg[0]);
|
std::string dbname = stringToLower(Set.arg[0]);
|
||||||
|
// TODO: remove db if loading was not successful
|
||||||
uint32 sections=((PseuInstance*)parentMethod)->GetSCPDatabase(dbname).LoadFromFile((char*)Set.defaultarg.c_str());
|
uint32 sections=((PseuInstance*)parentMethod)->GetSCPDatabase(dbname).LoadFromFile((char*)Set.defaultarg.c_str());
|
||||||
if(sections)
|
if(sections)
|
||||||
{
|
{
|
||||||
@ -243,10 +276,68 @@ DefReturnResult DefScriptPackage::SCloadscp(CmdSet& Set)
|
|||||||
{
|
{
|
||||||
logerror("Failed to load SCP: \"%s\" [%s]",dbname.c_str(),Set.defaultarg.c_str());
|
logerror("Failed to load SCP: \"%s\" [%s]",dbname.c_str(),Set.defaultarg.c_str());
|
||||||
}
|
}
|
||||||
return true;
|
r.ret=toString((uint64)sections);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
DefReturnResult DefScriptPackage::SCScpExists(CmdSet& Set)
|
||||||
|
{
|
||||||
|
return (!Set.defaultarg.empty()) && ((PseuInstance*)parentMethod)->HasSCPDatabase(Set.defaultarg);
|
||||||
|
}
|
||||||
|
|
||||||
|
DefReturnResult DefScriptPackage::SCScpSectionExists(CmdSet& Set)
|
||||||
|
{
|
||||||
|
static std::string dbname;
|
||||||
|
if(!Set.arg[0].empty())
|
||||||
|
dbname=Set.arg[0];
|
||||||
|
return (!Set.defaultarg.empty()) && (!dbname.empty())
|
||||||
|
&& ((PseuInstance*)parentMethod)->HasSCPDatabase(dbname)
|
||||||
|
&& ((PseuInstance*)parentMethod)->GetSCPDatabase(dbname).HasField((uint32)DefScriptTools::toNumber(Set.defaultarg));
|
||||||
|
}
|
||||||
|
|
||||||
|
DefReturnResult DefScriptPackage::SCScpEntryExists(CmdSet& Set)
|
||||||
|
{
|
||||||
|
static std::string dbname;
|
||||||
|
static uint32 keyid;
|
||||||
|
if(!Set.arg[0].empty())
|
||||||
|
dbname=Set.arg[0];
|
||||||
|
if(!Set.arg[1].empty())
|
||||||
|
keyid=(uint32)DefScriptTools::toNumber(Set.arg[1]);
|
||||||
|
return (!Set.defaultarg.empty()) && (!dbname.empty())
|
||||||
|
&& ((PseuInstance*)parentMethod)->HasSCPDatabase(dbname)
|
||||||
|
&& ((PseuInstance*)parentMethod)->GetSCPDatabase(dbname).HasField(keyid)
|
||||||
|
&& ((PseuInstance*)parentMethod)->GetSCPDatabase(dbname).GetField(keyid).HasEntry(Set.defaultarg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// GetScpValue,db,key entry
|
||||||
|
// db & key will be stored, that multiple calls like GetScpValue entryxyz are possible
|
||||||
|
DefReturnResult DefScriptPackage::SCGetScpValue(CmdSet& Set)
|
||||||
|
{
|
||||||
|
static std::string dbname;
|
||||||
|
static uint32 keyid;
|
||||||
|
std::string entry;
|
||||||
|
DefReturnResult r;
|
||||||
|
|
||||||
|
if(!Set.arg[0].empty())
|
||||||
|
dbname=Set.arg[0];
|
||||||
|
if(!Set.arg[1].empty())
|
||||||
|
keyid=(uint32)DefScriptTools::toNumber(Set.arg[1]);
|
||||||
|
if(!Set.defaultarg.empty())
|
||||||
|
entry=Set.defaultarg;
|
||||||
|
if( (!entry.empty()) && (!dbname.empty())
|
||||||
|
&& ((PseuInstance*)parentMethod)->HasSCPDatabase(dbname)
|
||||||
|
&& ((PseuInstance*)parentMethod)->GetSCPDatabase(dbname).HasField(keyid)
|
||||||
|
&& ((PseuInstance*)parentMethod)->GetSCPDatabase(dbname).GetField(keyid).HasEntry(entry))
|
||||||
|
{
|
||||||
|
r.ret = ((PseuInstance*)parentMethod)->GetSCPDatabase(dbname).GetField(keyid).GetString(entry);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
r.ret = "";
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
void DefScriptPackage::My_LoadUserPermissions(VarSet &vs)
|
void DefScriptPackage::My_LoadUserPermissions(VarSet &vs)
|
||||||
{
|
{
|
||||||
|
|||||||
31
src/Client/DefScriptInterfaceInclude.h
Normal file
31
src/Client/DefScriptInterfaceInclude.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef DEFSCRIPTINTERFACEINCLUDE_H
|
||||||
|
#define DEFSCRIPTINTERFACEINCLUDE_H
|
||||||
|
#define USING_DEFSCRIPT_EXTENSIONS true
|
||||||
|
|
||||||
|
void _InitDefScriptInterface();
|
||||||
|
// Useable own internal functions:
|
||||||
|
DefReturnResult SCpause(CmdSet&);
|
||||||
|
DefReturnResult SCSendChatMessage(CmdSet&);
|
||||||
|
DefReturnResult SCsavecache(CmdSet&);
|
||||||
|
DefReturnResult SCemote(CmdSet&);
|
||||||
|
DefReturnResult SCfollow(CmdSet&);
|
||||||
|
DefReturnResult SCshdn(CmdSet&);
|
||||||
|
DefReturnResult SCjoinchannel(CmdSet&);
|
||||||
|
DefReturnResult SCleavechannel(CmdSet&);
|
||||||
|
DefReturnResult SCloadconf(CmdSet&);
|
||||||
|
DefReturnResult SCapplypermissions(CmdSet&);
|
||||||
|
DefReturnResult SCapplyconf(CmdSet&);
|
||||||
|
DefReturnResult SClog(CmdSet&);
|
||||||
|
DefReturnResult SClogdetail(CmdSet&);
|
||||||
|
DefReturnResult SClogdebug(CmdSet&);
|
||||||
|
DefReturnResult SClogerror(CmdSet&);
|
||||||
|
DefReturnResult SCcastspell(CmdSet&);
|
||||||
|
DefReturnResult SCqueryitem(CmdSet&);
|
||||||
|
DefReturnResult SCtarget(CmdSet&);
|
||||||
|
DefReturnResult SCloadscp(CmdSet&);
|
||||||
|
DefReturnResult SCScpExists(CmdSet&);
|
||||||
|
DefReturnResult SCScpSectionExists(CmdSet&);
|
||||||
|
DefReturnResult SCScpEntryExists(CmdSet&);
|
||||||
|
DefReturnResult SCGetScpValue(CmdSet&);
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -79,7 +79,7 @@ PseuInstance::~PseuInstance()
|
|||||||
|
|
||||||
bool PseuInstance::Init(void) {
|
bool PseuInstance::Init(void) {
|
||||||
log_prepare("logfile.txt",this);
|
log_prepare("logfile.txt",this);
|
||||||
log("\n");
|
log("");
|
||||||
log("--- Initializing Instance ---");
|
log("--- Initializing Instance ---");
|
||||||
|
|
||||||
if(_confdir.empty())
|
if(_confdir.empty())
|
||||||
@ -242,7 +242,13 @@ SCPDatabase& PseuInstance::GetSCPDatabase(std::string dbname)
|
|||||||
return _dbmap[dbname];
|
return _dbmap[dbname];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PseuInstance::HasSCPDatabase(std::string dbname)
|
||||||
|
{
|
||||||
|
for(std::map<std::string,SCPDatabase>::iterator i = _dbmap.begin(); i != _dbmap.end(); i++)
|
||||||
|
if(i->first == dbname)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
PseuInstanceConf::PseuInstanceConf()
|
PseuInstanceConf::PseuInstanceConf()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -73,9 +73,7 @@ class PseuInstance
|
|||||||
BigNumber GetSessionKey(void) { return _sessionkey; }
|
BigNumber GetSessionKey(void) { return _sessionkey; }
|
||||||
void SetError(void) { _error = true; }
|
void SetError(void) { _error = true; }
|
||||||
SCPDatabase& GetSCPDatabase(std::string);
|
SCPDatabase& GetSCPDatabase(std::string);
|
||||||
|
bool HasSCPDatabase(std::string);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Init();
|
bool Init();
|
||||||
void SaveAllCache(void);
|
void SaveAllCache(void);
|
||||||
@ -86,7 +84,6 @@ class PseuInstance
|
|||||||
void Update(void);
|
void Update(void);
|
||||||
void Sleep(uint32 msecs);
|
void Sleep(uint32 msecs);
|
||||||
|
|
||||||
|
|
||||||
bool createWorldSession;
|
bool createWorldSession;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -51,3 +51,24 @@ uint32 SCPDatabase::LoadFromFile(char *fn)
|
|||||||
fh.close();
|
fh.close();
|
||||||
return sections;
|
return sections;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SCPDatabase::HasField(uint32 id)
|
||||||
|
{
|
||||||
|
for(SCPFieldMap::iterator i = _map.begin(); i != _map.end(); i++)
|
||||||
|
if(i->first == id)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SCPField::HasEntry(std::string e)
|
||||||
|
{
|
||||||
|
for(SCPEntryMap::iterator i = _map.begin(); i != _map.end(); i++)
|
||||||
|
if(i->first == e)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SCPField::GetString(std::string entry)
|
||||||
|
{
|
||||||
|
return HasEntry(entry) ? _map[entry] : "";
|
||||||
|
}
|
||||||
@ -14,10 +14,11 @@ typedef std::map<std::string,std::string> SCPEntryMap;
|
|||||||
class SCPField
|
class SCPField
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string GetString(std::string entry) { return _map[entry]; }
|
std::string GetString(std::string);
|
||||||
uint64 GetInteger(std::string entry) { return toInt(_map[entry]); }
|
uint64 GetInteger(std::string entry) { return toInt(GetString(entry)); }
|
||||||
double GetDouble(std::string entry) { return strtod(_map[entry].c_str(),NULL); }
|
double GetDouble(std::string entry) { return strtod(GetString(entry).c_str(),NULL); }
|
||||||
void Set(std::string entry,std::string value) { _map[entry]=value; }
|
void Set(std::string entry,std::string value) { _map[entry]=value; }
|
||||||
|
bool HasEntry(std::string);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SCPEntryMap _map;
|
SCPEntryMap _map;
|
||||||
@ -30,6 +31,7 @@ class SCPDatabase
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SCPField& GetField(uint32 id) { return _map[id]; }
|
SCPField& GetField(uint32 id) { return _map[id]; }
|
||||||
|
bool HasField(uint32 id);
|
||||||
uint32 LoadFromFile(char*);
|
uint32 LoadFromFile(char*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -161,6 +161,9 @@
|
|||||||
<File
|
<File
|
||||||
RelativePath=".\Client\DefScriptInterface.cpp">
|
RelativePath=".\Client\DefScriptInterface.cpp">
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\Client\DefScriptInterfaceInclude.h">
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\Client\HelperDefs.h">
|
RelativePath=".\Client\HelperDefs.h">
|
||||||
</File>
|
</File>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user