Fixed: permissions system for players & script commands.

Fixed: ingame commands ("-say hi") are useable again. 
/!\ Added now conf option: "allowgamecmd" 
+ fixed debugger working directory
This commit is contained in:
False.Genesis 2007-01-11 18:11:54 +00:00
parent 889238cfb7
commit e69375d76e
16 changed files with 170 additions and 42 deletions

View File

@ -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

View File

@ -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
// ...

View File

@ -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

View File

@ -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!

3
bin/scripts/quit.def Normal file
View File

@ -0,0 +1,3 @@
#permission=255
SAY Terminating proc...
SHDN

View File

@ -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")

View File

@ -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<std::string, unsigned char> scriptPermissionMap;
std::map<std::string,DefScript*> Script;
std::map<std::string,unsigned char> 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<std::string, unsigned char> my_usrPermissionMap;
};

View File

@ -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;
}

View File

@ -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<variables.Size();i++)
{
sub = variables[i].name.substr(0,strlen(prefix));
if(sub == prefix)
{
usr = variables[i].name.substr(strlen(prefix), variables[i].name.length() - strlen(prefix));
my_usrPermissionMap[usr] = atoi(variables[i].value.c_str());
DEBUG( printf("Player '%s' permission = %u\n",usr.c_str(),atoi(variables[i].value.c_str())); )
}
}
}
bool DefScriptPackage::My_Run(std::string line, std::string username)
{
DefXChgResult final=ReplaceVars(line,NULL,false);
CmdSet curSet=SplitLine(final.str);
#endif
uint8 scperm=0,usrperm=0;
for (std::map<std::string,unsigned char>::iterator i = my_usrPermissionMap.begin(); i != my_usrPermissionMap.end(); i++)
{
if(i->first == username)
{
usrperm = i->second;
}
}
for (std::map<std::string,unsigned char>::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;
}

View File

@ -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
{

View File

@ -38,6 +38,8 @@ class PseuInstanceConf
std::string worldhost;
uint16 networksleeptime;
uint8 showopcodes;
bool allowgamecmd;
bool enablecli;
};

View File

@ -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);
}
}

View File

@ -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"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="odbc32.lib odbccp32.lib sdl.lib sdl_net.lib sdlmain.lib libeay32MT.lib ssleay32MT.lib WS2_32.LIB"
AdditionalDependencies="odbc32.lib odbccp32.lib sdl.lib sdlmain.lib libeay32MT.lib WS2_32.LIB"
ShowProgress="0"
OutputFile="$(OutDir)/$(InputName).exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories=""
IgnoreAllDefaultLibraries="FALSE"
AssemblyDebug="0"
ProgramDatabaseFile="$(SolutionDir)/temp/$(ProjectName)/Release/PseuWoW.pdb"
SubSystem="1"
TargetMachine="1"/>
@ -104,7 +109,7 @@
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="odbc32.lib odbccp32.lib sdl.lib sdl_net.lib sdlmain.lib libeay32MT.lib ssleay32MT.lib WS2_32.LIB"
AdditionalDependencies="odbc32.lib odbccp32.lib sdl.lib sdlmain.lib libeay32MT.lib WS2_32.LIB"
OutputFile="$(OutDir)/$(InputName).exe"
LinkIncremental="2"
SuppressStartupBanner="TRUE"

View File

@ -29,9 +29,9 @@
BasicRuntimeChecks="3"
RuntimeLibrary="3"
PrecompiledHeaderFile=".\Debug/PseuWoW_Controller.pch"
AssemblerListingLocation=".\Debug/"
ObjectFile=".\Debug/"
ProgramDataBaseFileName=".\Debug/"
AssemblerListingLocation="$(SolutionDir)/temp/$(ProjectName)/"
ObjectFile="$(SolutionDir)/temp/$(ProjectName)/"
ProgramDataBaseFileName="$(SolutionDir)/temp/$(ProjectName)/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="4"/>
@ -73,17 +73,19 @@
WholeProgramOptimization="FALSE">
<Tool
Name="VCCLCompilerTool"
Optimization="1"
Optimization="3"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="dep/include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
StringPooling="TRUE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="TRUE"
BufferSecurityCheck="FALSE"
EnableFunctionLevelLinking="FALSE"
EnableEnhancedInstructionSet="0"
PrecompiledHeaderFile=".\Release/PseuWoW_Controller.pch"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
AssemblerListingLocation="$(SolutionDir)/temp/$(ProjectName)/"
ObjectFile="$(SolutionDir)/temp/$(ProjectName)/"
ProgramDataBaseFileName="$(SolutionDir)/temp/$(ProjectName)/"
WarningLevel="3"
SuppressStartupBanner="TRUE"/>
<Tool

View File

@ -37,7 +37,7 @@
Name="VCCustomBuildTool"/>
<Tool
Name="VCLibrarianTool"
OutputFile="./dep/lib/zlib.lib"/>
OutputFile="./dep/lib/debug/zlib.lib"/>
<Tool
Name="VCMIDLTool"/>
<Tool
@ -78,7 +78,7 @@
Name="VCCustomBuildTool"/>
<Tool
Name="VCLibrarianTool"
OutputFile="./dep/lib/zlib.lib"/>
OutputFile="./dep/lib/release/zlib.lib"/>
<Tool
Name="VCMIDLTool"/>
<Tool

View File

@ -26,7 +26,7 @@
BasicRuntimeChecks="3"
RuntimeLibrary="3"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="2"
UsePrecompiledHeader="0"
PrecompiledHeaderFile="$(SolutionDir)/temp/$(ProjectName)/zthread.pch"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
@ -35,7 +35,7 @@
Name="VCCustomBuildTool"/>
<Tool
Name="VCLibrarianTool"
OutputFile="./dep/lib/zthread.lib"/>
OutputFile="./dep/lib/debug/zthread.lib"/>
<Tool
Name="VCMIDLTool"/>
<Tool
@ -67,7 +67,7 @@
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
RuntimeLibrary="0"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="2"
UsePrecompiledHeader="0"
PrecompiledHeaderFile="$(SolutionDir)/temp/$(ProjectName)/zthread.pch"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
@ -76,7 +76,7 @@
Name="VCCustomBuildTool"/>
<Tool
Name="VCLibrarianTool"
OutputFile="./dep/lib/zthread.lib"/>
OutputFile="./dep/lib/release/zthread.lib"/>
<Tool
Name="VCMIDLTool"/>
<Tool