<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40274 >

 This patch adds /connectmsg command that can be used to set message
to display new clients connecting to server.

 This version is for S2_2 & TRUNK. I have been using S2_1 version in
my public server for custom rulesets to inform newcomers about need of
custom tileset (Try connecting to vcust127.louhi.net port 5575 with
2.1 client to see this in action)


 - ML

diff -Nurd -X.diff_ignore freeciv/common/game.c freeciv/common/game.c
--- freeciv/common/game.c       2008-03-08 16:32:49.000000000 +0200
+++ freeciv/common/game.c       2008-06-13 21:53:18.000000000 +0300
@@ -387,6 +387,7 @@
 
   game.meta_info.user_message_set = FALSE;
   game.meta_info.user_message[0] = '\0';
+  game.connectmsg[0] = '\0';
 }
 
 /****************************************************************************
diff -Nurd -X.diff_ignore freeciv/common/game.h freeciv/common/game.h
--- freeciv/common/game.h       2008-04-01 22:40:44.000000000 +0300
+++ freeciv/common/game.h       2008-06-13 21:53:18.000000000 +0300
@@ -59,7 +59,7 @@
    * use.  The "stored" value is a value the player can change; it won't
    * take effect until the next turn. */
   bool simultaneous_phases_stored;
-  char *startmessage;
+  char connectmsg[MAX_LEN_MSG];  
   struct player players[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS];
   struct conn_list *all_connections;        /* including not yet established */
   struct conn_list *est_connections;        /* all established client conns */
diff -Nurd -X.diff_ignore freeciv/server/commands.c freeciv/server/commands.c
--- freeciv/server/commands.c   2008-02-02 09:34:49.000000000 +0200
+++ freeciv/server/commands.c   2008-06-13 21:53:18.000000000 +0300
@@ -116,6 +116,13 @@
    N_("For each connected client, pops up a window showing the message "
       "entered.")
   },
+  {"connectmsg", ALLOW_HACK,
+   /* TRANS: translate text between <> only */
+   N_("connectmsg <message>"),
+   N_("Set message to show to connecting players."),
+   N_("Set message to sends to clients when they connect.\n"
+      "Empty message means that no message is sent.")
+  },
   {"vote",     ALLOW_INFO,
    /* TRANS: translate text between [] only */
    N_("vote yes|no [vote number]"),
diff -Nurd -X.diff_ignore freeciv/server/commands.h freeciv/server/commands.h
--- freeciv/server/commands.h   2008-02-02 09:34:49.000000000 +0200
+++ freeciv/server/commands.h   2008-06-13 21:53:18.000000000 +0300
@@ -37,6 +37,7 @@
   CMD_EXPLAIN,
   CMD_SHOW,
   CMD_WALL,
+  CMD_CONNECTMSG,
   CMD_VOTE,
   
   /* mostly non-harmful: */
diff -Nurd -X.diff_ignore freeciv/server/connecthand.c 
freeciv/server/connecthand.c
--- freeciv/server/connecthand.c        2008-05-07 17:44:45.000000000 +0300
+++ freeciv/server/connecthand.c        2008-06-13 21:53:18.000000000 +0300
@@ -202,6 +202,12 @@
 
   reset_all_start_commands();
   (void) send_server_info_to_metaserver(META_INFO);
+
+  if (game.connectmsg[0] != '\0') {
+    freelog(LOG_DEBUG, "Sending connectmsg: %s", game.connectmsg);
+    notify_conn(dest, NULL, E_MESSAGE_WALL,
+                "%s", game.connectmsg);
+  }
 }
 
 /**************************************************************************
diff -Nurd -X.diff_ignore freeciv/server/stdinhand.c freeciv/server/stdinhand.c
--- freeciv/server/stdinhand.c  2008-05-10 11:46:36.000000000 +0300
+++ freeciv/server/stdinhand.c  2008-06-13 21:53:18.000000000 +0300
@@ -1121,8 +1121,7 @@
 }
 
 /**************************************************************************
-...
-('caller' argument is unused)
+ Generate init script from settings currently in use
 **************************************************************************/
 static bool write_command(struct connection *caller, char *arg, bool check)
 {
@@ -1638,6 +1637,46 @@
   return TRUE;
 }
 
+/******************************************************************
+  Set message to send to all new connections
+******************************************************************/
+static bool connectmsg_command(struct connection *caller, char *str,
+                               bool check)
+{
+  unsigned int bufsize = sizeof(game.connectmsg);
+
+  if (is_restricted(caller)) {
+    return FALSE;
+  }
+  if (!check) {
+    int i;
+    int c = 0;
+
+    for (i = 0; c < bufsize -1 && str[i] != '\0'; i++) {
+      if (str[i] ==  '\\') {
+        i++;
+
+        if (str[i] == 'n') {
+          game.connectmsg[c++] = '\n';
+        } else {
+          game.connectmsg[c++] = str[i];
+        }
+      } else {
+        game.connectmsg[c++] = str[i];
+      }
+    }
+
+    game.connectmsg[c++] = '\0';
+
+    if (c == bufsize) {
+      /* Truncated */
+      cmd_reply(CMD_CONNECTMSG, caller, C_WARNING,
+               _("Connectmsg truncated to %u bytes."), bufsize);
+    }
+  }
+  return TRUE;
+}
+
 /****************************************************************************
   Tell the client about just one server setting.  Call this after a setting
   is saved.
@@ -3688,6 +3727,8 @@
     return set_rulesetdir(caller, arg, check);
   case CMD_WALL:
     return wall(arg, check);
+  case CMD_CONNECTMSG:
+    return connectmsg_command(caller, arg, check);
   case CMD_VOTE:
     return vote_command(caller, arg, check);
   case CMD_READ_SCRIPT:
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to