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

2008/6/21 Madeline Book <madeline.b...@gmail.com>:
>
> The widget that holds the text of the connect message (a label
> I believe it is) should be set to allow selecting text (e.g.
> for copy and pasting). Especially if the message would be used
> to display website addresses or somesuch.

 Original patch was written for 2.1 server and had to work with
already released clients. So exsting events system was used which
meant that standard event popup was used.

 When implementing this for 2.2 we are of course free to change
network protocol and to create completely new dialog for connect
message. Attached version of the patch does just that.

 If nobody objects, I'll commit this version. At least some
implementation should go to 2.2. If someone thinks that warclient
implementation should be ported and is willing to do that, I'm ready
to consider it instead (without checking the details I don't yet
promise that I would accept it).


 - ML

diff -Nurd -X.diff_ignore freeciv/client/gui-ftwl/dialogs.c freeciv/client/gui-ftwl/dialogs.c
--- freeciv/client/gui-ftwl/dialogs.c	2009-06-26 03:00:27.000000000 +0300
+++ freeciv/client/gui-ftwl/dialogs.c	2009-07-06 22:20:03.000000000 +0300
@@ -53,6 +53,17 @@
 }
 
 /**************************************************************************
+  Popup a dialog to display connection message from server.
+**************************************************************************/
+void popup_connect_msg(const char *headline, const char *message)
+{
+  /* FIXME: Needs proper implementation.
+   *        Now just puts to chat window so message is not completely lost. */
+
+  append_output_window(message);
+}
+
+/**************************************************************************
   Popup a generic dialog to display some generic information.
 **************************************************************************/
 void popup_notify_dialog(const char *caption, const char *headline,
diff -Nurd -X.diff_ignore freeciv/client/gui-gtk-2.0/dialogs.c freeciv/client/gui-gtk-2.0/dialogs.c
--- freeciv/client/gui-gtk-2.0/dialogs.c	2009-06-26 03:00:26.000000000 +0300
+++ freeciv/client/gui-gtk-2.0/dialogs.c	2009-07-06 21:57:02.000000000 +0300
@@ -173,6 +173,14 @@
   gtk_widget_destroy(w);
 }
 
+/****************************************************************
+  User clicked close for connect message dialog
+*****************************************************************/
+static void notify_connect_msg_response(GtkWidget *w, gint response)
+{
+  gtk_widget_destroy(w);
+}
+
 /**************************************************************************
   Popup a dialog to display information about an event that has a
   specific location.  The user should be given the option to goto that
@@ -225,6 +233,35 @@
   gtk_widget_show(shell);
 }
 
+/**************************************************************************
+  Popup a dialog to display connection message from server.
+**************************************************************************/
+void popup_connect_msg(const char *headline, const char *message)
+{
+  GtkWidget *shell, *label;
+  
+  shell = gtk_dialog_new_with_buttons(headline,
+        NULL,
+        0,
+        NULL);
+  setup_dialog(shell, toplevel);
+  gtk_dialog_set_default_response(GTK_DIALOG(shell), GTK_RESPONSE_CLOSE);
+  gtk_window_set_position(GTK_WINDOW(shell), GTK_WIN_POS_CENTER_ON_PARENT);
+
+  label = gtk_label_new(message);
+  gtk_label_set_selectable(GTK_LABEL(label), 1);
+
+  gtk_container_add(GTK_CONTAINER(GTK_DIALOG(shell)->vbox), label);
+  gtk_widget_show(label);
+
+  gtk_dialog_add_button(GTK_DIALOG(shell), GTK_STOCK_CLOSE,
+			GTK_RESPONSE_CLOSE);
+
+  g_signal_connect(shell, "response", G_CALLBACK(notify_connect_msg_response),
+                   NULL);
+  gtk_widget_show(shell);
+}
+
 /****************************************************************
 ...
 *****************************************************************/
diff -Nurd -X.diff_ignore freeciv/client/gui-sdl/dialogs.c freeciv/client/gui-sdl/dialogs.c
--- freeciv/client/gui-sdl/dialogs.c	2009-06-26 03:03:16.000000000 +0300
+++ freeciv/client/gui-sdl/dialogs.c	2009-07-06 23:00:23.000000000 +0300
@@ -211,6 +211,14 @@
   			a: %s\nb: %s",headline, lines );
 }
 
+/**************************************************************************
+  Popup a dialog to display connection message from server.
+**************************************************************************/
+void popup_connect_msg(const char *headline, const char *message)
+{
+  freelog(LOG_ERROR, "popup_connect_msg() PORT ME");
+}
+
 /* ----------------------------------------------------------------------- */
 struct ADVANCED_DLG *pNotifyDlg = NULL;
 
diff -Nurd -X.diff_ignore freeciv/client/gui-stub/dialogs.c freeciv/client/gui-stub/dialogs.c
--- freeciv/client/gui-stub/dialogs.c	2008-10-27 04:14:03.000000000 +0200
+++ freeciv/client/gui-stub/dialogs.c	2009-07-06 22:20:33.000000000 +0300
@@ -32,6 +32,14 @@
 }
 
 /**************************************************************************
+  Popup a dialog to display connection message from server.
+**************************************************************************/
+void popup_connect_msg(const char *headline, const char *message)
+{
+  /* PORTME */
+}
+
+/**************************************************************************
   Popup a generic dialog to display some generic information.
 **************************************************************************/
 void popup_notify_dialog(const char *caption, const char *headline,
diff -Nurd -X.diff_ignore freeciv/client/gui-win32/dialogs.c freeciv/client/gui-win32/dialogs.c
--- freeciv/client/gui-win32/dialogs.c	2009-06-26 03:00:26.000000000 +0300
+++ freeciv/client/gui-win32/dialogs.c	2009-07-06 22:19:51.000000000 +0300
@@ -196,6 +196,17 @@
 }
 
 /**************************************************************************
+  Popup a dialog to display connection message from server.
+**************************************************************************/
+void popup_connect_msg(const char *headline, const char *message)
+{
+  /* FIXME: Needs proper implementation.
+   *        Now just puts to chat window so message is not completely lost. */
+
+  append_output_window(message);
+}
+
+/**************************************************************************
 
 **************************************************************************/
 static LONG CALLBACK notify_proc(HWND hWnd,
diff -Nurd -X.diff_ignore freeciv/client/gui-xaw/dialogs.c freeciv/client/gui-xaw/dialogs.c
--- freeciv/client/gui-xaw/dialogs.c	2009-06-26 03:00:26.000000000 +0300
+++ freeciv/client/gui-xaw/dialogs.c	2009-07-06 22:19:33.000000000 +0300
@@ -391,7 +391,16 @@
   /*  XtSetSensitive(toplevel, FALSE); */
 }
 
+/**************************************************************************
+  Popup a dialog to display connection message from server.
+**************************************************************************/
+void popup_connect_msg(const char *headline, const char *message)
+{
+  /* FIXME: Needs proper implementation.
+   *        Now just puts to chat window so message is not completely lost. */
 
+  append_output_window(message);
+}
 
 /****************************************************************
 ...
diff -Nurd -X.diff_ignore freeciv/client/include/dialogs_g.h freeciv/client/include/dialogs_g.h
--- freeciv/client/include/dialogs_g.h	2008-10-27 04:14:00.000000000 +0200
+++ freeciv/client/include/dialogs_g.h	2009-07-06 21:14:04.000000000 +0300
@@ -26,6 +26,7 @@
 			      struct tile *ptile);
 void popup_notify_dialog(const char *caption, const char *headline,
 			 const char *lines);
+void popup_connect_msg(const char *headline, const char *message);
 
 void popup_races_dialog(struct player *pplayer);
 void popdown_races_dialog(void);
diff -Nurd -X.diff_ignore freeciv/client/packhand.c freeciv/client/packhand.c
--- freeciv/client/packhand.c	2009-06-29 21:40:20.000000000 +0300
+++ freeciv/client/packhand.c	2009-07-06 21:13:37.000000000 +0300
@@ -1134,7 +1134,16 @@
 
   handle_event(message, ptile, event, conn_id);
 }
- 
+
+/**************************************************************************
+  Handle a connect message packet. Server sends connect message to
+  client immediately when client connects.
+**************************************************************************/
+void handle_connect_msg(char *message)
+{
+  popup_connect_msg(_("Welcome"), message);
+}
+
 /**************************************************************************
 ...
 **************************************************************************/
diff -Nurd -X.diff_ignore freeciv/common/game.c freeciv/common/game.c
--- freeciv/common/game.c	2009-06-26 03:44:40.000000000 +0300
+++ freeciv/common/game.c	2009-07-06 20:04:35.000000000 +0300
@@ -409,6 +409,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	2009-07-06 01:49:26.000000000 +0300
+++ freeciv/common/game.h	2009-07-06 20:04:35.000000000 +0300
@@ -69,7 +69,7 @@
    * use.  The "stored" value is a value the player can change; it won't
    * take effect until the next turn. */
   int phase_mode_stored;
-  char *startmessage;
+  char connectmsg[MAX_LEN_MSG];
   struct player players[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS];
   int nplayers;
   struct conn_list *all_connections;        /* including not yet established */
diff -Nurd -X.diff_ignore freeciv/common/packets.def freeciv/common/packets.def
--- freeciv/common/packets.def	2009-06-26 03:44:40.000000000 +0300
+++ freeciv/common/packets.def	2009-07-06 20:07:09.000000000 +0300
@@ -257,7 +257,7 @@
   Voting
   Editor
 
-The last used packet number is 181.
+The last used packet number is 182.
 ****************************************************/
 
 
@@ -519,6 +519,10 @@
   STRING message[MAX_LEN_MSG];
 end
 
+PACKET_CONNECT_MSG=182;sc,dsend
+  STRING message[MAX_LEN_MSG];
+end
+
 /************** City packets **********************/
 
 PACKET_CITY_REMOVE=20;sc,dsend,lsend
diff -Nurd -X.diff_ignore freeciv/server/commands.c freeciv/server/commands.c
--- freeciv/server/commands.c	2009-06-26 03:25:51.000000000 +0300
+++ freeciv/server/commands.c	2009-07-06 20:04:35.000000000 +0300
@@ -126,6 +126,13 @@
       "entered."),
    VCF_NONE, 0
   },
+  {"connectmsg", ALLOW_ADMIN,
+   /* 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_BASIC,
    /* TRANS: translate text between [] only */
    N_("vote yes|no|abstain [vote number]"),
diff -Nurd -X.diff_ignore freeciv/server/commands.h freeciv/server/commands.h
--- freeciv/server/commands.h	2009-06-26 03:25:51.000000000 +0300
+++ freeciv/server/commands.h	2009-07-06 20:04:35.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	2009-06-29 21:40:20.000000000 +0300
+++ freeciv/server/connecthand.c	2009-07-06 20:43:05.000000000 +0300
@@ -325,6 +325,11 @@
     }
   } conn_list_iterate_end;
 
+  if (game.connectmsg[0] != '\0') {
+    freelog(LOG_DEBUG, "Sending connectmsg: %s", game.connectmsg);
+    dsend_packet_connect_msg(pconn, game.connectmsg);
+  }
+
   if (srvarg.auth_enabled) {
     return authenticate_user(pconn, req->username);
   } else {
diff -Nurd -X.diff_ignore freeciv/server/stdinhand.c freeciv/server/stdinhand.c
--- freeciv/server/stdinhand.c	2009-06-29 21:40:20.000000000 +0300
+++ freeciv/server/stdinhand.c	2009-07-06 20:04:35.000000000 +0300
@@ -1077,8 +1077,7 @@
 }
 
 /**************************************************************************
-...
-('caller' argument is unused)
+ Generate init script from settings currently in use
 **************************************************************************/
 static bool write_command(struct connection *caller, char *arg, bool check)
 {
@@ -1599,6 +1598,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.
@@ -3816,6 +3855,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:
diff -Nurd -X.diff_ignore freeciv/version.in freeciv/version.in
--- freeciv/version.in	2009-06-26 03:44:41.000000000 +0300
+++ freeciv/version.in	2009-07-06 23:02:26.000000000 +0300
@@ -23,5 +23,5 @@
 #   - Avoid adding a new mandatory capability to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel.2009.Jun.09"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel.2009.Jul.06"
 NETWORK_CAPSTRING_OPTIONAL=""
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to