diff --git a/source/src/command.cpp b/source/src/command.cpp index 1f527ae0..47ad7de9 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -784,6 +784,11 @@ bool exechook(int context, const char *ident, const char *body,...) // execute return false; } +void identhash(uint64_t *d) +{ + enumerate(*idents, ident, id, if(id.type == ID_COMMAND || id.type == ID_VAR) { *d ^= id.type == ID_VAR ? (size_t)"" - (size_t)id.name : (size_t)identhash - (size_t)id.fun; *d *= 16777619; }); +} + // tab-completion of all idents // always works at the end of the command line - the cursor position does not matter diff --git a/source/src/crypto.cpp b/source/src/crypto.cpp index 42102b93..ffa66b04 100644 --- a/source/src/crypto.cpp +++ b/source/src/crypto.cpp @@ -3,7 +3,7 @@ #ifdef STANDALONE #define DEBUGCOND (true) #else -VARP(cryptodebug, 0, 0, 1); +VARP(cryptodebug, 0, 1, 1); #define DEBUGCOND (cryptodebug==1) #endif @@ -159,6 +159,12 @@ namespace tiger lilswap(val.chunks, 3); } } + +void tigerhash(uchar *hash, const uchar *msg, int len) +{ + tiger::hash(msg, len, *((tiger::hashval *) hash)); +} + #undef sb1 #undef sb2 #undef sb3 diff --git a/source/src/protos.h b/source/src/protos.h index 5ef5c3f6..7973f7b9 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -939,6 +939,8 @@ extern const char *fullmodestr(int n); extern int defaultgamelimit(int gamemode); // crypto +#define TIGERHASHSIZE 24 +extern void tigerhash(uchar *hash, const uchar *msg, int len); extern void loadcertdir(); // load all certs in "config/certs" #if 0 // crypto // for AUTH @@ -970,6 +972,7 @@ extern bool addcommand(const char *name, void (*fun)(), const char *sig); extern int execute(const char *p); enum { HOOK_SP_MP = 1, HOOK_SP, HOOK_MP, HOOK_FLAGMASK = 0xff, HOOK_TEAM = 0x100, HOOK_NOTEAM = 0x200, HOOK_BOTMODE = 0x400, HOOK_FLAGMODE = 0x800, HOOK_ARENA = 0x1000 }; extern bool exechook(int context, const char *ident, const char *body,...) PRINTFARGS(3, 4); // execute cubescript hook if available and allowed in current context/gamemode +extern void identhash(uint64_t *d); extern char *executeret(const char *p); extern char *conc(const char **w, int n, bool space); extern void intret(int v); diff --git a/source/src/serverfiles.h b/source/src/serverfiles.h index 14454596..7a39ab1a 100644 --- a/source/src/serverfiles.h +++ b/source/src/serverfiles.h @@ -21,6 +21,7 @@ struct servermap // in-memory version of a map file on a server { const char *fname, *fpath; // map name and path (fname has to be first member of this struct! hardcoded!) uchar *cgzraw, *cfgrawgz; // direct copies of the cgz and cfg files (cfg is already gzipped) + uchar cgzhash[TIGERHASHSIZE], cfghash[TIGERHASHSIZE]; int cgzlen, cfglen, cfggzlen; // file lengths and cfg-gz length int version, headersize, sfactor, numents, maprevision, waterlevel; // from map header @@ -65,11 +66,13 @@ struct servermap // in-memory version of a map file on a server uchar *cfgraw = (uchar *)loadfile(filename, &cfglen); if(cfgraw) { + tigerhash(cfghash, cfgraw, cfglen); loopk(cfglen) if(cfgraw[k] > 0x7f || (cfgraw[k] < 0x20 && !isspace(cfgraw[k]))) err = "illegal chars in cfg file"; } formatstring(filename)("%s%s.cgz", fpath, fname); path(filename); cgzraw = (uchar *)loadfile(filename, &cgzlen); + if(cgzraw) tigerhash(cgzhash, cgzraw, cgzlen); if(!cgzraw) err = "loading cgz failed"; else if(cfglen > MAXCFGFILESIZE) err = "cfg file too big"; else if(cgzlen >= MAXMAPSENDSIZE) err = "cgz file too big";