From e69375d76e10855c426991a952f10f1dbc05212a Mon Sep 17 00:00:00 2001 From: "False.Genesis" Date: Thu, 11 Jan 2007 18:11:54 +0000 Subject: [PATCH] Fixed: permissions system for players & script commands. Fixed: ingame commands ("-say hi") are useable again. /!\ Added now conf option: "allowgamecmd" + fixed debugger working directory --- bin/conf/PseuWoW.conf.default | 4 ++ bin/scripts/_enterworld.def | 7 +-- bin/scripts/_nopermission.def | 15 ++++++ bin/scripts/_startup.def | 22 ++++++++ bin/scripts/quit.def | 3 ++ src/Client/DefScript/DefScript.cpp | 4 +- src/Client/DefScript/DefScript.h | 12 ++++- src/Client/DefScript/DefScriptFunctions.cpp | 13 ++++- src/Client/DefScriptInterface.cpp | 59 +++++++++++++++++++-- src/Client/PseuWoW.cpp | 4 ++ src/Client/PseuWoW.h | 2 + src/Client/World/WorldSession.cpp | 28 +++++----- src/PseuWoW.vcproj | 9 +++- src/shared.vcproj | 18 ++++--- src/zlib.vcproj | 4 +- src/zthread.vcproj | 8 +-- 16 files changed, 170 insertions(+), 42 deletions(-) create mode 100644 bin/scripts/_nopermission.def create mode 100644 bin/scripts/quit.def diff --git a/bin/conf/PseuWoW.conf.default b/bin/conf/PseuWoW.conf.default index 118e553..4bb4f59 100644 --- a/bin/conf/PseuWoW.conf.default +++ b/bin/conf/PseuWoW.conf.default @@ -57,4 +57,8 @@ ClientLanguage=enUS // 1 is a good setting for maximum network performance and lowest ping times NetworkSleepTime=50 +// defines if players may say/yell/whisper commands to PseuWoW +// set this to 0 and PseuWoW will not react to given commands +allowgamecmd=1 + diff --git a/bin/scripts/_enterworld.def b/bin/scripts/_enterworld.def index 88dd6ab..5e114a3 100644 --- a/bin/scripts/_enterworld.def +++ b/bin/scripts/_enterworld.def @@ -7,9 +7,6 @@ OUT * World entered, executing appropriate script... // not yet implemented // CASTSPELL 836 -// yaay we are online -EMOTE 5 - // MaNGOS: make PseuWoW invincible SAY .gmon @@ -20,6 +17,10 @@ SAY .gmon // to know everything worked fine, etc SAY [${@version_short}] login successful. +// yaay we are online. Ready! +// 126 = TEXTEMOTE_READY +EMOTE 126 + // add your own stuff here // ... diff --git a/bin/scripts/_nopermission.def b/bin/scripts/_nopermission.def new file mode 100644 index 0000000..d0210a7 --- /dev/null +++ b/bin/scripts/_nopermission.def @@ -0,0 +1,15 @@ +#permission=255 + +// GETS EXECUTED IF A PLAYER TRIES TO GIVE PSEUWOW A COMMAND AND IS NOT ALLOWED TO + +// Arguments: +// ========== +// @0 : name of the player who wanted to execute a command +// @1 : permission level of this user +// @2 : permission level needed to execute the script +// @3 : name of the script that should get executed + +SAY Forget it, ${@0}, you have only permission ${@1} but need ${@2} to run the script '${@3}' + +// say NO! +EMOTE 66 \ No newline at end of file diff --git a/bin/scripts/_startup.def b/bin/scripts/_startup.def index 9d9f204..d3850e9 100644 --- a/bin/scripts/_startup.def +++ b/bin/scripts/_startup.def @@ -27,6 +27,28 @@ UNSET #ACCNAME OUT * Dangerous variables removed. +OUT * Assigning permissions for internal functions... + +// this is important because players could reset permissions for dangerous functions +SETSCRIPTPERMISSION,setscriptpermission 255 + +SETSCRIPTPERMISSION,out 0 +SETSCRIPTPERMISSION,set 255 +SETSCRIPTPERMISSION,default 255 +SETSCRIPTPERMISSION,unset 255 +SETSCRIPTPERMISSION,shdn 255 +SETSCRIPTPERMISSION,loaddef 255 +SETSCRIPTPERMISSION,reloaddef 255 +SETSCRIPTPERMISSION,pause 255 +SETSCRIPTPERMISSION,emote 0 +SETSCRIPTPERMISSION,savecache 10 +SETSCRIPTPERMISSION,sendchatmessage 255 + +OUT * Permissions set. + + + + // do more stuff here in future... OUT * StartUp complete! diff --git a/bin/scripts/quit.def b/bin/scripts/quit.def new file mode 100644 index 0000000..7b1e606 --- /dev/null +++ b/bin/scripts/quit.def @@ -0,0 +1,3 @@ +#permission=255 +SAY Terminating proc... +SHDN \ No newline at end of file diff --git a/src/Client/DefScript/DefScript.cpp b/src/Client/DefScript/DefScript.cpp index 978bc73..0a761e9 100644 --- a/src/Client/DefScript/DefScript.cpp +++ b/src/Client/DefScript/DefScript.cpp @@ -45,6 +45,8 @@ DefScriptFunctionTable *DefScriptPackage::_GetFunctionTable(void) const {"shdn",&DefScriptPackage::func_shdn}, {"loaddef",&DefScriptPackage::func_loaddef}, {"reloaddef",&DefScriptPackage::func_reloaddef}, + {"setscriptpermission",&DefScriptPackage::func_setscriptpermission}, + // user functions: {"pause",&DefScriptPackage::SCpause}, @@ -134,7 +136,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn, std::string sn){ if(label=="permission") { scriptPermissionMap[sn] = atoi(value.c_str()); - } // ... + } if(line=="load_debug") load_debug=true; if(line=="load_notify") diff --git a/src/Client/DefScript/DefScript.h b/src/Client/DefScript/DefScript.h index 0a55e1a..bff38eb 100644 --- a/src/Client/DefScript/DefScript.h +++ b/src/Client/DefScript/DefScript.h @@ -92,6 +92,10 @@ public: std::string scPath; + // Own executor functions + void My_LoadUserPermissions(VarSet&); + bool My_Run(std::string line,std::string username); + private: DefXChgResult ReplaceVars(std::string, CmdSet*, bool); CmdSet SplitLine(std::string); @@ -102,9 +106,8 @@ private: DefScriptFunctionTable *functionTable; unsigned int functions; void *parentMethod; - - std::map scriptPermissionMap; std::map Script; + std::map scriptPermissionMap; // Usable internal basic functions: bool func_default(CmdSet); @@ -115,6 +118,7 @@ private: bool func_out(CmdSet); bool func_eof(CmdSet); bool func_shdn(CmdSet); + bool func_setscriptpermission(CmdSet); // Useable own internal functions: bool SCpause(CmdSet); @@ -122,6 +126,10 @@ private: bool SCsavecache(CmdSet); bool SCemote(CmdSet); bool SCfollow(CmdSet); + bool SCshdn(CmdSet); + + // Own variable declarations + std::map my_usrPermissionMap; }; diff --git a/src/Client/DefScript/DefScriptFunctions.cpp b/src/Client/DefScript/DefScriptFunctions.cpp index ca5dcb6..d043c1e 100644 --- a/src/Client/DefScript/DefScriptFunctions.cpp +++ b/src/Client/DefScript/DefScriptFunctions.cpp @@ -9,7 +9,9 @@ bool DefScriptPackage::func_shdn(CmdSet Set){ - exit(0); + //exit(0); + // need to define own + SCshdn(Set); return true; } @@ -124,3 +126,12 @@ bool DefScriptPackage::func_default(CmdSet Set){ return true; } + +bool DefScriptPackage::func_setscriptpermission(CmdSet Set) +{ + if(Set.defaultarg.empty() || Set.arg[0].empty()) + return false; + + scriptPermissionMap[Set.arg[0]] = atoi(Set.defaultarg.c_str()); + return true; +} \ No newline at end of file diff --git a/src/Client/DefScriptInterface.cpp b/src/Client/DefScriptInterface.cpp index 81744c5..124d1e2 100644 --- a/src/Client/DefScriptInterface.cpp +++ b/src/Client/DefScriptInterface.cpp @@ -1,5 +1,3 @@ -#ifndef __DEFSCRIPTINTERFACE_H -#define __DEFSCRIPTINTERFACE_H #include "common.h" #include "PseuWoW.h" @@ -10,6 +8,11 @@ #include "SharedDefines.h" #include "WorldSession.h" +bool DefScriptPackage::SCshdn(CmdSet Set) +{ + ((PseuInstance*)parentMethod)->Stop(); + return true; +} bool DefScriptPackage::SCpause(CmdSet Set){ ((PseuInstance*)parentMethod)->Sleep(atoi(Set.defaultarg.c_str())); @@ -78,6 +81,56 @@ bool DefScriptPackage::SCfollow(CmdSet Set){ } +void DefScriptPackage::My_LoadUserPermissions(VarSet &vs) +{ + static char *prefix = "USERS::"; + std::string sub,usr; + for(uint32 i=0;i::iterator i = my_usrPermissionMap.begin(); i != my_usrPermissionMap.end(); i++) + { + if(i->first == username) + { + usrperm = i->second; + } + } + + for (std::map::iterator i = scriptPermissionMap.begin(); i != scriptPermissionMap.end(); i++) + { + if(i->first == curSet.cmd) + { + scperm = i->second; + } + } + + if(usrperm < scperm) + { + CmdSet Set(NULL); + Set.arg[0] = username; + Set.arg[1] = toString(usrperm); + Set.arg[2] = toString(scperm); + Set.arg[3] = curSet.cmd; + RunScript("_nopermission",&Set); + return false; + } + + Interpret(curSet); + return true; +} \ No newline at end of file diff --git a/src/Client/PseuWoW.cpp b/src/Client/PseuWoW.cpp index 3def836..764dbe5 100644 --- a/src/Client/PseuWoW.cpp +++ b/src/Client/PseuWoW.cpp @@ -103,6 +103,8 @@ bool PseuInstance::Init(void) { _scp->variables.Set("@version_short",_ver_short); _scp->variables.Set("@version",_ver); + _scp->My_LoadUserPermissions(_scp->variables); + // //DEBUG1(printf("Main_Init: Loading DefScripts from folder '%s'\n",defScpPath.c_str());); if(!_scp->RunScript("_startup",NULL)) @@ -318,6 +320,8 @@ void PseuInstanceConf::ApplyFromVarSet(VarSet &v) charname=v.Get("CHARNAME"); networksleeptime=atoi(v.Get("NETWORKSLEEPTIME").c_str()); showopcodes=atoi(v.Get("SHOWOPCODES").c_str()); + enablecli=(bool)atoi(v.Get("ENABLECLI").c_str()); + allowgamecmd=(bool)atoi(v.Get("ALLOWGAMECMD").c_str()); // clientversion is a bit more complicated to add { diff --git a/src/Client/PseuWoW.h b/src/Client/PseuWoW.h index 3a761e3..feb7e03 100644 --- a/src/Client/PseuWoW.h +++ b/src/Client/PseuWoW.h @@ -38,6 +38,8 @@ class PseuInstanceConf std::string worldhost; uint16 networksleeptime; uint8 showopcodes; + bool allowgamecmd; + bool enablecli; }; diff --git a/src/Client/World/WorldSession.cpp b/src/Client/World/WorldSession.cpp index ccf5f92..b23ba8e 100644 --- a/src/Client/World/WorldSession.cpp +++ b/src/Client/World/WorldSession.cpp @@ -91,7 +91,7 @@ void WorldSession::Update(void) OpcodeHandler *table = _GetOpcodeHandlerTable(); bool known=false; - while(!pktQueue.empty()) + while(pktQueue.size()) { WorldPacket *packet = pktQueue.next(); @@ -386,7 +386,7 @@ void WorldSession::_HandleMessageChatOpcode(WorldPacket& recvPacket) printf("W:CHAT: %s [%s]: %s\n",plrname.c_str(),LookupName(lang,langNames),msg.c_str()); } - if(target_guid!=_myGUID && msg.length()>1 && msg.at(0)=='-') + if(target_guid!=_myGUID && msg.length()>1 && msg.at(0)=='-' && GetInstance()->GetConf()->allowgamecmd) isCmd=true; // some fun code :P @@ -410,28 +410,24 @@ void WorldSession::_HandleMessageChatOpcode(WorldPacket& recvPacket) if(isCmd) { - /*defScp.variables.Set("@lastcmd_name",defScp.variables.Get("@thiscmd_name")); - defScp.variables.Set("@lastcmd",defScp.variables.Get("@lastcmd")); - defScp.variables.Set("@thiscmd_name",plrname); - defScp.variables.Set("@thiscmd",toString(target_guid)); + GetInstance()->GetScripts()->variables.Set("@thiscmd_name",plrname); + GetInstance()->GetScripts()->variables.Set("@thiscmd",toString(target_guid)); std::string lin=msg.substr(1,msg.length()-1); - uint8 perm=atoi(playerPermissions.Get(plrname).c_str()); - try{ - if(!defScp.RunSingleLine(lin,perm)) - defScp.RunScriptByName("_nopermission",NULL,255); - } catch (...) { + try + { + GetInstance()->GetScripts()->My_Run(lin,plrname); + } + catch (...) + { SendChatMessage(CHAT_MSG_SAY,0,"Exception while trying to execute: [ "+lin+" ]",""); - }*/ + } } if(type==CHAT_MSG_WHISPER && !isCmd) { - /*defScp.variables.Set("@lastwhisper_name",defScp.variables.Get("@thiswhisper_name")); - defScp.variables.Set("@lastwhisper",defScp.variables.Get("@thiswhisper")); - 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.variables.Set("@thiswhisper_lang",toString((uint64)lang)); GetInstance()->GetScripts()->RunScript("_onwhisper",NULL); } } diff --git a/src/PseuWoW.vcproj b/src/PseuWoW.vcproj index f2adaad..8ea61ce 100644 --- a/src/PseuWoW.vcproj +++ b/src/PseuWoW.vcproj @@ -32,7 +32,9 @@ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" StringPooling="FALSE" RuntimeLibrary="2" + BufferSecurityCheck="FALSE" EnableFunctionLevelLinking="FALSE" + EnableEnhancedInstructionSet="1" PrecompiledHeaderFile=".\Release/PseuWoW.pch" AssemblerListingLocation="$(SolutionDir)/temp/$(ProjectName)/" ObjectFile="$(SolutionDir)/temp/$(ProjectName)/" @@ -43,11 +45,14 @@ Name="VCCustomBuildTool"/> @@ -104,7 +109,7 @@ Name="VCCustomBuildTool"/> @@ -73,17 +73,19 @@ WholeProgramOptimization="FALSE"> + OutputFile="./dep/lib/debug/zlib.lib"/> + OutputFile="./dep/lib/release/zlib.lib"/> + OutputFile="./dep/lib/debug/zthread.lib"/> + OutputFile="./dep/lib/release/zthread.lib"/>