]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - host_cmd.c
improved shadowmap side culling
[xonotic/darkplaces.git] / host_cmd.c
index 341026ce2e0258fb2e11bea4705171dff35c3a4d..5c1f0969d90e16558938df19c185739895a1e628 100644 (file)
@@ -33,7 +33,8 @@ cvar_t sv_adminnick = {CVAR_SAVE, "sv_adminnick", "", "nick name to use for admi
 cvar_t sv_status_privacy = {CVAR_SAVE, "sv_status_privacy", "0", "do not show IP addresses in 'status' replies to clients"};
 cvar_t sv_status_show_qcstatus = {CVAR_SAVE, "sv_status_show_qcstatus", "0", "show the 'qcstatus' field in status replies, not the 'frags' field. Turn this on if your mod uses this field, and the 'frags' field on the other hand has no meaningful value."};
 cvar_t rcon_password = {CVAR_PRIVATE, "rcon_password", "", "password to authenticate rcon commands; NOTE: changing rcon_secure clears rcon_password, so set rcon_secure always before rcon_password"};
-cvar_t rcon_secure = {CVAR_NQUSERINFOHACK, "rcon_secure", "0", "force secure rcon authentication; NOTE: changing rcon_secure clears rcon_password, so set rcon_secure always before rcon_password"};
+cvar_t rcon_secure = {CVAR_NQUSERINFOHACK, "rcon_secure", "0", "force secure rcon authentication (1 = time based, 2 = challenge based); NOTE: changing rcon_secure clears rcon_password, so set rcon_secure always before rcon_password"};
+cvar_t rcon_secure_challengetimeout = {0, "rcon_secure_challengetimeout", "5", "challenge-based secure rcon: time out requests if no challenge came within this time interval"};
 cvar_t rcon_address = {0, "rcon_address", "", "server address to send rcon commands to (when not connected to a server)"};
 cvar_t team = {CVAR_USERINFO | CVAR_SAVE, "team", "none", "QW team (4 character limit, example: blue)"};
 cvar_t skin = {CVAR_USERINFO | CVAR_SAVE, "skin", "", "QW player skin name (example: base)"};
@@ -139,7 +140,7 @@ void Host_Status_f (void)
                        packetloss = 0;
                        if (client->netconnection)
                                for (j = 0;j < NETGRAPH_PACKETS;j++)
-                                       if (client->netconnection->incoming_unreliablesize[j] == NETGRAPH_LOSTPACKET)
+                                       if (client->netconnection->incoming_netgraph[j].unreliablebytes == NETGRAPH_LOSTPACKET)
                                                packetloss++;
                        packetloss = packetloss * 100 / NETGRAPH_PACKETS;
                        ping = bound(0, (int)floor(client->ping*1000+0.5), 9999);
@@ -171,29 +172,16 @@ void Host_Status_f (void)
                
                if (in == 0) // default layout
                {
-                       print ("#%-3u ", i+1);
-                       print ("%-16.16s ", client->name);
-                       print ("%4i  ", frags);
-                       print ("%2i:%02i:%02i\n   ", hours, minutes, seconds);
-                       print ("%s\n", ip);
+                       print ("#%-3u %-16.16s  %3i  %2i:%02i:%02i\n", i+1, client->name, frags, hours, minutes, seconds);
+                       print ("  %s\n", ip);
                }
                else if (in == 1) // extended layout
                {
-                       k%2 ? print("^3") : print("^7");
-                       print ("%-21s ", ip);
-                       print ("%2i ", packetloss);
-                       print ("%4i ", ping);
-                       print ("%2i:%02i:%02i ", hours, minutes, seconds);
-                       print ("%4i  ", frags);
-                       print ("#%-3u ", i+1);
-                       print ("^7%s\n", client->name);
+                       print ("%s%-21s %2i %4i %2i:%02i:%02i %4i  #%-3u ^7%s\n", k%2 ? "^3" : "^7", ip, packetloss, ping, hours, minutes, seconds, frags, i+1, client->name);
                }
                else if (in == 2) // reduced layout
                {
-                       k%2 ? print("^3") : print("^7");
-                       print ("%-21s ", ip);
-                       print ("#%-3u ", i+1);
-                       print ("^7%s\n", client->name);
+                       print ("%s%-21s #%-3u ^7%s\n", k%2 ? "^3" : "^7", ip, i+1, client->name);
                }
        }
 
@@ -889,7 +877,7 @@ void Host_Loadgame_f (void)
 
                        // link it into the bsp tree
                        if (!ent->priv.server->free)
-                               SV_LinkEdict (ent, false);
+                               SV_LinkEdict(ent);
                }
 
                end = t;
@@ -997,7 +985,7 @@ void Host_Name_f (void)
        }
 
        if (Cmd_Argc () == 2)
-               newNameSource = Cmd_Argv(i);
+               newNameSource = Cmd_Argv(1);
        else
                newNameSource = Cmd_Args();
 
@@ -1008,7 +996,7 @@ void Host_Name_f (void)
                Cvar_Set ("_cl_name", newName);
                if (strlen(newNameSource) >= sizeof(newName)) // overflowed
                {
-                       Con_Printf("Your name is longer than %i chars! It has been truncated.\n", sizeof(newName) - 1);
+                       Con_Printf("Your name is longer than %i chars! It has been truncated.\n", (int) (sizeof(newName) - 1));
                        Con_Printf("name: %s\n", cl_name.string);
                }
                return;
@@ -2347,6 +2335,63 @@ static void MaxPlayers_f(void)
                Cvar_Set ("deathmatch", "1");
 }
 
+/*
+=====================
+Host_PQRcon_f
+
+ProQuake rcon support
+=====================
+*/
+void Host_PQRcon_f (void)
+{
+       int i;
+       lhnetaddress_t to;
+       lhnetsocket_t *mysocket;
+       char peer_address[64];
+
+       if (!rcon_password.string || !rcon_password.string[0] || rcon_secure.integer)
+       {
+               Con_Printf ("You must set rcon_password before issuing an pqrcon command, and rcon_secure must be 0.\n");
+               return;
+       }
+
+       for (i = 0;rcon_password.string[i];i++)
+       {
+               if (ISWHITESPACE(rcon_password.string[i]))
+               {
+                       Con_Printf("rcon_password is not allowed to have any whitespace.\n");
+                       return;
+               }
+       }
+
+       if (cls.netcon)
+       {
+               InfoString_GetValue(cls.userinfo, "*ip", peer_address, sizeof(peer_address));
+       }
+       else
+       {
+               if (!rcon_address.string[0])
+               {
+                       Con_Printf ("You must either be connected, or set the rcon_address cvar to issue rcon commands\n");
+                       return;
+               }
+               strlcpy(peer_address, rcon_address.string, strlen(rcon_address.string)+1);
+       }
+       LHNETADDRESS_FromString(&to, peer_address, sv_netport.integer);
+       mysocket = NetConn_ChooseClientSocketForAddress(&to);
+       if (mysocket)
+       {
+               SZ_Clear(&net_message);
+               MSG_WriteLong (&net_message, 0);
+               MSG_WriteByte (&net_message, CCREQ_RCON);
+               MSG_WriteString (&net_message, rcon_password.string);
+               MSG_WriteString (&net_message, Cmd_Args());
+               *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
+               NetConn_Write(mysocket, net_message.data, net_message.cursize, &to);
+               SZ_Clear (&net_message);
+       }
+}
+
 //=============================================================================
 
 // QuakeWorld commands
@@ -2392,14 +2437,36 @@ void Host_Rcon_f (void) // credit: taken from QuakeWorld
                LHNETADDRESS_FromString(&to, rcon_address.string, sv_netport.integer);
        }
        mysocket = NetConn_ChooseClientSocketForAddress(&to);
-       if (mysocket)
+       if (mysocket && Cmd_Args()[0])
        {
                // simply put together the rcon packet and send it
-               if(Cmd_Argv(0)[0] == 's' || rcon_secure.integer)
+               if(Cmd_Argv(0)[0] == 's' || rcon_secure.integer > 1)
+               {
+                       if(cls.rcon_commands[cls.rcon_ringpos][0])
+                       {
+                               char s[128];
+                               LHNETADDRESS_ToString(&cls.rcon_addresses[cls.rcon_ringpos], s, sizeof(s), true);
+                               Con_Printf("rcon to %s (for command %s) failed: too many buffered commands (possibly increase MAX_RCONS)\n", s, cls.rcon_commands[cls.rcon_ringpos]);
+                               cls.rcon_commands[cls.rcon_ringpos][0] = 0;
+                               --cls.rcon_trying;
+                       }
+                       for (i = 0;i < MAX_RCONS;i++)
+                               if(cls.rcon_commands[i][0])
+                                       if (!LHNETADDRESS_Compare(&to, &cls.rcon_addresses[i]))
+                                               break;
+                       ++cls.rcon_trying;
+                       if(i >= MAX_RCONS)
+                               NetConn_WriteString(mysocket, "\377\377\377\377getchallenge", &to); // otherwise we'll request the challenge later
+                       strlcpy(cls.rcon_commands[cls.rcon_ringpos], Cmd_Args(), sizeof(cls.rcon_commands[cls.rcon_ringpos]));
+                       cls.rcon_addresses[cls.rcon_ringpos] = to;
+                       cls.rcon_timeout[cls.rcon_ringpos] = realtime + rcon_secure_challengetimeout.value;
+                       cls.rcon_ringpos = (cls.rcon_ringpos + 1) % MAX_RCONS;
+               }
+               else if(rcon_secure.integer)
                {
                        char buf[1500];
                        char argbuf[1500];
-                       dpsnprintf(argbuf, sizeof(argbuf), "%ld %s", (long) time(NULL), Cmd_Args());
+                       dpsnprintf(argbuf, sizeof(argbuf), "%ld.%06d %s", (long) time(NULL), (int) (rand() % 1000000), Cmd_Args());
                        memcpy(buf, "\377\377\377\377srcon HMAC-MD4 TIME ", 24);
                        if(HMAC_MDFOUR_16BYTES((unsigned char *) (buf + 24), (unsigned char *) argbuf, strlen(argbuf), (unsigned char *) rcon_password.string, strlen(rcon_password.string)))
                        {
@@ -2603,7 +2670,7 @@ void Host_Packet_f (void) // credit: taken from QuakeWorld
 
        in = Cmd_Argv(2);
        out = send+4;
-       send[0] = send[1] = send[2] = send[3] = 0xff;
+       send[0] = send[1] = send[2] = send[3] = -1;
 
        l = (int)strlen (in);
        for (i=0 ; i<l ; i++)
@@ -2671,7 +2738,7 @@ void Host_Pings_f (void)
                packetloss = 0;
                if (svs.clients[i].netconnection)
                        for (j = 0;j < NETGRAPH_PACKETS;j++)
-                               if (svs.clients[i].netconnection->incoming_unreliablesize[j] == NETGRAPH_LOSTPACKET)
+                               if (svs.clients[i].netconnection->incoming_netgraph[j].unreliablebytes == NETGRAPH_LOSTPACKET)
                                        packetloss++;
                packetloss = packetloss * 100 / NETGRAPH_PACKETS;
                ping = (int)floor(svs.clients[i].ping*1000+0.5);
@@ -2790,8 +2857,10 @@ void Host_InitCommands (void)
        Cvar_RegisterVariable (&rcon_password);
        Cvar_RegisterVariable (&rcon_address);
        Cvar_RegisterVariable (&rcon_secure);
-       Cmd_AddCommand ("rcon", Host_Rcon_f, "sends a command to the server console (if your rcon_password matches the server's rcon_password), or to the address specified by rcon_address when not connected (again rcon_password must match the server's)");
-       Cmd_AddCommand ("srcon", Host_Rcon_f, "sends a command to the server console (if your rcon_password matches the server's rcon_password), or to the address specified by rcon_address when not connected (again rcon_password must match the server's); this always works as if rcon_secure is set");
+       Cvar_RegisterVariable (&rcon_secure_challengetimeout);
+       Cmd_AddCommand ("rcon", Host_Rcon_f, "sends a command to the server console (if your rcon_password matches the server's rcon_password), or to the address specified by rcon_address when not connected (again rcon_password must match the server's); note: if rcon_secure is set, client and server clocks must be synced e.g. via NTP");
+       Cmd_AddCommand ("srcon", Host_Rcon_f, "sends a command to the server console (if your rcon_password matches the server's rcon_password), or to the address specified by rcon_address when not connected (again rcon_password must match the server's); this always works as if rcon_secure is set; note: client and server clocks must be synced e.g. via NTP");
+       Cmd_AddCommand ("pqrcon", Host_PQRcon_f, "sends a command to a proquake server console (if your rcon_password matches the server's rcon_password), or to the address specified by rcon_address when not connected (again rcon_password must match the server's)");
        Cmd_AddCommand ("user", Host_User_f, "prints additional information about a player number or name on the scoreboard");
        Cmd_AddCommand ("users", Host_Users_f, "prints additional information about all players on the scoreboard");
        Cmd_AddCommand ("fullserverinfo", Host_FullServerinfo_f, "internal use only, sent by server to client to update client's local copy of serverinfo string");