diff --git a/include/netmain.h b/include/netmain.h index 0a4587b26..882b7acc9 100644 --- a/include/netmain.h +++ b/include/netmain.h @@ -270,9 +270,11 @@ extern double net_time; extern struct msg_s *net_message; extern unsigned net_activeconnections; +struct cbuf_s; + /** Initialize the networking sub-system. */ -void NET_Init (void); +void NET_Init (struct cbuf_s *cbuf); /** Check for new connections. @@ -447,6 +449,7 @@ typedef struct { extern int net_numdrivers; extern net_driver_t net_drivers[MAX_NET_DRIVERS]; +extern int net_is_dedicated; ///@} diff --git a/libs/net/net_main.c b/libs/net/net_main.c index e534c4156..6ef7e9a0f 100644 --- a/libs/net/net_main.c +++ b/libs/net/net_main.c @@ -47,9 +47,10 @@ #include "netmain.h" #include "net_vcr.h" -#include "../nq/include/host.h" #include "../nq/include/server.h" +int net_is_dedicated = 0; + qsocket_t *net_activeSockets = NULL; qsocket_t *net_freeSockets = NULL; int net_numsockets = 0; @@ -102,6 +103,8 @@ double net_time; static int hostCacheCount = 0; static hostcache_t hostcache[HOSTCACHESIZE]; +static cbuf_t *net_cbuf; + double SetNetTime (void) { @@ -219,10 +222,10 @@ MaxPlayers_f (void) } if ((n == 1) && listening) - Cbuf_AddText (host_cbuf, "listen 0\n"); + Cbuf_AddText (net_cbuf, "listen 0\n"); if ((n > 1) && (!listening)) - Cbuf_AddText (host_cbuf, "listen 1\n"); + Cbuf_AddText (net_cbuf, "listen 1\n"); svs.maxclients = n; if (n == 1) @@ -253,8 +256,8 @@ NET_Port_f (void) if (listening) { // force a change to the new port - Cbuf_AddText (host_cbuf, "listen 0\n"); - Cbuf_AddText (host_cbuf, "listen 1\n"); + Cbuf_AddText (net_cbuf, "listen 0\n"); + Cbuf_AddText (net_cbuf, "listen 1\n"); } } @@ -796,12 +799,14 @@ NET_shutdown (void *data) } void -NET_Init (void) +NET_Init (cbuf_t *cbuf) { int i; int controlSocket; qsocket_t *s; + net_cbuf = cbuf; + Sys_RegisterShutdown (NET_shutdown, 0); if (COM_CheckParm ("-playback")) { @@ -826,10 +831,10 @@ NET_Init (void) } net_hostport = DEFAULTnet_hostport; - if (COM_CheckParm ("-listen") || cls.state == ca_dedicated) + if (COM_CheckParm ("-listen") || net_is_dedicated) listening = true; net_numsockets = svs.maxclientslimit; - if (cls.state != ca_dedicated) + if (!net_is_dedicated) net_numsockets++; SetNetTime (); diff --git a/libs/net/nm/net_dgrm.c b/libs/net/nm/net_dgrm.c index 9aa10ef31..71f74ff4a 100644 --- a/libs/net/nm/net_dgrm.c +++ b/libs/net/nm/net_dgrm.c @@ -46,9 +46,7 @@ #include "netmain.h" -#include "../nq/include/client.h" #include "../nq/include/server.h" -#include "../nq/include/game.h" // This is enables a simple IP banning mechanism #define BAN_TEST diff --git a/libs/net/nm/net_loop.c b/libs/net/nm/net_loop.c index cb1ddb180..ddf61f6f3 100644 --- a/libs/net/nm/net_loop.c +++ b/libs/net/nm/net_loop.c @@ -35,7 +35,6 @@ #include "netmain.h" #include "net_loop.h" -#include "../nq/include/client.h" #include "../nq/include/server.h" qboolean localconnectpending = false; @@ -45,7 +44,7 @@ qsocket_t *loop_server = NULL; __attribute__((pure)) int Loop_Init (void) { - if (cls.state == ca_dedicated) + if (net_is_dedicated) return -1; return 0; } diff --git a/libs/net/nm/net_wins.c b/libs/net/nm/net_wins.c index 6b779bfa5..411c0b838 100644 --- a/libs/net/nm/net_wins.c +++ b/libs/net/nm/net_wins.c @@ -1,4 +1,3 @@ - /* net_wins.c diff --git a/nq/include/client.h b/nq/include/client.h index 3096f6321..4e5c148e8 100644 --- a/nq/include/client.h +++ b/nq/include/client.h @@ -70,7 +70,6 @@ typedef enum { #define MAX_DEMONAME 16 typedef enum { - ca_dedicated, // a dedicated server with no ability to start a client ca_disconnected, // full screen console with no connection ca_connected, // talking to a server ca_active, // everything is in, so frames can be rendered diff --git a/nq/source/cl_main.c b/nq/source/cl_main.c index 3b63db068..1a489621a 100644 --- a/nq/source/cl_main.c +++ b/nq/source/cl_main.c @@ -306,7 +306,7 @@ CL_Disconnect_f (void) void CL_EstablishConnection (const char *host) { - if (cls.state == ca_dedicated) + if (net_is_dedicated) return; if (cls.demoplayback) @@ -510,8 +510,6 @@ CL_SetState (cactive_t state) r_funcs->R_ClearState (); } switch (state) { - case ca_dedicated: - break; case ca_disconnected: CL_ClearState (); cls.signon = so_none; diff --git a/nq/source/host.c b/nq/source/host.c index d19d30114..86b428c5a 100644 --- a/nq/source/host.c +++ b/nq/source/host.c @@ -157,7 +157,7 @@ Host_EndGame (const char *message, ...) if (sv.active) Host_ShutdownServer (false); - if (cls.state == ca_dedicated) + if (net_is_dedicated) Sys_Error ("Host_EndGame: %s", str->str); // dedicated servers exit if (cls.demonum != -1) @@ -197,7 +197,7 @@ Host_Error (const char *error, ...) if (sv.active) Host_ShutdownServer (false); - if (cls.state == ca_dedicated) + if (net_is_dedicated) Sys_Error ("Host_Error: %s", str->str); // dedicated servers exit Sys_Printf ("Host_Error: %s\n", str->str); @@ -219,17 +219,17 @@ Host_FindMaxClients (void) i = COM_CheckParm ("-dedicated"); if (i) { - cls.state = ca_dedicated; if (i != (com_argc - 1)) { svs.maxclients = atoi (com_argv[i + 1]); } else svs.maxclients = 8; - } else - cls.state = ca_disconnected; + } + cls.state = ca_disconnected; + net_is_dedicated = i; i = COM_CheckParm ("-listen"); if (i) { - if (cls.state == ca_dedicated) + if (net_is_dedicated) Sys_Error ("Only one of -dedicated or -listen can be specified"); if (i != (com_argc - 1)) svs.maxclients = atoi (com_argv[i + 1]); @@ -676,10 +676,10 @@ _Host_Frame (float time) return; } - if (cls.state != ca_dedicated) + if (!net_is_dedicated) IN_ProcessEvents (); - if (cls.state == ca_dedicated) + if (net_is_dedicated) Con_ProcessInput (); GIB_Thread_Execute (); @@ -708,7 +708,7 @@ _Host_Frame (float time) Host_ServerFrame (); } - if (cls.state != ca_dedicated) + if (!net_is_dedicated) Host_ClientFrame (); else host_time += host_frametime; //FIXME is this needed? vcr stuff @@ -920,13 +920,13 @@ Host_Init (void) Host_InitVCR (&host_parms); Host_InitLocal (); - NET_Init (); + NET_Init (host_cbuf); Mod_Init (); SV_Init (); - if (cls.state != ca_dedicated) + if (!net_is_dedicated) CL_Init (host_cbuf); if (con_module) { diff --git a/nq/source/host_cmd.c b/nq/source/host_cmd.c index e58098241..2ad67d3b3 100644 --- a/nq/source/host_cmd.c +++ b/nq/source/host_cmd.c @@ -303,7 +303,7 @@ Host_Map_f (void) if (!sv.active) return; - if (cls.state != ca_dedicated) { + if (!net_is_dedicated) { Cmd_ExecuteString ("connect local", src_command); } } @@ -717,7 +717,7 @@ Host_Loadgame_f (void) for (i = 0; i < NUM_SPAWN_PARMS; i++) svs.clients->spawn_parms[i] = spawn_parms[i]; - if (cls.state != ca_dedicated) { + if (!net_is_dedicated) { CL_EstablishConnection ("local"); Host_Reconnect_f (); } @@ -790,7 +790,7 @@ Host_Say (qboolean teamonly) qboolean fromServer = false; if (cmd_source == src_command) { - if (cls.state == ca_dedicated) { + if (net_is_dedicated) { fromServer = true; teamonly = false; } else { @@ -1134,7 +1134,7 @@ Host_Kick_f (void) if (i < svs.maxclients) { if (cmd_source == src_command) - if (cls.state == ca_dedicated) + if (net_is_dedicated) who = "Console"; else who = cl_name->string; @@ -1403,7 +1403,7 @@ Host_Startdemos_f (void) { int i, c; - if (cls.state == ca_dedicated) { + if (net_is_dedicated) { if (!sv.active) Cbuf_AddText (host_cbuf, "map start\n"); return; @@ -1434,7 +1434,7 @@ Host_Startdemos_f (void) static void Host_Demos_f (void) { - if (cls.state == ca_dedicated) + if (net_is_dedicated) return; if (cls.demonum == -1) cls.demonum = 1; @@ -1450,7 +1450,7 @@ Host_Demos_f (void) static void Host_Stopdemo_f (void) { - if (cls.state == ca_dedicated) + if (net_is_dedicated) return; if (!cls.demoplayback) return; diff --git a/nq/source/sv_main.c b/nq/source/sv_main.c index 21a18fbfc..57282ea1d 100644 --- a/nq/source/sv_main.c +++ b/nq/source/sv_main.c @@ -1064,7 +1064,7 @@ SV_SendReconnect (void) MSG_WriteString (&msg, "reconnect\n"); NET_SendToAll (&msg, 5.0); - if (cls.state != ca_dedicated) + if (!net_is_dedicated) Cmd_ExecuteString ("reconnect\n", src_command); } diff --git a/nq/source/sys_sdl.c b/nq/source/sys_sdl.c index 76e84b558..68c2e91eb 100644 --- a/nq/source/sys_sdl.c +++ b/nq/source/sys_sdl.c @@ -136,7 +136,7 @@ SDL_main (int argc, char *argv[]) newtime = Sys_DoubleTime (); time = newtime - oldtime; - if (cls.state == ca_dedicated) { // play vcrfiles at max speed + if (net_is_dedicated) { // play vcrfiles at max speed if (time < sys_ticrate->value && (!vcrFile || recording)) { usleep (1); continue; // not time to run a server-only tic yet diff --git a/nq/source/sys_unix.c b/nq/source/sys_unix.c index 20cce79a5..e244b940e 100644 --- a/nq/source/sys_unix.c +++ b/nq/source/sys_unix.c @@ -91,7 +91,7 @@ main (int argc, const char **argv) newtime = Sys_DoubleTime (); time = newtime - oldtime; - if (cls.state == ca_dedicated) { // play vcrfiles at max speed + if (net_is_dedicated) { // play vcrfiles at max speed if (time < sys_ticrate->value && (!vcrFile || recording)) { usleep (1); continue; // not time to run a server-only tic yet diff --git a/nq/source/sys_win.c b/nq/source/sys_win.c index ee040f956..59c61b796 100644 --- a/nq/source/sys_win.c +++ b/nq/source/sys_win.c @@ -228,7 +228,7 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, newtime = Sys_DoubleTime (); time = newtime - oldtime; - if (cls.state == ca_dedicated) { // play vcrfiles at max speed + if (net_is_dedicated) { // play vcrfiles at max speed if (time < sys_ticrate->value && (!vcrFile || recording)) { Sleep (1); continue; // not time to run a server-only tic yet