X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=sv_main.c;h=10b321e27fd2a7181424a5cbd6ea16f95d669e41;hb=ab101cc2288c382f7480a78f4f849cc65bd5f2e6;hp=8aa475c94ff9e1ac5eaa6245049aa115480be4b8;hpb=882c947a5fe7634e70355fb0ba530409af5fc9bd;p=xonotic%2Fdarkplaces.git diff --git a/sv_main.c b/sv_main.c index 8aa475c9..10b321e2 100644 --- a/sv_main.c +++ b/sv_main.c @@ -432,6 +432,80 @@ static void SV_AreaStats_f(cmd_state_t *cmd) World_PrintAreaStats(&sv.world, "server"); } +static qbool SV_CanSave(void) +{ + prvm_prog_t *prog = SVVM_prog; + if(SV_IsLocalServer() == 1) + { + // singleplayer checks + if ((svs.clients[0].active && PRVM_serveredictfloat(svs.clients[0].edict, deadflag))) + { + Con_Print("Can't savegame with a dead player\n"); + return false; + } + + if(host.hook.CL_Intermission && host.hook.CL_Intermission()) + { + Con_Print("Can't save in intermission.\n"); + return false; + } + } + else + Con_Print(CON_WARN "Warning: saving a multiplayer game may have strange results when restored (to properly resume, all players must join in the same player slots and then the game can be reloaded).\n"); + return true; + +} + +static void SV_ServerOptions (void) +{ + int i; + + // general default + svs.maxclients = 8; + +// COMMANDLINEOPTION: Server: -dedicated [playerlimit] starts a dedicated server (with a command console), default playerlimit is 8 +// COMMANDLINEOPTION: Server: -listen [playerlimit] starts a multiplayer server with graphical client, like singleplayer but other players can connect, default playerlimit is 8 + // if no client is in the executable or -dedicated is specified on + // commandline, start a dedicated server + i = Sys_CheckParm ("-dedicated"); + if (i || !cl_available) + { + cls.state = ca_dedicated; + // check for -dedicated specifying how many players + if (i && i + 1 < sys.argc && atoi (sys.argv[i+1]) >= 1) + svs.maxclients = atoi (sys.argv[i+1]); + if (Sys_CheckParm ("-listen")) + Con_Printf ("Only one of -dedicated or -listen can be specified\n"); + // default sv_public on for dedicated servers (often hosted by serious administrators), off for listen servers (often hosted by clueless users) + Cvar_SetValue(&cvars_all, "sv_public", 1); + } + else if (cl_available) + { + // client exists and not dedicated, check if -listen is specified + cls.state = ca_disconnected; + i = Sys_CheckParm ("-listen"); + if (i) + { + // default players unless specified + if (i + 1 < sys.argc && atoi (sys.argv[i+1]) >= 1) + svs.maxclients = atoi (sys.argv[i+1]); + } + else + { + // default players in some games, singleplayer in most + if (gamemode != GAME_GOODVSBAD2 && !IS_NEXUIZ_DERIVED(gamemode) && gamemode != GAME_BATTLEMECH) + svs.maxclients = 1; + } + } + + svs.maxclients = svs.maxclients_next = bound(1, svs.maxclients, MAX_SCOREBOARD); + + svs.clients = (client_t *)Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients); + + if (svs.maxclients > 1 && !deathmatch.integer && !coop.integer) + Cvar_SetValueQuick(&deathmatch, 1); +} + /* =============== SV_Init @@ -632,8 +706,11 @@ void SV_Init (void) Cvar_RegisterVariable (&sv_mapformat_is_quake3); SV_InitOperatorCommands(); + host.hook.SV_CanSave = SV_CanSave; sv_mempool = Mem_AllocPool("server", 0, NULL); + + SV_ServerOptions(); } static void SV_SaveEntFile_f(cmd_state_t *cmd) @@ -1300,7 +1377,7 @@ SV_ModelIndex */ int SV_ModelIndex(const char *s, int precachemode) { - int i, limit = ((sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_QUAKEDP || sv.protocol == PROTOCOL_NEHAHRAMOVIE || sv.protocol == PROTOCOL_NEHAHRABJP || sv.protocol == PROTOCOL_NEHAHRABJP2 || sv.protocol == PROTOCOL_NEHAHRABJP3) ? 256 : MAX_MODELS); + int i, limit = ((sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_QUAKEDP || sv.protocol == PROTOCOL_NEHAHRAMOVIE) ? 256 : MAX_MODELS); char filename[MAX_QPATH]; if (!s || !*s) return 0; @@ -1363,7 +1440,7 @@ SV_SoundIndex */ int SV_SoundIndex(const char *s, int precachemode) { - int i, limit = ((sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_QUAKEDP || sv.protocol == PROTOCOL_NEHAHRAMOVIE || sv.protocol == PROTOCOL_NEHAHRABJP || sv.protocol == PROTOCOL_NEHAHRABJP2 || sv.protocol == PROTOCOL_NEHAHRABJP3) ? 256 : MAX_SOUNDS); + int i, limit = ((sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_QUAKEDP || sv.protocol == PROTOCOL_NEHAHRAMOVIE || sv.protocol == PROTOCOL_NEHAHRABJP) ? 256 : MAX_SOUNDS); char filename[MAX_QPATH]; if (!s || !*s) return 0; @@ -1494,12 +1571,12 @@ int SV_ParticleEffectIndex(const char *name) return 0; } -dp_model_t *SV_GetModelByIndex(int modelindex) +model_t *SV_GetModelByIndex(int modelindex) { return (modelindex > 0 && modelindex < MAX_MODELS) ? sv.models[modelindex] : NULL; } -dp_model_t *SV_GetModelFromEdict(prvm_edict_t *ed) +model_t *SV_GetModelFromEdict(prvm_edict_t *ed) { prvm_prog_t *prog = SVVM_prog; int modelindex; @@ -1669,6 +1746,12 @@ void SV_SaveSpawnparms (void) } } +// Returns 1 if we're singleplayer, > 1 if we're a listen server +int SV_IsLocalServer(void) +{ + return (host_isclient.integer && sv.active ? svs.maxclients : 0); +} + /* ================ SV_SpawnServer @@ -1683,7 +1766,7 @@ void SV_SpawnServer (const char *map) prvm_edict_t *ent; int i; char *entities; - dp_model_t *worldmodel; + model_t *worldmodel; char modelname[sizeof(sv.worldname)]; char vabuf[1024]; @@ -1703,10 +1786,9 @@ void SV_SpawnServer (const char *map) // SV_LockThreadMutex(); - if(cls.state == ca_dedicated) + if(!host_isclient.integer) Sys_MakeProcessNice(); - - if (cls.state != ca_dedicated) + else { SCR_BeginLoadingPlaque(false); S_StopAllSounds(); @@ -1741,7 +1823,7 @@ void SV_SpawnServer (const char *map) { Con_Printf("Couldn't load map %s\n", modelname); - if(cls.state == ca_dedicated) + if(!host_isclient.integer) Sys_MakeProcessMean(); // SV_UnlockThreadMutex(); @@ -1933,7 +2015,7 @@ void SV_SpawnServer (const char *map) // Once all init frames have been run, we consider svqc code fully initialized. prog->inittime = host.realtime; - if (cls.state == ca_dedicated) + if(!host_isclient.integer) Mod_PurgeUnused(); // create a baseline for more efficient communications @@ -1977,7 +2059,7 @@ void SV_SpawnServer (const char *map) Con_Printf("Server spawned.\n"); NetConn_Heartbeat (2); - if(cls.state == ca_dedicated) + if(!host_isclient.integer) Sys_MakeProcessMean(); // SV_UnlockThreadMutex(); @@ -2373,6 +2455,21 @@ static void SV_VM_Setup(void) SV_Prepare_CSQC(); } +static void SV_CheckTimeouts(void) +{ + int i; + + // never timeout loopback connections + for (i = (host_isclient.integer ? 1 : 0), host_client = &svs.clients[i]; i < svs.maxclients; i++, host_client++) + { + if (host_client->netconnection && host.realtime > host_client->netconnection->timeout) + { + Con_Printf("Client \"%s\" connection timed out\n", host_client->name); + SV_DropClient(false); + } + } +} + extern cvar_t host_maxwait; extern cvar_t host_framerate; extern cvar_t cl_maxphysicsframesperserverframe; @@ -2426,7 +2523,10 @@ double SV_Frame(double time) * be undersleeping due to select() detecting a new packet */ if (sv.active) + { NetConn_ServerFrame(); + SV_CheckTimeouts(); + } } /* @@ -2605,7 +2705,10 @@ static int SV_ThreadFunc(void *voiddata) // get new packets if (sv.active) + { NetConn_ServerFrame(); + SV_CheckTimeouts(); + } // if the accumulators haven't become positive yet, wait a while wait = sv_timer * -1000000.0;