Author: cazfi
Date: Sun Apr 17 05:56:17 2016
New Revision: 32424

URL: http://svn.gna.org/viewcvs/freeciv?rev=32424&view=rev
Log:
Added new chat package type to be used for some chats related to login procedure
on auth-enabled server. Unlike normal chat packet, this one is accepted by the 
client
in the early phase.

Reported by Jacob Nevins <jtn>

See bug #19526

Modified:
    branches/S2_6/client/client_main.c
    branches/S2_6/client/packhand.c
    branches/S2_6/common/packets.def
    branches/S2_6/fc_version
    branches/S2_6/server/auth.c
    branches/S2_6/server/notify.c
    branches/S2_6/server/notify.h

Modified: branches/S2_6/client/client_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/client_main.c?rev=32424&r1=32423&r2=32424&view=diff
==============================================================================
--- branches/S2_6/client/client_main.c  (original)
+++ branches/S2_6/client/client_main.c  Sun Apr 17 05:56:17 2016
@@ -752,7 +752,8 @@
       && PACKET_SERVER_JOIN_REPLY != type
       && PACKET_AUTHENTICATION_REQ != type
       && PACKET_SERVER_SHUTDOWN != type
-      && PACKET_CONNECT_MSG != type) {
+      && PACKET_CONNECT_MSG != type
+      && PACKET_EARLY_CHAT_MSG != type) {
     log_error("Received packet %s (%d) before establishing connection!",
               packet_name(type), type);
     disconnect_from_server();

Modified: branches/S2_6/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/packhand.c?rev=32424&r1=32423&r2=32424&view=diff
==============================================================================
--- branches/S2_6/client/packhand.c     (original)
+++ branches/S2_6/client/packhand.c     Sun Apr 17 05:56:17 2016
@@ -1322,6 +1322,26 @@
   in-game messages and chats from other players.
 **************************************************************************/
 void handle_chat_msg(const struct packet_chat_msg *packet)
+{
+  handle_event(packet->message,
+               index_to_tile(packet->tile),
+               packet->event,
+               packet->turn,
+               packet->phase,
+               packet->conn_id);
+}
+
+/**************************************************************************
+  Handle an early message packet. Thease have format like other chat
+  messages but server sends them only about events related to establishing
+  the connection and other setup in the early phase. They are a separate
+  packet just so that client knows thse to be already relevant when it's
+  only setting itself up - other chat messages might be just something
+  sent to all clients, and we might want to still consider ourselves
+  "not connected" (not receivers of those messages) until we are fully
+  in the game.
+**************************************************************************/
+void handle_early_chat_msg(const struct packet_early_chat_msg *packet)
 {
   handle_event(packet->message,
                index_to_tile(packet->tile),

Modified: branches/S2_6/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/packets.def?rev=32424&r1=32423&r2=32424&view=diff
==============================================================================
--- branches/S2_6/common/packets.def    (original)
+++ branches/S2_6/common/packets.def    Sun Apr 17 05:56:17 2016
@@ -577,7 +577,20 @@
 
 /************** Chat/event packets **********************/
 
+/* This MUST have identical structure to PACKET_EARLY_CHAT_MSG as there's 
casting
+ * the two. */
 PACKET_CHAT_MSG = 25; sc, lsend
+  STRING message[MAX_LEN_MSG];
+  TILE tile;
+  EVENT event;
+  TURN turn;
+  PHASE phase;
+  CONNECTION conn_id;
+end
+
+/* This MUST have identical structure to PACKET_CHAT_MSG as there's casting
+ * the two. */
+PACKET_EARLY_CHAT_MSG = 28; sc, lsend
   STRING message[MAX_LEN_MSG];
   TILE tile;
   EVENT event;

Modified: branches/S2_6/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/fc_version?rev=32424&r1=32423&r2=32424&view=diff
==============================================================================
--- branches/S2_6/fc_version    (original)
+++ branches/S2_6/fc_version    Sun Apr 17 05:56:17 2016
@@ -55,7 +55,7 @@
 #   - 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-2.6-2016.Mar.10"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2016.Apr.17"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: branches/S2_6/server/auth.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/auth.c?rev=32424&r1=32423&r2=32424&view=diff
==============================================================================
--- branches/S2_6/server/auth.c (original)
+++ branches/S2_6/server/auth.c Sun Apr 17 05:56:17 2016
@@ -84,9 +84,9 @@
       get_unique_guest_name(username);
 
       if (strncmp(tmpname, username, MAX_LEN_NAME) != 0) {
-        notify_conn(pconn->self, NULL, E_CONNECTION, ftc_warning,
-                    _("Warning: the guest name '%s' has been "
-                      "taken, renaming to user '%s'."), tmpname, username);
+        notify_conn_early(pconn->self, NULL, E_CONNECTION, ftc_warning,
+                          _("Warning: the guest name '%s' has been "
+                            "taken, renaming to user '%s'."), tmpname, 
username);
       }
       sz_strlcpy(pconn->username, username);
       establish_new_connection(pconn);
@@ -111,10 +111,10 @@
         sz_strlcpy(pconn->username, tmpname);
 
         log_error("Error reading database; connection -> guest");
-        notify_conn(pconn->self, NULL, E_CONNECTION, ftc_warning,
-                    _("There was an error reading the user "
-                      "database, logging in as guest connection '%s'."),
-                    pconn->username);
+        notify_conn_early(pconn->self, NULL, E_CONNECTION, ftc_warning,
+                          _("There was an error reading the user "
+                            "database, logging in as guest connection '%s'."),
+                          pconn->username);
         establish_new_connection(pconn);
       } else {
         reject_new_connection(_("There was an error reading the user database "

Modified: branches/S2_6/server/notify.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/notify.c?rev=32424&r1=32423&r2=32424&view=diff
==============================================================================
--- branches/S2_6/server/notify.c       (original)
+++ branches/S2_6/server/notify.c       Sun Apr 17 05:56:17 2016
@@ -191,7 +191,8 @@
   coordinates have been normalized.
 **************************************************************************/
 static void notify_conn_packet(struct conn_list *dest,
-                               const struct packet_chat_msg *packet)
+                               const struct packet_chat_msg *packet,
+                               bool early)
 {
   struct packet_chat_msg real_packet = *packet;
   int tile = packet->tile;
@@ -224,7 +225,11 @@
       real_packet.tile = -1;
     }
 
-    send_packet_chat_msg(pconn, &real_packet);
+    if (early) {
+      send_packet_early_chat_msg(pconn, (struct packet_early_chat_msg 
*)(&real_packet));
+    } else {
+      send_packet_chat_msg(pconn, &real_packet);
+    }
   } conn_list_iterate_end;
 }
 
@@ -244,7 +249,32 @@
   vpackage_event(&genmsg, ptile, event, color, format, args);
   va_end(args);
 
-  notify_conn_packet(dest, &genmsg);
+  notify_conn_packet(dest, &genmsg, FALSE);
+
+  if (!dest || dest == game.est_connections) {
+    /* Add to the cache */
+    event_cache_add_for_all(&genmsg);
+  }
+}
+
+/**************************************************************************
+  See notify_conn_packet - this is just the "non-v" version, with varargs.
+  Use for early connecting protocol messages.
+**************************************************************************/
+void notify_conn_early(struct conn_list *dest,
+                       const struct tile *ptile,
+                       enum event_type event,
+                       const struct ft_color color,
+                       const char *format, ...)
+{
+  struct packet_chat_msg genmsg;
+  va_list args;
+
+  va_start(args, format);
+  vpackage_event(&genmsg, ptile, event, color, format, args);
+  va_end(args);
+
+  notify_conn_packet(dest, &genmsg, TRUE);
 
   if (!dest || dest == game.est_connections) {
     /* Add to the cache */
@@ -273,7 +303,7 @@
   vpackage_event(&genmsg, ptile, event, color, format, args);
   va_end(args);
 
-  notify_conn_packet(dest, &genmsg);
+  notify_conn_packet(dest, &genmsg, FALSE);
 
   /* Add to the cache */
   event_cache_add_for_player(&genmsg, pplayer);
@@ -300,7 +330,7 @@
   players_iterate(other_player) {
     if (player_has_embassy(other_player, pplayer)
         && pplayer != other_player) {
-      notify_conn_packet(other_player->connections, &genmsg);
+      notify_conn_packet(other_player->connections, &genmsg, FALSE);
       players = event_cache_player_add(players, other_player);
     }
   } players_iterate_end;
@@ -348,7 +378,7 @@
     event_cache_add_for_all(&genmsg);
   }
 
-  notify_conn_packet(dest, &genmsg);
+  notify_conn_packet(dest, &genmsg, FALSE);
 
   if (pplayer) {
     conn_list_destroy(dest);
@@ -738,9 +768,9 @@
         pcm = pdata->packet;
         fc_snprintf(pcm.message, sizeof(pcm.message), "(T%d - %s) %s",
                     pdata->packet.turn, timestr, pdata->packet.message);
-        notify_conn_packet(pconn->self, &pcm);
+        notify_conn_packet(pconn->self, &pcm, FALSE);
       } else {
-        notify_conn_packet(pconn->self, &pdata->packet);
+        notify_conn_packet(pconn->self, &pdata->packet, FALSE);
       }
     }
   } event_cache_iterate_end;

Modified: branches/S2_6/server/notify.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/notify.h?rev=32424&r1=32423&r2=32424&view=diff
==============================================================================
--- branches/S2_6/server/notify.h       (original)
+++ branches/S2_6/server/notify.h       Sun Apr 17 05:56:17 2016
@@ -59,6 +59,12 @@
                  const struct ft_color color,
                  const char *format, ...)
                  fc__attribute((__format__ (__printf__, 5, 6)));
+void notify_conn_early(struct conn_list *dest,
+                       const struct tile *ptile,
+                       enum event_type event,
+                       const struct ft_color color,
+                       const char *format, ...)
+                       fc__attribute((__format__ (__printf__, 5, 6)));
 void notify_player(const struct player *pplayer,
                    const struct tile *ptile,
                    enum event_type event,


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to