Skip to content

Commit

Permalink
Add ‘sv_idlekick’ variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
skullernet committed Feb 24, 2013
1 parent 4cefffa commit 10e0588
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
8 changes: 8 additions & 0 deletions doc/server.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ sv_ghostime::
request processing stage. Helps to avoid attacks flooding server with
zombie clients, combined with ‘sv_iplimit’ variable. Default value is 6.

sv_idlekick::
Time, in seconds, before dropping inactive clients. Default value is 0
(don't kick idling clients). Moving, pressing buttons while in game and
issuing chat commands counts as activity.

NOTE: Don't set ‘sv_idlekick’ too low to avoid kicking clients that are
downloading or otherwise taking long time to enter the game.

sv_force_reconnect::
When set to an address string, forces new clients to quickly reconnect to
this address as an additional proxy protection measure. Default value is
Expand Down
12 changes: 8 additions & 4 deletions src/server/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,16 +589,20 @@ static void dump_time(void)
client_t *client;
char buffer[MAX_QPATH];
time_t clock = time(NULL);
unsigned idle;

Com_Printf(
"num name time\n"
"--- --------------- --------\n");
"num name idle time\n"
"--- --------------- ---- --------\n");

FOR_EACH_CLIENT(client) {
idle = (svs.realtime - client->lastactivity) / 1000;
if (idle > 9999)
idle = 9999;
Com_TimeDiff(buffer, sizeof(buffer),
&client->connect_time, clock);
Com_Printf("%3i %-15.15s %s\n",
client->number, client->name, buffer);
Com_Printf("%3i %-15.15s %4u %s\n",
client->number, client->name, idle, buffer);
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/server/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ cvar_t *sv_fps;
cvar_t *sv_timeout; // seconds without any message
cvar_t *sv_zombietime; // seconds to sink messages after disconnect
cvar_t *sv_ghostime;
cvar_t *sv_idlekick;

cvar_t *sv_password;
cvar_t *sv_reserved_password;
Expand Down Expand Up @@ -1120,6 +1121,7 @@ static void SVC_DirectConnect(void)
newcl->framenum = 1; // frame 0 can't be used
newcl->lastframe = -1;
newcl->lastmessage = svs.realtime; // don't timeout
newcl->lastactivity = svs.realtime;
newcl->min_ping = 9999;
}

Expand Down Expand Up @@ -1534,6 +1536,7 @@ static void SV_CheckTimeouts(void)
unsigned zombie_time = 1000 * sv_zombietime->value;
unsigned drop_time = 1000 * sv_timeout->value;
unsigned ghost_time = 1000 * sv_ghostime->value;
unsigned idle_time = 1000 * sv_idlekick->value;
unsigned delta;

FOR_EACH_CLIENT(client) {
Expand Down Expand Up @@ -1572,6 +1575,12 @@ static void SV_CheckTimeouts(void)
SV_DropClient(client, "too many nodelta frames");
continue;
}

delta = svs.realtime - client->lastactivity;
if (idle_time && delta > idle_time) {
SV_DropClient(client, "idling");
continue;
}
}
}

Expand Down Expand Up @@ -2035,6 +2044,7 @@ void SV_Init(void)
sv_timeout = Cvar_Get("timeout", "90", 0);
sv_zombietime = Cvar_Get("zombietime", "2", 0);
sv_ghostime = Cvar_Get("sv_ghostime", "6", 0);
sv_idlekick = Cvar_Get("sv_idlekick", "0", 0);
sv_showclamp = Cvar_Get("showclamp", "0", 0);
sv_enforcetime = Cvar_Get("sv_enforcetime", "1", 0);
sv_allow_nodelta = Cvar_Get("sv_allow_nodelta", "1", 0);
Expand Down
1 change: 1 addition & 0 deletions src/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ typedef struct client_s {

// usercmd stuff
unsigned lastmessage; // svs.realtime when packet was last received
unsigned lastactivity; // svs.realtime when user activity was last seen
int lastframe; // for delta compression
usercmd_t lastcmd; // for filling in big drops
int command_msec; // every seconds this is reset, if user
Expand Down
15 changes: 15 additions & 0 deletions src/server/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,11 @@ static void SV_ExecuteUserCommand(const char *s)
}
}

if (!strcmp(c, "say") || !strcmp(c, "say_team")) {
// don't timeout. only chat commands count as activity.
sv_client->lastactivity = svs.realtime;
}

ge->ClientCommand(sv_player);
}

Expand All @@ -1015,6 +1020,8 @@ SV_ClientThink
*/
static inline void SV_ClientThink(usercmd_t *cmd)
{
usercmd_t *old = &sv_client->lastcmd;

sv_client->command_msec -= cmd->msec;
sv_client->num_moves++;

Expand All @@ -1024,6 +1031,14 @@ static inline void SV_ClientThink(usercmd_t *cmd)
return;
}

if (cmd->buttons != old->buttons
|| cmd->forwardmove != old->forwardmove
|| cmd->sidemove != old->sidemove
|| cmd->upmove != old->upmove) {
// don't timeout
sv_client->lastactivity = svs.realtime;
}

ge->ClientThink(sv_player, cmd);
}

Expand Down

0 comments on commit 10e0588

Please sign in to comment.