* fixed line-end problems in different platforms
* one more toNumber() -> toUint64() fix * fixed logging from DefScript not only to console, but also to logfile (errors and such) - coloring included * fixed: display correct image of currently used video driver on startup ;) - thx shlainn for 1 & 4
This commit is contained in:
parent
fce0efcfc2
commit
de92dd9fc4
@ -12,6 +12,7 @@ using namespace DefScriptTools;
|
|||||||
|
|
||||||
#define SN_ONLOAD "?onload?"
|
#define SN_ONLOAD "?onload?"
|
||||||
|
|
||||||
|
|
||||||
enum DefScriptBlockType
|
enum DefScriptBlockType
|
||||||
{
|
{
|
||||||
BLOCK_IF,
|
BLOCK_IF,
|
||||||
@ -21,9 +22,6 @@ enum DefScriptBlockType
|
|||||||
// --- SECTION FOR SCRIPT PACKAGES ---
|
// --- SECTION FOR SCRIPT PACKAGES ---
|
||||||
DefScriptPackage::DefScriptPackage()
|
DefScriptPackage::DefScriptPackage()
|
||||||
{
|
{
|
||||||
SetLog(printf);
|
|
||||||
SetDebugLog(printf);
|
|
||||||
SetErrorLog(printf);
|
|
||||||
_DEFSC_DEBUG
|
_DEFSC_DEBUG
|
||||||
(
|
(
|
||||||
hLogfile.open("DefScriptLog.txt",std::ios_base::out);
|
hLogfile.open("DefScriptLog.txt",std::ios_base::out);
|
||||||
@ -44,30 +42,6 @@ DefScriptPackage::~DefScriptPackage()
|
|||||||
_DEFSC_DEBUG(hLogfile.close());
|
_DEFSC_DEBUG(hLogfile.close());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefScriptPackage::Log(const char* fmt,...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, fmt);
|
|
||||||
(*_slog)(fmt,ap);
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefScriptPackage::DebugLog(const char* fmt,...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, fmt);
|
|
||||||
(*_sdebuglog)(fmt,ap);
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefScriptPackage::ErrorLog(const char* fmt,...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, fmt);
|
|
||||||
(*_serrorlog)(fmt,ap);
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefScriptPackage::SetParentMethod(void *p)
|
void DefScriptPackage::SetParentMethod(void *p)
|
||||||
{
|
{
|
||||||
parentMethod = p;
|
parentMethod = p;
|
||||||
@ -293,7 +267,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){
|
|||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
f.get(z);
|
f.get(z);
|
||||||
if(z=='\n' || f.eof())
|
if(z=='\n' || z==10 || z==13 || f.eof()) // checking for all just to be sure
|
||||||
break;
|
break;
|
||||||
line+=z;
|
line+=z;
|
||||||
}
|
}
|
||||||
@ -303,6 +277,8 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){
|
|||||||
|
|
||||||
while( !line.empty() && (line.at(0)==' ' || line.at(0)=='\t') )
|
while( !line.empty() && (line.at(0)==' ' || line.at(0)=='\t') )
|
||||||
line.erase(0,1);
|
line.erase(0,1);
|
||||||
|
//while( !line.empty() && (line.at(line.length()-1)==13 || line.at(line.length()-1)==10) )
|
||||||
|
// line.erase(line.length()-1);
|
||||||
if(line.empty())
|
if(line.empty())
|
||||||
continue;
|
continue;
|
||||||
if(line.at(0)=='/' && line.at(1)=='/')
|
if(line.at(0)=='/' && line.at(1)=='/')
|
||||||
@ -360,7 +336,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){
|
|||||||
DeleteScript(curScript->GetName());
|
DeleteScript(curScript->GetName());
|
||||||
sn = stringToLower(value);
|
sn = stringToLower(value);
|
||||||
_UpdateOrCreateScriptByName(sn);
|
_UpdateOrCreateScriptByName(sn);
|
||||||
_DEFSC_DEBUG(printf("DefScript: now loading '%s'\n",sn.c_str()));
|
_DEFSC_DEBUG(PRINT_DEBUG("DefScript: now loading '%s'",sn.c_str()));
|
||||||
curScript=Script[sn];
|
curScript=Script[sn];
|
||||||
}
|
}
|
||||||
else if(label=="linestrip")
|
else if(label=="linestrip")
|
||||||
@ -476,7 +452,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){
|
|||||||
}
|
}
|
||||||
if(mismatch || bopen) // no bracket must be left open now
|
if(mismatch || bopen) // no bracket must be left open now
|
||||||
{
|
{
|
||||||
printf("DefScript [%s:%u]: Bracket mismatch at line '%s'\n",sn.c_str(),absline,line.c_str());
|
PRINT_ERROR("DefScript [%s:%u]: Bracket mismatch at line '%s'",sn.c_str(),absline,line.c_str());
|
||||||
continue; // continue with next line without adding the current line to script
|
continue; // continue with next line without adding the current line to script
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -485,7 +461,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){
|
|||||||
f.close();
|
f.close();
|
||||||
if(cantload || Blocks.size())
|
if(cantload || Blocks.size())
|
||||||
{
|
{
|
||||||
printf("DefScript: Error loading file '%s'. block mismatch?\n",fn.c_str());
|
PRINT_ERROR("DefScript: Error loading file '%s'. block mismatch?",fn.c_str());
|
||||||
DeleteScript(sn);
|
DeleteScript(sn);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -615,7 +591,7 @@ DefReturnResult DefScriptPackage::RunScript(std::string name, CmdSet *pSet,std::
|
|||||||
{
|
{
|
||||||
if(!Blocks.size())
|
if(!Blocks.size())
|
||||||
{
|
{
|
||||||
printf("DEBUG: else-block without any block?! [%s:%u]\n",name.c_str(),i);
|
PRINT_ERROR("DEBUG: else-block without any block?! [%s:%u]",name.c_str(),i);
|
||||||
r.ok=false;
|
r.ok=false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -642,13 +618,13 @@ DefReturnResult DefScriptPackage::RunScript(std::string name, CmdSet *pSet,std::
|
|||||||
{
|
{
|
||||||
if(!Blocks.size())
|
if(!Blocks.size())
|
||||||
{
|
{
|
||||||
printf("DEBUG: endif without any block [%s:%u]\n",name.c_str(),i);
|
PRINT_ERROR("DEBUG: endif without any block [%s:%u]",name.c_str(),i);
|
||||||
r.ok=false;
|
r.ok=false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(Blocks.back().type!=BLOCK_IF)
|
if(Blocks.back().type!=BLOCK_IF)
|
||||||
{
|
{
|
||||||
printf("DEBUG: endif: closed block is not an if block! [%s:%u]\n",name.c_str(),i);
|
PRINT_ERROR("DEBUG: endif: closed block is not an if block! [%s:%u]",name.c_str(),i);
|
||||||
r.ok=false;
|
r.ok=false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -668,13 +644,13 @@ DefReturnResult DefScriptPackage::RunScript(std::string name, CmdSet *pSet,std::
|
|||||||
{
|
{
|
||||||
if(!Blocks.size())
|
if(!Blocks.size())
|
||||||
{
|
{
|
||||||
printf("DEBUG: endloop without any block [%s:%u]\n",name.c_str(),i);
|
PRINT_ERROR("DEBUG: endloop without any block [%s:%u]",name.c_str(),i);
|
||||||
r.ok=false;
|
r.ok=false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(Blocks.back().type!=BLOCK_LOOP)
|
if(Blocks.back().type!=BLOCK_LOOP)
|
||||||
{
|
{
|
||||||
printf("DEBUG: endloop: closed block is not a loop block! [%s:%u]\n",name.c_str(),i);
|
PRINT_ERROR("DEBUG: endloop: closed block is not a loop block! [%s:%u]",name.c_str(),i);
|
||||||
r.ok=false;
|
r.ok=false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1263,3 +1239,14 @@ bool DefScriptPackage::RunScriptIfExists(std::string name,CmdSet *pSet)
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DefScriptPackage::def_print(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
if(!fmt)
|
||||||
|
return;
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vprintf( fmt, ap );
|
||||||
|
va_end(ap);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|||||||
@ -15,8 +15,6 @@
|
|||||||
class DefScriptPackage;
|
class DefScriptPackage;
|
||||||
class DefScript;
|
class DefScript;
|
||||||
|
|
||||||
typedef void (*_slog_func)(const char*,...);
|
|
||||||
|
|
||||||
// general struct for if..else..endif / loop..endloop blocks
|
// general struct for if..else..endif / loop..endloop blocks
|
||||||
struct Def_Block
|
struct Def_Block
|
||||||
{
|
{
|
||||||
@ -143,18 +141,6 @@ public:
|
|||||||
std::string EscapeString(std::string);
|
std::string EscapeString(std::string);
|
||||||
std::string UnescapeString(std::string);
|
std::string UnescapeString(std::string);
|
||||||
std::string GetUnescapedVar(std::string);
|
std::string GetUnescapedVar(std::string);
|
||||||
|
|
||||||
|
|
||||||
// own logging functions. default is printf.
|
|
||||||
// DO NOT USE THEM YET! THEY DO NOT WORK CORRECTLY!
|
|
||||||
// need some help with this [FG]
|
|
||||||
inline void SetLog(void *ptr) { _slog=(_slog_func)ptr; }
|
|
||||||
inline void SetDebugLog(void *ptr) { _sdebuglog=(_slog_func)ptr; }
|
|
||||||
inline void SetErrorLog(void *ptr) { _serrorlog=(_slog_func)ptr; }
|
|
||||||
void Log(const char*,...);
|
|
||||||
void DebugLog(const char*,...);
|
|
||||||
void ErrorLog(const char*,...);
|
|
||||||
|
|
||||||
|
|
||||||
std::string scPath;
|
std::string scPath;
|
||||||
|
|
||||||
@ -171,12 +157,12 @@ private:
|
|||||||
void RemoveBrackets(CmdSet&);
|
void RemoveBrackets(CmdSet&);
|
||||||
void UnescapeSet(CmdSet&);
|
void UnescapeSet(CmdSet&);
|
||||||
std::string RemoveBracketsFromString(std::string);
|
std::string RemoveBracketsFromString(std::string);
|
||||||
|
void def_print(const char *fmt, ...);
|
||||||
void *parentMethod;
|
void *parentMethod;
|
||||||
DefScript_DynamicEventMgr *_eventmgr;
|
DefScript_DynamicEventMgr *_eventmgr;
|
||||||
std::map<std::string,DefScript*> Script;
|
std::map<std::string,DefScript*> Script;
|
||||||
std::map<std::string,unsigned char> scriptPermissionMap;
|
std::map<std::string,unsigned char> scriptPermissionMap;
|
||||||
DefScriptFunctionTable _functable;
|
DefScriptFunctionTable _functable;
|
||||||
_slog_func _slog,_serrorlog,_sdebuglog;
|
|
||||||
_DEFSC_DEBUG(std::fstream hLogfile);
|
_DEFSC_DEBUG(std::fstream hLogfile);
|
||||||
|
|
||||||
// Usable internal basic functions:
|
// Usable internal basic functions:
|
||||||
|
|||||||
@ -37,4 +37,8 @@ typedef long double ldbl;
|
|||||||
|
|
||||||
#define SCRIPT_NAMESPACE "DEFSCRIPT::SCRIPT::"
|
#define SCRIPT_NAMESPACE "DEFSCRIPT::SCRIPT::"
|
||||||
|
|
||||||
|
#define PRINT def_print
|
||||||
|
#define PRINT_DEBUG def_print
|
||||||
|
#define PRINT_ERROR def_print
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -473,8 +473,8 @@ DefReturnResult DefScriptPackage::func_substr(CmdSet& Set)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned int start,len;
|
unsigned int start,len;
|
||||||
len=(unsigned int)toNumber(Set.arg[0]);
|
len=(unsigned int)toUint64(Set.arg[0]);
|
||||||
start=(unsigned int)toNumber(Set.arg[1]);
|
start=(unsigned int)toUint64(Set.arg[1]);
|
||||||
if(start+len>Set.defaultarg.length())
|
if(start+len>Set.defaultarg.length())
|
||||||
len=Set.defaultarg.length()-start;
|
len=Set.defaultarg.length()-start;
|
||||||
r.ret=Set.defaultarg.substr(start,len);
|
r.ret=Set.defaultarg.substr(start,len);
|
||||||
@ -502,7 +502,7 @@ DefReturnResult DefScriptPackage::func_random(CmdSet& Set)
|
|||||||
int min,max;
|
int min,max;
|
||||||
min=(int)toUint64(Set.arg[0]);
|
min=(int)toUint64(Set.arg[0]);
|
||||||
max=(int)toUint64(Set.defaultarg);
|
max=(int)toUint64(Set.defaultarg);
|
||||||
r.ret=toString(ldbl( min + ( rand() % (max - min + 1)) ));
|
r.ret=toString(min + ( rand() % (max - min + 1)) );
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -92,7 +92,7 @@ bool VarSet::ReadVarsFromFile(std::string fn)
|
|||||||
while(!fh.eof())
|
while(!fh.eof())
|
||||||
{
|
{
|
||||||
c=fh.get();
|
c=fh.get();
|
||||||
if(c=='\n' || fh.eof())
|
if(c=='\n' || c==13 || c==10 || fh.eof())
|
||||||
{
|
{
|
||||||
if(line.empty())
|
if(line.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@ -1235,7 +1235,41 @@ void DefScriptPackage::My_Run(std::string line, std::string username)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DefScriptPackage::my_print(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
if(!fmt)
|
||||||
|
return;
|
||||||
|
char buf[1000];
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(buf,1000, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
log(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DefScriptPackage::my_print_error(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
if(!fmt)
|
||||||
|
return;
|
||||||
|
char buf[1000];
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(buf,1000, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
logerror(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DefScriptPackage::my_print_debug(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
if(!fmt)
|
||||||
|
return;
|
||||||
|
char buf[1000];
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(buf,1000, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
logdebug(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -53,4 +53,24 @@ DefReturnResult SCSwitchOpcodeHandler(CmdSet&);
|
|||||||
DefReturnResult SCOpcodeDisabled(CmdSet&);
|
DefReturnResult SCOpcodeDisabled(CmdSet&);
|
||||||
DefReturnResult SCSpoofWorldPacket(CmdSet&);
|
DefReturnResult SCSpoofWorldPacket(CmdSet&);
|
||||||
|
|
||||||
|
|
||||||
|
void my_print(const char *fmt, ...);
|
||||||
|
void my_print_error(const char *fmt, ...);
|
||||||
|
void my_print_debug(const char *fmt, ...);
|
||||||
|
|
||||||
|
#ifdef PRINT
|
||||||
|
#undef PRINT
|
||||||
|
#define PRINT my_print
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef PRINT_ERROR
|
||||||
|
#undef PRINT_ERROR
|
||||||
|
#define PRINT_ERROR my_print_error
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef PRINT_DEBUG
|
||||||
|
#undef PRINT_DEBUG
|
||||||
|
#define PRINT_DEBUG my_print_debug
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -11,12 +11,12 @@ SceneGuiStart::SceneGuiStart(PseuGUI *gui) : Scene(gui)
|
|||||||
char *fn;
|
char *fn;
|
||||||
switch(gui->_driverType)
|
switch(gui->_driverType)
|
||||||
{
|
{
|
||||||
case DIRECTX8:
|
case video::EDT_DIRECT3D8:
|
||||||
case DIRECTX9:
|
case video::EDT_DIRECT3D9:
|
||||||
fn = "data/misc/directxlogo.png";
|
fn = "data/misc/directxlogo.png";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OPENGL:
|
case video::EDT_OPENGL:
|
||||||
fn = "data/misc/opengllogo.png";
|
fn = "data/misc/opengllogo.png";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@ -110,9 +110,6 @@ bool PseuInstance::Init(void)
|
|||||||
_conf=new PseuInstanceConf();
|
_conf=new PseuInstanceConf();
|
||||||
|
|
||||||
_scp->SetPath(_scpdir);
|
_scp->SetPath(_scpdir);
|
||||||
_scp->SetLog(logdetail); // does anyone have an idea why log() is not accepted here?
|
|
||||||
_scp->SetDebugLog(logdebug);
|
|
||||||
_scp->SetErrorLog(logerror);
|
|
||||||
|
|
||||||
_scp->variables.Set("@version_short",_ver_short);
|
_scp->variables.Set("@version_short",_ver_short);
|
||||||
_scp->variables.Set("@version",_ver);
|
_scp->variables.Set("@version",_ver);
|
||||||
|
|||||||
@ -185,7 +185,7 @@ void ItemProtoCache_InsertDataToSession(WorldSession *session)
|
|||||||
{
|
{
|
||||||
buf.clear();
|
buf.clear();
|
||||||
fh.read((char*)&datasize,sizeof(uint32));
|
fh.read((char*)&datasize,sizeof(uint32));
|
||||||
DEBUG(logdebug("ItemProtoCache: (%u/%u) - datasize=%u",i,total,datasize));
|
//DEBUG(logdebug("ItemProtoCache: (%u/%u) - datasize=%u",i,total,datasize));
|
||||||
buf.resize(datasize);
|
buf.resize(datasize);
|
||||||
fh.read((char*)buf.contents(),datasize);
|
fh.read((char*)buf.contents(),datasize);
|
||||||
ItemProto *proto = new ItemProto();
|
ItemProto *proto = new ItemProto();
|
||||||
|
|||||||
@ -839,7 +839,7 @@ void WorldSession::_HandleNameQueryResponseOpcode(WorldPacket& recvPacket)
|
|||||||
uint64 pguid;
|
uint64 pguid;
|
||||||
std::string pname;
|
std::string pname;
|
||||||
recvPacket >> pguid >> pname;
|
recvPacket >> pguid >> pname;
|
||||||
if(pname.length()>12 || pname.length()<2)
|
if(pname.length()>MAX_PLAYERNAME_LENGTH || pname.length()<MIN_PLAYERNAME_LENGTH)
|
||||||
return; // playernames maxlen=12, minlen=2
|
return; // playernames maxlen=12, minlen=2
|
||||||
// rest of the packet is not interesting for now
|
// rest of the packet is not interesting for now
|
||||||
if(plrNameCache.AddInfo(pguid,pname))
|
if(plrNameCache.AddInfo(pguid,pname))
|
||||||
|
|||||||
@ -54,7 +54,7 @@ void _OnSignal(int s)
|
|||||||
|
|
||||||
void quitproc(void)
|
void quitproc(void)
|
||||||
{
|
{
|
||||||
printf("Waiting for all instances to finish... [%u]\n",instanceList.size());
|
log("Waiting for all instances to finish... [%u]\n",instanceList.size());
|
||||||
for(std::list<PseuInstanceRunnable*>::iterator i=instanceList.begin();i!=instanceList.end();i++)
|
for(std::list<PseuInstanceRunnable*>::iterator i=instanceList.begin();i!=instanceList.end();i++)
|
||||||
{
|
{
|
||||||
(*i)->GetInstance()->Stop();
|
(*i)->GetInstance()->Stop();
|
||||||
@ -63,7 +63,7 @@ void quitproc(void)
|
|||||||
|
|
||||||
void abortproc(void)
|
void abortproc(void)
|
||||||
{
|
{
|
||||||
printf("Terminating all instances... [%u]\n",instanceList.size());
|
log("Terminating all instances... [%u]\n",instanceList.size());
|
||||||
for(std::list<PseuInstanceRunnable*>::iterator i=instanceList.begin();i!=instanceList.end();i++)
|
for(std::list<PseuInstanceRunnable*>::iterator i=instanceList.begin();i!=instanceList.end();i++)
|
||||||
{
|
{
|
||||||
(*i)->GetInstance()->SetFastQuit(true);
|
(*i)->GetInstance()->SetFastQuit(true);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user