]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/registry.qh
Registry: network and verify checksums on connect
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / registry.qh
index eb8372f7638c980791a48179988f8f4f4f6deb3a..59ddf25ff87ee30c627f14fc4cfd25b4ec23b072 100644 (file)
        STATIC_INIT(Registry_sort_##id) \
        { \
                heapsort(id##_COUNT - (skip), _REGISTRY_SWAP_##id, _REGISTRY_CMP_##id, NULL); \
-       } \
-       REGISTRY_CHECK(id)
+       }
+
+#define REGISTRY_HASH(id) Registry_hash_##id
+
+[[accumulate]] void Registry_check(string r, string server) { }
+[[accumulate]] void Registry_send_all() { }
+
+#ifdef SVQC
+void Registry_send(string id, string hash);
+#else
+#define Registry_send(id, hash)
+#endif
 
 #define REGISTRY_CHECK(id) \
+       string REGISTRY_HASH(id); \
        STATIC_INIT(Registry_check_##id) \
        { \
                string algo = "SHA256"; \
                string s = ""; \
                FOREACH(id, true, LAMBDA(s = strcat(s, join, it.registered_id))); \
                s = substring(s, strlen(join), -1); \
-               LOG_TRACEF(#id ": %s\n[%s]\n", digest_hex(algo, s), s); \
-       }
+               string h = REGISTRY_HASH(id) = strzone(digest_hex(algo, s)); \
+               LOG_TRACEF(#id ": %s\n[%s]\n", h, s); \
+       } \
+       [[accumulate]] void Registry_check(string r, string sv) \
+       { \
+               if (r == #id) \
+               { \
+                       string cl = REGISTRY_HASH(id); \
+                       if (cl != sv) \
+                       { \
+                               LOG_FATALF("client/server mismatch (%s).\nCL: %s\nSV: %s\n", r, cl, sv); \
+                       } \
+               } \
+       } \
+       [[accumulate]] void Registry_send_all() { Registry_send(#id, REGISTRY_HASH(id)); } \
 
 #endif