]> git.pond.sub.org Git - empserver/commitdiff
Separate login_grace_time from max_idle
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 18 Mar 2012 17:11:35 +0000 (18:11 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 26 Apr 2012 17:57:19 +0000 (19:57 +0200)
max_idle applies in state PS_PLAYING, login_grace_time before (login,
state PS_INIT) and after (logout, state PS_SHUTDOWN).

Cut login_grace_time to two minutes, from max_idle's 15.  Two minutes
is plenty to complete login and logout.  Makes swamping the server
with connections slightly harder, as they get dropped faster.  While
that makes sense all by itself, the real aim is making increasing
max_idle safe.  The next commit will complete that job.

include/econfig-spec.h
include/prototypes.h
src/lib/global/constants.c
src/lib/player/accept.c
src/lib/player/login.c
src/lib/player/recvclient.c
src/lib/subs/pr.c

index 69fb01a9e4af17804244a9b24dcee7ce8135a7da..f69838cd5ee491119c4b3a2bc1bdd3bd9b390da3 100644 (file)
@@ -28,7 +28,7 @@
  *
  *  Known contributors to this file:
  *     Marc Olzheim, 2004
- *     Markus Armbruster, 2004-2011
+ *     Markus Armbruster, 2004-2012
  */
 
 /*
@@ -200,6 +200,8 @@ EMPCFBOTH("max_btus", max_btus, int, NSC_INT, 0,
     "Maximum number of BTUs a country can have")
 EMPCFBOTH("max_idle", max_idle, int, NSC_INT, 0,
     "Maximum number of minutes a player can sit idle while logged in")
+EMPCFBOTH("login_grace_time", login_grace_time, int, NSC_INT, 0,
+    "Grace time for clients to complete login and logout (seconds)")
 EMPCFBOTH("players_at_00", players_at_00, int, NSC_INT, 0,
     "Players have their coordinate system at deity 0,0 (0 - no, 1 - yes)")
 EMPCFBOTH("at_least_one_100", at_least_one_100, int, NSC_INT, KM_INTERNAL,
index 5dd3fbbd3240930dc62583a4647536014994c3ab..ffe87a5e601558c77df34240916cf940eb6de552 100644 (file)
@@ -338,6 +338,7 @@ extern struct player *player_next(struct player *);
 extern struct player *player_prev(struct player *);
 extern struct player *getplayer(natid);
 extern void player_accept(void *);
+extern time_t player_io_deadline(struct player *, int);
 /* dispatch.c */
 extern int dispatch(char *, char *);
 /* empdis.c */
index fafb40559924e1d3cc135597fee2e9ba23a73a05..e051fd78046b94ded2c84a6d9c2e46bf5f02b930 100644 (file)
@@ -29,7 +29,7 @@
  *  Known contributors to this file:
  *     Ken Stevens, 1995
  *     Steve McClure, 1996
- *     Markus Armbruster, 2004-2011
+ *     Markus Armbruster, 2004-2012
  */
 
 #include <config.h>
@@ -65,6 +65,7 @@ char *game_days = "";         /* days game is running */
 char *game_hours = "";         /* hours game is running */
 char *pre_update_hook = "";
 int max_idle = 15;             /* session dies after max_idle minutes idle */
+int login_grace_time = 120;    /* Grace time for completing login (sec) */
 
 int sect_mob_max = 127;                /* sector mobility limits */
 float sect_mob_scale = 1.0;    /* accumulation multiplier */
index 8d459182d019aa12c37806fe9c4513da9dfc8975..f32548e0cfad842ee5bba0bbaf222858b29582f8 100644 (file)
@@ -99,7 +99,7 @@ player_delete(struct player *lp)
 
     if (lp->iop) {
        /* it's a real player */
-       io_close(lp->iop, player->curup + minutes(max_idle));
+       io_close(lp->iop, player->curup + login_grace_time);
        lp->iop = NULL;
     }
     back = (struct player *)lp->queue.q_back;
@@ -152,6 +152,16 @@ getplayer(natid cnum)
     return NULL;
 }
 
+time_t
+player_io_deadline(struct player *pl, int write)
+{
+    if (pl->may_sleep < (write ? PLAYER_SLEEP_FREELY : PLAYER_SLEEP_ON_INPUT))
+       return 0;
+    if (pl->state != PS_PLAYING)
+       return pl->curup + login_grace_time;
+    return pl->curup + minutes(max_idle);
+}
+
 /*ARGSUSED*/
 void
 player_accept(void *unused)
index ba415d8bfb28c441195b90a0ad43bea4ab162208..aa0033bee9d44e8024e382105112ac2673547b9c 100644 (file)
@@ -88,7 +88,7 @@ player_login(void *ud)
     pr_id(player, C_INIT, "Empire server ready\n");
 
     for (;;) {
-       deadline = player->curup + minutes(max_idle);
+       deadline = player_io_deadline(player, 0);
        if (io_outputwaiting(player->iop)) {
            if (io_output(player->iop, deadline) <= 0)
                break;
index f9f3453481d09ca53a8f27cca811ef60cbbebf2d..b89bbef66c4b8c4e948fe909519f254fdd06b449 100644 (file)
@@ -36,7 +36,6 @@
 
 #include "empio.h"
 #include "journal.h"
-#include "optlist.h"
 #include "player.h"
 #include "prototypes.h"
 
@@ -81,20 +80,15 @@ recvclient(char *cmd, int size)
         * Flush all queued output before potentially sleeping in
         * io_input(), to make sure player sees the prompt.
         */
-       deadline = player->curup + minutes(max_idle);
-       if (player->may_sleep < PLAYER_SLEEP_ON_INPUT)
-           deadline = 0;
+       deadline = player_io_deadline(player, 0);
        while (io_output(player->iop, deadline) > 0)
            ;
 
        /*
-        * Try to receive some input.  Need to check player->may_sleep
-        * again; command abortion during io_output() might have
-        * changed it.
+        * Try to receive some input.  Need to recompute deadline;
+        * command abortion during io_output() might have changed it.
         */
-       deadline = player->curup + minutes(max_idle);
-       if (player->may_sleep < PLAYER_SLEEP_ON_INPUT)
-           deadline = 0;
+       deadline = player_io_deadline(player, 0);
        res = io_input(player->iop, deadline);
        if (res > 0)
            ;
index fb46bef021873aa2717c2ba4bb0e1cd5d16554c3..6413a5e6f5f8445cec547d101317d9c9b0eabff0 100644 (file)
@@ -58,7 +58,6 @@
 #include "journal.h"
 #include "misc.h"
 #include "nat.h"
-#include "optlist.h"
 #include "player.h"
 #include "proto.h"
 #include "prototypes.h"
@@ -332,11 +331,8 @@ outid(struct player *pl, int n)
 static void
 player_output_some(void)
 {
-    time_t deadline;
+    time_t deadline = player_io_deadline(player, 1);
 
-    deadline = player->curup + minutes(max_idle);
-    if (player->may_sleep != PLAYER_SLEEP_FREELY)
-       deadline = 0;
     while (io_output_if_queue_long(player->iop, deadline) > 0)
        ;
 }