+ added default config files + SDL.dll
+ added some DefScripts + fixed the DefScript system. TODO: permissions & stuff will come in next rev. :)
This commit is contained in:
parent
0b1ae6f9ca
commit
889238cfb7
60
bin/conf/PseuWoW.conf.default
Normal file
60
bin/conf/PseuWoW.conf.default
Normal file
@ -0,0 +1,60 @@
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PseuWoW config file
|
||||
//
|
||||
// still under development :D
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// use // for comments (C++ style)
|
||||
|
||||
// its important to read & store the main conf variables UPPERCASED!!
|
||||
[#uppercase]
|
||||
[#noprefix]
|
||||
|
||||
// 3=max, 0=no debug output
|
||||
debug=0
|
||||
|
||||
// defines if the program should quit on error/exception or stay opened (for debugging)
|
||||
exitonerror=0
|
||||
|
||||
// reconnect on failure/disconnect
|
||||
reconnect=0
|
||||
|
||||
// 0 - show none
|
||||
// 1 - show only known/handled
|
||||
// 2 - show only unknown/unhandled
|
||||
// 3 - show all
|
||||
showopcodes=3
|
||||
|
||||
|
||||
// the IP or hostname the wow server is running on
|
||||
realmlist=localhost
|
||||
|
||||
// port on which the realm server is listening (default=3724)
|
||||
realmport=3724
|
||||
|
||||
// PseuWoW will login on this realm
|
||||
realmname=My WoW Realm
|
||||
|
||||
// your account name
|
||||
accname=test
|
||||
|
||||
// your account password
|
||||
accpass=test
|
||||
|
||||
// the character name PseuWoW should choose to enter the world
|
||||
charname=PseuWoW
|
||||
|
||||
|
||||
// Client emulation configuration
|
||||
ClientVersion=1.12.1
|
||||
ClientBuild=5875
|
||||
ClientLanguage=enUS
|
||||
// or change to enGB, deDE, ...
|
||||
|
||||
|
||||
// packets get fetched every xx msecs. default=50
|
||||
// setting this to 0 will let PseuWoW eat up all CPU power
|
||||
// 1 is a good setting for maximum network performance and lowest ping times
|
||||
NetworkSleepTime=50
|
||||
|
||||
|
||||
1
bin/conf/todo.txt
Normal file
1
bin/conf/todo.txt
Normal file
@ -0,0 +1 @@
|
||||
RENAME or COPY *.conf.default to *.conf and modify it to your needs.
|
||||
18
bin/conf/users.conf.default
Normal file
18
bin/conf/users.conf.default
Normal file
@ -0,0 +1,18 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Player Permission Configuration file
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Permission reaches from 0 to 255
|
||||
|
||||
[USERS]
|
||||
|
||||
Gamemaster=100
|
||||
Admin=255
|
||||
Trusted=30
|
||||
Niceplayer=10
|
||||
Falsegenesis=150
|
||||
//...
|
||||
// Add your names here
|
||||
|
||||
|
||||
|
||||
// rest is 0 automatically
|
||||
28
bin/scripts/_enterworld.def
Normal file
28
bin/scripts/_enterworld.def
Normal file
@ -0,0 +1,28 @@
|
||||
#permission=255
|
||||
|
||||
// PSEUWOW DEF_SCRIPT WORLD-ENTER FILE
|
||||
|
||||
OUT * World entered, executing appropriate script...
|
||||
|
||||
// not yet implemented
|
||||
// CASTSPELL 836
|
||||
|
||||
// yaay we are online
|
||||
EMOTE 5
|
||||
|
||||
// MaNGOS: make PseuWoW invincible
|
||||
SAY .gmon
|
||||
|
||||
// you can also teleport on every startup to a certain player...
|
||||
// simple: use the .goname command as usual.
|
||||
// SAY .goname Gamemaster
|
||||
|
||||
// to know everything worked fine, etc
|
||||
SAY [${@version_short}] login successful.
|
||||
|
||||
|
||||
// add your own stuff here
|
||||
// ...
|
||||
|
||||
|
||||
OUT * finished executing script.
|
||||
6
bin/scripts/_onwhisper.def
Normal file
6
bin/scripts/_onwhisper.def
Normal file
@ -0,0 +1,6 @@
|
||||
#permission=255
|
||||
|
||||
// EXECUTED EVERYTIME A WHISPER IS BEEING RECIEVED
|
||||
|
||||
|
||||
REPLY No need to whisper me, i am not yet programmed for it!
|
||||
33
bin/scripts/_startup.def
Normal file
33
bin/scripts/_startup.def
Normal file
@ -0,0 +1,33 @@
|
||||
#permission=255
|
||||
|
||||
|
||||
// PSEUWOW DEF_SCRIPT STARTUP FILE
|
||||
|
||||
OUT * DefScript StartUp [${@version_short}]...
|
||||
|
||||
// preload the script here, however its not important to load it now. it will get
|
||||
// loaded automatically if needed
|
||||
loaddef _enterworld
|
||||
loaddef _onwhisper
|
||||
loaddef _nopermission
|
||||
loaddef _setconf
|
||||
loaddef yell
|
||||
loaddef say
|
||||
loaddef whisper
|
||||
loaddef outv
|
||||
loaddef sayv
|
||||
loaddef reply
|
||||
loaddef quit
|
||||
// ...
|
||||
|
||||
// remove dangerous variables
|
||||
OUT * Cleaning up variables...
|
||||
UNSET #ACCPASS
|
||||
UNSET #ACCNAME
|
||||
OUT * Dangerous variables removed.
|
||||
|
||||
|
||||
// do more stuff here in future...
|
||||
|
||||
OUT * StartUp complete!
|
||||
|
||||
11
bin/scripts/reply.def
Normal file
11
bin/scripts/reply.def
Normal file
@ -0,0 +1,11 @@
|
||||
#permission=255
|
||||
|
||||
SET,player ${@thiswhisper_name}
|
||||
SET,lang ${@thiswhisper_lang}
|
||||
SET,msg ${@def}
|
||||
|
||||
WHISPER,{${player}},{${lang}} ${msg}
|
||||
|
||||
UNSET player
|
||||
UNSET lang
|
||||
UNSET msg
|
||||
12
bin/scripts/say.def
Normal file
12
bin/scripts/say.def
Normal file
@ -0,0 +1,12 @@
|
||||
#permission=255
|
||||
// setup some default values
|
||||
SET,lang ${@0}
|
||||
SET,msg ${@def}
|
||||
|
||||
default,lang 0
|
||||
|
||||
OUT * Saying '${msg}' in lang ${lang}
|
||||
|
||||
SENDCHATMESSAGE,0,${lang},{${msg}}
|
||||
UNSET lang
|
||||
UNSET msg
|
||||
15
bin/scripts/whisper.def
Normal file
15
bin/scripts/whisper.def
Normal file
@ -0,0 +1,15 @@
|
||||
#permissionn=255
|
||||
|
||||
// setup some default values
|
||||
SET,msg ${@def}
|
||||
SET,player ${@0}
|
||||
SET,lang ${@1}
|
||||
|
||||
DEFAULT,lang 0
|
||||
|
||||
OUT * Whisp to '{${player}}' '{${msg}}' in lang '${lang}'
|
||||
|
||||
SENDCHATMESSAGE,6,{${lang}},{${msg}},{${player}}
|
||||
UNSET lang
|
||||
UNSET msg
|
||||
UNSET player
|
||||
13
bin/scripts/yell.def
Normal file
13
bin/scripts/yell.def
Normal file
@ -0,0 +1,13 @@
|
||||
#permission=255
|
||||
|
||||
// setup some default values
|
||||
SET,lang ${@0}
|
||||
SET,msg ${@def}
|
||||
|
||||
default,lang 0
|
||||
|
||||
OUT * Yelling '${msg}' in lang ${lang}
|
||||
|
||||
SENDCHATMESSAGE,5,${lang},{${msg}}
|
||||
UNSET lang
|
||||
UNSET msg
|
||||
@ -7,26 +7,15 @@
|
||||
#include "VarSet.h"
|
||||
#include "DefScript.h"
|
||||
|
||||
struct DefScriptXChgResult {
|
||||
std::string str;
|
||||
bool change;
|
||||
};
|
||||
|
||||
// --- SECTION FOR SCRIPT PACKAGES ---
|
||||
DefScriptPackage::DefScriptPackage(){
|
||||
scripts=0;
|
||||
Script=NULL;
|
||||
curIsDebug=false;
|
||||
recursionLevel=0;
|
||||
functions=0;
|
||||
DefScriptPackage::DefScriptPackage()
|
||||
{
|
||||
functionTable=_GetFunctionTable();
|
||||
|
||||
|
||||
|
||||
// printf("---> DefScriptPackage inited!\n");
|
||||
}
|
||||
|
||||
DefScriptPackage::~DefScriptPackage(){
|
||||
DefScriptPackage::~DefScriptPackage()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
@ -35,21 +24,23 @@ void DefScriptPackage::SetParentMethod(void *p)
|
||||
parentMethod = p;
|
||||
}
|
||||
|
||||
void DefScriptPackage::Clear(void){
|
||||
//for(unsigned int i=0;i<scripts;i++){
|
||||
// Script[i].Clear();
|
||||
//}
|
||||
delete [] Script;
|
||||
Script=NULL;
|
||||
scripts=0;
|
||||
void DefScriptPackage::Clear(void)
|
||||
{
|
||||
for(std::map<std::string,DefScript*>::iterator i = Script.begin(); i != Script.end(); i++)
|
||||
{
|
||||
delete i->second; // delete each script
|
||||
}
|
||||
|
||||
Script.empty();
|
||||
}
|
||||
|
||||
DefScriptFunctionTable *DefScriptPackage::_GetFunctionTable(void) const
|
||||
{
|
||||
static DefScriptFunctionTable table[] = {
|
||||
// basic functions:
|
||||
{"out",&DefScriptPackage::func_out},
|
||||
{"set",&DefScriptPackage::func_set},
|
||||
{"defult",&DefScriptPackage::func_default},
|
||||
{"default",&DefScriptPackage::func_default},
|
||||
{"unset",&DefScriptPackage::func_unset},
|
||||
{"shdn",&DefScriptPackage::func_shdn},
|
||||
{"loaddef",&DefScriptPackage::func_loaddef},
|
||||
@ -69,7 +60,8 @@ DefScriptFunctionTable *DefScriptPackage::_GetFunctionTable(void) const
|
||||
return table;
|
||||
}
|
||||
|
||||
void DefScriptPackage::SetFunctionTable(DefScriptFunctionTable *tab){
|
||||
void DefScriptPackage::SetFunctionTable(DefScriptFunctionTable *tab)
|
||||
{
|
||||
functionTable=tab;
|
||||
}
|
||||
|
||||
@ -77,38 +69,26 @@ void DefScriptPackage::SetPath(std::string p){
|
||||
scPath=p;
|
||||
}
|
||||
|
||||
DefScript DefScriptPackage::GetScript(unsigned int id){
|
||||
return Script[id];
|
||||
DefScript *DefScriptPackage::GetScript(std::string scname){
|
||||
if(Script.find(scname) != NULL)
|
||||
return Script[scname];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned int DefScriptPackage::GetScripts(void){
|
||||
return scripts;
|
||||
return Script.size();
|
||||
}
|
||||
|
||||
std::string DefScriptPackage::GetScriptName(unsigned int id){
|
||||
if(id>scripts) return NULL;
|
||||
return Script[id].GetName();
|
||||
}
|
||||
|
||||
// returns array position!
|
||||
unsigned int DefScriptPackage::GetScriptID(std::string name){
|
||||
for(unsigned int i=0;i<scripts;i++){
|
||||
if( !Script[i].GetName().empty() && Script[i].GetName()==name ){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0; // Be careful you check if the script exists before you trust it. this could
|
||||
// also mean Script[0]!!
|
||||
}
|
||||
|
||||
bool DefScriptPackage::ScriptExists(std::string name){
|
||||
if(Script==NULL) return false;
|
||||
for(unsigned int i=0;i<scripts;i++){
|
||||
if( !Script[i].GetName().empty() && Script[i].GetName()==name ){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
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)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefScriptPackage::LoadByName(std::string name){
|
||||
@ -116,32 +96,8 @@ bool DefScriptPackage::LoadByName(std::string name){
|
||||
}
|
||||
|
||||
bool DefScriptPackage::LoadScriptFromFile(std::string fn, std::string sn){
|
||||
bool increase_flag=false;
|
||||
std::string label, value;
|
||||
unsigned int id;
|
||||
if(fn.empty() || sn.empty()) return false;
|
||||
if(ScriptExists(sn)){ // if the script already exists, clear it and reassign content
|
||||
id=GetScriptID(sn); // script exists, get ID...
|
||||
Script[id].Clear(); // ... and remove content to refill it later on
|
||||
} else { // if not, set scripts as ID for new script. scripts is equal to new array index then
|
||||
id=scripts;
|
||||
increase_flag=true;
|
||||
|
||||
// Script does not yet exist, since the scriptcount will be increased we have to alloc mem before
|
||||
DefScript *Script_old;
|
||||
if(scripts){
|
||||
Script_old=new DefScript[scripts];
|
||||
memcpy(Script_old,Script,scripts*sizeof(DefScript));
|
||||
delete [] Script;
|
||||
}
|
||||
Script = new DefScript[scripts+1];
|
||||
if(scripts){
|
||||
memcpy(Script,Script_old,scripts*sizeof(DefScript));
|
||||
delete [] Script_old;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(fn.empty() || sn.empty()) return false;
|
||||
std::fstream f;
|
||||
f.open(fn.c_str(),std::ios_base::in);
|
||||
if(!f.is_open())
|
||||
@ -149,6 +105,10 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn, std::string sn){
|
||||
std::string line;
|
||||
char z;
|
||||
bool load_debug=false,load_notify=false;
|
||||
if(GetScript(sn))
|
||||
delete GetScript(sn);
|
||||
DefScript *newscript = new DefScript(this);
|
||||
Script[sn] = newscript;
|
||||
while(!f.eof()){
|
||||
line.clear();
|
||||
while (true) {
|
||||
@ -166,175 +126,160 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn, std::string sn){
|
||||
continue;
|
||||
if(line.at(0)=='/' && line.at(1)=='/')
|
||||
continue; // line is comment, proceed with next line
|
||||
if(line.at(0)=='#'){
|
||||
if(line.at(0)=='#')
|
||||
{
|
||||
line.erase(0,1); // remove #
|
||||
label=line.substr(0,line.find('=',0));
|
||||
value=line.substr(line.find('=',0)+1,line.length());
|
||||
if(label=="permission"){
|
||||
Script[id].SetPermission((unsigned char)atoi(value.c_str())); // MAYBE: instead of this use Var @permission
|
||||
if(label=="permission")
|
||||
{
|
||||
scriptPermissionMap[sn] = atoi(value.c_str());
|
||||
} // ...
|
||||
if(line=="load_debug")
|
||||
load_debug=true;
|
||||
if(line=="load_notify")
|
||||
load_notify=true;
|
||||
if(line=="debug")
|
||||
Script[id].SetDebug(true);
|
||||
Script[sn]->SetDebug(true);
|
||||
//...
|
||||
continue; // line was an option, not script content
|
||||
}
|
||||
if(load_debug)
|
||||
std::cout<<"~LOAD: "<<line<<"\n";
|
||||
Script[id].AddLine(line);
|
||||
Script[sn]->AddLine(line);
|
||||
|
||||
|
||||
}
|
||||
f.close();
|
||||
//Script[id].AddLine("eof"); // to be sure the script is terminated correctly
|
||||
Script[id].SetName(sn);
|
||||
Script[sn]->SetName(sn); // necessary that the script knows its own name
|
||||
if(load_notify)
|
||||
std::cout << "+> Script '" << sn << "' [" << fn << "] successfully loaded.\n";
|
||||
|
||||
// ...
|
||||
if(increase_flag) scripts++;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// --- SECTION FOR THE INDIVIDUAL SCRIPTS IN A PACKAGE ---
|
||||
|
||||
DefScript::DefScript(){
|
||||
lines=0;
|
||||
Line=NULL;
|
||||
permission=0;
|
||||
DefScript::DefScript(DefScriptPackage *p)
|
||||
{
|
||||
_parent=p;
|
||||
scriptname="{NONAME}";
|
||||
debugmode=false;
|
||||
// printf("--> DefScript inited!\n");
|
||||
}
|
||||
|
||||
DefScript::~DefScript(){
|
||||
DefScript::~DefScript()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void DefScript::Clear(void){
|
||||
//if(lines)
|
||||
// delete [] Line; //?! causes crash!
|
||||
Line=NULL;
|
||||
lines=0;
|
||||
permission=0;
|
||||
void DefScript::Clear(void)
|
||||
{
|
||||
Line.clear();
|
||||
}
|
||||
|
||||
void DefScript::SetDebug(bool d){
|
||||
void DefScript::SetDebug(bool d)
|
||||
{
|
||||
debugmode=d;
|
||||
}
|
||||
|
||||
bool DefScript::GetDebug(void){
|
||||
bool DefScript::GetDebug(void)
|
||||
{
|
||||
return debugmode;
|
||||
}
|
||||
|
||||
void DefScript::SetName(std::string name){
|
||||
void DefScript::SetName(std::string name)
|
||||
{
|
||||
scriptname=name;
|
||||
}
|
||||
|
||||
std::string DefScript::GetName(void){
|
||||
std::string DefScript::GetName(void)
|
||||
{
|
||||
return scriptname;
|
||||
}
|
||||
|
||||
void DefScript::SetPermission(unsigned char p){
|
||||
permission=p;
|
||||
unsigned int DefScript::GetLines(void)
|
||||
{
|
||||
return Line.size();
|
||||
}
|
||||
|
||||
unsigned char DefScript::GetPermission(void){
|
||||
return permission;
|
||||
}
|
||||
|
||||
unsigned int DefScript::GetLines(void){
|
||||
return lines;
|
||||
}
|
||||
|
||||
std::string DefScript::GetLine(unsigned int id){
|
||||
if(id>lines)
|
||||
return "";
|
||||
std::string DefScript::GetLine(unsigned int id)
|
||||
{
|
||||
return Line[id];
|
||||
}
|
||||
|
||||
bool DefScript::AddLine(std::string l){
|
||||
if(l.empty())
|
||||
return false;
|
||||
std::string *Line_old=new std::string[lines];
|
||||
for(unsigned int i=0;i<lines;i++)
|
||||
Line_old[i]=Line[i];
|
||||
delete [] Line;
|
||||
Line=new std::string[lines+1];
|
||||
for(unsigned int i=0;i<lines;i++)
|
||||
Line[i]=Line_old[i];
|
||||
Line[lines]=l;
|
||||
lines++;
|
||||
delete [] Line_old;
|
||||
Line.insert(Line.end(),l);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// --- SECTION FOR COMMAND SETS ---
|
||||
|
||||
CmdSet::CmdSet(){
|
||||
for(unsigned int i=0;i<MAXARGS;i++){
|
||||
arg[i]="";
|
||||
}
|
||||
cmd="";
|
||||
defaultarg="";
|
||||
CmdSet::CmdSet(DefScript *p){
|
||||
Clear();
|
||||
owner = p;
|
||||
}
|
||||
|
||||
CmdSet::~CmdSet(){
|
||||
Clear();
|
||||
}
|
||||
|
||||
void CmdSet::Clear(){
|
||||
|
||||
void CmdSet::Clear()
|
||||
{
|
||||
for(unsigned int i=0;i<MAXARGS;i++){
|
||||
arg[i]="";
|
||||
}
|
||||
cmd="";
|
||||
defaultarg="";
|
||||
caller="";
|
||||
}
|
||||
|
||||
|
||||
// --- FUNCTIONS TO PARSE AND EXECUTE A SCRIPT --- PARENT: DefScriptPackage!
|
||||
|
||||
bool DefScriptPackage::RunScriptByID(unsigned int id, CmdSet *pSet, unsigned char p){
|
||||
if(id>GetScripts())
|
||||
|
||||
// the referred pSet is the parent from which RunScript() has been called
|
||||
bool DefScriptPackage::RunScript(std::string name, CmdSet *pSet)
|
||||
{
|
||||
if(!ScriptExists(name))
|
||||
if(!LoadByName(name))
|
||||
return false; // doesnt exist & cant be loaded
|
||||
|
||||
DefScript *sc = GetScript(name);
|
||||
if(!sc)
|
||||
return false;
|
||||
|
||||
curIsDebug=GetScript(id).GetDebug();
|
||||
CmdSet temp(sc);
|
||||
if(!pSet)
|
||||
{
|
||||
pSet = &temp;
|
||||
}
|
||||
pSet->caller=pSet->myname;
|
||||
pSet->myname=name;
|
||||
|
||||
for(unsigned int cur_line=0;cur_line<GetScript(id).GetLines();cur_line++){
|
||||
|
||||
std::string line=GetScript(id).GetLine(cur_line);
|
||||
std::string final=ReplaceVars(line,pSet,false,0,GetScript(id).GetName()); // must only parse globals if pSet == NULL
|
||||
CmdSet curSet=SplitLine(final);
|
||||
Interpret(curSet,GetScript(id).GetName(), p);
|
||||
}
|
||||
|
||||
curIsDebug=false;
|
||||
for(unsigned int i=0;i<sc->GetLines();i++)
|
||||
{
|
||||
CmdSet curSet(NULL);
|
||||
DefXChgResult final=ReplaceVars(sc->GetLine(i),pSet,false);
|
||||
//printf("SC: \"%s\"\n",final.str.c_str());
|
||||
curSet=SplitLine(final.str);
|
||||
curSet.owner=sc; // must set the owner after SplitLine()
|
||||
curSet.myname=name;
|
||||
curSet.caller=pSet?pSet->myname:"";
|
||||
Interpret(curSet);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DefScriptPackage::RunScriptByName(std::string scname, CmdSet *pSet, unsigned char p){
|
||||
if(scname.empty())
|
||||
return false;
|
||||
if(ScriptExists(scname)){
|
||||
RunScriptByID(GetScriptID(scname),pSet,p);
|
||||
return true;
|
||||
} else {
|
||||
bool result=LoadByName(scname);
|
||||
if(result){
|
||||
RunScriptByID(GetScriptID(scname),pSet,p);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
bool DefScriptPackage::RunSingleLine(std::string line, unsigned char p){
|
||||
unsigned int temp=0;
|
||||
std::string final=ReplaceVars(line,NULL,false,temp,"");
|
||||
CmdSet curSet=SplitLine(final);
|
||||
return Interpret(curSet,"",p);
|
||||
bool DefScriptPackage::RunSingleLine(std::string line){
|
||||
DefXChgResult final=ReplaceVars(line,NULL,false);
|
||||
CmdSet curSet=SplitLine(final.str);
|
||||
return Interpret(curSet);
|
||||
}
|
||||
|
||||
CmdSet DefScriptPackage::SplitLine(std::string line){
|
||||
@ -343,7 +288,7 @@ CmdSet DefScriptPackage::SplitLine(std::string line){
|
||||
unsigned int bracketsOpen=0,curParam=0;
|
||||
bool cmdDefined=false;
|
||||
std::string tempLine;
|
||||
CmdSet outSet;
|
||||
CmdSet outSet(NULL);
|
||||
|
||||
// extract cmd+params and txt
|
||||
for(i=0;i<line.length();i++){
|
||||
@ -391,7 +336,8 @@ CmdSet DefScriptPackage::SplitLine(std::string line){
|
||||
if(cmdDefined && !outSet.cmd.empty() && outSet.defaultarg.empty())
|
||||
outSet.arg[curParam]=tempLine;
|
||||
|
||||
outSet.cmd.assign(strlwr((char*)outSet.cmd.c_str()));
|
||||
outSet.cmd.assign(strlwr((char*)outSet.cmd.c_str())); // TODO: use toLower() instead!
|
||||
outSet.owner=GetScript(outSet.cmd);
|
||||
return RemoveBrackets(outSet);
|
||||
}
|
||||
|
||||
@ -469,28 +415,31 @@ CmdSet DefScriptPackage::RemoveBrackets(CmdSet oldSet){
|
||||
}
|
||||
|
||||
|
||||
std::string DefScriptPackage::ReplaceVars(std::string str, CmdSet *pSet, bool isVar, unsigned int vardepth, std::string sc_name){
|
||||
//std::cout<<">>ReplaceVars: '"<<str<<"' var="<<isVar<<"\n";
|
||||
DefXChgResult DefScriptPackage::ReplaceVars(std::string str, CmdSet *pSet, bool isVar){
|
||||
|
||||
unsigned int
|
||||
|
||||
openingBracket=0, // defines the position from where the recursive call should be started
|
||||
openingBracket=0, // defines the position from where the recursive call is started
|
||||
closingBracket=0, // the closing bracket
|
||||
bracketsOpen=0,
|
||||
bracketsOpen=0, // amount of brackets opened
|
||||
bLen=0; // the lenth of the string in brackets, e.g. ${abc} == 3
|
||||
|
||||
bool nextIsVar=false, hasVar=false;
|
||||
bool
|
||||
nextIsVar=false, // true if the last bracket was preceded by '$'
|
||||
hasVar=false, // true if openingBracket (= the first bracket) was preceded by '$'
|
||||
hasChanged=false; // additional helper. once true, xchg.result will be true later also
|
||||
|
||||
// isVar (arg) : defines if the current string is a variable (can only be true in recursive calls!)
|
||||
|
||||
|
||||
std::string subStr,retStr;
|
||||
char temp;
|
||||
std::string subStr;
|
||||
DefXChgResult xchg;
|
||||
|
||||
while(str.at(0)==' ' || str.at(0)=='\t')
|
||||
str.erase(0,1); // trim spaces if there are any
|
||||
|
||||
for(unsigned int i=0;i<str.length();i++){
|
||||
temp=str.at(i);
|
||||
|
||||
//while(str.at(0)==' ' || str.at(0)=='\t')
|
||||
// str.erase(0,1); // trim spaces if there are any
|
||||
|
||||
for(unsigned int i=0;i<str.length();i++)
|
||||
{
|
||||
if(str[i]=='{')
|
||||
{
|
||||
if(!bracketsOpen)
|
||||
@ -515,54 +464,56 @@ std::string DefScriptPackage::ReplaceVars(std::string str, CmdSet *pSet, bool is
|
||||
{
|
||||
str.erase(closingBracket,1);
|
||||
str.erase(openingBracket,1);
|
||||
i-=2;
|
||||
i=openingBracket; // jump to the pos where the opening bracket was
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
bLen=closingBracket-openingBracket-1;
|
||||
subStr=str.substr(openingBracket+1,bLen);
|
||||
retStr=ReplaceVars(subStr,pSet,nextIsVar,vardepth+(nextIsVar?1:0),sc_name);
|
||||
if( hasVar && !nextIsVar && subStr!=retStr )
|
||||
//printf("SUBSTR: \"%s\"\n",subStr.c_str());
|
||||
xchg=ReplaceVars(subStr,pSet,nextIsVar);
|
||||
if( (!nextIsVar) && hasVar && xchg.changed )
|
||||
{
|
||||
str.erase(openingBracket+1,subStr.length());
|
||||
str.insert(openingBracket+1,retStr);
|
||||
str.insert(openingBracket+1,xchg.str);
|
||||
hasVar=false;
|
||||
nextIsVar=false;
|
||||
i-=(subStr.length()+1);
|
||||
hasChanged=true;
|
||||
}
|
||||
else if( hasVar && nextIsVar && subStr!=retStr )
|
||||
else if( nextIsVar && hasVar && xchg.changed )
|
||||
{
|
||||
str.erase(openingBracket-1,bLen+3); // remove {...
|
||||
str.erase(openingBracket-1,bLen+3); // remove ${...} (+3 because of '${}')
|
||||
i-=(bLen+2); // adjust position
|
||||
str.insert(i,retStr);
|
||||
str.insert(i,xchg.str);
|
||||
//i--;
|
||||
hasVar=false;
|
||||
nextIsVar=false;
|
||||
}
|
||||
else
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} // end if {
|
||||
} // end if '}'
|
||||
} // end for
|
||||
if(!bracketsOpen && isVar && vardepth)
|
||||
if(!bracketsOpen && isVar)
|
||||
{
|
||||
std::string vname=_NormalizeVarName(str, sc_name);
|
||||
std::string vname=_NormalizeVarName(str, (pSet==NULL) ? "" : pSet->myname);
|
||||
if(vname[0]=='@')
|
||||
{
|
||||
std::stringstream vns;
|
||||
std::string subs=vname.substr(1,str.length()-1);
|
||||
unsigned int vn=atoi( subs.c_str() );
|
||||
vns << vn;
|
||||
if(pSet && vns.str()==subs)
|
||||
if(pSet && vns.str()==subs) // resolve arg macros @0 - @99
|
||||
str=pSet->arg[vn];
|
||||
else if(pSet && subs=="def")
|
||||
str=pSet->defaultarg;
|
||||
else if(pSet && subs=="myname")
|
||||
str=pSet->myname;
|
||||
else if(pSet && subs=="cmd")
|
||||
str=pSet->cmd;
|
||||
//else if(pSet && subs=="parent")
|
||||
// str=pSet->parent;
|
||||
else if(pSet && subs=="caller")
|
||||
str=pSet->caller;
|
||||
else if(variables.Exists(vname))
|
||||
str=variables.Get(vname);
|
||||
else
|
||||
@ -571,18 +522,21 @@ std::string DefScriptPackage::ReplaceVars(std::string str, CmdSet *pSet, bool is
|
||||
//...
|
||||
str.clear();
|
||||
}
|
||||
|
||||
|
||||
xchg.changed=true;
|
||||
}
|
||||
else
|
||||
if(variables.Exists(vname))
|
||||
{
|
||||
str=variables.Get(vname);
|
||||
else if(!variables.Exists(vname) && !subStr.empty())
|
||||
str="${"+str+"}";
|
||||
xchg.changed=true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return str;
|
||||
xchg.str = str;
|
||||
if(hasChanged)
|
||||
xchg.changed=true;
|
||||
//printf("XCHG:%u: \"%s\"\n",xchg.changed,xchg.str.c_str());
|
||||
return xchg;
|
||||
}
|
||||
|
||||
std::string DefScriptPackage::_NormalizeVarName(std::string vn_in, std::string sn){
|
||||
@ -600,39 +554,33 @@ std::string DefScriptPackage::_NormalizeVarName(std::string vn_in, std::string s
|
||||
return vn;
|
||||
}
|
||||
|
||||
bool DefScriptPackage::Interpret(CmdSet Set, std::string sc_name, unsigned char p){
|
||||
bool DefScriptPackage::Interpret(CmdSet Set)
|
||||
{
|
||||
bool result=false;
|
||||
|
||||
for(unsigned int i=0;result==false;i++){
|
||||
if(functionTable[i].func==NULL || functionTable[i].name==NULL){ // reached the end of the table?
|
||||
// first search if the script is defined in the internal functions
|
||||
for(unsigned int i=0;result==false;i++)
|
||||
{
|
||||
if(functionTable[i].func==NULL || functionTable[i].name==NULL) // reached the end of the table?
|
||||
{
|
||||
break;
|
||||
}
|
||||
if(Set.cmd==functionTable[i].name){
|
||||
if(Set.cmd==functionTable[i].name)
|
||||
{
|
||||
result=(this->*functionTable[i].func)(Set);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if still nothing has been found its maybe a script command
|
||||
if(!result){
|
||||
unsigned int perm=GetScript(GetScriptID(Set.cmd)).GetPermission();
|
||||
if(p<perm)
|
||||
return false; // permisson level too low
|
||||
|
||||
result=RunScriptByName(Set.cmd,&Set,255); // call the subscript, this time with full privileges
|
||||
if(!result && curIsDebug)
|
||||
// if nothing has been found its maybe an external script file to run
|
||||
if(!result)
|
||||
{
|
||||
result=RunScript(Set.cmd, &Set);
|
||||
if((!result) /*&& Script[Set.cmd]->GetDebug()*/)
|
||||
std::cout << "Could not execute script command '" << Set.cmd << "'\n";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// TODO: how to get this work?!
|
||||
/*
|
||||
bool DefScriptPackage::CallFunction(bool *func, CmdSet *pSet){
|
||||
//bool result = *func(pSet, this);
|
||||
//return result;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@ -10,20 +10,29 @@
|
||||
#endif
|
||||
|
||||
#include <map>
|
||||
#include <deque>
|
||||
#include "VarSet.h"
|
||||
|
||||
class DefScriptPackage;
|
||||
class DefScript;
|
||||
|
||||
struct DefXChgResult {
|
||||
DefXChgResult() { changed=false; }
|
||||
bool changed;
|
||||
std::string str;
|
||||
};
|
||||
|
||||
class CmdSet {
|
||||
public:
|
||||
CmdSet();
|
||||
CmdSet(DefScript *p);
|
||||
~CmdSet();
|
||||
void Clear();
|
||||
std::string cmd;
|
||||
std::string arg[MAXARGS];
|
||||
std::string defaultarg;
|
||||
DefScriptPackage *pack;
|
||||
std::string myname;
|
||||
std::string caller;
|
||||
DefScript *owner;
|
||||
void *ptr;
|
||||
};
|
||||
|
||||
@ -34,7 +43,7 @@ struct DefScriptFunctionTable {
|
||||
|
||||
class DefScript {
|
||||
public:
|
||||
DefScript();
|
||||
DefScript(DefScriptPackage *p);
|
||||
~DefScript();
|
||||
std::string GetLine(unsigned int);
|
||||
unsigned int GetLines(void);
|
||||
@ -50,13 +59,13 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
std::string *Line;
|
||||
std::deque<std::string> Line;
|
||||
unsigned int lines;
|
||||
std::string scriptname;
|
||||
unsigned char permission;
|
||||
bool debugmode;
|
||||
|
||||
//DefScriptPackage *_parent;
|
||||
DefScriptPackage *_parent;
|
||||
//CmdSet _mySet;
|
||||
|
||||
};
|
||||
@ -66,43 +75,36 @@ class DefScriptPackage {
|
||||
public:
|
||||
DefScriptPackage();
|
||||
~DefScriptPackage();
|
||||
void SetParentMethod(void*);
|
||||
void SetParentMethod(void*); // used to extend the scripts with own c++ interface functions
|
||||
void Clear(void);
|
||||
DefScript GetScript(unsigned int);
|
||||
DefScript *GetScript(std::string);
|
||||
unsigned int GetScripts(void);
|
||||
bool LoadScriptFromFile(std::string,std::string);
|
||||
bool RunScriptByName(std::string,CmdSet*,unsigned char);
|
||||
bool RunScriptByID(unsigned int,CmdSet*,unsigned char);
|
||||
std::string GetScriptName(unsigned int);
|
||||
bool RunScript(std::string,CmdSet*);
|
||||
unsigned int GetScriptID(std::string);
|
||||
bool RunSingleLine(std::string, unsigned char);
|
||||
bool RunSingleLine(std::string);
|
||||
bool ScriptExists(std::string);
|
||||
VarSet variables;
|
||||
void SetPath(std::string);
|
||||
bool LoadByName(std::string);
|
||||
void SetFunctionTable(DefScriptFunctionTable*);
|
||||
std::string _NormalizeVarName(std::string, std::string);
|
||||
bool DefScriptPackage::CallFunction(bool *func, CmdSet *pSet);
|
||||
|
||||
std::string scPath;
|
||||
|
||||
private:
|
||||
std::string ReplaceVars(std::string, CmdSet*, bool, unsigned int, std::string); // changes the string directly
|
||||
DefXChgResult ReplaceVars(std::string, CmdSet*, bool);
|
||||
CmdSet SplitLine(std::string);
|
||||
bool Interpret(CmdSet, std::string, unsigned char);
|
||||
bool Interpret(CmdSet);
|
||||
CmdSet RemoveBrackets(CmdSet);
|
||||
std::string RemoveBracketsFromString(std::string);
|
||||
DefScriptFunctionTable *_GetFunctionTable(void) const;
|
||||
|
||||
bool curIsDebug;
|
||||
unsigned int scripts;
|
||||
DefScript *Script;
|
||||
unsigned int recursionLevel;
|
||||
DefScriptFunctionTable *functionTable;
|
||||
unsigned int functions;
|
||||
void *parentMethod;
|
||||
|
||||
std::map<std::string, unsigned int> permissionMap;
|
||||
std::map<std::string, unsigned char> scriptPermissionMap;
|
||||
std::map<std::string,DefScript*> Script;
|
||||
|
||||
// Usable internal basic functions:
|
||||
bool func_default(CmdSet);
|
||||
|
||||
@ -92,13 +92,16 @@ bool DefScriptPackage::func_set(CmdSet Set){
|
||||
return false;
|
||||
}
|
||||
std::string vname,vval=Set.defaultarg;
|
||||
vname=_NormalizeVarName(Set.arg[0], Set.caller);
|
||||
vname=_NormalizeVarName(Set.arg[0], Set.myname);
|
||||
|
||||
if(!stricmp(Set.arg[1].c_str(),"onfail") && vval.find("${")!=std::string::npos)
|
||||
vval=Set.arg[2];
|
||||
|
||||
variables.Set(vname,vval);
|
||||
|
||||
if(Set.owner && Set.owner->GetDebug())
|
||||
printf("VAR: %s = '%s'\n",vname.c_str(),vval.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -133,6 +133,10 @@ bool VarSet::ReadVarsFromFile(std::string fn)
|
||||
upper=false;
|
||||
prefix.clear();
|
||||
}
|
||||
else if(prefix=="#noprefix")
|
||||
{
|
||||
prefix.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
prefix+="::";
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
|
||||
bool DefScriptPackage::SCpause(CmdSet Set){
|
||||
SDL_Delay(atoi(Set.defaultarg.c_str()));
|
||||
((PseuInstance*)parentMethod)->Sleep(atoi(Set.defaultarg.c_str()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -99,18 +99,16 @@ bool PseuInstance::Init(void) {
|
||||
// //DEBUG1(printf("Main_Init: Setting up DefScripts path '%s'\n",defScpPath.c_str()););
|
||||
_scp->SetPath(_scpdir);
|
||||
|
||||
// //DEBUG1(printf("Main_Init: Setting up custom DefScript function interface...\n"););
|
||||
//_scp->SetFunctionTable(_GetSCTable());
|
||||
|
||||
// //DEBUG1(printf("Main_Init: Setting up predefined DefScript macros...\n"););
|
||||
_scp->variables.Set("@version_short",_ver_short);
|
||||
_scp->variables.Set("@version",_ver);
|
||||
|
||||
|
||||
// //DEBUG1(printf("Main_Init: Loading DefScripts from folder '%s'\n",defScpPath.c_str()););
|
||||
//if(!_scp->RunScriptByName("_startup",NULL,255)){
|
||||
// printf("Main_Init: Error executing '_startup.def'\n");
|
||||
//}
|
||||
if(!_scp->RunScript("_startup",NULL))
|
||||
{
|
||||
printf("Main_Init: Error executing '_startup.def'\n");
|
||||
}
|
||||
|
||||
if(_stop){
|
||||
printf("Errors while initializing, proc halted!!\n");
|
||||
@ -319,6 +317,7 @@ void PseuInstanceConf::ApplyFromVarSet(VarSet &v)
|
||||
realmname=v.Get("REALMNAME");
|
||||
charname=v.Get("CHARNAME");
|
||||
networksleeptime=atoi(v.Get("NETWORKSLEEPTIME").c_str());
|
||||
showopcodes=atoi(v.Get("SHOWOPCODES").c_str());
|
||||
|
||||
// clientversion is a bit more complicated to add
|
||||
{
|
||||
|
||||
@ -37,6 +37,7 @@ class PseuInstanceConf
|
||||
std::string charname;
|
||||
std::string worldhost;
|
||||
uint16 networksleeptime;
|
||||
uint8 showopcodes;
|
||||
|
||||
|
||||
};
|
||||
|
||||
@ -94,7 +94,6 @@ void WorldSession::Update(void)
|
||||
while(!pktQueue.empty())
|
||||
{
|
||||
WorldPacket *packet = pktQueue.next();
|
||||
printf(">> Opcode %u [%s]\n",packet->GetOpcode(),LookupName(packet->GetOpcode(),g_worldOpcodeNames));
|
||||
|
||||
for (uint16 i = 0; table[i].handler != NULL; i++)
|
||||
{
|
||||
@ -105,7 +104,13 @@ void WorldSession::Update(void)
|
||||
break;
|
||||
}
|
||||
}
|
||||
//if(!known)
|
||||
if( (known && GetInstance()->GetConf()->showopcodes==1)
|
||||
|| ((!known) && GetInstance()->GetConf()->showopcodes==2)
|
||||
|| (GetInstance()->GetConf()->showopcodes==3) )
|
||||
{
|
||||
printf(">> Opcode %u [%s]\n",packet->GetOpcode(),LookupName(packet->GetOpcode(),g_worldOpcodeNames));
|
||||
}
|
||||
|
||||
|
||||
|
||||
delete packet;
|
||||
@ -170,7 +175,7 @@ void WorldSession::_OnEnterWorld(void)
|
||||
if(!_logged)
|
||||
{
|
||||
_logged=true;
|
||||
//GetInstance()->GetScripts()->RunScriptByName("_enterworld",NULL,255);
|
||||
GetInstance()->GetScripts()->RunScript("_enterworld",NULL);
|
||||
|
||||
}
|
||||
}
|
||||
@ -426,8 +431,8 @@ void WorldSession::_HandleMessageChatOpcode(WorldPacket& recvPacket)
|
||||
defScp.variables.Set("@lastwhisper_lang",defScp.variables.Get("@thiswhisper_lang"));
|
||||
defScp.variables.Set("@thiswhisper_name",plrname);
|
||||
defScp.variables.Set("@thiswhisper",toString(target_guid));
|
||||
defScp.variables.Set("@thiswhisper_lang",toString((uint64)lang));
|
||||
defScp.RunScriptByName("_onwhisper",NULL,255);*/
|
||||
defScp.variables.Set("@thiswhisper_lang",toString((uint64)lang));*/
|
||||
GetInstance()->GetScripts()->RunScript("_onwhisper",NULL);
|
||||
}
|
||||
}
|
||||
void WorldSession::_HandleNameQueryResponseOpcode(WorldPacket& recvPacket)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user