* more updates around DefScript stuff
* added some databases to make a start * misc stuff * added macro "@myrace"
This commit is contained in:
parent
2f459f9d0f
commit
d9a56b2a00
@ -87,4 +87,8 @@ showmyopcodes=0
|
||||
// DO NOT put 1 here!
|
||||
disablespellcheck=0
|
||||
|
||||
// will be used for all sendchatmessage calls. remove number/leave blank
|
||||
// to use the default language for your race (defined in race.scp)
|
||||
defaultlang=0
|
||||
|
||||
|
||||
|
||||
32
bin/data/class.scp
Normal file
32
bin/data/class.scp
Normal file
@ -0,0 +1,32 @@
|
||||
[1]
|
||||
name=Warrior
|
||||
|
||||
[2]
|
||||
name=Paladin
|
||||
|
||||
[3]
|
||||
name=Hunter
|
||||
|
||||
[4]
|
||||
name=Rogue
|
||||
|
||||
[5]
|
||||
name=Priest
|
||||
|
||||
[6]
|
||||
name=UNKNOWN CLASS(6)
|
||||
|
||||
[7]
|
||||
name=Shaman
|
||||
|
||||
[8]
|
||||
name=Mage
|
||||
|
||||
[9]
|
||||
name=Paladin
|
||||
|
||||
[10]
|
||||
name=UNKNOWN CLASS(10)
|
||||
|
||||
[11]
|
||||
name=Druid
|
||||
10
bin/data/gender.scp
Normal file
10
bin/data/gender.scp
Normal file
@ -0,0 +1,10 @@
|
||||
// define names of genders
|
||||
|
||||
[0]
|
||||
name=male
|
||||
|
||||
[1]
|
||||
name=female
|
||||
|
||||
[2]
|
||||
name=none
|
||||
41
bin/data/language.scp
Normal file
41
bin/data/language.scp
Normal file
@ -0,0 +1,41 @@
|
||||
[0]
|
||||
name=Global
|
||||
|
||||
[1]
|
||||
name=Orcish
|
||||
|
||||
[2]
|
||||
name=Darnassian
|
||||
|
||||
[3]
|
||||
name=Taurahe
|
||||
|
||||
[6]
|
||||
name=Dwarvish
|
||||
|
||||
[7]
|
||||
name=Common
|
||||
|
||||
[8]
|
||||
name=Demonic
|
||||
|
||||
[9]
|
||||
name=Titan
|
||||
|
||||
[10]
|
||||
name=Thalassian
|
||||
|
||||
[11]
|
||||
name=Draconic
|
||||
|
||||
[12]
|
||||
name=Kalimag
|
||||
|
||||
[13]
|
||||
name=Gnomish
|
||||
|
||||
[14]
|
||||
name=Troll
|
||||
|
||||
[33]
|
||||
name=Gutterspeak
|
||||
130
bin/data/map.scp
Normal file
130
bin/data/map.scp
Normal file
@ -0,0 +1,130 @@
|
||||
[0]
|
||||
name=Azeroth
|
||||
|
||||
[1]
|
||||
name=Kalimdor
|
||||
|
||||
[2]
|
||||
name=UnderMine
|
||||
|
||||
[13]
|
||||
name=Test zone
|
||||
|
||||
[17]
|
||||
name=Kalidar
|
||||
|
||||
[30]
|
||||
name=Alterac Valley
|
||||
|
||||
[33]
|
||||
name=Shadowfang Keep Instance
|
||||
|
||||
[34]
|
||||
name=The Stockade Instance
|
||||
|
||||
[35]
|
||||
name=Stormwind Prizon
|
||||
|
||||
[36]
|
||||
name=Deadmines Instance
|
||||
|
||||
[37]
|
||||
name=Plains of Snow
|
||||
|
||||
[43]
|
||||
name=Wailing Caverns Instance
|
||||
[44]
|
||||
name=Monastery Interior
|
||||
|
||||
[47]
|
||||
name=Razorfen Kraul Instance
|
||||
|
||||
[48]
|
||||
name=Blackfathom Deeps Instance
|
||||
|
||||
[70]
|
||||
name=Uldaman Instance
|
||||
|
||||
[90]
|
||||
name=Gnomeregan Instance
|
||||
|
||||
[109]
|
||||
name=Sunken Temple Instance
|
||||
|
||||
[129]
|
||||
name=Razorfen Downs Instance
|
||||
|
||||
[150]
|
||||
name=Outland
|
||||
|
||||
[169]
|
||||
name=Emerald Forest
|
||||
|
||||
[189]
|
||||
name=Scarlet Monastery Instance
|
||||
|
||||
[209]
|
||||
name=Zul\'Farrak Instance
|
||||
|
||||
[229]
|
||||
name=Blackrock Spire Instance
|
||||
|
||||
[230]
|
||||
name=Blackrock Depths Instance
|
||||
|
||||
[249]
|
||||
name=Onyxia\'s Lair Instance
|
||||
|
||||
[269]
|
||||
name=Caverns of Time
|
||||
|
||||
[289]
|
||||
name=Scholomance Instance
|
||||
|
||||
[309]
|
||||
name=Zul'Gurub Instance
|
||||
|
||||
[329]
|
||||
name=Stratholme Instance
|
||||
|
||||
[349]
|
||||
name=Mauradon Instance
|
||||
|
||||
[369]
|
||||
name=Deeprun Tram
|
||||
|
||||
[389]
|
||||
name=Ragefire Chasm Instance
|
||||
|
||||
[409]
|
||||
name=The Molten Core Instance
|
||||
|
||||
[429]
|
||||
name=Dire Maul Instance
|
||||
|
||||
[449]
|
||||
name=Alliance PVP Barracks
|
||||
|
||||
[450]
|
||||
name=Horde PVP Barracks
|
||||
|
||||
[451]
|
||||
name=Development Land
|
||||
|
||||
[469]
|
||||
name=Blackwing Lair Instance
|
||||
|
||||
[489]
|
||||
name=Warsong Gulch
|
||||
|
||||
[509]
|
||||
name=Ruins of Ahn'Qiraj Instance
|
||||
|
||||
[529]
|
||||
name=Arathi Basin
|
||||
|
||||
[531]
|
||||
name=Temple of Ahn'Qiraj Instance
|
||||
|
||||
[533]
|
||||
name=Naxxramas Instance
|
||||
31
bin/data/race.scp
Normal file
31
bin/data/race.scp
Normal file
@ -0,0 +1,31 @@
|
||||
[1]
|
||||
defaultlang=7
|
||||
name=Human
|
||||
|
||||
[2]
|
||||
defaultlang=1
|
||||
name=Orc
|
||||
|
||||
[3]
|
||||
defaultlang=7
|
||||
name=Dwarf
|
||||
|
||||
[4]
|
||||
defaultlang=7
|
||||
name=Night Elf
|
||||
|
||||
[5]
|
||||
defaultlang=1
|
||||
name=Undead
|
||||
|
||||
[6]
|
||||
defaultlang=1
|
||||
name=Tauren
|
||||
|
||||
[7]
|
||||
defaultlang=7
|
||||
name=Gnome
|
||||
|
||||
[8]
|
||||
defaultlang=1
|
||||
name=Troll
|
||||
130
bin/data/zone.scp
Normal file
130
bin/data/zone.scp
Normal file
@ -0,0 +1,130 @@
|
||||
[0]
|
||||
name=Azeroth
|
||||
|
||||
[1]
|
||||
name=Kalimdor
|
||||
|
||||
[2]
|
||||
name=UnderMine
|
||||
|
||||
[13]
|
||||
name=Test zone
|
||||
|
||||
[17]
|
||||
name=Kalidar
|
||||
|
||||
[30]
|
||||
name=Alterac Valley
|
||||
|
||||
[33]
|
||||
name=Shadowfang Keep Instance
|
||||
|
||||
[34]
|
||||
name=The Stockade Instance
|
||||
|
||||
[35]
|
||||
name=Stormwind Prizon
|
||||
|
||||
[36]
|
||||
name=Deadmines Instance
|
||||
|
||||
[37]
|
||||
name=Plains of Snow
|
||||
|
||||
[43]
|
||||
name=Wailing Caverns Instance
|
||||
[44]
|
||||
name=Monastery Interior
|
||||
|
||||
[47]
|
||||
name=Razorfen Kraul Instance
|
||||
|
||||
[48]
|
||||
name=Blackfathom Deeps Instance
|
||||
|
||||
[70]
|
||||
name=Uldaman Instance
|
||||
|
||||
[90]
|
||||
name=Gnomeregan Instance
|
||||
|
||||
[109]
|
||||
name=Sunken Temple Instance
|
||||
|
||||
[129]
|
||||
name=Razorfen Downs Instance
|
||||
|
||||
[150]
|
||||
name=Outland
|
||||
|
||||
[169]
|
||||
name=Emerald Forest
|
||||
|
||||
[189]
|
||||
name=Scarlet Monastery Instance
|
||||
|
||||
[209]
|
||||
name=Zul\'Farrak Instance
|
||||
|
||||
[229]
|
||||
name=Blackrock Spire Instance
|
||||
|
||||
[230]
|
||||
name=Blackrock Depths Instance
|
||||
|
||||
[249]
|
||||
name=Onyxia\'s Lair Instance
|
||||
|
||||
[269]
|
||||
name=Caverns of Time
|
||||
|
||||
[289]
|
||||
name=Scholomance Instance
|
||||
|
||||
[309]
|
||||
name=Zul'Gurub Instance
|
||||
|
||||
[329]
|
||||
name=Stratholme Instance
|
||||
|
||||
[349]
|
||||
name=Mauradon Instance
|
||||
|
||||
[369]
|
||||
name=Deeprun Tram
|
||||
|
||||
[389]
|
||||
name=Ragefire Chasm Instance
|
||||
|
||||
[409]
|
||||
name=The Molten Core Instance
|
||||
|
||||
[429]
|
||||
name=Dire Maul Instance
|
||||
|
||||
[449]
|
||||
name=Alliance PVP Barracks
|
||||
|
||||
[450]
|
||||
name=Horde PVP Barracks
|
||||
|
||||
[451]
|
||||
name=Development Land
|
||||
|
||||
[469]
|
||||
name=Blackwing Lair Instance
|
||||
|
||||
[489]
|
||||
name=Warsong Gulch
|
||||
|
||||
[509]
|
||||
name=Ruins of Ahn'Qiraj Instance
|
||||
|
||||
[529]
|
||||
name=Arathi Basin
|
||||
|
||||
[531]
|
||||
name=Temple of Ahn'Qiraj Instance
|
||||
|
||||
[533]
|
||||
name=Naxxramas Instance
|
||||
@ -2,8 +2,14 @@
|
||||
|
||||
LOG * Loading SCP data storages...
|
||||
|
||||
// TODO: load stuff here
|
||||
// example:
|
||||
// LOADSCP,test data/test.scp
|
||||
|
||||
LOADSCP,class data/class.scp
|
||||
LOADSCP,gender data/gender.scp
|
||||
LOADSCP,language data/language.scp
|
||||
LOADSCP,map data/map.scp
|
||||
LOADSCP,race data/race.scp
|
||||
|
||||
LOG * SCP loaded.
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
SET,player ${@thiswhisper_name}
|
||||
SET,lang ${@0}
|
||||
DEFAULT,lang ${@thiswhisper_lang}
|
||||
DEFAULT,lang 0
|
||||
SET,msg ${@def}
|
||||
|
||||
WHISPER,{${player}},{${lang}} ${msg}
|
||||
|
||||
@ -3,7 +3,8 @@
|
||||
SET,lang ${@0}
|
||||
SET,msg ${@def}
|
||||
|
||||
default,lang 0
|
||||
DEFAULT,#DEFAULTLANG ?{GETSCPVALUE,race,{${@myrace}} defaultlang}
|
||||
DEFAULT,lang ${#DEFAULTLANG}
|
||||
|
||||
LOGDEBUG * Saying '${msg}' in lang ${lang}
|
||||
|
||||
|
||||
@ -5,7 +5,8 @@ SET,msg ${@def}
|
||||
SET,player ${@0}
|
||||
SET,lang ${@1}
|
||||
|
||||
DEFAULT,lang 0
|
||||
DEFAULT,#DEFAULTLANG ?{GETSCPVALUE,race,{${@myrace}} defaultlang}
|
||||
DEFAULT,lang ${#DEFAULTLANG}
|
||||
|
||||
LOGDEBUG * Whisp to '{${player}}' '{${msg}}' in lang '${lang}'
|
||||
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
#permission=255
|
||||
|
||||
// setup some default values
|
||||
SET,lang ${@0}
|
||||
SET,msg ${@def}
|
||||
|
||||
default,lang 0
|
||||
DEFAULT,#DEFAULTLANG ?{GETSCPVALUE,race,{${@myrace}} defaultlang}
|
||||
DEFAULT,lang ${#DEFAULTLANG}
|
||||
|
||||
LOGDEBUG * Yelling '${msg}' in lang ${lang}
|
||||
|
||||
|
||||
@ -61,6 +61,15 @@ void DefScriptPackage::_InitFunctions(void)
|
||||
AddFunc("bitxor",&DefScriptPackage::func_bitxor);
|
||||
AddFunc("addevent",&DefScriptPackage::func_addevent);
|
||||
AddFunc("removeevent",&DefScriptPackage::func_removeevent);
|
||||
AddFunc("abs",&DefScriptPackage::func_abs);
|
||||
AddFunc("greater",&DefScriptPackage::func_bigger);
|
||||
AddFunc("bigger",&DefScriptPackage::func_bigger);
|
||||
AddFunc("equal",&DefScriptPackage::func_equal);
|
||||
AddFunc("isset",&DefScriptPackage::func_isset);
|
||||
AddFunc("not",&DefScriptPackage::func_not);
|
||||
AddFunc("smaller",&DefScriptPackage::func_smaller);
|
||||
AddFunc("strlen",&DefScriptPackage::func_strlen);
|
||||
AddFunc("tohex",&DefScriptPackage::func_tohex);
|
||||
}
|
||||
|
||||
void DefScriptPackage::AddFunc(std::string n,DefReturnResult (DefScriptPackage::*f)(CmdSet& Set))
|
||||
|
||||
@ -154,6 +154,14 @@ private:
|
||||
DefReturnResult func_bitxor(CmdSet&);
|
||||
DefReturnResult func_addevent(CmdSet&);
|
||||
DefReturnResult func_removeevent(CmdSet&);
|
||||
DefReturnResult func_abs(CmdSet&);
|
||||
DefReturnResult func_bigger(CmdSet&);
|
||||
DefReturnResult func_equal(CmdSet&);
|
||||
DefReturnResult func_isset(CmdSet&);
|
||||
DefReturnResult func_not(CmdSet&);
|
||||
DefReturnResult func_smaller(CmdSet&);
|
||||
DefReturnResult func_strlen(CmdSet&);
|
||||
DefReturnResult func_tohex(CmdSet&);
|
||||
|
||||
// setup own function declarations here
|
||||
# include "DefScriptInterfaceInclude.h"
|
||||
|
||||
@ -14,6 +14,7 @@ typedef unsigned __int64 uint64;
|
||||
#else
|
||||
typedef __int64_t int64;
|
||||
typedef unsigned __int64_t uint64;
|
||||
// TODO: correct ATOI64 for linux if necessary
|
||||
#endif
|
||||
|
||||
enum VariableType
|
||||
@ -23,4 +24,6 @@ enum VariableType
|
||||
DEFSCRIPT_FUNC
|
||||
};
|
||||
|
||||
typedef long double ldbl;
|
||||
|
||||
#endif
|
||||
@ -170,8 +170,8 @@ 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);
|
||||
ldbl a=toNumber(variables.Get(vname));
|
||||
ldbl b=toNumber(Set.defaultarg);
|
||||
a+=b;
|
||||
variables.Set(vname,toString(a));
|
||||
r.ret=toString(a);
|
||||
@ -187,8 +187,8 @@ 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);
|
||||
ldbl a=toNumber(variables.Get(vname));
|
||||
ldbl b=toNumber(Set.defaultarg);
|
||||
a-=b;
|
||||
variables.Set(vname,toString(a));
|
||||
r.ret=toString(a);
|
||||
@ -204,8 +204,8 @@ 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);
|
||||
ldbl a=toNumber(variables.Get(vname));
|
||||
ldbl b=toNumber(Set.defaultarg);
|
||||
a*=b;
|
||||
variables.Set(vname,toString(a));
|
||||
r.ret=toString(a);
|
||||
@ -221,8 +221,8 @@ 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);
|
||||
ldbl a=toNumber(variables.Get(vname));
|
||||
ldbl b=toNumber(Set.defaultarg);
|
||||
if(b==0)
|
||||
a=0;
|
||||
else
|
||||
@ -261,8 +261,8 @@ 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);
|
||||
ldbl a=toNumber(variables.Get(vname));
|
||||
ldbl b=toNumber(Set.defaultarg);
|
||||
a=pow(a,b);
|
||||
variables.Set(vname,toString(a));
|
||||
r.ret=toString(a);
|
||||
@ -322,14 +322,84 @@ DefReturnResult DefScriptPackage::func_bitxor(CmdSet& Set)
|
||||
|
||||
DefReturnResult DefScriptPackage::func_addevent(CmdSet& Set)
|
||||
{
|
||||
DefReturnResult r;
|
||||
GetEventMgr()->Add(Set.arg[0],Set.defaultarg,(clock_t)toNumber(Set.arg[1]),Set.myname.c_str());
|
||||
return r;
|
||||
return true;
|
||||
}
|
||||
|
||||
DefReturnResult DefScriptPackage::func_removeevent(CmdSet& Set)
|
||||
{
|
||||
DefReturnResult r;
|
||||
GetEventMgr()->Remove(Set.defaultarg);
|
||||
return true;
|
||||
}
|
||||
|
||||
DefReturnResult DefScriptPackage::func_strlen(CmdSet& Set)
|
||||
{
|
||||
DefReturnResult r;
|
||||
r.ret=toString((uint64)Set.defaultarg.length());
|
||||
return r;
|
||||
}
|
||||
|
||||
DefReturnResult DefScriptPackage::func_equal(CmdSet& Set)
|
||||
{
|
||||
if(stringToLower(Set.arg[1])=="ignore")
|
||||
{
|
||||
return stringToLower(Set.defaultarg)==stringToLower(Set.arg[0]);
|
||||
}
|
||||
return Set.defaultarg==Set.arg[0];
|
||||
}
|
||||
|
||||
DefReturnResult DefScriptPackage::func_smaller(CmdSet& Set)
|
||||
{
|
||||
return toNumber(Set.defaultarg) < toNumber(Set.arg[0]);
|
||||
}
|
||||
|
||||
DefReturnResult DefScriptPackage::func_bigger(CmdSet& Set)
|
||||
{
|
||||
return toNumber(Set.defaultarg) > toNumber(Set.arg[0]);
|
||||
}
|
||||
|
||||
DefReturnResult DefScriptPackage::func_not(CmdSet& Set)
|
||||
{
|
||||
return !isTrue(Set.defaultarg);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
#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);
|
||||
return r;
|
||||
}
|
||||
|
||||
DefReturnResult DefScriptPackage::func_abs(CmdSet& Set)
|
||||
{
|
||||
DefReturnResult r;
|
||||
r.ret=toString(fabs(toNumber(Set.defaultarg)));
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ std::string DefScriptTools::stringToUpper(std::string s)
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string DefScriptTools::toString(double num)
|
||||
std::string DefScriptTools::toString(ldbl num)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << num;
|
||||
@ -35,15 +35,16 @@ std::string DefScriptTools::toString(uint64 num)
|
||||
ss << num;
|
||||
return ss.str();
|
||||
}
|
||||
// convert a string into double
|
||||
// convert a string into ldbl
|
||||
// valid input formats:
|
||||
// normal numbers: 5439
|
||||
// hex numbers: 0xa56ff, 0XFF, 0xDEADBABE, etc (must begin with 0x)
|
||||
// float numbers: 99.65, 0.025
|
||||
// negative numbers: -100, -0x3d, -55.123
|
||||
double DefScriptTools::toNumber(std::string str)
|
||||
ldbl DefScriptTools::toNumber(std::string str)
|
||||
{
|
||||
double num;
|
||||
ldbl num=0;
|
||||
uint64 u=0;
|
||||
bool negative=false;
|
||||
if(str.empty())
|
||||
return 0;
|
||||
@ -52,19 +53,90 @@ double DefScriptTools::toNumber(std::string str)
|
||||
str.erase(0,1);
|
||||
negative=true;
|
||||
}
|
||||
if(str.find('.')==std::string::npos)
|
||||
unsigned int ppos=str.find('.');
|
||||
str=stringToUpper(str);
|
||||
|
||||
if(str.length() > 2 && str[0]=='0' && str[1]=='X')
|
||||
{
|
||||
str=stringToUpper(str);
|
||||
if(str.length() > 2 && str[0]=='0' && str[1]=='X')
|
||||
num = strtoul(&(str.c_str()[2]),NULL,16);
|
||||
else
|
||||
num = strtoul(str.c_str(),NULL,10);
|
||||
std::string lo(str.c_str()+2);
|
||||
std::string hi;
|
||||
while(lo.length()>8)
|
||||
{
|
||||
hi+=lo.at(0);
|
||||
lo.erase(0,1);
|
||||
}
|
||||
unsigned int hibits,lobits;
|
||||
hibits=strtoul(hi.c_str(),NULL,16);
|
||||
lobits=strtoul(lo.c_str(),NULL,16);
|
||||
u|=hibits;
|
||||
u<<=32;
|
||||
u|=lobits;
|
||||
}
|
||||
else
|
||||
u = atoi64(str.c_str());
|
||||
|
||||
if(ppos!=std::string::npos)
|
||||
{
|
||||
num = strtod(str.c_str(),NULL);
|
||||
std::string mantissa("0.");
|
||||
mantissa+=str.c_str()+ppos;
|
||||
num=(ldbl)strtod(mantissa.c_str(),NULL);
|
||||
}
|
||||
num=(unsigned long double)num + u;
|
||||
|
||||
if(negative)
|
||||
num = -num;
|
||||
return num;
|
||||
}
|
||||
|
||||
bool DefScriptTools::isTrue(std::string s)
|
||||
{
|
||||
if(s.empty() || s=="false" || s=="0")
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64 DefScriptTools::toUint64(std::string str)
|
||||
{
|
||||
bool negative=false;
|
||||
uint64 num;
|
||||
if(str.empty())
|
||||
return 0;
|
||||
if(str[0]=='-')
|
||||
{
|
||||
str.erase(0,1);
|
||||
negative=true;
|
||||
}
|
||||
str=stringToUpper(str);
|
||||
if(str.length() > 2 && str[0]=='0' && str[1]=='X')
|
||||
{
|
||||
std::string lo(str.c_str()+2);
|
||||
std::string hi;
|
||||
while(lo.length()>8)
|
||||
{
|
||||
hi+=lo.at(0);
|
||||
lo.erase(0,1);
|
||||
}
|
||||
unsigned int hibits,lobits;
|
||||
hibits=strtoul(hi.c_str(),NULL,16);
|
||||
lobits=strtoul(lo.c_str(),NULL,16);
|
||||
num|=hibits;
|
||||
num<<=32;
|
||||
num|=lobits;
|
||||
}
|
||||
else
|
||||
num = atoi64(str.c_str());
|
||||
if(negative)
|
||||
num = (uint64)(-1) - num;
|
||||
return num;
|
||||
}
|
||||
|
||||
uint64 DefScriptTools::atoi64(const char *str)
|
||||
{
|
||||
#if COMPILER == COMPILER_MICROSOFT
|
||||
__int64 tmp = _atoi64(str);
|
||||
return tmp;
|
||||
#else
|
||||
#error "Fix Me!"
|
||||
//return _atoi64(str);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -5,9 +5,12 @@ namespace DefScriptTools
|
||||
{
|
||||
std::string stringToUpper(std::string);
|
||||
std::string stringToLower(std::string);
|
||||
std::string toString(double);
|
||||
std::string toString(ldbl);
|
||||
std::string toString(uint64);
|
||||
double toNumber(std::string);
|
||||
ldbl toNumber(std::string);
|
||||
bool isTrue(std::string);
|
||||
uint64 toUint64(std::string);
|
||||
uint64 atoi64(const char*);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -31,10 +31,12 @@ void DefScriptPackage::_InitDefScriptInterface(void)
|
||||
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);
|
||||
AddFunc("scpexists",&DefScriptPackage::SCScpExists);
|
||||
AddFunc("scpsectionexists",&DefScriptPackage::SCScpSectionExists);
|
||||
AddFunc("scpentryexists",&DefScriptPackage::SCScpEntryExists);
|
||||
AddFunc("getscpvalue",&DefScriptPackage::SCGetScpValue);
|
||||
AddFunc("getplayerguid",&DefScriptPackage::SCGetPlayerGuid);
|
||||
AddFunc("getname",&DefScriptPackage::SCGetName);
|
||||
}
|
||||
|
||||
DefReturnResult DefScriptPackage::SCshdn(CmdSet& Set)
|
||||
@ -339,6 +341,57 @@ DefReturnResult DefScriptPackage::SCGetScpValue(CmdSet& Set)
|
||||
return r;
|
||||
}
|
||||
|
||||
DefReturnResult DefScriptPackage::SCGetPlayerGuid(CmdSet& Set)
|
||||
{
|
||||
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
||||
{
|
||||
logerror("Invalid Script call: SCGetPlayerGuid: WorldSession not valid");
|
||||
DEF_RETURN_ERROR;
|
||||
}
|
||||
DefReturnResult r;
|
||||
if(Set.defaultarg.empty())
|
||||
{
|
||||
r.ret="0";
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64 guid=((PseuInstance*)parentMethod)->GetWSession()->plrNameCache.GetGuid(Set.defaultarg);
|
||||
r.ret=toString(guid);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
DefReturnResult DefScriptPackage::SCGetName(CmdSet& Set)
|
||||
{
|
||||
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
|
||||
{
|
||||
logerror("Invalid Script call: SCGetName: WorldSession not valid");
|
||||
DEF_RETURN_ERROR;
|
||||
}
|
||||
DefReturnResult r;
|
||||
uint64 guid=DefScriptTools::toNumber(Set.defaultarg);
|
||||
r.ret="Unknown Entity";
|
||||
if(!guid)
|
||||
{
|
||||
return r;
|
||||
}
|
||||
else
|
||||
{
|
||||
Object *o=((PseuInstance*)parentMethod)->GetWSession()->objmgr.GetObj(guid);
|
||||
if(o->GetTypeId()==TYPEID_ITEM || o->GetTypeId()==TYPEID_CONTAINER)
|
||||
{
|
||||
ItemProto *proto=((PseuInstance*)parentMethod)->GetWSession()->objmgr.GetItemProto(o->GetEntry());
|
||||
r.ret=proto->Name[0]; // and whats with Name[1] - Name[3]?
|
||||
}
|
||||
else if(o->GetTypeId()==TYPEID_UNIT || o->GetTypeId()==TYPEID_PLAYER || o->GetTypeId()==TYPEID_GAMEOBJECT || o->GetTypeId()==TYPEID_CORPSE)
|
||||
{
|
||||
r.ret=((WorldObject*)o)->GetName();
|
||||
}
|
||||
// TODO: add support for gameobjects etc.
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
void DefScriptPackage::My_LoadUserPermissions(VarSet &vs)
|
||||
{
|
||||
static char *prefix = "USERS::";
|
||||
@ -370,7 +423,7 @@ void DefScriptPackage::My_Run(std::string line, std::string username)
|
||||
// temp fix to prevent users from executing scripts via return values exploit. example:
|
||||
// -out ?{say .shutdown}
|
||||
// note that the following code can still be executed:
|
||||
// -out ${q}?{say .shutdown}
|
||||
// -out ${q}{say .shutdown}
|
||||
// where var q = "?"
|
||||
if(usrperm < 255 && line.find("?{")!=std::string::npos)
|
||||
{
|
||||
|
||||
@ -27,5 +27,7 @@ DefReturnResult SCScpExists(CmdSet&);
|
||||
DefReturnResult SCScpSectionExists(CmdSet&);
|
||||
DefReturnResult SCScpEntryExists(CmdSet&);
|
||||
DefReturnResult SCGetScpValue(CmdSet&);
|
||||
DefReturnResult SCGetName(CmdSet&);
|
||||
DefReturnResult SCGetPlayerGuid(CmdSet&);
|
||||
|
||||
#endif
|
||||
@ -354,6 +354,7 @@ void WorldSession::_HandleCharEnumOpcode(WorldPacket& recvPacket)
|
||||
{
|
||||
char_found=true;
|
||||
_myGUID=plr[i]._guid;
|
||||
GetInstance()->GetScripts()->variables.Set("@myrace",toString(plr[i]._race));
|
||||
playerNum = i;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user