]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - netconn.c
changed sv.time to realtime in name change time limit code
[xonotic/darkplaces.git] / netconn.c
index d876b929e2a6baab2b9e6e74b002fd7a625bf05f..c0c4c1e8db1f63e613e47e967c29deeef072f54f 100755 (executable)
--- a/netconn.c
+++ b/netconn.c
@@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #define DPMASTER_PORT 27950
 
 // note this defaults on for dedicated servers, off for listen servers
-cvar_t sv_public = {0, "sv_public", "0", "advertises this server on the master server (so that players can find it in the server browser)"};
+cvar_t sv_public = {0, "sv_public", "0", "1: advertises this server on the master server (so that players can find it in the server browser); 0: allow direct queries only; -1: do not respond to direct queries; -2: do not allow anyone to connect"};
 static cvar_t sv_heartbeatperiod = {CVAR_SAVE, "sv_heartbeatperiod", "120", "how often to send heartbeat in seconds (only used if sv_public is 1)"};
 
 static cvar_t sv_masters [] =
@@ -38,8 +38,7 @@ static cvar_t sv_masters [] =
        {CVAR_SAVE, "sv_master4", "", "user-chosen master server 4"},
        {0, "sv_masterextra1", "ghdigital.com", "default master server 1 (admin: LordHavoc)"}, // admin: LordHavoc
        {0, "sv_masterextra2", "dpmaster.deathmask.net", "default master server 2 (admin: Willis)"}, // admin: Willis
-       {0, "sv_masterextra3", "12.166.196.192", "default master server 3 (admin: Venim)"}, // admin: Venim
-       {0, "sv_masterextra4", "excalibur.nvg.ntnu.no", "default master server 4 (admin: tChr)"}, // admin: tChr
+       {0, "sv_masterextra3", "excalibur.nvg.ntnu.no", "default master server 3 (admin: tChr)"}, // admin: tChr
        {0, NULL, NULL, NULL}
 };
 
@@ -126,6 +125,10 @@ cvar_t sv_netport = {0, "port", "26000", "server port for players to connect to"
 cvar_t net_address = {0, "net_address", "0.0.0.0", "network address to open ports on"};
 //cvar_t net_netaddress_ipv6 = {0, "net_address_ipv6", "[0:0:0:0:0:0:0:0]", "network address to open ipv6 ports on"};
 
+char net_extresponse[NET_EXTRESPONSE_MAX][1400];
+int net_extresponse_count = 0;
+int net_extresponse_last = 0;
+
 // ServerList interface
 serverlist_mask_t serverlist_andmasks[SERVERLIST_ANDMASKCOUNT];
 serverlist_mask_t serverlist_ormasks[SERVERLIST_ORMASKCOUNT];
@@ -401,8 +404,7 @@ static void _ServerList_Test(void)
 
 void ServerList_QueryList(qboolean querydp, qboolean queryqw)
 {
-       //masterquerytime = realtime;
-       masterquerytime = Sys_DoubleTime();
+       masterquerytime = realtime;
        masterquerycount = 0;
        masterreplycount = 0;
        serverquerycount = 0;
@@ -576,7 +578,7 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers
                {
                        if (conn->message.cursize > (int)sizeof(conn->sendMessage))
                        {
-                               Con_Printf("NetConn_SendUnreliableMessage: reliable message too big (%u > %u)\n", conn->message.cursize, sizeof(conn->sendMessage));
+                               Con_Printf("NetConn_SendUnreliableMessage: reliable message too big (%u > %u)\n", conn->message.cursize, (int)sizeof(conn->sendMessage));
                                conn->message.overflowed = true;
                                return -1;
                        }
@@ -1088,18 +1090,21 @@ void NetConn_ConnectionEstablished(lhnetsocket_t *mysocket, lhnetaddress_t *peer
        cls.state = ca_connected;
        cls.signon = 0;                         // need all the signon messages before playing
        cls.protocol = initialprotocol;
+       // reset move sequence numbering on this new connection
+       cls.movesequence = 0;
+       cls.servermovesequence = 0;
        if (cls.protocol == PROTOCOL_QUAKEWORLD)
                Cmd_ForwardStringToServer("new");
        if (cls.protocol == PROTOCOL_QUAKE)
        {
-               // write a keepalive (svc_nop) as it seems to greatly improve the
+               // write a keepalive (clc_nop) as it seems to greatly improve the
                // chances of connecting to a netquake server
                sizebuf_t msg;
                unsigned char buf[4];
                memset(&msg, 0, sizeof(msg));
                msg.data = buf;
                msg.maxsize = sizeof(buf);
-               MSG_WriteChar(&msg, svc_nop);
+               MSG_WriteChar(&msg, clc_nop);
                NetConn_SendUnreliableMessage(cls.netcon, &msg, cls.protocol);
        }
 }
@@ -1132,8 +1137,7 @@ static int NetConn_ClientParsePacket_ServerList_ProcessReply(const char *address
                // store the data the engine cares about (address and ping)
                strlcpy(serverlist_cache[serverlist_cachecount].info.cname, addressstring, sizeof(serverlist_cache[serverlist_cachecount].info.cname));
                serverlist_cache[serverlist_cachecount].info.ping = 100000;
-               //serverlist_cache[serverlist_cachecount].querytime = realtime;
-               serverlist_cache[serverlist_cachecount].querytime = Sys_DoubleTime();
+               serverlist_cache[serverlist_cachecount].querytime = realtime;
                // if not in the slist menu we should print the server to console
                if (serverlist_consoleoutput)
                        Con_Printf("querying %s\n", addressstring);
@@ -1142,7 +1146,7 @@ static int NetConn_ClientParsePacket_ServerList_ProcessReply(const char *address
        // if this is the first reply from this server, count it as having replied
        if (serverlist_cache[n].info.ping == 100000)
                serverreplycount++;
-       pingtime = (int)((Sys_DoubleTime() - serverlist_cache[n].querytime) * 1000.0 + 0.5);
+       pingtime = (int)((realtime - serverlist_cache[n].querytime) * 1000.0 + 0.5);
        pingtime = bound(0, pingtime, 9999);
        // update the ping
        serverlist_cache[n].info.ping = min(serverlist_cache[n].info.ping, pingtime);
@@ -1343,6 +1347,15 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        serverlist_querywaittime = realtime + 3;
                        return true;
                }
+               if (!strncmp(string, "extResponse ", 12))
+               {
+                       ++net_extresponse_count;
+                       if(net_extresponse_count > NET_EXTRESPONSE_MAX)
+                               net_extresponse_count = NET_EXTRESPONSE_MAX;
+                       net_extresponse_last = (net_extresponse_last + 1) % NET_EXTRESPONSE_MAX;
+                       dpsnprintf(net_extresponse[net_extresponse_last], sizeof(net_extresponse[net_extresponse_last]), "'%s' %s", addressstring2, string + 12);
+                       return true;
+               }
                if (!strncmp(string, "ping", 4))
                {
                        if (developer.integer >= 10)
@@ -1439,9 +1452,12 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                int n;
                serverlist_info_t *info;
 
-               c = data[4];
-               data += 5;
-               length -= 5;
+               data += 4;
+               length -= 4;
+               SZ_Clear(&net_message);
+               SZ_Write(&net_message, data, length);
+               MSG_BeginReading();
+               c = MSG_ReadByte();
                switch (c)
                {
                case CCREP_ACCEPT:
@@ -1451,13 +1467,7 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        {
                                lhnetaddress_t clientportaddress;
                                clientportaddress = *peeraddress;
-                               if (length >= 4)
-                               {
-                                       unsigned int port = (data[0] << 0) | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
-                                       data += 4;
-                                       length -= 4;
-                                       LHNETADDRESS_SetPort(&clientportaddress, port);
-                               }
+                               LHNETADDRESS_SetPort(&clientportaddress, MSG_ReadLong());
                                // update the server IP in the userinfo (QW servers expect this, and it is used by the reconnect command)
                                InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "*ip", addressstring2);
                                M_Update_Return_Reason("Accepted");
@@ -1468,7 +1478,7 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        if (developer.integer >= 10)
                                Con_Printf("Datagram_ParseConnectionless: received CCREP_REJECT from %s.\n", addressstring2);
                        cls.connect_trying = false;
-                       M_Update_Return_Reason((char *)data);
+                       M_Update_Return_Reason((char *)MSG_ReadString());
                        break;
                case CCREP_SERVER_INFO:
                        if (developer.integer >= 10)
@@ -1506,6 +1516,7 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                default:
                        break;
                }
+               SZ_Clear(&net_message);
                // we may not have liked the packet, but it was a valid control
                // packet, so we're done processing this packet now
                return true;
@@ -1577,8 +1588,7 @@ void NetConn_QueryQueueFrame(void)
                                        NetConn_WriteString(cl_sockets[socket], "\377\377\377\377getinfo", &address);
                        }
 
-                       //entry->querytime = realtime;
-                       entry->querytime = Sys_DoubleTime();
+                       entry->querytime = realtime;
                        entry->querycounter++;
 
                        // if not in the slist menu we should print the server to console
@@ -1700,7 +1710,7 @@ static qboolean NetConn_BuildStatusResponse(const char* challenge, char* out_msg
                        client_t *cl = &svs.clients[i];
                        if (cl->active)
                        {
-                               int nameind, cleanind;
+                               int nameind, cleanind, pingvalue;
                                char curchar;
                                char cleanname [sizeof(cl->name)];
 
@@ -1718,9 +1728,14 @@ static qboolean NetConn_BuildStatusResponse(const char* challenge, char* out_msg
                                        }
                                } while (curchar != '\0');
 
+                               pingvalue = (int)(cl->ping * 1000.0f);
+                               if(cl->netconnection)
+                                       pingvalue = bound(1, pingvalue, 9999);
+                               else
+                                       pingvalue = 0;
                                length = dpsnprintf(ptr, left, "%d %d \"%s\"\n",
                                                                        cl->frags,
-                                                                       (int)(cl->ping * 1000.0f),
+                                                                       pingvalue,
                                                                        cleanname);
                                if(length < 0)
                                        return false;
@@ -1833,7 +1848,7 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        Com_HexDumpToConsole(data, length);
                }
 
-               if (length >= 12 && !memcmp(string, "getchallenge", 12))
+               if (length >= 12 && !memcmp(string, "getchallenge", 12) && sv_public.integer > -2)
                {
                        for (i = 0, best = 0, besttime = realtime;i < MAX_CHALLENGES;i++)
                        {
@@ -1855,7 +1870,7 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        NetConn_WriteString(mysocket, va("\377\377\377\377challenge %s", challenge[i].string), peeraddress);
                        return true;
                }
-               if (length > 8 && !memcmp(string, "connect\\", 8))
+               if (length > 8 && !memcmp(string, "connect\\", 8) && sv_public.integer > -2)
                {
                        string += 7;
                        length -= 7;
@@ -1893,7 +1908,9 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                                                if (developer.integer >= 10)
                                                        Con_Printf("Datagram_ParseConnectionless: sending \"accept\" to %s.\n", addressstring2);
                                                NetConn_WriteString(mysocket, "\377\377\377\377accept", peeraddress);
+                                               SV_VM_Begin();
                                                SV_SendServerinfo(client);
+                                               SV_VM_End();
                                        }
                                        else
                                        {
@@ -1936,7 +1953,7 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
 
                        return true;
                }
-               if (length >= 7 && !memcmp(string, "getinfo", 7))
+               if (length >= 7 && !memcmp(string, "getinfo", 7) && sv_public.integer > -1)
                {
                        const char *challenge = NULL;
 
@@ -1952,7 +1969,7 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        }
                        return true;
                }
-               if (length >= 9 && !memcmp(string, "getstatus", 9))
+               if (length >= 9 && !memcmp(string, "getstatus", 9) && sv_public.integer > -1)
                {
                        const char *challenge = NULL;
 
@@ -2028,18 +2045,26 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
        //  Quake packet flood Denial Of Service attacks)
        if (length >= 5 && (i = BigLong(*((int *)data))) && (i & (~NETFLAG_LENGTH_MASK)) == (int)NETFLAG_CTL && (i & NETFLAG_LENGTH_MASK) == length && (sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_QUAKEDP || sv.protocol == PROTOCOL_NEHAHRAMOVIE || sv.protocol == PROTOCOL_DARKPLACES1 || sv.protocol == PROTOCOL_DARKPLACES2 || sv.protocol == PROTOCOL_DARKPLACES3))
        {
-               int c = data[4];
-               data += 5;
-               length -= 5;
+               int c;
+               int protocolnumber;
+               const char *protocolname;
+               data += 4;
+               length -= 4;
+               SZ_Clear(&net_message);
+               SZ_Write(&net_message, data, length);
+               MSG_BeginReading();
+               c = MSG_ReadByte();
                switch (c)
                {
                case CCREQ_CONNECT:
                        if (developer.integer >= 10)
                                Con_Printf("Datagram_ParseConnectionless: received CCREQ_CONNECT from %s.\n", addressstring2);
-                       if (length < (int)strlen("QUAKE") + 1 + 1)
+                       if(sv_public.integer <= -2)
                                break;
 
-                       if (memcmp(data, "QUAKE", strlen("QUAKE") + 1) != 0 || (int)data[strlen("QUAKE") + 1] != NET_PROTOCOL_VERSION)
+                       protocolname = MSG_ReadString();
+                       protocolnumber = MSG_ReadByte();
+                       if (strcmp(protocolname, "QUAKE") || protocolnumber != NET_PROTOCOL_VERSION)
                        {
                                if (developer.integer >= 10)
                                        Con_Printf("Datagram_ParseConnectionless: sending CCREP_REJECT \"Incompatible version.\" to %s.\n", addressstring2);
@@ -2078,7 +2103,11 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                                        // if client is already spawned, re-send the
                                        // serverinfo message as they'll need it to play
                                        if (client->spawned)
+                                       {
+                                               SV_VM_Begin();
                                                SV_SendServerinfo(client);
+                                               SV_VM_End();
+                                       }
                                        return true;
                                }
                        }
@@ -2131,6 +2160,8 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                case CCREQ_SERVER_INFO:
                        if (developer.integer >= 10)
                                Con_Printf("Datagram_ParseConnectionless: received CCREQ_SERVER_INFO from %s.\n", addressstring2);
+                       if(sv_public.integer <= -1)
+                               break;
                        if (sv.active && !strcmp(MSG_ReadString(), "QUAKE"))
                        {
                                int numclients;
@@ -2160,6 +2191,8 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                case CCREQ_PLAYER_INFO:
                        if (developer.integer >= 10)
                                Con_Printf("Datagram_ParseConnectionless: received CCREQ_PLAYER_INFO from %s.\n", addressstring2);
+                       if(sv_public.integer <= -1)
+                               break;
                        if (sv.active)
                        {
                                int playerNumber, activeNumber, clientNumber;
@@ -2179,7 +2212,7 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                                        MSG_WriteByte(&net_message, playerNumber);
                                        MSG_WriteString(&net_message, client->name);
                                        MSG_WriteLong(&net_message, client->colors);
-                                       MSG_WriteLong(&net_message, (int)client->edict->fields.server->frags);
+                                       MSG_WriteLong(&net_message, client->frags);
                                        MSG_WriteLong(&net_message, (int)(realtime - client->connecttime));
                                        MSG_WriteString(&net_message, client->netconnection ? client->netconnection->address : "botclient");
                                        *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
@@ -2191,6 +2224,8 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                case CCREQ_RULE_INFO:
                        if (developer.integer >= 10)
                                Con_Printf("Datagram_ParseConnectionless: received CCREQ_RULE_INFO from %s.\n", addressstring2);
+                       if(sv_public.integer <= -1)
+                               break;
                        if (sv.active)
                        {
                                char *prevCvarName;
@@ -2218,6 +2253,7 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                default:
                        break;
                }
+               SZ_Clear(&net_message);
                // we may not have liked the packet, but it was a valid control
                // packet, so we're done processing this packet now
                return true;
@@ -2255,6 +2291,11 @@ void NetConn_ServerFrame(void)
        }
 }
 
+void NetConn_SleepMicroseconds(int microseconds)
+{
+       LHNET_SleepUntilPacket_Microseconds(microseconds);
+}
+
 void NetConn_QueryMasters(qboolean querydp, qboolean queryqw)
 {
        int i;
@@ -2368,7 +2409,7 @@ void NetConn_Heartbeat(int priority)
 
        // make advertising optional and don't advertise singleplayer games, and
        // only send a heartbeat as often as the admin wants
-       if (sv.active && sv_public.integer && svs.maxclients >= 2 && (priority > 1 || realtime > nextheartbeattime))
+       if (sv.active && sv_public.integer > 0 && svs.maxclients >= 2 && (priority > 1 || realtime > nextheartbeattime))
        {
                nextheartbeattime = realtime + sv_heartbeatperiod.value;
                for (masternum = 0;sv_masters[masternum].name;masternum++)
@@ -2472,7 +2513,7 @@ void NetConn_Init(void)
        {
                if (LHNETADDRESS_FromString(&tempaddress, com_argv[i + 1], 0) == 1)
                {
-                       Con_Printf("-ip option used, setting net_address to \"%s\"\n");
+                       Con_Printf("-ip option used, setting net_address to \"%s\"\n", com_argv[i + 1]);
                        Cvar_SetQuick(&net_address, com_argv[i + 1]);
                }
                else