* fixed DefScript tohex function to work with numbers up to 2^64
* fixed a bug that allowed to execute scripts via ingame commands without any permission * added DefScript functions substr, getplayerperm, getscriptperm
This commit is contained in:
parent
c8015e9929
commit
74ded46daa
@ -81,6 +81,7 @@ void DefScriptPackage::_InitFunctions(void)
|
||||
AddFunc("and",&DefScriptPackage::func_and);
|
||||
AddFunc("or",&DefScriptPackage::func_or);
|
||||
AddFunc("xor",&DefScriptPackage::func_xor);
|
||||
AddFunc("substr",&DefScriptPackage::func_substr);
|
||||
}
|
||||
|
||||
void DefScriptPackage::AddFunc(std::string n,DefReturnResult (DefScriptPackage::*f)(CmdSet& Set))
|
||||
@ -688,7 +689,7 @@ DefXChgResult DefScriptPackage::ReplaceVars(std::string str, CmdSet *pSet, unsig
|
||||
bLen=closingBracket-openingBracket-1;
|
||||
subStr=str.substr(openingBracket+1,bLen);
|
||||
//printf("SUBSTR: \"%s\"\n",subStr.c_str());
|
||||
xchg=ReplaceVars(subStr,pSet,nextVar,true);
|
||||
xchg=ReplaceVars(subStr,pSet,nextVar,run_embedded);
|
||||
if( nextVar==DEFSCRIPT_NONE && hasVar && xchg.changed )
|
||||
{
|
||||
str.erase(openingBracket+1,subStr.length());
|
||||
|
||||
@ -172,7 +172,7 @@ private:
|
||||
DefReturnResult func_and(CmdSet&);
|
||||
DefReturnResult func_or(CmdSet&);
|
||||
DefReturnResult func_xor(CmdSet&);
|
||||
|
||||
DefReturnResult func_substr(CmdSet&);
|
||||
// setup own function declarations here
|
||||
# include "DefScriptInterfaceInclude.h"
|
||||
|
||||
|
||||
@ -368,32 +368,22 @@ DefReturnResult DefScriptPackage::func_isset(CmdSet& Set)
|
||||
return variables.Exists(Set.defaultarg);
|
||||
}
|
||||
|
||||
// TODO: fix this funtion to work with large values up to (0xFFFF FFFF FFFF FFFF = 2^64)
|
||||
DefReturnResult DefScriptPackage::func_tohex(CmdSet& Set)
|
||||
{
|
||||
DefReturnResult r;
|
||||
char buf[50];
|
||||
ldbl d=toNumber(Set.defaultarg);
|
||||
bool negative=d<0;
|
||||
if(stringToLower(Set.arg[0])=="abs")
|
||||
{
|
||||
negative=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
d=fabs(d);
|
||||
}
|
||||
uint64 u=(uint64)floor(d);
|
||||
|
||||
bool full=stringToLower(Set.arg[0])=="full";
|
||||
uint64 u=toUint64(Set.defaultarg);
|
||||
#if COMPILER == COMPILER_MICROSOFT
|
||||
sprintf(buf,"%016I64X",u);
|
||||
#else
|
||||
sprintf(buf,"%016llX",u);
|
||||
#endif
|
||||
std::string str=buf;
|
||||
while(str.length() && str.at(0)=='0')
|
||||
str.erase(0,1);
|
||||
r.ret = negative ? (std::string("-0x").append(str)) : std::string("0x").append(str);
|
||||
if(!full)
|
||||
while(str.length() && str.at(0)=='0')
|
||||
str.erase(0,1);
|
||||
r.ret = std::string("0x").append(str);
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -419,3 +409,15 @@ DefReturnResult DefScriptPackage::func_xor(CmdSet& Set)
|
||||
return (isTrue(Set.defaultarg) && isTrue(Set.arg[0])) || ( (!isTrue(Set.defaultarg)) && (!isTrue(Set.arg[0]) ) );
|
||||
}
|
||||
|
||||
DefReturnResult DefScriptPackage::func_substr(CmdSet& Set)
|
||||
{
|
||||
DefReturnResult r;
|
||||
unsigned int start,len;
|
||||
len=(unsigned int)toNumber(Set.arg[0]);
|
||||
start=(unsigned int)toNumber(Set.arg[1]);
|
||||
if(start+len<Set.defaultarg.length())
|
||||
len=Set.defaultarg.length()-start;
|
||||
r.ret=Set.defaultarg.substr(start,len);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
@ -126,7 +126,7 @@ uint64 DefScriptTools::toUint64(std::string str)
|
||||
else
|
||||
num = atoi64(str.c_str());
|
||||
if(negative)
|
||||
num = (uint64)(-1) - num;
|
||||
num = (uint64)(-1) - num; // is this correct?
|
||||
return num;
|
||||
}
|
||||
|
||||
|
||||
@ -41,6 +41,8 @@ void DefScriptPackage::_InitDefScriptInterface(void)
|
||||
AddFunc("getitemprotovalue",&DefScriptPackage::SCGetName);
|
||||
AddFunc("getobjecttype",&DefScriptPackage::SCGetObjectType);
|
||||
AddFunc("objectknown",&DefScriptPackage::SCObjectKnown);
|
||||
AddFunc("getplayerperm",&DefScriptPackage::SCGetPlayerPerm);
|
||||
AddFunc("getscriptperm",&DefScriptPackage::SCGetScriptPerm);
|
||||
}
|
||||
|
||||
DefReturnResult DefScriptPackage::SCshdn(CmdSet& Set)
|
||||
@ -458,6 +460,28 @@ DefReturnResult DefScriptPackage::SCObjectKnown(CmdSet& Set)
|
||||
return o!=NULL;
|
||||
}
|
||||
|
||||
DefReturnResult DefScriptPackage::SCGetPlayerPerm(CmdSet& Set)
|
||||
{
|
||||
DefReturnResult r;
|
||||
uint8 perm=0;
|
||||
for (std::map<std::string,unsigned char>::iterator i = my_usrPermissionMap.begin(); i != my_usrPermissionMap.end(); i++)
|
||||
if(i->first == Set.defaultarg)
|
||||
perm = i->second;
|
||||
r.ret = toString(perm);
|
||||
return r;
|
||||
}
|
||||
|
||||
DefReturnResult DefScriptPackage::SCGetScriptPerm(CmdSet& Set)
|
||||
{
|
||||
DefReturnResult r;
|
||||
uint8 perm=0;
|
||||
for (std::map<std::string,unsigned char>::iterator i = scriptPermissionMap.begin(); i != scriptPermissionMap.end(); i++)
|
||||
if(i->first == Set.defaultarg)
|
||||
perm = i->second;
|
||||
r.ret = toString(perm);
|
||||
return r;
|
||||
}
|
||||
|
||||
DefReturnResult DefScriptPackage::SCGetItemProtoValue(CmdSet& Set)
|
||||
{
|
||||
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
||||
|
||||
@ -33,5 +33,7 @@ DefReturnResult SCGetEntry(CmdSet&);
|
||||
DefReturnResult SCGetItemProtoValue(CmdSet&);
|
||||
DefReturnResult SCGetObjectType(CmdSet&);
|
||||
DefReturnResult SCObjectKnown(CmdSet&);
|
||||
DefReturnResult SCGetPlayerPerm(CmdSet&);
|
||||
DefReturnResult SCGetScriptPerm(CmdSet&);
|
||||
|
||||
#endif
|
||||
Loading…
x
Reference in New Issue
Block a user