diff --git a/bin/scripts/_startup.def b/bin/scripts/_startup.def index e396c85..cee92a6 100644 --- a/bin/scripts/_startup.def +++ b/bin/scripts/_startup.def @@ -7,13 +7,6 @@ LOG * DefScript StartUp [${@version_short}]... // loads & applies the configuration CONFIG -// preload the scripts, however its not important to load them now. -//they will get loaded automatically if needed -LOADALL - -// RELOADDEF myscript -// ... - // set permissions for internal functions INTERNAL_PERM diff --git a/bin/scripts/gcl.def b/bin/scripts/gcl.def new file mode 100644 index 0000000..078179a --- /dev/null +++ b/bin/scripts/gcl.def @@ -0,0 +1,3 @@ +// write leetspeak to channel generalchat (see gc.def) +#permission=0 +gc ?{toleet ${@def}} \ No newline at end of file diff --git a/bin/scripts/loadall.def b/bin/scripts/loadall.def.obsoelete similarity index 100% rename from bin/scripts/loadall.def rename to bin/scripts/loadall.def.obsoelete diff --git a/bin/scripts/sl.def b/bin/scripts/sl.def new file mode 100644 index 0000000..a0c9e88 --- /dev/null +++ b/bin/scripts/sl.def @@ -0,0 +1,3 @@ +// say leetspeak text. gmcommands can't be executed this way +#permission=0 +s,{${@0}} ?{toleet ${@def}} diff --git a/bin/scripts/slap.def b/bin/scripts/slap.def new file mode 100644 index 0000000..1021575 --- /dev/null +++ b/bin/scripts/slap.def @@ -0,0 +1,35 @@ +// purpose: let a player fly. (at least works on MaNGOS) +// args: @def: player name +// returns: guid of the targeted player, else false. empty string if we are not in the world. +#permission=100 + +// we can use this script only if we are in the world +if ?{not ${@inworld}} + logerror Can't slap anything if i am not in the world! + return +endif + +// normalize player name. first char uppercased, rest lowercased. +set,name ?{uppercase ?{substr,1 ${@def}}} +out name1: ${name} +set,len ?{strlen ${@def}} +out strlen: ${len} +sub,len 1 +out len: ${len} +append,name ?{lowercase ?{substr,${len},1 ${@def}}} +out name2: ${name} + + +// target the player. if targeting was successful, cast spell "Knockback 500". +set,t ?{target ${name}} +if ${t} + logdebug slapping player '${name}' + castspell 11027 + target 0 +else + logerror Can't target player '${name}' +endif + +unset name + +return ${t} diff --git a/bin/scripts/toleet.def b/bin/scripts/toleet.def new file mode 100644 index 0000000..c301d24 --- /dev/null +++ b/bin/scripts/toleet.def @@ -0,0 +1,95 @@ +// toleet.def +// ========== +// purpose: convert any text into leetspeak [1337sp34k] +// args: +// @def: the text to convert +// returns: leetspeak^^ + +// call it from script only +#permission=255 + +#onload + // this can be used by other scripts to check if we have loaded this script + set,#HAVE_LEET true +#endonload + +// --- Begin of main function --- + +// empty the string where the leet will be stored +set,str + +// total length of the string to convert +set,l ?{strlen ${@def}} + +// position counter +set,x 0 + +loop + + // check if we have reached the end of the string + if ?{bigger,${x} ${l}} + exitloop + endif + + // c stores current char (@def at position x); c2 is the same char but always lowercased + set,c ?{substr,1,${x} ${@def}} + set,c2 ?{lowercase ${c}} + + // conversion functions: + + // note that "+" is a variable name here! + // it will store the "new" char if c/c2 could be converted + + if ?{equal,${c2} a} + set,+ 4 + endif + if ?{equal,${c2} e} + set,+ 3 + endif + if ?{equal,${c2} i} + set,+ ! + endif + if ?{equal,${c2} l} + set,+ 1 + endif + if ?{equal,${c2} t} + set,+ 7 + endif + if ?{equal,${c2} s} + set,+ 5 + endif + if ?{equal,${c2} o} + set,+ 0 + endif + if ?{equal,${c2} f} + set,+ ph + endif + if ?{equal,${c2} h} + set,+ # + endif + if ?{equal,${c} Z} + set,+ 7 + endif + if ?{equal,${c} R} + set,+ 2 + endif + if ?{equal,${c} B} + set,+ <3 + endif + + // if var "+" is still empty, default it to our current char + default,+ ${c} + // and append it to the final output + append,str ${+} + // finally delete it again + unset + + // and increase the counter by 1 + add,x 1 +endloop + +unset l +unset x +unset c +unset c2 + +return ${str} diff --git a/src/Client/DefScript/DefScript.cpp b/src/Client/DefScript/DefScript.cpp index bdbd7bf..c8cd1b3 100644 --- a/src/Client/DefScript/DefScript.cpp +++ b/src/Client/DefScript/DefScript.cpp @@ -84,6 +84,9 @@ void DefScriptPackage::_InitFunctions(void) AddFunc("or",&DefScriptPackage::func_or); AddFunc("xor",&DefScriptPackage::func_xor); AddFunc("substr",&DefScriptPackage::func_substr); + AddFunc("uppercase",&DefScriptPackage::func_uppercase); + AddFunc("lowercase",&DefScriptPackage::func_lowercase); + AddFunc("random",&DefScriptPackage::func_random); } void DefScriptPackage::AddFunc(std::string n,DefReturnResult (DefScriptPackage::*f)(CmdSet& Set)) @@ -155,12 +158,14 @@ bool DefScriptPackage::LoadByName(std::string name){ } bool DefScriptPackage::LoadScriptFromFile(std::string fn, std::string sn){ - if(fn.empty() || sn.empty()) return false; + if(fn.empty() || sn.empty()) + return false; std::string label, value, line; std::fstream f; bool load_debug=false,load_notify=false, exec=false, cantload=false; char z; + unsigned int absline=0; f.open(fn.c_str(),std::ios_base::in); if(!f.is_open()) @@ -182,6 +187,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn, std::string sn){ break; line+=z; } + absline++; if(line.empty()) continue; // line is empty, proceed with next line @@ -274,7 +280,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn, std::string sn){ } if(mismatch || bopen) // no bracket must be left open now { - printf("DefScript: Bracket mismatch at line '%s'\n",line.c_str()); + printf("DefScript [%s:%u]: Bracket mismatch at line '%s'\n",sn.c_str(),absline,line.c_str()); continue; // continue with next line without adding the current line to script } @@ -292,7 +298,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn, std::string sn){ f.close(); if(cantload || Blocks.size()) { - printf("DefScript: Error loading script '%s'\n",sn.c_str()); + printf("DefScript: Error loading script '%s'. block mismatch?\n",sn.c_str()); DeleteScript(sn); return false; } diff --git a/src/Client/DefScript/DefScript.h b/src/Client/DefScript/DefScript.h index 1db10a3..cb70ebc 100644 --- a/src/Client/DefScript/DefScript.h +++ b/src/Client/DefScript/DefScript.h @@ -174,6 +174,9 @@ private: DefReturnResult func_or(CmdSet&); DefReturnResult func_xor(CmdSet&); DefReturnResult func_substr(CmdSet&); + DefReturnResult func_uppercase(CmdSet&); + DefReturnResult func_lowercase(CmdSet&); + DefReturnResult func_random(CmdSet&); // setup own function declarations here # include "DefScriptInterfaceInclude.h" diff --git a/src/Client/DefScript/DefScriptFunctions.cpp b/src/Client/DefScript/DefScriptFunctions.cpp index f436997..8f81f54 100644 --- a/src/Client/DefScript/DefScriptFunctions.cpp +++ b/src/Client/DefScript/DefScriptFunctions.cpp @@ -413,12 +413,45 @@ DefReturnResult DefScriptPackage::func_xor(CmdSet& Set) 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); + if(Set.defaultarg.empty()) + { + r.ret=""; + } + else + { + 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; } +DefReturnResult DefScriptPackage::func_uppercase(CmdSet& Set) +{ + DefReturnResult r; + r.ret=stringToUpper(Set.defaultarg); + return r; +} + +DefReturnResult DefScriptPackage::func_lowercase(CmdSet& Set) +{ + DefReturnResult r; + r.ret=stringToLower(Set.defaultarg); + return r; +} + +DefReturnResult DefScriptPackage::func_random(CmdSet& Set) +{ + DefReturnResult r; + int min,max; + min=(int)toUint64(Set.arg[0]); + max=(int)toUint64(Set.defaultarg); + r.ret=toString(ldbl( min + ( rand() % (max - min + 1)) )); + return r; +} + + + diff --git a/src/Client/PseuWoW.cpp b/src/Client/PseuWoW.cpp index a5feb60..05cae2f 100644 --- a/src/Client/PseuWoW.cpp +++ b/src/Client/PseuWoW.cpp @@ -100,14 +100,37 @@ bool PseuInstance::Init(void) { _scp->variables.Set("@version",_ver); _scp->variables.Set("@inworld","false"); - log("Loading DefScripts from folder '%s'",_scpdir.c_str()); - if(!_scp->BoolRunScript("_startup",NULL)) { logerror("Error executing '_startup.def'"); SetError(); } + // load all .def files in scripts directory + log("Loading DefScripts from folder '%s'",_scpdir.c_str()); + std::deque fl = GetFileList(_scpdir); + for(uint32 i = 0; i < fl.size(); i++) + { + std::string fn = fl[i]; // do not lowercase filename because of linux case sensitivity + if(fn.length() <= 4) // must be at least "x.def" + continue; + std::string ext = stringToLower(fn.substr(fn.length()-4,4)); + std::string sn; + if(ext==".def") + sn = stringToLower(fn.substr(0,fn.length()-ext.length())); + if(sn.length()) + { + if(!_scp->ScriptExists(sn)) + { + std::string ffn = _scpdir + fn; + if(_scp->LoadScriptFromFile(ffn,sn)) + logdebug("-> Auto-loaded script [ %s ]",ffn.c_str()); + else + logerror("-> Can't auto-load script [ %s ]",ffn.c_str()); + } + } + } + if(GetConf()->enablecli) { log("Starting CLI..."); diff --git a/src/shared/tools.cpp b/src/shared/tools.cpp index 9dc4d91..6afeca7 100644 --- a/src/shared/tools.cpp +++ b/src/shared/tools.cpp @@ -5,6 +5,13 @@ #include #include "tools.h" +#ifndef _WIN32 +# include +# include +#else +# include +#endif + void printchex(std::string in, bool spaces=true){ unsigned int len=0,i; len=in.length(); @@ -84,3 +91,46 @@ std::string toHexDump(uint8* array,uint32 size,bool spaces) return ss.str(); } +std::deque GetFileList(std::string path) +{ + std::deque files; + +# ifndef _WIN32 // TODO: fix this function for linux if needed + const char *p = path.c_str(); + DIR * dirp; + struct dirent * dp; + dirp = opendir(p); + while (dirp) + { + errno = 0; + if ((dp = readdir(dirp)) != NULL) + files.push_back(std::string(dp->d_name)); + else + break; + } + if(dirp) + closedir(dirp); + +# else + + if(path.at(path.length()-1)!='/') + path += "/"; + path += "*.*"; + const char *p = path.c_str(); + WIN32_FIND_DATA fil; + HANDLE hFil=FindFirstFile(p,&fil); + if(hFil!=INVALID_HANDLE_VALUE) + { + files.push_back(std::string(fil.cFileName)); + while(FindNextFile(hFil,&fil)) + files.push_back(std::string(fil.cFileName)); + } + +# endif + + while(files.front()=="." || files.front()=="..") + files.pop_front(); + + return files; +} + diff --git a/src/shared/tools.h b/src/shared/tools.h index 4261104..23327d4 100644 --- a/src/shared/tools.h +++ b/src/shared/tools.h @@ -15,5 +15,6 @@ std::string toString(uint64); std::string getDateString(void); uint64 toInt(std::string); std::string toHexDump(uint8* array,uint32 size,bool spaces=true); +std::deque GetFileList(std::string); #endif \ No newline at end of file diff --git a/src/tools/sqlite3.exe b/src/tools/sqlite3.exe deleted file mode 100644 index d8bcca0..0000000 Binary files a/src/tools/sqlite3.exe and /dev/null differ