mirror of
https://git.code.sf.net/p/quake/newtree
synced 2025-02-02 12:41:40 +00:00
make qf-server REALY sleep when there are no clients currently connected
This commit is contained in:
parent
c71fc78360
commit
73980fe852
3 changed files with 12 additions and 4 deletions
|
@ -256,6 +256,7 @@ typedef struct
|
||||||
int spawncount; // number of servers spawned since start,
|
int spawncount; // number of servers spawned since start,
|
||||||
// used to check late spawns
|
// used to check late spawns
|
||||||
client_t clients[MAX_CLIENTS];
|
client_t clients[MAX_CLIENTS];
|
||||||
|
int num_clients;
|
||||||
int serverflags; // episode completion information
|
int serverflags; // episode completion information
|
||||||
|
|
||||||
double last_heartbeat;
|
double last_heartbeat;
|
||||||
|
|
|
@ -813,6 +813,7 @@ SVC_DirectConnect (void)
|
||||||
Netchan_Setup (&newcl->netchan, adr, qport);
|
Netchan_Setup (&newcl->netchan, adr, qport);
|
||||||
|
|
||||||
newcl->state = cs_connected;
|
newcl->state = cs_connected;
|
||||||
|
svs.num_clients++;
|
||||||
|
|
||||||
newcl->datagram.allowoverflow = true;
|
newcl->datagram.allowoverflow = true;
|
||||||
newcl->datagram.data = newcl->datagram_buf;
|
newcl->datagram.data = newcl->datagram_buf;
|
||||||
|
@ -1341,11 +1342,13 @@ SV_CheckTimeouts (void)
|
||||||
SV_BroadcastPrintf (PRINT_HIGH, "%s timed out\n", cl->name);
|
SV_BroadcastPrintf (PRINT_HIGH, "%s timed out\n", cl->name);
|
||||||
SV_DropClient (cl);
|
SV_DropClient (cl);
|
||||||
cl->state = cs_free; // don't bother with zombie state
|
cl->state = cs_free; // don't bother with zombie state
|
||||||
|
svs.num_clients--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cl->state == cs_zombie &&
|
if (cl->state == cs_zombie &&
|
||||||
realtime - cl->connection_started > zombietime->value) {
|
realtime - cl->connection_started > zombietime->value) {
|
||||||
cl->state = cs_free; // can now be reused
|
cl->state = cs_free; // can now be reused
|
||||||
|
svs.num_clients--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sv.paused && !nclients) {
|
if (sv.paused && !nclients) {
|
||||||
|
|
|
@ -168,12 +168,15 @@ main
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
static struct timeval _timeout;
|
||||||
double time, oldtime, newtime;
|
double time, oldtime, newtime;
|
||||||
fd_set fdset;
|
fd_set fdset;
|
||||||
extern int net_socket;
|
extern int net_socket;
|
||||||
struct timeval timeout;
|
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
|
_timeout.tv_sec = 1;
|
||||||
|
_timeout.tv_usec = 0;
|
||||||
|
|
||||||
memset (&host_parms, 0, sizeof (host_parms));
|
memset (&host_parms, 0, sizeof (host_parms));
|
||||||
|
|
||||||
COM_InitArgv (argc, argv);
|
COM_InitArgv (argc, argv);
|
||||||
|
@ -198,6 +201,7 @@ main (int argc, char *argv[])
|
||||||
//
|
//
|
||||||
oldtime = Sys_DoubleTime () - 0.1;
|
oldtime = Sys_DoubleTime () - 0.1;
|
||||||
while (1) {
|
while (1) {
|
||||||
|
struct timeval *timeout = 0;
|
||||||
// select on the net socket and stdin
|
// select on the net socket and stdin
|
||||||
// the only reason we have a timeout at all is so that if the last
|
// the only reason we have a timeout at all is so that if the last
|
||||||
// connected client times out, the message would not otherwise
|
// connected client times out, the message would not otherwise
|
||||||
|
@ -206,9 +210,9 @@ main (int argc, char *argv[])
|
||||||
if (do_stdin)
|
if (do_stdin)
|
||||||
FD_SET (0, &fdset);
|
FD_SET (0, &fdset);
|
||||||
FD_SET (net_socket, &fdset);
|
FD_SET (net_socket, &fdset);
|
||||||
timeout.tv_sec = 1;
|
if (svs.num_clients)
|
||||||
timeout.tv_usec = 0;
|
timeout = &_timeout;
|
||||||
if (select (net_socket + 1, &fdset, NULL, NULL, &timeout) == -1)
|
if (select (net_socket + 1, &fdset, NULL, NULL, timeout) == -1)
|
||||||
continue;
|
continue;
|
||||||
stdin_ready = FD_ISSET (0, &fdset);
|
stdin_ready = FD_ISSET (0, &fdset);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue