]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Map: explicit remove function
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 15 Nov 2015 03:00:52 +0000 (14:00 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Sun, 15 Nov 2015 03:00:52 +0000 (14:00 +1100)
qcsrc/lib/map.qc
qcsrc/server/miscfunctions.qc
qcsrc/server/race.qc

index d71c2639fb1997a24975d11ce86869a612e0542c..aee2a363765d50bb7f52629b6af65d161f4c10ac 100644 (file)
@@ -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()
index d12a903778571195c13999e904daa605330ba24d..8c874044faa42db0b81096576ccb4bfb2a2c032b 100644 (file)
@@ -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));
                }
        }
 
index 3d6e9e85e80eacdfd3bf2371af6dcdcbf46a5afb..bc9fafc4c293f821ef6e3f36e951e123946cf39b 100644 (file)
@@ -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
                {