]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - crypto.c
host: Implement a hook struct in host_t. Use a hook to connect to local server
[xonotic/darkplaces.git] / crypto.c
index b5a4cc8b5670e4153db5bb1c610f2f0a10c92638..4589741a18095bdc32d3574c3e8ffad4c3f3688a 100644 (file)
--- a/crypto.c
+++ b/crypto.c
@@ -158,7 +158,7 @@ static size_t Crypto_UnParsePack(char *buf, size_t len, unsigned long header, co
 
 // d0_blind_id interface
 #define D0_EXPORT
-#ifdef __GNUC__
+#if defined (__GNUC__) || (__clang__) || (__TINYC__)
 #define D0_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
 #else
 #define D0_WARN_UNUSED_RESULT
@@ -518,7 +518,7 @@ static crypto_t *Crypto_ServerFindInstance(lhnetaddress_t *peeraddress, qboolean
        if(i < MAX_CRYPTOCONNECTS && (allow_create || cryptoconnects[i].crypto.data))
        {
                crypto = &cryptoconnects[i].crypto;
-               cryptoconnects[i].lasttime = realtime;
+               cryptoconnects[i].lasttime = host.realtime;
                return crypto;
        }
        if(!allow_create)
@@ -528,7 +528,7 @@ static crypto_t *Crypto_ServerFindInstance(lhnetaddress_t *peeraddress, qboolean
                if(cryptoconnects[i].lasttime < cryptoconnects[best].lasttime)
                        best = i;
        crypto = &cryptoconnects[best].crypto;
-       cryptoconnects[best].lasttime = realtime;
+       cryptoconnects[best].lasttime = host.realtime;
        memcpy(&cryptoconnects[best].address, peeraddress, sizeof(cryptoconnects[best].address));
        CLEAR_CDATA;
        return crypto;
@@ -1429,17 +1429,11 @@ void Crypto_Init_Commands(void)
 {
        if(d0_blind_id_dll)
        {
-               Cmd_AddCommand(&cmd_client, "crypto_reload", Crypto_Reload_f, "reloads cryptographic keys");
-               Cmd_AddCommand(&cmd_client, "crypto_keygen", Crypto_KeyGen_f, "generates and saves a cryptographic key");
-               Cmd_AddCommand(&cmd_client, "crypto_keys", Crypto_Keys_f, "lists the loaded keys");
-               Cmd_AddCommand(&cmd_client, "crypto_hostkeys", Crypto_HostKeys_f, "lists the cached host keys");
-               Cmd_AddCommand(&cmd_client, "crypto_hostkey_clear", Crypto_HostKey_Clear_f, "clears a cached host key");
-
-               Cmd_AddCommand(&cmd_server, "crypto_reload", Crypto_Reload_f, "reloads cryptographic keys");
-               Cmd_AddCommand(&cmd_server, "crypto_keygen", Crypto_KeyGen_f, "generates and saves a cryptographic key");
-               Cmd_AddCommand(&cmd_server, "crypto_keys", Crypto_Keys_f, "lists the loaded keys");
-               Cmd_AddCommand(&cmd_server, "crypto_hostkeys", Crypto_HostKeys_f, "lists the cached host keys");
-               Cmd_AddCommand(&cmd_server, "crypto_hostkey_clear", Crypto_HostKey_Clear_f, "clears a cached host key");
+               Cmd_AddCommand(CMD_SHARED, "crypto_reload", Crypto_Reload_f, "reloads cryptographic keys");
+               Cmd_AddCommand(CMD_SHARED, "crypto_keygen", Crypto_KeyGen_f, "generates and saves a cryptographic key");
+               Cmd_AddCommand(CMD_SHARED, "crypto_keys", Crypto_Keys_f, "lists the loaded keys");
+               Cmd_AddCommand(CMD_SHARED, "crypto_hostkeys", Crypto_HostKeys_f, "lists the cached host keys");
+               Cmd_AddCommand(CMD_SHARED, "crypto_hostkey_clear", Crypto_HostKey_Clear_f, "clears a cached host key");
 
                Cvar_RegisterVariable(&crypto_developer);
                if(d0_rijndael_dll)
@@ -2043,7 +2037,7 @@ int Crypto_ServerParsePacket(const char *data_in, size_t len_in, char *data_out,
                // check if we may perform crypto...
                if(crypto_servercpupercent.value > 0)
                {
-                       crypto_servercpu_accumulator += (realtime - crypto_servercpu_lastrealtime) * crypto_servercpupercent.value * 0.01;
+                       crypto_servercpu_accumulator += (host.realtime - crypto_servercpu_lastrealtime) * crypto_servercpupercent.value * 0.01;
                        if(crypto_servercpumaxtime.value)
                                if(crypto_servercpu_accumulator > crypto_servercpumaxtime.value)
                                        crypto_servercpu_accumulator = crypto_servercpumaxtime.value;
@@ -2051,13 +2045,13 @@ int Crypto_ServerParsePacket(const char *data_in, size_t len_in, char *data_out,
                else
                {
                        if(crypto_servercpumaxtime.value > 0)
-                               if(realtime != crypto_servercpu_lastrealtime)
+                               if(host.realtime != crypto_servercpu_lastrealtime)
                                        crypto_servercpu_accumulator = crypto_servercpumaxtime.value;
                }
-               crypto_servercpu_lastrealtime = realtime;
+               crypto_servercpu_lastrealtime = host.realtime;
                if(do_reject && crypto_servercpu_accumulator < 0)
                {
-                       if(realtime > complain_time + 5)
+                       if(host.realtime > complain_time + 5)
                                Con_Printf("crypto: cannot perform requested crypto operations; denial service attack or crypto_servercpupercent/crypto_servercpumaxtime are too low\n");
                        *len_out = 0;
                        return CRYPTO_DISCARD;
@@ -2426,7 +2420,7 @@ int Crypto_ClientParsePacket(const char *data_in, size_t len_in, char *data_out,
                        if(CDATA->next_step != 1)
                                return Crypto_SoftClientError(data_out, len_out, va(vabuf, sizeof(vabuf), "Got d0pk\\cnt\\%s when expecting %d", cnt, CDATA->next_step));
 
-                       cls.connect_nextsendtime = max(cls.connect_nextsendtime, realtime + 1); // prevent "hammering"
+                       cls.connect_nextsendtime = max(cls.connect_nextsendtime, host.realtime + 1); // prevent "hammering"
 
                        if((s = InfoString_GetValue(string + 4, "aes", infostringvalue, sizeof(infostringvalue))))
                                aes = atoi(s);
@@ -2475,7 +2469,7 @@ int Crypto_ClientParsePacket(const char *data_in, size_t len_in, char *data_out,
                        if(CDATA->next_step != 3)
                                return Crypto_SoftClientError(data_out, len_out, va(vabuf, sizeof(vabuf), "Got d0pk\\cnt\\%s when expecting %d", cnt, CDATA->next_step));
 
-                       cls.connect_nextsendtime = max(cls.connect_nextsendtime, realtime + 1); // prevent "hammering"
+                       cls.connect_nextsendtime = max(cls.connect_nextsendtime, host.realtime + 1); // prevent "hammering"
 
                        if(!qd0_blind_id_authenticate_with_private_id_verify(CDATA->id, data_in, len_in, msgbuf, &msgbuflen, &status))
                        {
@@ -2557,7 +2551,7 @@ int Crypto_ClientParsePacket(const char *data_in, size_t len_in, char *data_out,
                        if(CDATA->next_step != 5)
                                return Crypto_SoftClientError(data_out, len_out, va(vabuf, sizeof(vabuf), "Got d0pk\\cnt\\%s when expecting %d", cnt, CDATA->next_step));
 
-                       cls.connect_nextsendtime = max(cls.connect_nextsendtime, realtime + 1); // prevent "hammering"
+                       cls.connect_nextsendtime = max(cls.connect_nextsendtime, host.realtime + 1); // prevent "hammering"
 
                        if(CDATA->s < 0) // only if server didn't auth
                        {