Make telnet keepalive functionality a @configurable setting
authorAri Johnson <ari@theari.com>
Fri, 25 Sep 2015 03:34:31 +0000 (23:34 -0400)
committerAri Johnson <ari@theari.com>
Fri, 25 Sep 2015 03:34:31 +0000 (23:34 -0400)
hdrs/conf.h
hdrs/dbdefs.h
options.h.dist
src/bsd.c
src/conf.c
src/flags.c

index 31220eb8e24442be4c6f27c51ab41e93b7ac00e2..d62880d556696dc910c430c003eaf2f8782a4688 100644 (file)
@@ -159,6 +159,7 @@ struct options_table {
   int idle_time;       /** Time for the system to consider player 'idle' used in conjuntion with @AUNIDLE */
   int unconnected_idle_timeout;        /**< Maximum idle time for connections without dbrefs, in minutes */
   int keepalive_timeout; /**< Number of seconds between TCP keepalive pings */
+  int telnet_keepalive_interval; /**< Number of seconds between telnet NOP transmissions */
   int dump_interval;   /**< Interval between database dumps, in seconds */
   char dump_message[256]; /**< Message shown at start of nonforking dump */
   char dump_complete[256]; /**< Message shown at end of nonforking dump */
@@ -396,6 +397,7 @@ int cf_time(const char *opt, const char *val, void *loc, int maxval,
 
 #define PURGE_INTERVAL   (options.purge_interval)
 #define DBCK_INTERVAL    (options.dbck_interval)
+#define TELNET_KEEPALIVE_INTERVAL      (options.telnet_keepalive_interval)
 #define MAX_PARENTS (options.max_parents)
 #define MAX_DEPTH (options.max_depth)
 #define MAX_PENNIES (options.max_pennies)
index cfd6a94af689ffd6570e0477b9965c9e737bde0e..80d338a59f03163d3184f033edaaa3b2b8578db5 100644 (file)
@@ -154,6 +154,7 @@ extern dbref first_free;    /* pointer to free list */
 #define Halted(x)       (has_flag_by_name(x, "HALT", NOTYPE))
 #define Haven(x)        (has_flag_by_name(x, "HAVEN", NOTYPE))
 #define Inherit(x)     (has_flag_by_name(x, "INHERIT", TYPE_THING|TYPE_EXIT|TYPE_ROOM))
+#define Keepalive(x)   (has_flag_by_name(x, "KEEPALIVE", TYPE_PLAYER))
 #define Light(x)        (has_flag_by_name(x, "LIGHT", NOTYPE))
 #define LinkOk(x)       (has_flag_by_name(x, "LINK_OK", NOTYPE))
 #define Loud(x)                (has_flag_by_name(x, "LOUD", NOTYPE))
index f2908c8d50dd2d58c734f5b10d4ca38db478a899..4e01b875404cc9801f9e900302123412529ec17f 100644 (file)
 /* These are options specific to CobraMUSH.
  */
 
-/* Automatic keepalive for telnet-enabled connections */
-#define TELNET_KEEPALIVE /* */
-
-/* Keepalive timer interval (in seconds) */
-#define KEEPALIVE_INTERVAL 300
-
 /* Colored WHO */
 #define COLOREDWHO /* */
 
index 39c81c1f4d001d59987ece096873ee7b276f26a0..ec20b63c4b73b984f527427a333d3a179bb76854 100644 (file)
--- a/src/bsd.c
+++ b/src/bsd.c
@@ -4773,15 +4773,15 @@ inactivity_check(void)
       d->conn_flags &= ~CONN_TELNET_QUERY;
 
 #ifndef COMPILE_CONSOLE
-#ifdef TELNET_KEEPALIVE
-    if (idle_for && !(idle_for % KEEPALIVE_INTERVAL) &&
-        (d->conn_flags & CONN_TELNET)) {
+    if (TELNET_KEEPALIVE_INTERVAL && idle_for &&
+        !(idle_for % TELNET_KEEPALIVE_INTERVAL) &&
+        (d->conn_flags & CONN_TELNET) &&
+        Keepalive(d->player)) {
       tbuf[0] = IAC;
       tbuf[1] = NOP;
       tbuf[2] = '\0';
       queue_newwrite(d, (unsigned char *) tbuf, 2);
     }
-#endif /* TELNET_KEEPALIVE */
 #endif /* !COMPILE_CONSOLE */
 
     if(d->connected && GoodObject(d->player) && ((a = atr_get(d->player, "IDLE_TIMEOUT"))!=NULL)) {
index 0e71f63ff564203282ec683bd9ffd4391f55e43d..026ea53959946cbfe753724531101817ec95a3a6 100644 (file)
@@ -297,6 +297,8 @@ COBRA_CONF conftable[] = {
   ,
   {"keepalive_timeout", cf_time, &options.keepalive_timeout, 10000, 0, "limits"}
   ,
+  {"telnet_keepalive_interval", cf_time, &options.telnet_keepalive_interval, 10000, 0, "limits"}
+  ,
   {"whisper_loudness", cf_int, &options.whisper_loudness, 100, 0, "limits"}
   ,
   {"starting_quota", cf_int, &options.starting_quota, 10000, 0, "limits"}
@@ -1076,6 +1078,7 @@ conf_default_set(void)
   options.idle_time = 0;
   options.unconnected_idle_timeout = 300;
   options.keepalive_timeout = 300;
+  options.telnet_keepalive_interval = 300;
   options.dump_interval = 3601;
   strcpy(options.dump_message,
         T("GAME: Dumping database. Game may freeze for a minute"));
index 0691252f568ecb03d8f9678d386ea97cfca05ff4..6a0d8f9b18085f2b1d46f5d045b587b40b0683af 100644 (file)
@@ -771,6 +771,7 @@ flag_add_additional(void)
   add_flag("PARALYZED", '\0', TYPE_PLAYER, F_PRIVILEGE, F_PRIVILEGE);
   add_flag("RPAPPROVED", '\0', TYPE_THING, F_PRIVILEGE, F_PRIVILEGE);
 #endif
+  add_flag("KEEPALIVE", '\0', TYPE_PLAYER, F_ANY, F_ANY);
   if ((f = match_flag("TERSE")))
     f->type |= TYPE_THING;
   if ((f = match_flag("PUPPET")))