* 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 ---
|
||||
DefScriptPackage::DefScriptPackage()
|
||||
{
|
||||
functionTable=_GetFunctionTable();
|
||||
_eventmgr=new DefScript_DynamicEventMgr(this);
|
||||
_InitFunctions();
|
||||
# ifdef USING_DEFSCRIPT_EXTENSIONS
|
||||
_InitDefScriptInterface();
|
||||
# endif
|
||||
}
|
||||
|
||||
DefScriptPackage::~DefScriptPackage()
|
||||
@ -36,63 +39,58 @@ void DefScriptPackage::Clear(void)
|
||||
Script.empty();
|
||||
}
|
||||
|
||||
DefScriptFunctionTable *DefScriptPackage::_GetFunctionTable(void) const
|
||||
void DefScriptPackage::_InitFunctions(void)
|
||||
{
|
||||
static DefScriptFunctionTable table[] = {
|
||||
// basic functions:
|
||||
{"out",&DefScriptPackage::func_out},
|
||||
{"set",&DefScriptPackage::func_set},
|
||||
{"default",&DefScriptPackage::func_default},
|
||||
{"unset",&DefScriptPackage::func_unset},
|
||||
{"shdn",&DefScriptPackage::func_shdn},
|
||||
{"loaddef",&DefScriptPackage::func_loaddef},
|
||||
{"reloaddef",&DefScriptPackage::func_reloaddef},
|
||||
{"setscriptpermission",&DefScriptPackage::func_setscriptpermission},
|
||||
|
||||
// mathematical functions:
|
||||
{"toint",&DefScriptPackage::func_toint},
|
||||
{"add",&DefScriptPackage::func_add},
|
||||
{"sub",&DefScriptPackage::func_sub},
|
||||
{"mul",&DefScriptPackage::func_mul},
|
||||
{"div",&DefScriptPackage::func_div},
|
||||
{"mod",&DefScriptPackage::func_mod},
|
||||
{"pow",&DefScriptPackage::func_pow},
|
||||
{"bitor",&DefScriptPackage::func_bitor},
|
||||
{"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;
|
||||
AddFunc("out",&DefScriptPackage::func_out);
|
||||
AddFunc("set",&DefScriptPackage::func_set);
|
||||
AddFunc("default",&DefScriptPackage::func_default);
|
||||
AddFunc("unset",&DefScriptPackage::func_unset);
|
||||
AddFunc("shdn",&DefScriptPackage::func_shdn);
|
||||
AddFunc("loaddef",&DefScriptPackage::func_loaddef);
|
||||
AddFunc("reloaddef",&DefScriptPackage::func_reloaddef);
|
||||
AddFunc("setscriptpermission",&DefScriptPackage::func_setscriptpermission);
|
||||
AddFunc("toint",&DefScriptPackage::func_toint);
|
||||
AddFunc("add",&DefScriptPackage::func_add);
|
||||
AddFunc("sub",&DefScriptPackage::func_sub);
|
||||
AddFunc("mul",&DefScriptPackage::func_mul);
|
||||
AddFunc("div",&DefScriptPackage::func_div);
|
||||
AddFunc("mod",&DefScriptPackage::func_mod);
|
||||
AddFunc("pow",&DefScriptPackage::func_pow);
|
||||
AddFunc("bitor",&DefScriptPackage::func_bitor);
|
||||
AddFunc("bitand",&DefScriptPackage::func_bitand);
|
||||
AddFunc("bitxor",&DefScriptPackage::func_bitxor);
|
||||
AddFunc("addevent",&DefScriptPackage::func_addevent);
|
||||
AddFunc("removeevent",&DefScriptPackage::func_removeevent);
|
||||
}
|
||||
|
||||
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){
|
||||
@ -117,8 +115,8 @@ bool DefScriptPackage::ScriptExists(std::string name)
|
||||
for (std::map<std::string,DefScript*>::iterator i = Script.begin();i != Script.end();i++)
|
||||
if(i->first == name && i->second != NULL)
|
||||
return true;
|
||||
for(unsigned int i=0;functionTable[i].func!=NULL;i++)
|
||||
if(name == functionTable[i].name)
|
||||
for(unsigned int i=0;i<_functable.size();i++)
|
||||
if(name == _functable[i].name)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
@ -647,15 +645,11 @@ DefReturnResult DefScriptPackage::Interpret(CmdSet& Set)
|
||||
DefReturnResult result;
|
||||
|
||||
// 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;
|
||||
}
|
||||
if(Set.cmd==functionTable[i].name)
|
||||
{
|
||||
result=(this->*functionTable[i].func)(Set);
|
||||
result=(this->*(_functable[i].func))(Set);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ class DefScript;
|
||||
struct DefReturnResult
|
||||
{
|
||||
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 mustreturn;
|
||||
std::string ret; // return value used by ?{..}
|
||||
@ -24,6 +24,8 @@ struct DefReturnResult
|
||||
//std::string err; // error string, including tracestack, etc.
|
||||
};
|
||||
|
||||
#define DEF_RETURN_ERROR { DefReturnResult __defreturnresult(false); __defreturnresult.ok=false; return __defreturnresult; }
|
||||
|
||||
struct DefXChgResult
|
||||
{
|
||||
DefXChgResult() { changed=false; }
|
||||
@ -44,11 +46,18 @@ class CmdSet {
|
||||
std::string caller;
|
||||
};
|
||||
|
||||
struct DefScriptFunctionTable {
|
||||
char *name;
|
||||
struct DefScriptFunctionEntry {
|
||||
DefScriptFunctionEntry(std::string n,DefReturnResult (DefScriptPackage::*f)(CmdSet& Set))
|
||||
{
|
||||
name=n;
|
||||
func=f;
|
||||
}
|
||||
std::string name;
|
||||
DefReturnResult (DefScriptPackage::*func)(CmdSet& Set);
|
||||
};
|
||||
|
||||
typedef std::deque<DefScriptFunctionEntry> DefScriptFunctionTable;
|
||||
|
||||
class DefScript {
|
||||
public:
|
||||
DefScript(DefScriptPackage *p);
|
||||
@ -94,10 +103,14 @@ public:
|
||||
VarSet variables;
|
||||
void SetPath(std::string);
|
||||
bool LoadByName(std::string);
|
||||
void SetFunctionTable(DefScriptFunctionTable*);
|
||||
std::string _NormalizeVarName(std::string, std::string);
|
||||
DefReturnResult RunSingleLineFromScript(std::string line, DefScript *pScript);
|
||||
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;
|
||||
|
||||
@ -106,18 +119,18 @@ public:
|
||||
void My_Run(std::string line,std::string username);
|
||||
|
||||
private:
|
||||
void _InitFunctions(void);
|
||||
DefXChgResult ReplaceVars(std::string str, CmdSet* pSet, unsigned char VarType);
|
||||
void SplitLine(CmdSet&,std::string);
|
||||
DefReturnResult Interpret(CmdSet&);
|
||||
void RemoveBrackets(CmdSet&);
|
||||
std::string RemoveBracketsFromString(std::string);
|
||||
DefScriptFunctionTable *_GetFunctionTable(void) const;
|
||||
DefScriptFunctionTable *functionTable;
|
||||
unsigned int functions;
|
||||
void *parentMethod;
|
||||
DefScript_DynamicEventMgr *_eventmgr;
|
||||
std::map<std::string,DefScript*> Script;
|
||||
std::map<std::string,unsigned char> scriptPermissionMap;
|
||||
DefScriptFunctionTable _functable;
|
||||
|
||||
// Usable internal basic functions:
|
||||
DefReturnResult func_default(CmdSet&);
|
||||
@ -142,26 +155,8 @@ private:
|
||||
DefReturnResult func_addevent(CmdSet&);
|
||||
DefReturnResult func_removeevent(CmdSet&);
|
||||
|
||||
// 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&);
|
||||
// setup own function declarations here
|
||||
# include "DefScriptInterfaceInclude.h"
|
||||
|
||||
// Own variable declarations
|
||||
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 r;
|
||||
std::string num=toString(floor(toNumber(Set.defaultarg.c_str())));
|
||||
std::string num=toString(floor(toNumber(Set.defaultarg)));
|
||||
if(!Set.arg[0].empty())
|
||||
{
|
||||
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);
|
||||
double a=toNumber(variables.Get(vname));
|
||||
double b=toNumber(Set.defaultarg.c_str());
|
||||
double b=toNumber(Set.defaultarg);
|
||||
a+=b;
|
||||
variables.Set(vname,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);
|
||||
double a=toNumber(variables.Get(vname));
|
||||
double b=toNumber(Set.defaultarg.c_str());
|
||||
double b=toNumber(Set.defaultarg);
|
||||
a-=b;
|
||||
variables.Set(vname,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);
|
||||
double a=toNumber(variables.Get(vname));
|
||||
double b=toNumber(Set.defaultarg.c_str());
|
||||
double b=toNumber(Set.defaultarg);
|
||||
a*=b;
|
||||
variables.Set(vname,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);
|
||||
double a=toNumber(variables.Get(vname));
|
||||
double b=toNumber(Set.defaultarg.c_str());
|
||||
double b=toNumber(Set.defaultarg);
|
||||
if(b==0)
|
||||
a=0;
|
||||
else
|
||||
@ -242,7 +242,7 @@ DefReturnResult DefScriptPackage::func_mod(CmdSet& Set)
|
||||
|
||||
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
||||
uint64 a=(uint64)toNumber(variables.Get(vname));
|
||||
uint64 b=(uint64)toNumber(Set.defaultarg.c_str());
|
||||
uint64 b=(uint64)toNumber(Set.defaultarg);
|
||||
if(b==0)
|
||||
a=0;
|
||||
else
|
||||
@ -262,7 +262,7 @@ DefReturnResult DefScriptPackage::func_pow(CmdSet& Set)
|
||||
|
||||
std::string vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
||||
double a=toNumber(variables.Get(vname));
|
||||
double b=toNumber(Set.defaultarg.c_str());
|
||||
double b=toNumber(Set.defaultarg);
|
||||
a=pow(a,b);
|
||||
variables.Set(vname,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);
|
||||
uint64 a=(uint64)toNumber(variables.Get(vname));
|
||||
uint64 b=(uint64)toNumber(Set.defaultarg.c_str());
|
||||
uint64 b=(uint64)toNumber(Set.defaultarg);
|
||||
a|=b;
|
||||
variables.Set(vname,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);
|
||||
uint64 a=(uint64)toNumber(variables.Get(vname));
|
||||
uint64 b=(uint64)toNumber(Set.defaultarg.c_str());
|
||||
uint64 b=(uint64)toNumber(Set.defaultarg);
|
||||
a&=b;
|
||||
variables.Set(vname,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);
|
||||
uint64 a=(uint64)toNumber(variables.Get(vname));
|
||||
uint64 b=(uint64)toNumber(Set.defaultarg.c_str());
|
||||
uint64 b=(uint64)toNumber(Set.defaultarg);
|
||||
a^=b;
|
||||
variables.Set(vname,toString(a));
|
||||
r.ret=toString(a);
|
||||
@ -323,7 +323,7 @@ DefReturnResult DefScriptPackage::func_bitxor(CmdSet& Set)
|
||||
DefReturnResult DefScriptPackage::func_addevent(CmdSet& Set)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include "PseuWoW.h"
|
||||
#include "NameTables.h"
|
||||
#include "DefScript/DefScript.h"
|
||||
#include "DefScript/DefScriptTools.h"
|
||||
#include "Player.h"
|
||||
#include "Opcodes.h"
|
||||
#include "SharedDefines.h"
|
||||
@ -11,6 +12,31 @@
|
||||
#include "CacheHandler.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)
|
||||
{
|
||||
((PseuInstance*)parentMethod)->Stop();
|
||||
@ -26,7 +52,7 @@ DefReturnResult DefScriptPackage::SCSendChatMessage(CmdSet& Set){
|
||||
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
||||
{
|
||||
logerror("Invalid Script call: SCSendChatMessage: WorldSession not valid");
|
||||
return false;
|
||||
DEF_RETURN_ERROR;
|
||||
}
|
||||
std::stringstream ss;
|
||||
uint32 type=atoi(Set.arg[0].c_str());
|
||||
@ -68,18 +94,20 @@ DefReturnResult DefScriptPackage::SCsavecache(CmdSet& Set){
|
||||
|
||||
DefReturnResult DefScriptPackage::SCemote(CmdSet& Set){
|
||||
if(Set.defaultarg.empty())
|
||||
return true;
|
||||
return false;
|
||||
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
||||
{
|
||||
logerror("Invalid Script call: SCEmote: WorldSession not valid");
|
||||
return false;
|
||||
DEF_RETURN_ERROR;
|
||||
}
|
||||
uint32 id=atoi(Set.defaultarg.c_str());
|
||||
((PseuInstance*)parentMethod)->GetWSession()->SendEmote(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
DefReturnResult DefScriptPackage::SCfollow(CmdSet& Set){
|
||||
DefReturnResult DefScriptPackage::SCfollow(CmdSet& Set)
|
||||
{
|
||||
DEF_RETURN_ERROR; // prevent execution for now
|
||||
WorldSession *ws=((PseuInstance*)parentMethod)->GetWSession();
|
||||
if(Set.defaultarg.empty()){
|
||||
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){
|
||||
if(Set.defaultarg.empty())
|
||||
return true;
|
||||
return false;
|
||||
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
||||
{
|
||||
logerror("Invalid Script call: SCjoinchannel: WorldSession not valid");
|
||||
return false;
|
||||
DEF_RETURN_ERROR;
|
||||
}
|
||||
((PseuInstance*)parentMethod)->GetWSession()->GetChannels()->Join(Set.defaultarg,Set.arg[0]);
|
||||
return true;
|
||||
@ -111,11 +139,11 @@ DefReturnResult DefScriptPackage::SCjoinchannel(CmdSet& Set){
|
||||
|
||||
DefReturnResult DefScriptPackage::SCleavechannel(CmdSet& Set){
|
||||
if(Set.defaultarg.empty())
|
||||
return true;
|
||||
return false;
|
||||
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
||||
{
|
||||
logerror("Invalid Script call: SCleavechannel: WorldSession not valid");
|
||||
return false;
|
||||
DEF_RETURN_ERROR;
|
||||
}
|
||||
((PseuInstance*)parentMethod)->GetWSession()->GetChannels()->Leave(Set.defaultarg);
|
||||
return true;
|
||||
@ -123,17 +151,20 @@ DefReturnResult DefScriptPackage::SCleavechannel(CmdSet& Set){
|
||||
|
||||
DefReturnResult DefScriptPackage::SCloadconf(CmdSet& Set){
|
||||
if(Set.defaultarg.empty())
|
||||
return true;
|
||||
return false;
|
||||
std::string fn;
|
||||
if(Set.defaultarg.find('/')==std::string::npos && Set.defaultarg.find('\\')==std::string::npos)
|
||||
fn += ((PseuInstance*)parentMethod)->GetConfDir();
|
||||
fn += Set.defaultarg;
|
||||
|
||||
if(variables.ReadVarsFromFile(fn))
|
||||
{
|
||||
log("Loaded conf file [%s]",fn.c_str());
|
||||
else
|
||||
log("Error loading conf file [%s]",fn.c_str());
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
log("Error loading conf file [%s]",fn.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
DefReturnResult DefScriptPackage::SCapplypermissions(CmdSet& Set){
|
||||
@ -169,11 +200,11 @@ DefReturnResult DefScriptPackage::SClogerror(CmdSet& Set){
|
||||
DefReturnResult DefScriptPackage::SCcastspell(CmdSet& Set)
|
||||
{
|
||||
if(Set.defaultarg.empty())
|
||||
return true;
|
||||
return false;
|
||||
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
||||
{
|
||||
logerror("Invalid Script call: SCcastspell: WorldSession not valid");
|
||||
return false;
|
||||
DEF_RETURN_ERROR;
|
||||
}
|
||||
|
||||
uint32 spellId = atoi(Set.defaultarg.c_str());
|
||||
@ -181,7 +212,7 @@ DefReturnResult DefScriptPackage::SCcastspell(CmdSet& Set)
|
||||
if (spellId <= 0)
|
||||
{
|
||||
logerror("Invalid Script call: SCcastspell: SpellId not valid");
|
||||
return false;
|
||||
DEF_RETURN_ERROR;
|
||||
}
|
||||
|
||||
((PseuInstance*)parentMethod)->GetWSession()->SendCastSpell(spellId);
|
||||
@ -191,12 +222,12 @@ DefReturnResult DefScriptPackage::SCcastspell(CmdSet& Set)
|
||||
DefReturnResult DefScriptPackage::SCqueryitem(CmdSet& Set){
|
||||
uint32 id = atoi(Set.defaultarg.c_str());
|
||||
if(!id)
|
||||
return true;
|
||||
return false;
|
||||
|
||||
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
||||
{
|
||||
logerror("Invalid Script call: SCqueryitem: WorldSession not valid");
|
||||
return false;
|
||||
DEF_RETURN_ERROR;
|
||||
}
|
||||
((PseuInstance*)parentMethod)->GetWSession()->SendQueryItem(id,0);
|
||||
return true;
|
||||
@ -209,7 +240,7 @@ DefReturnResult DefScriptPackage::SCtarget(CmdSet& Set)
|
||||
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
||||
{
|
||||
logerror("Invalid Script call: SCtarget: WorldSession not valid");
|
||||
return false;
|
||||
DEF_RETURN_ERROR;
|
||||
}
|
||||
|
||||
if(Set.defaultarg.empty())
|
||||
@ -231,9 +262,11 @@ DefReturnResult DefScriptPackage::SCtarget(CmdSet& Set)
|
||||
|
||||
DefReturnResult DefScriptPackage::SCloadscp(CmdSet& Set)
|
||||
{
|
||||
DefReturnResult r;
|
||||
if(Set.arg[0].empty() || Set.defaultarg.empty())
|
||||
return true;
|
||||
return false;
|
||||
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());
|
||||
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());
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
||||
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) {
|
||||
log_prepare("logfile.txt",this);
|
||||
log("\n");
|
||||
log("");
|
||||
log("--- Initializing Instance ---");
|
||||
|
||||
if(_confdir.empty())
|
||||
@ -242,7 +242,13 @@ SCPDatabase& PseuInstance::GetSCPDatabase(std::string 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()
|
||||
{
|
||||
|
||||
@ -72,10 +72,8 @@ class PseuInstance
|
||||
void SetSessionKey(BigNumber key) { _sessionkey = key; }
|
||||
BigNumber GetSessionKey(void) { return _sessionkey; }
|
||||
void SetError(void) { _error = true; }
|
||||
SCPDatabase& GetSCPDatabase(std::string);
|
||||
|
||||
|
||||
|
||||
SCPDatabase& GetSCPDatabase(std::string);
|
||||
bool HasSCPDatabase(std::string);
|
||||
|
||||
bool Init();
|
||||
void SaveAllCache(void);
|
||||
@ -86,7 +84,6 @@ class PseuInstance
|
||||
void Update(void);
|
||||
void Sleep(uint32 msecs);
|
||||
|
||||
|
||||
bool createWorldSession;
|
||||
|
||||
private:
|
||||
|
||||
@ -50,4 +50,25 @@ uint32 SCPDatabase::LoadFromFile(char *fn)
|
||||
}
|
||||
fh.close();
|
||||
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
|
||||
{
|
||||
public:
|
||||
std::string GetString(std::string entry) { return _map[entry]; }
|
||||
uint64 GetInteger(std::string entry) { return toInt(_map[entry]); }
|
||||
double GetDouble(std::string entry) { return strtod(_map[entry].c_str(),NULL); }
|
||||
std::string GetString(std::string);
|
||||
uint64 GetInteger(std::string entry) { return toInt(GetString(entry)); }
|
||||
double GetDouble(std::string entry) { return strtod(GetString(entry).c_str(),NULL); }
|
||||
void Set(std::string entry,std::string value) { _map[entry]=value; }
|
||||
bool HasEntry(std::string);
|
||||
|
||||
private:
|
||||
SCPEntryMap _map;
|
||||
@ -30,6 +31,7 @@ class SCPDatabase
|
||||
{
|
||||
public:
|
||||
SCPField& GetField(uint32 id) { return _map[id]; }
|
||||
bool HasField(uint32 id);
|
||||
uint32 LoadFromFile(char*);
|
||||
|
||||
private:
|
||||
|
||||
@ -161,6 +161,9 @@
|
||||
<File
|
||||
RelativePath=".\Client\DefScriptInterface.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Client\DefScriptInterfaceInclude.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Client\HelperDefs.h">
|
||||
</File>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user