Author: cazfi
Date: Thu Aug 13 19:08:46 2015
New Revision: 29490

URL: http://svn.gna.org/viewcvs/freeciv?rev=29490&view=rev
Log:
Send current turns History Report to all clients connecting during the turn.

See patch #6195

Modified:
    trunk/server/connecthand.c
    trunk/server/report.c
    trunk/server/report.h

Modified: trunk/server/connecthand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/connecthand.c?rev=29490&r1=29489&r2=29490&view=diff
==============================================================================
--- trunk/server/connecthand.c  (original)
+++ trunk/server/connecthand.c  Thu Aug 13 19:08:46 2015
@@ -303,6 +303,9 @@
     reset_all_start_commands(TRUE);
     (void) send_server_info_to_metaserver(META_INFO);
   }
+
+  send_current_history_report(pconn->self);
+
   conn_compression_thaw(pconn);
 }
 

Modified: trunk/server/report.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/report.c?rev=29490&r1=29489&r2=29490&view=diff
==============================================================================
--- trunk/server/report.c       (original)
+++ trunk/server/report.c       Thu Aug 13 19:08:46 2015
@@ -59,6 +59,10 @@
   int last_turn;
   struct plrdata_slot *plrdata;
 };
+
+/* Have to be initialized to value less than -1 so it doesn't seem like report 
was created at
+ * the end of previous turn in the beginning to turn 0. */
+struct history_report latest_history_report = { -2 };
 
 static struct logging_civ_score *score_log = NULL;
 
@@ -227,15 +231,15 @@
 }
 
 /**************************************************************************
-  Publish historian report.
-**************************************************************************/
-static void historian_generic(enum historian_type which_news)
+  Construct Historian Report
+**************************************************************************/
+static void historian_generic(struct history_report *report,
+                              enum historian_type which_news)
 {
   int i, j = 0, rank = 0;
-  char buffer[4096];
-  char title[1024];
   struct player_score_entry size[player_count()];
 
+  report->turn = game.info.turn;
   players_iterate(pplayer) {
     if (GOOD_PLAYER(pplayer)) {
       switch(which_news) {
@@ -264,7 +268,7 @@
   } players_iterate_end;
 
   qsort(size, j, sizeof(size[0]), secompare);
-  buffer[0] = '\0';
+  report->body[0] = '\0';
   for (i = 0; i < j; i++) {
     if (i > 0 && size[i].value < size[i - 1].value) {
       /* since i < j, only top entry reigns Supreme */
@@ -274,17 +278,28 @@
       /* clamp to final entry */
       rank = ARRAY_SIZE(ranking) - 1;
     }
-    cat_snprintf(buffer, sizeof(buffer),
+    cat_snprintf(report->body, REPORT_BODYSIZE,
                 _(ranking[rank]),
                 i + 1,
                 nation_plural_for_player(size[i].player));
-    fc_strlcat(buffer, "\n", sizeof(buffer));
-  }
-  fc_snprintf(title, sizeof(title), _(historian_message[which_news]),
+    fc_strlcat(report->body, "\n", REPORT_BODYSIZE);
+  }
+  fc_snprintf(report->title, REPORT_TITLESIZE, 
_(historian_message[which_news]),
               calendar_text(),
               _(historian_name[fc_rand(ARRAY_SIZE(historian_name))]));
-  page_conn_etype(game.est_connections, _("Historian Publishes!"),
-                 title, buffer, E_BROADCAST_REPORT);
+}
+
+/**************************************************************************
+  Send history report of this turn.
+**************************************************************************/
+void send_current_history_report(struct conn_list *dest)
+{
+  /* History report is actually constructed at the end of previous turn. */
+  if (latest_history_report.turn >= game.info.turn - 1) {
+    page_conn_etype(dest, _("Historian Publishes!"),
+                    latest_history_report.title, latest_history_report.body,
+                    E_BROADCAST_REPORT);
+  }
 }
 
 /**************************************************************************
@@ -1283,6 +1298,8 @@
                                    + player_slot_index(pslot);
     plrdata->name = NULL;
   } player_slots_iterate_end;
+
+  latest_history_report.turn = -2;
 }
 
 /**************************************************************************
@@ -1525,7 +1542,8 @@
   game.server.scoreturn = (game.info.turn + GAME_DEFAULT_SCORETURN
                            + fc_rand(GAME_DEFAULT_SCORETURN));
 
-  historian_generic(game.server.scoreturn % HISTORIAN_LAST);
+  historian_generic(&latest_history_report, game.server.scoreturn % 
HISTORIAN_LAST);
+  send_current_history_report(game.est_connections);
 }
 
 /**************************************************************************

Modified: trunk/server/report.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/report.h?rev=29490&r1=29489&r2=29490&view=diff
==============================================================================
--- trunk/server/report.h       (original)
+++ trunk/server/report.h       Thu Aug 13 19:08:46 2015
@@ -18,6 +18,16 @@
 struct connection;
 struct conn_list;
 
+#define REPORT_TITLESIZE 1024
+#define REPORT_BODYSIZE 4096
+
+struct history_report
+{
+  int turn;
+  char title[REPORT_TITLESIZE];
+  char body[REPORT_BODYSIZE];
+};
+
 void page_conn(struct conn_list *dest, const char *caption,
                const char *headline, const char *lines);
 
@@ -26,6 +36,7 @@
 void log_civ_score_now(void);
 
 void make_history_report(void);
+void send_current_history_report(struct conn_list *dest);
 void report_wonders_of_the_world(struct conn_list *dest);
 void report_top_five_cities(struct conn_list *dest);
 bool is_valid_demography(const char *demography, int *error);


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

Reply via email to