From: TimePath Date: Sun, 15 Nov 2015 03:00:52 +0000 (+1100) Subject: Map: explicit remove function X-Git-Tag: xonotic-v0.8.2~1663 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d82c939f09ed20bd6b229e6a1f362e1d16c80953;p=xonotic%2Fxonotic-data.pk3dir.git Map: explicit remove function --- diff --git a/qcsrc/lib/map.qc b/qcsrc/lib/map.qc index d71c2639f..aee2a3637 100644 --- a/qcsrc/lib/map.qc +++ b/qcsrc/lib/map.qc @@ -2,18 +2,17 @@ #define MAP_H // Databases (hash tables) -const float DB_BUCKETS = 8192; -void db_save(float db, string pFilename) +const int DB_BUCKETS = 8192; +void db_save(int db, string filename) { - int fh = fopen(pFilename, FILE_WRITE); + int fh = fopen(filename, FILE_WRITE); if (fh < 0) { - LOG_INFO(strcat("^1Can't write DB to ", pFilename)); + LOG_WARNINGF("^1Can't write DB to %s\n", filename); return; } - int n = buf_getsize(db); fputs(fh, strcat(ftos(DB_BUCKETS), "\n")); - for (int i = 0; i < n; ++i) + for (int i = 0, n = buf_getsize(db); i < n; ++i) fputs(fh, strcat(bufstr_get(db, i), "\n")); fclose(fh); } @@ -23,16 +22,16 @@ int db_create() return buf_create(); } -void db_put(float db, string pKey, string pValue); +void db_put(int db, string key, string value); -int db_load(string pFilename) +int db_load(string filename) { int db = buf_create(); if (db < 0) return -1; - int fh = fopen(pFilename, FILE_READ); + int fh = fopen(filename, FILE_READ); if (fh < 0) return db; string l = fgets(fh); - if (stof(l) == DB_BUCKETS) + if (stoi(l) == DB_BUCKETS) { for (int i = 0; (l = fgets(fh)); ++i) { @@ -58,13 +57,12 @@ int db_load(string pFilename) return db; } -void db_dump(float db, string pFilename) +void db_dump(int db, string filename) { - int fh = fopen(pFilename, FILE_WRITE); - if (fh < 0) error(strcat("Can't dump DB to ", pFilename)); - int n = buf_getsize(db); + int fh = fopen(filename, FILE_WRITE); + if (fh < 0) LOG_FATALF("Can't dump DB to %s\n"); fputs(fh, "0\n"); - for (int i = 0; i < n; ++i) + for (int i = 0, n = buf_getsize(db); i < n; ++i) { int m = tokenizebyseparator(bufstr_get(db, i), "\\"); for (int j = 2; j < m; j += 2) @@ -73,21 +71,23 @@ void db_dump(float db, string pFilename) fclose(fh); } -void db_close(float db) +void db_close(int db) { buf_del(db); } -string db_get(float db, string pKey) +string db_get(int db, string key) { - int h = crc16(false, pKey) % DB_BUCKETS; - return uri_unescape(infoget(bufstr_get(db, h), pKey)); + int h = crc16(false, key) % DB_BUCKETS; + return uri_unescape(infoget(bufstr_get(db, h), key)); } -void db_put(float db, string pKey, string pValue) +#define db_remove(db, key) db_put(db, key, "") + +void db_put(int db, string key, string value) { - int h = crc16(false, pKey) % DB_BUCKETS; - bufstr_set(db, h, infoadd(bufstr_get(db, h), pKey, uri_escape(pValue))); + int h = crc16(false, key) % DB_BUCKETS; + bufstr_set(db, h, infoadd(bufstr_get(db, h), key, uri_escape(value))); } void db_test() diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index d12a90377..8c874044f 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -1159,7 +1159,7 @@ string uid2name(string myuid) { if(s != "") { db_put(ServerProgsDB, strcat("/uid2name/", myuid), s); - db_put(ServerProgsDB, strcat("uid2name", myuid), ""); + db_remove(ServerProgsDB, strcat("uid2name", myuid)); } } diff --git a/qcsrc/server/race.qc b/qcsrc/server/race.qc index 3d6e9e85e..bc9fafc4c 100644 --- a/qcsrc/server/race.qc +++ b/qcsrc/server/race.qc @@ -328,8 +328,8 @@ void race_deleteTime(string map, float pos) { if (i == RANKINGS_CNT) { - db_put(ServerProgsDB, strcat(map, rr, "time", ftos(i)), string_null); - db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(i)), string_null); + db_remove(ServerProgsDB, strcat(map, rr, "time", ftos(i))); + db_remove(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(i))); } else {