X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=net_dgrm.c;h=e609b552188c3816e566825e3b6ecb26ef2762dc;hb=8d4a595ba1b90a62dc781b93b12c2edbfff5080f;hp=fb7c7e7ce01cb52388b2b3735fdd84ac79e4a73f;hpb=e411cc7d14dad08cbbe27f5b3af86700f7eb5184;p=xonotic%2Fdarkplaces.git diff --git a/net_dgrm.c b/net_dgrm.c index fb7c7e7c..e609b552 100644 --- a/net_dgrm.c +++ b/net_dgrm.c @@ -8,7 +8,7 @@ of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -55,6 +55,8 @@ unsigned long inet_addr(const char *cp); #include "quakedef.h" #include "net_dgrm.h" +cvar_t cl_port = {CVAR_SAVE, "cl_port", "0"}; + // these two macros are to make the code more readable #define sfunc net_landrivers[sock->landriver] #define dfunc net_landrivers[net_landriverlevel] @@ -75,7 +77,7 @@ struct { unsigned int length; unsigned int sequence; - byte data[MAX_DATAGRAM]; + qbyte data[MAX_DATAGRAM]; } packetBuffer; @@ -83,7 +85,7 @@ struct char *StrAddr (struct qsockaddr *addr) { static char buf[34]; - byte *p = (byte *)addr; + qbyte *p = (qbyte *)addr; int n; for (n = 0; n < 16; n++) @@ -191,7 +193,7 @@ int Datagram_SendMessage (qsocket_t *sock, sizebuf_t *data) sock->canSend = false; - if (sfunc.Write (sock->socket, (byte *)&packetBuffer, packetLen, &sock->addr) == -1) + if (sfunc.Write (sock->socket, (qbyte *)&packetBuffer, packetLen, &sock->addr) == -1) return -1; sock->lastSendTime = net_time; @@ -224,7 +226,7 @@ int SendMessageNext (qsocket_t *sock) sock->sendNext = false; - if (sfunc.Write (sock->socket, (byte *)&packetBuffer, packetLen, &sock->addr) == -1) + if (sfunc.Write (sock->socket, (qbyte *)&packetBuffer, packetLen, &sock->addr) == -1) return -1; sock->lastSendTime = net_time; @@ -257,7 +259,7 @@ int ReSendMessage (qsocket_t *sock) sock->sendNext = false; - if (sfunc.Write (sock->socket, (byte *)&packetBuffer, packetLen, &sock->addr) == -1) + if (sfunc.Write (sock->socket, (qbyte *)&packetBuffer, packetLen, &sock->addr) == -1) return -1; sock->lastSendTime = net_time; @@ -299,7 +301,7 @@ int Datagram_SendUnreliableMessage (qsocket_t *sock, sizebuf_t *data) packetBuffer.sequence = BigLong(sock->unreliableSendSequence++); memcpy (packetBuffer.data, data->data, data->cursize); - if (sfunc.Write (sock->socket, (byte *)&packetBuffer, packetLen, &sock->addr) == -1) + if (sfunc.Write (sock->socket, (qbyte *)&packetBuffer, packetLen, &sock->addr) == -1) return -1; packetsSent++; @@ -321,8 +323,8 @@ int Datagram_GetMessage (qsocket_t *sock) ReSendMessage (sock); while(1) - { - length = sfunc.Read (sock->socket, (byte *)&packetBuffer, NET_DATAGRAMSIZE, &readaddr); + { + length = sfunc.Read (sock->socket, (qbyte *)&packetBuffer, NET_DATAGRAMSIZE, &readaddr); // if ((rand() & 255) > 220) // continue; @@ -423,7 +425,7 @@ int Datagram_GetMessage (qsocket_t *sock) { packetBuffer.length = BigLong(NET_HEADERSIZE | NETFLAG_ACK); packetBuffer.sequence = BigLong(sequence); - sfunc.Write (sock->socket, (byte *)&packetBuffer, NET_HEADERSIZE, &readaddr); + sfunc.Write (sock->socket, (qbyte *)&packetBuffer, NET_HEADERSIZE, &readaddr); if (sequence != sock->receiveSequence) { @@ -487,18 +489,20 @@ void NET_Stats_f (void) { for (s = net_activeSockets; s; s = s->next) PrintStats(s); - for (s = net_freeSockets; s; s = s->next) - PrintStats(s); + // LordHavoc: sockets are dynamically allocated now + //for (s = net_freeSockets; s; s = s->next) + // PrintStats(s); } else { for (s = net_activeSockets; s; s = s->next) if (Q_strcasecmp(Cmd_Argv(1), s->address) == 0) break; - if (s == NULL) - for (s = net_freeSockets; s; s = s->next) - if (Q_strcasecmp(Cmd_Argv(1), s->address) == 0) - break; + // LordHavoc: sockets are dynamically allocated now + //if (s == NULL) + // for (s = net_freeSockets; s; s = s->next) + // if (Q_strcasecmp(Cmd_Argv(1), s->address) == 0) + // break; if (s == NULL) return; PrintStats(s); @@ -524,7 +528,8 @@ static void Test_Poll(void) int colors; int frags; int connectTime; - byte playerNumber; + qbyte playerNumber; + int c; net_landriverlevel = testDriver; @@ -546,7 +551,8 @@ static void Test_Poll(void) if ((control & NETFLAG_LENGTH_MASK) != len) break; - if (MSG_ReadByte() != CCREP_PLAYER_INFO) + c = MSG_ReadByte(); + if (c != CCREP_PLAYER_INFO) Sys_Error("Unexpected repsonse to Player Info request\n"); playerNumber = MSG_ReadByte(); @@ -647,6 +653,7 @@ static void Test2_Poll(void) struct qsockaddr clientaddr; int control; int len; + int c; char name[256]; char value[256]; @@ -669,7 +676,8 @@ static void Test2_Poll(void) if ((control & NETFLAG_LENGTH_MASK) != len) goto Error; - if (MSG_ReadByte() != CCREP_RULE_INFO) + c = MSG_ReadByte(); + if (c != CCREP_RULE_INFO) goto Error; strcpy(name, MSG_ReadString()); @@ -765,6 +773,7 @@ int Datagram_Init (void) myDriverLevel = net_driverlevel; Cmd_AddCommand ("net_stats", NET_Stats_f); + Cvar_RegisterVariable (&cl_port); if (COM_CheckParm("-nolan")) return -1; @@ -834,6 +843,7 @@ static qsocket_t *_Datagram_CheckNewConnections (void) int command; int control; int ret; + int c; acceptsock = dfunc.CheckNewConnections(); if (acceptsock == -1) @@ -885,7 +895,7 @@ static qsocket_t *_Datagram_CheckNewConnections (void) int activeNumber; int clientNumber; client_t *client; - + playerNumber = MSG_ReadByte(); activeNumber = -1; for (clientNumber = 0, client = svs.clients; clientNumber < svs.maxclients; clientNumber++, client++) @@ -937,7 +947,7 @@ static qsocket_t *_Datagram_CheckNewConnections (void) // search for the next server cvar while (var) { - if (var->server) + if (var->flags & CVAR_NOTIFY) break; var = var->next; } @@ -966,7 +976,8 @@ static qsocket_t *_Datagram_CheckNewConnections (void) if (strcmp(MSG_ReadString(), "QUAKE") != 0) return NULL; - if (MSG_ReadByte() != NET_PROTOCOL_VERSION) + c = MSG_ReadByte(); + if (c != NET_PROTOCOL_VERSION) { SZ_Clear(&net_message); // save space for the header, filled in later @@ -1062,7 +1073,7 @@ static qsocket_t *_Datagram_CheckNewConnections (void) return NULL; } - // everything is allocated, just fill in the details + // everything is allocated, just fill in the details sock->socket = newsock; sock->landriver = net_landriverlevel; sock->addr = clientaddr; @@ -1103,6 +1114,7 @@ static void _Datagram_SearchForHosts (qboolean xmit) struct qsockaddr readaddr; struct qsockaddr myaddr; int control; + int c; dfunc.GetSocketAddr (dfunc.controlSock, &myaddr); if (xmit) @@ -1142,7 +1154,8 @@ static void _Datagram_SearchForHosts (qboolean xmit) if ((control & NETFLAG_LENGTH_MASK) != ret) continue; - if (MSG_ReadByte() != CCREP_SERVER_INFO) + c = MSG_ReadByte(); + if (c != CCREP_SERVER_INFO) continue; dfunc.GetAddrFromName(MSG_ReadString(), &readaddr); @@ -1161,7 +1174,8 @@ static void _Datagram_SearchForHosts (qboolean xmit) strcpy(hostcache[n].map, MSG_ReadString()); hostcache[n].users = MSG_ReadByte(); hostcache[n].maxusers = MSG_ReadByte(); - if (MSG_ReadByte() != NET_PROTOCOL_VERSION) + c = MSG_ReadByte(); + if (c != NET_PROTOCOL_VERSION) { strcpy(hostcache[n].cname, hostcache[n].name); hostcache[n].cname[14] = 0; @@ -1222,7 +1236,7 @@ static qsocket_t *_Datagram_Connect (char *host) if (dfunc.GetAddrFromName(host, &sendaddr) == -1) return NULL; - newsock = dfunc.OpenSocket (0); + newsock = dfunc.OpenSocket (cl_port.integer); if (newsock == -1) return NULL; @@ -1237,7 +1251,7 @@ static qsocket_t *_Datagram_Connect (char *host) goto ErrorReturn; // send the connection request - Con_Printf("trying...\n"); SCR_UpdateScreen (); + Con_Printf("trying...\n");CL_UpdateScreen();CL_UpdateScreen(); start_time = net_time; for (reps = 0; reps < 3; reps++) @@ -1264,7 +1278,7 @@ static qsocket_t *_Datagram_Connect (char *host) Con_DPrintf("wrong reply address\n"); Con_DPrintf("Expected: %s\n", StrAddr (&sendaddr)); Con_DPrintf("Received: %s\n", StrAddr (&readaddr)); - SCR_UpdateScreen (); + CL_UpdateScreen (); //#endif ret = 0; continue; @@ -1301,7 +1315,7 @@ static qsocket_t *_Datagram_Connect (char *host) while (ret == 0 && (SetNetTime() - start_time) < 2.5); if (ret) break; - Con_Printf("still trying...\n"); SCR_UpdateScreen (); + Con_Printf("still trying...\n");CL_UpdateScreen();CL_UpdateScreen(); start_time = SetNetTime(); } @@ -1325,7 +1339,7 @@ static qsocket_t *_Datagram_Connect (char *host) if (ret == CCREP_REJECT) { reason = MSG_ReadString(); - Con_Printf(reason); + Con_Printf("%s", reason); strncpy(m_return_reason, reason, 31); goto ErrorReturn; } @@ -1345,7 +1359,7 @@ static qsocket_t *_Datagram_Connect (char *host) dfunc.GetNameFromAddr (&sendaddr, sock->address); - Con_Printf ("Connection accepted\n"); + Con_Printf ("Connection accepted to %s\n", sock->address); sock->lastMessageTime = SetNetTime(); // switch the connection to the specified address