diff --git a/src/Client/DefScript/DefScript.cpp b/src/Client/DefScript/DefScript.cpp index ffb5272..bb22efb 100644 --- a/src/Client/DefScript/DefScript.cpp +++ b/src/Client/DefScript/DefScript.cpp @@ -12,6 +12,7 @@ using namespace DefScriptTools; #define SN_ONLOAD "?onload?" + enum DefScriptBlockType { BLOCK_IF, @@ -21,9 +22,6 @@ enum DefScriptBlockType // --- SECTION FOR SCRIPT PACKAGES --- DefScriptPackage::DefScriptPackage() { - SetLog(printf); - SetDebugLog(printf); - SetErrorLog(printf); _DEFSC_DEBUG ( hLogfile.open("DefScriptLog.txt",std::ios_base::out); @@ -44,30 +42,6 @@ DefScriptPackage::~DefScriptPackage() _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) { parentMethod = p; @@ -293,7 +267,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){ while (true) { 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; line+=z; } @@ -303,6 +277,8 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){ while( !line.empty() && (line.at(0)==' ' || line.at(0)=='\t') ) 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()) continue; if(line.at(0)=='/' && line.at(1)=='/') @@ -360,7 +336,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){ DeleteScript(curScript->GetName()); sn = stringToLower(value); _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]; } else if(label=="linestrip") @@ -476,7 +452,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){ } 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 } @@ -485,7 +461,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){ f.close(); 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); return false; } @@ -615,7 +591,7 @@ DefReturnResult DefScriptPackage::RunScript(std::string name, CmdSet *pSet,std:: { 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; break; } @@ -642,13 +618,13 @@ DefReturnResult DefScriptPackage::RunScript(std::string name, CmdSet *pSet,std:: { 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; break; } 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; break; } @@ -668,13 +644,13 @@ DefReturnResult DefScriptPackage::RunScript(std::string name, CmdSet *pSet,std:: { 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; break; } 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; break; } @@ -1263,3 +1239,14 @@ bool DefScriptPackage::RunScriptIfExists(std::string name,CmdSet *pSet) } 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"); +} diff --git a/src/Client/DefScript/DefScript.h b/src/Client/DefScript/DefScript.h index c8143ba..14d8ca0 100644 --- a/src/Client/DefScript/DefScript.h +++ b/src/Client/DefScript/DefScript.h @@ -15,8 +15,6 @@ class DefScriptPackage; class DefScript; -typedef void (*_slog_func)(const char*,...); - // general struct for if..else..endif / loop..endloop blocks struct Def_Block { @@ -143,18 +141,6 @@ public: std::string EscapeString(std::string); std::string UnescapeString(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; @@ -171,12 +157,12 @@ private: void RemoveBrackets(CmdSet&); void UnescapeSet(CmdSet&); std::string RemoveBracketsFromString(std::string); + void def_print(const char *fmt, ...); void *parentMethod; DefScript_DynamicEventMgr *_eventmgr; std::map Script; std::map scriptPermissionMap; DefScriptFunctionTable _functable; - _slog_func _slog,_serrorlog,_sdebuglog; _DEFSC_DEBUG(std::fstream hLogfile); // Usable internal basic functions: diff --git a/src/Client/DefScript/DefScriptDefines.h b/src/Client/DefScript/DefScriptDefines.h index 672b14d..f27e0bc 100644 --- a/src/Client/DefScript/DefScriptDefines.h +++ b/src/Client/DefScript/DefScriptDefines.h @@ -37,4 +37,8 @@ typedef long double ldbl; #define SCRIPT_NAMESPACE "DEFSCRIPT::SCRIPT::" +#define PRINT def_print +#define PRINT_DEBUG def_print +#define PRINT_ERROR def_print + #endif \ No newline at end of file diff --git a/src/Client/DefScript/DefScriptFunctions.cpp b/src/Client/DefScript/DefScriptFunctions.cpp index 1e74c99..e49b515 100644 --- a/src/Client/DefScript/DefScriptFunctions.cpp +++ b/src/Client/DefScript/DefScriptFunctions.cpp @@ -473,8 +473,8 @@ DefReturnResult DefScriptPackage::func_substr(CmdSet& Set) else { unsigned int start,len; - len=(unsigned int)toNumber(Set.arg[0]); - start=(unsigned int)toNumber(Set.arg[1]); + len=(unsigned int)toUint64(Set.arg[0]); + start=(unsigned int)toUint64(Set.arg[1]); if(start+len>Set.defaultarg.length()) len=Set.defaultarg.length()-start; r.ret=Set.defaultarg.substr(start,len); @@ -502,7 +502,7 @@ DefReturnResult DefScriptPackage::func_random(CmdSet& Set) int min,max; min=(int)toUint64(Set.arg[0]); max=(int)toUint64(Set.defaultarg); - r.ret=toString(ldbl( min + ( rand() % (max - min + 1)) )); + r.ret=toString(min + ( rand() % (max - min + 1)) ); return r; } diff --git a/src/Client/DefScript/VarSet.cpp b/src/Client/DefScript/VarSet.cpp index 5c55fb6..8adcd31 100644 --- a/src/Client/DefScript/VarSet.cpp +++ b/src/Client/DefScript/VarSet.cpp @@ -92,7 +92,7 @@ bool VarSet::ReadVarsFromFile(std::string fn) while(!fh.eof()) { c=fh.get(); - if(c=='\n' || fh.eof()) + if(c=='\n' || c==13 || c==10 || fh.eof()) { if(line.empty()) continue; diff --git a/src/Client/DefScriptInterface.cpp b/src/Client/DefScriptInterface.cpp index 68309f6..f5f695c 100644 --- a/src/Client/DefScriptInterface.cpp +++ b/src/Client/DefScriptInterface.cpp @@ -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); +} diff --git a/src/Client/DefScriptInterfaceInclude.h b/src/Client/DefScriptInterfaceInclude.h index 0844877..2d65db1 100644 --- a/src/Client/DefScriptInterfaceInclude.h +++ b/src/Client/DefScriptInterfaceInclude.h @@ -53,4 +53,24 @@ DefReturnResult SCSwitchOpcodeHandler(CmdSet&); DefReturnResult SCOpcodeDisabled(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 diff --git a/src/Client/GUI/SceneGuiStart.cpp b/src/Client/GUI/SceneGuiStart.cpp index a736d03..8bdf092 100644 --- a/src/Client/GUI/SceneGuiStart.cpp +++ b/src/Client/GUI/SceneGuiStart.cpp @@ -11,12 +11,12 @@ SceneGuiStart::SceneGuiStart(PseuGUI *gui) : Scene(gui) char *fn; switch(gui->_driverType) { - case DIRECTX8: - case DIRECTX9: + case video::EDT_DIRECT3D8: + case video::EDT_DIRECT3D9: fn = "data/misc/directxlogo.png"; break; - case OPENGL: + case video::EDT_OPENGL: fn = "data/misc/opengllogo.png"; break; diff --git a/src/Client/PseuWoW.cpp b/src/Client/PseuWoW.cpp index 36cc55b..9643840 100644 --- a/src/Client/PseuWoW.cpp +++ b/src/Client/PseuWoW.cpp @@ -110,9 +110,6 @@ bool PseuInstance::Init(void) _conf=new PseuInstanceConf(); _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",_ver); diff --git a/src/Client/World/CacheHandler.cpp b/src/Client/World/CacheHandler.cpp index 783144d..f1d2964 100644 --- a/src/Client/World/CacheHandler.cpp +++ b/src/Client/World/CacheHandler.cpp @@ -185,7 +185,7 @@ void ItemProtoCache_InsertDataToSession(WorldSession *session) { buf.clear(); 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); fh.read((char*)buf.contents(),datasize); ItemProto *proto = new ItemProto(); diff --git a/src/Client/World/WorldSession.cpp b/src/Client/World/WorldSession.cpp index eb13b83..94dc920 100644 --- a/src/Client/World/WorldSession.cpp +++ b/src/Client/World/WorldSession.cpp @@ -839,7 +839,7 @@ void WorldSession::_HandleNameQueryResponseOpcode(WorldPacket& recvPacket) uint64 pguid; std::string pname; recvPacket >> pguid >> pname; - if(pname.length()>12 || pname.length()<2) + if(pname.length()>MAX_PLAYERNAME_LENGTH || pname.length()::iterator i=instanceList.begin();i!=instanceList.end();i++) { (*i)->GetInstance()->Stop(); @@ -63,7 +63,7 @@ void quitproc(void) void abortproc(void) { - printf("Terminating all instances... [%u]\n",instanceList.size()); + log("Terminating all instances... [%u]\n",instanceList.size()); for(std::list::iterator i=instanceList.begin();i!=instanceList.end();i++) { (*i)->GetInstance()->SetFastQuit(true);