* fixed a little bug(?) in the variable importer

* implemented SCP database functionality (.scp files). (sounds familiar? :P )
* new DefScript command: "loadscp,name filename"
* added .def file: append.def. (wrapper to concat strings)
** -> note that the scp db has no real use right now, just some program internal stuff which will come tomorrow. soon i'll have a go at DefScript return values, useable e.g. to get data from the dbs.
This commit is contained in:
False.Genesis 2007-03-04 00:18:58 +00:00
parent 0379c2ccf0
commit 06942daea6
15 changed files with 205 additions and 21 deletions

View File

@ -11,18 +11,20 @@ CONFIG
//they will get loaded automatically if needed
LOADALL
// load the uptime counter
LOADDEF uptime
// RELOADDEF myscript
// ...
// set permissions for internal functions
INTERNAL_PERM
// Load some SCP files
LOADALLSCP
// do more stuff here in future...
// load the uptime counter
LOADDEF uptime
LOG * StartUp complete!

15
bin/scripts/append.def Normal file
View File

@ -0,0 +1,15 @@
#permission=255
// usage: append text to a string.
// args:
// @def: text to append
// @0: variable to which the text should be appended
// get the var name if the original variable
SET,v #${@caller}::${@0}
// if it has not been set before, init it now
DEFAULT,${v}
// append to the original var. inner ${..} gets the var name, outer ${..} get the value of the var name we just got.
SET,${v} ${${v}}${@def}
// remove the name placeholder
UNSET v

View File

@ -1,6 +1,8 @@
#psermission=255
LOG * Assigning permissions for internal functions...
// default permission level for all internal script commands
set,p 255
// this is important because players could reset permissions for dangerous functions
@ -24,7 +26,6 @@ SETSCRIPTPERMISSION,pow ${p}
SETSCRIPTPERMISSION,bitor ${p}
SETSCRIPTPERMISSION,bitand ${p}
SETSCRIPTPERMISSION,bitxor ${p}
SETSCRIPTPERMISSION,sendchatmessage ${p}
SETSCRIPTPERMISSION,pause ${p}
// emotes are not relly dangerous, allow for all users
@ -39,6 +40,8 @@ SETSCRIPTPERMISSION,applypermissions ${p}
SETSCRIPTPERMISSION,log ${p}
SETSCRIPTPERMISSION,logdetail ${p}
SETSCRIPTPERMISSION,logdebug ${p}
SETSCRIPTPERMISSION,target ${p}
SETSCRIPTPERMISSION,loadscp ${p}
UNSET p

View File

@ -0,0 +1,9 @@
#permission=255
LOG * Loading SCP data storages...
// TODO: load stuff here
// example:
// LOADSCP,test data/test.scp
LOG * SCP loaded.

View File

@ -80,6 +80,7 @@ DefScriptFunctionTable *DefScriptPackage::_GetFunctionTable(void) const
{"castspell", &DefScriptPackage::SCcastspell},
{"queryitem", &DefScriptPackage::SCqueryitem},
{"target", &DefScriptPackage::SCtarget},
{"loadscp", &DefScriptPackage::SCloadscp},
// table termination
{NULL,NULL}

View File

@ -25,12 +25,22 @@ typedef __int64_t def_int64;
class DefScriptPackage;
class DefScript;
struct DefXChgResult {
struct DefXChgResult
{
DefXChgResult() { changed=false; }
bool changed;
std::string str;
};
struct SecReturnResult
{
bool ok; // true if the execution of the current statement was successful
bool abrt; // true if ALL current script execution must be aborted.
std::string ret; // return value used by ?{..}
std::string err; // error string, including tracestack, etc.
};
class CmdSet {
public:
CmdSet(DefScript *p);
@ -163,6 +173,7 @@ private:
bool SCcastspell(CmdSet);
bool SCqueryitem(CmdSet);
bool SCtarget(CmdSet);
bool SCloadscp(CmdSet);
// Own variable declarations
std::map<std::string, unsigned char> my_usrPermissionMap;

View File

@ -110,43 +110,41 @@ bool VarSet::ReadVarsFromFile(std::string fn)
}
if(line.at(0)=='[' && line.at(line.length()-1)==']')
{
prefix=line.substr(1,line.length()-2);
if(!prefix.empty())
std::string loadinfo;
loadinfo=line.substr(1,line.length()-2);
if(!loadinfo.empty())
{
if(prefix.at(0)=='#')
prefix=toLower(prefix);
if(prefix=="#uppercase")
if(loadinfo.at(0)=='#')
loadinfo=toLower(loadinfo);
if(loadinfo=="#uppercase")
{
upper=true;
lower=false;
prefix.clear();
}
else if(prefix=="#normal")
else if(loadinfo=="#normal")
{
upper=false;
lower=false;
prefix.clear();
}
else if(prefix=="#lowercase")
else if(loadinfo=="#lowercase")
{
lower=true;
upper=false;
prefix.clear();
}
else if(prefix=="#noprefix")
else if(loadinfo=="#noprefix")
{
prefix.clear();
}
else
{
prefix+="::";
prefix=loadinfo+"::";
}
}
}
else
{
unsigned int pos=line.find("=");
if(pos)
if(pos!=std::string::npos)
{
std::string v=line.substr(0,pos);;

View File

@ -9,6 +9,7 @@
#include "WorldSession.h"
#include "Channel.h"
#include "CacheHandler.h"
#include "SCPDatabase.h"
bool DefScriptPackage::SCshdn(CmdSet Set)
{
@ -236,6 +237,23 @@ bool DefScriptPackage::SCtarget(CmdSet Set)
return true;
}
bool DefScriptPackage::SCloadscp(CmdSet Set)
{
if(Set.arg[0].empty() || Set.defaultarg.empty())
return true;
std::string dbname = stringToLower(Set.arg[0]);
uint32 sections=((PseuInstance*)parentMethod)->GetSCPDatabase(dbname).LoadFromFile((char*)Set.defaultarg.c_str());
if(sections)
{
logdetail("Loaded SCP: \"%s\" [%s] (%u sections)",dbname.c_str(),Set.defaultarg.c_str(),sections);
}
else
{
logerror("Failed to load SCP: \"%s\" [%s]",dbname.c_str(),Set.defaultarg.c_str());
}
return true;
}
void DefScriptPackage::My_LoadUserPermissions(VarSet &vs)

View File

@ -27,9 +27,14 @@ void PseuInstanceRunnable::run(void)
_i = new PseuInstance(this);
_i->SetConfDir("./conf/");
_i->SetScpDir("./scripts/");
_i->Init();
// more
if(_i->Init())
{
_i->Run();
}
else
{
getchar();
}
delete _i;
}
@ -53,6 +58,7 @@ PseuInstance::PseuInstance(PseuInstanceRunnable *run)
_startrealm=true;
createWorldSession=false;
_error=false;
_initialized=false;
}
@ -230,10 +236,17 @@ void PseuInstance::Sleep(uint32 msecs)
GetRunnable()->sleep(msecs);
}
SCPDatabase& PseuInstance::GetSCPDatabase(std::string dbname)
{
return _dbmap[dbname];
}
PseuInstanceConf::PseuInstanceConf()
{
enablecli=false;
exitonerror=false;
}
void PseuInstanceConf::ApplyFromVarSet(VarSet &v)

View File

@ -7,6 +7,7 @@
#include "Auth/BigNumber.h"
#include "DefScript/DefScript.h"
#include "Network/SocketHandler.h"
#include "SCPDatabase.h"
class RealmSocket;
class WorldSession;
@ -70,6 +71,7 @@ class PseuInstance
void SetSessionKey(BigNumber key) { _sessionkey = key; }
BigNumber GetSessionKey(void) { return _sessionkey; }
void SetError(void) { _error = true; }
SCPDatabase& GetSCPDatabase(std::string);
@ -103,6 +105,7 @@ class PseuInstance
SocketHandler _sh;
CliRunnable *_cli;
ZThread::Thread _clithread;
std::map<std::string,SCPDatabase> _dbmap;
};

View File

@ -0,0 +1,53 @@
#include <fstream>
#include "common.h"
#include "SCPDatabase.h"
uint32 SCPDatabase::LoadFromFile(char *fn)
{
std::fstream fh;
std::string line,value,entry,storage;
uint32 id=0,sections=0;
char c;
fh.open(fn,std::ios_base::in);
if( !fh.is_open() )
return 0;
while(!fh.eof())
{
c=fh.get();
if(c=='\n' || fh.eof())
{
if(line.empty())
continue;
while(line[0]==' ' || line[0]=='\t')
line.erase(0,1);
if(line.empty() || (line.length() > 1 && (line[0]=='/' && line[1]=='/')) )
{
line.clear();
continue;
}
if(line[0]=='[')
{
id=(uint32)toInt(line.c_str()+1); // start reading after '['
sections++;
}
else
{
uint32 pos=line.find("=");
if(pos!=std::string::npos)
{
entry=stringToLower(line.substr(0,pos));
value=line.substr(pos+1,line.length()-1);
_map[id].Set(entry,value);
}
// else invalid line, must have '='
}
line.clear();
}
else
line+=c; // fill up line until a newline is reached (see above)
}
fh.close();
return sections;
}

40
src/Client/SCPDatabase.h Normal file
View File

@ -0,0 +1,40 @@
#ifndef _SCPDATABASE_H
#define _SCPDATABASE_H
#include <map>
struct SCPEntry
{
std::string entry;
std::string value;
};
typedef std::map<std::string,std::string> SCPEntryMap;
class SCPField
{
public:
std::string GetString(std::string entry) { return _map[entry]; }
uint64 GetInteger(std::string entry) { return toInt(_map[entry]); }
double GetDouble(std::string entry) { return strtod(_map[entry].c_str(),NULL); }
void Set(std::string entry,std::string value) { _map[entry]=value; }
private:
SCPEntryMap _map;
};
typedef std::map<uint32,SCPField> SCPFieldMap;
class SCPDatabase
{
public:
SCPField& GetField(uint32 id) { return _map[id]; }
uint32 LoadFromFile(char*);
private:
SCPFieldMap _map;
};
#endif

View File

@ -185,6 +185,12 @@
<File
RelativePath=".\Client\PseuWoW.h">
</File>
<File
RelativePath=".\Client\SCPDatabase.cpp">
</File>
<File
RelativePath=".\Client\SCPDatabase.h">
</File>
<File
RelativePath=".\Client\SysDefs.h">
</File>

View File

@ -59,3 +59,14 @@ std::string getDateString(void)
return std::string(str);
}
uint64 toInt(std::string str)
{
if(str.empty())
return 0;
str=stringToUpper(str);
if(str.length() > 2 && str[0]=='0' && str[1]=='X')
return strtoul(&(str.c_str()[2]),NULL,16);
else
return strtoul(str.c_str(),NULL,10);
}

View File

@ -13,5 +13,6 @@ std::string stringToUpper(std::string);
std::string stringToLower(std::string);
std::string toString(uint64);
std::string getDateString(void);
uint64 toInt(std::string);
#endif