mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2024-11-10 07:21:58 +00:00
added IS_LOOP_DRIVER macro and made the confusing loop driver checks
more readable. from uhexen2. git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@488 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
parent
eaafb0906f
commit
7eb20be3fe
2 changed files with 25 additions and 18 deletions
|
@ -217,6 +217,9 @@ typedef struct
|
||||||
extern net_driver_t net_drivers[MAX_NET_DRIVERS];
|
extern net_driver_t net_drivers[MAX_NET_DRIVERS];
|
||||||
extern int net_numdrivers;
|
extern int net_numdrivers;
|
||||||
|
|
||||||
|
/* Loop driver must always be registered the first */
|
||||||
|
#define IS_LOOP_DRIVER(p) ((p) == 0)
|
||||||
|
|
||||||
extern int net_driverlevel;
|
extern int net_driverlevel;
|
||||||
|
|
||||||
extern int messagesSent;
|
extern int messagesSent;
|
||||||
|
|
|
@ -68,13 +68,6 @@ cvar_t hostname = {"hostname", "UNNAMED"};
|
||||||
#define sfunc net_drivers[sock->driver]
|
#define sfunc net_drivers[sock->driver]
|
||||||
#define dfunc net_drivers[net_driverlevel]
|
#define dfunc net_drivers[net_driverlevel]
|
||||||
|
|
||||||
/* NOTE: several sock->driver checks in the code serve the
|
|
||||||
purpose of ignoring local connections, because the loop
|
|
||||||
driver always takes number 0: it is the first member in
|
|
||||||
the net_drivers[] array. If you ever change that, such
|
|
||||||
as by removing the loop driver, you must re-visit those
|
|
||||||
checks and adjust them properly!. */
|
|
||||||
|
|
||||||
int net_driverlevel;
|
int net_driverlevel;
|
||||||
|
|
||||||
double net_time;
|
double net_time;
|
||||||
|
@ -311,7 +304,7 @@ static void Slist_Send (void *unused)
|
||||||
{
|
{
|
||||||
for (net_driverlevel = 0; net_driverlevel < net_numdrivers; net_driverlevel++)
|
for (net_driverlevel = 0; net_driverlevel < net_numdrivers; net_driverlevel++)
|
||||||
{
|
{
|
||||||
if (!slistLocal && net_driverlevel == 0)
|
if (!slistLocal && IS_LOOP_DRIVER(net_driverlevel))
|
||||||
continue;
|
continue;
|
||||||
if (net_drivers[net_driverlevel].initialized == false)
|
if (net_drivers[net_driverlevel].initialized == false)
|
||||||
continue;
|
continue;
|
||||||
|
@ -327,7 +320,7 @@ static void Slist_Poll (void *unused)
|
||||||
{
|
{
|
||||||
for (net_driverlevel = 0; net_driverlevel < net_numdrivers; net_driverlevel++)
|
for (net_driverlevel = 0; net_driverlevel < net_numdrivers; net_driverlevel++)
|
||||||
{
|
{
|
||||||
if (!slistLocal && net_driverlevel == 0)
|
if (!slistLocal && IS_LOOP_DRIVER(net_driverlevel))
|
||||||
continue;
|
continue;
|
||||||
if (net_drivers[net_driverlevel].initialized == false)
|
if (net_drivers[net_driverlevel].initialized == false)
|
||||||
continue;
|
continue;
|
||||||
|
@ -455,7 +448,7 @@ qsocket_t *NET_CheckNewConnections (void)
|
||||||
{
|
{
|
||||||
if (net_drivers[net_driverlevel].initialized == false)
|
if (net_drivers[net_driverlevel].initialized == false)
|
||||||
continue;
|
continue;
|
||||||
if (net_driverlevel && listening == false)
|
if (!IS_LOOP_DRIVER(net_driverlevel) && listening == false)
|
||||||
continue;
|
continue;
|
||||||
ret = dfunc.CheckNewConnections ();
|
ret = dfunc.CheckNewConnections ();
|
||||||
if (ret)
|
if (ret)
|
||||||
|
@ -518,7 +511,7 @@ int NET_GetMessage (qsocket_t *sock)
|
||||||
ret = sfunc.QGetMessage(sock);
|
ret = sfunc.QGetMessage(sock);
|
||||||
|
|
||||||
// see if this connection has timed out
|
// see if this connection has timed out
|
||||||
if (ret == 0 && sock->driver)
|
if (ret == 0 && !IS_LOOP_DRIVER(sock->driver))
|
||||||
{
|
{
|
||||||
if (net_time - sock->lastMessageTime > net_messagetimeout.value)
|
if (net_time - sock->lastMessageTime > net_messagetimeout.value)
|
||||||
{
|
{
|
||||||
|
@ -529,7 +522,7 @@ int NET_GetMessage (qsocket_t *sock)
|
||||||
|
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
{
|
{
|
||||||
if (sock->driver)
|
if (!IS_LOOP_DRIVER(sock->driver))
|
||||||
{
|
{
|
||||||
sock->lastMessageTime = net_time;
|
sock->lastMessageTime = net_time;
|
||||||
if (ret == 1)
|
if (ret == 1)
|
||||||
|
@ -569,7 +562,7 @@ int NET_SendMessage (qsocket_t *sock, sizebuf_t *data)
|
||||||
|
|
||||||
SetNetTime();
|
SetNetTime();
|
||||||
r = sfunc.QSendMessage(sock, data);
|
r = sfunc.QSendMessage(sock, data);
|
||||||
if (r == 1 && sock->driver)
|
if (r == 1 && !IS_LOOP_DRIVER(sock->driver))
|
||||||
messagesSent++;
|
messagesSent++;
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
|
@ -591,7 +584,7 @@ int NET_SendUnreliableMessage (qsocket_t *sock, sizebuf_t *data)
|
||||||
|
|
||||||
SetNetTime();
|
SetNetTime();
|
||||||
r = sfunc.SendUnreliableMessage(sock, data);
|
r = sfunc.SendUnreliableMessage(sock, data);
|
||||||
if (r == 1 && sock->driver)
|
if (r == 1 && !IS_LOOP_DRIVER(sock->driver))
|
||||||
unreliableMessagesSent++;
|
unreliableMessagesSent++;
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
|
@ -637,7 +630,7 @@ int NET_SendToAll (sizebuf_t *data, double blocktime)
|
||||||
*/
|
*/
|
||||||
if (host_client->netconnection && host_client->active)
|
if (host_client->netconnection && host_client->active)
|
||||||
{
|
{
|
||||||
if (host_client->netconnection->driver == 0) /* Loop */
|
if (IS_LOOP_DRIVER(host_client->netconnection->driver))
|
||||||
{
|
{
|
||||||
NET_SendMessage(host_client->netconnection, data);
|
NET_SendMessage(host_client->netconnection, data);
|
||||||
msg_init[i] = true;
|
msg_init[i] = true;
|
||||||
|
@ -715,6 +708,7 @@ void NET_Init (void)
|
||||||
i = COM_CheckParm ("-udpport");
|
i = COM_CheckParm ("-udpport");
|
||||||
if (!i)
|
if (!i)
|
||||||
i = COM_CheckParm ("-ipxport");
|
i = COM_CheckParm ("-ipxport");
|
||||||
|
|
||||||
if (i)
|
if (i)
|
||||||
{
|
{
|
||||||
if (i < com_argc-1)
|
if (i < com_argc-1)
|
||||||
|
@ -724,11 +718,11 @@ void NET_Init (void)
|
||||||
}
|
}
|
||||||
net_hostport = DEFAULTnet_hostport;
|
net_hostport = DEFAULTnet_hostport;
|
||||||
|
|
||||||
if (COM_CheckParm("-listen") || cls.state == ca_dedicated)
|
|
||||||
listening = true;
|
|
||||||
net_numsockets = svs.maxclientslimit;
|
net_numsockets = svs.maxclientslimit;
|
||||||
if (cls.state != ca_dedicated)
|
if (cls.state != ca_dedicated)
|
||||||
net_numsockets++;
|
net_numsockets++;
|
||||||
|
if (COM_CheckParm("-listen") || cls.state == ca_dedicated)
|
||||||
|
listening = true;
|
||||||
|
|
||||||
SetNetTime();
|
SetNetTime();
|
||||||
|
|
||||||
|
@ -762,13 +756,23 @@ void NET_Init (void)
|
||||||
net_drivers[net_driverlevel].Listen (true);
|
net_drivers[net_driverlevel].Listen (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == 0 && cls.state == ca_dedicated)
|
/* Loop_Init() returns -1 for dedicated server case,
|
||||||
|
* therefore the i == 0 check is correct */
|
||||||
|
if (i == 0
|
||||||
|
&& cls.state == ca_dedicated
|
||||||
|
)
|
||||||
|
{
|
||||||
Sys_Error("Network not available!");
|
Sys_Error("Network not available!");
|
||||||
|
}
|
||||||
|
|
||||||
if (*my_ipx_address)
|
if (*my_ipx_address)
|
||||||
|
{
|
||||||
Con_DPrintf("IPX address %s\n", my_ipx_address);
|
Con_DPrintf("IPX address %s\n", my_ipx_address);
|
||||||
|
}
|
||||||
if (*my_tcpip_address)
|
if (*my_tcpip_address)
|
||||||
|
{
|
||||||
Con_DPrintf("TCP/IP address %s\n", my_tcpip_address);
|
Con_DPrintf("TCP/IP address %s\n", my_tcpip_address);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue