Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] Re: (PR#9321) pubserver rankings are based on player name
Home

[Freeciv-Dev] Re: (PR#9321) pubserver rankings are based on player name

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#9321) pubserver rankings are based on player name not username
From: "Mike Kaufman" <kaufman@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 26 Sep 2004 08:03:31 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9321 >

here is a patch which adds usernames to the gamelog. I've added a
version identifier string to the top of the gamelog, so the parsers
know what to do. 

I've changed the previous format a bit so that the parser won't get
confused on strange UTF-8 names (that might have commas in them)

The format is thus:

Freeciv Gamelog - v2.0    <--- version string
0 Starting new log

 < map >

NATION 0,Romans
NATION 1,Babylonians
NATION 2,Galicians
-4000 USER 0,Unassigned,1,1,Caesar
-4000 USER 1,kauf,1,0,Hammurabi
-4000 USER 2,Unassigned,1,1,Hermerico


  NATION player_no, nation_name
  year, USER player_no, username, connecting, ai controlled, playername

-3950 A Coruña (8, 21) founded by the Galicians
***  1: Babylonians(2)   2: Galicians(2)   3: Romans(1)
RANK 1,4|2,4|0,3|
STATUS 1,kauf,0,1,4|2,Unassigned,1,0,4|0,Unassigned,1,0,3|
-3900 USER 1,kauf,0,1,Hammurabi
-3850 Beneventum (41, 21) founded by the Romans
***  1: Romans(2)   2: Babylonians(2)   3: Galicians(2)
RANK 0,4|1,4|2,4|
STATUS 0,Unassigned,1,0,4|1,kauf,1,0,4|2,Unassigned,1,0,4|
-3800 Lagash (66, 30) founded by the Babylonians


  RANK player_no,rank|player_no,rank|etc
  STATUS player_no,username,skill_level,rank|etc

I need feedback, especially from those of you who maintain the files that
parse the gamelog.

-mike

? .gamelog.swp
? gamelog
Index: server/connecthand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/connecthand.c,v
retrieving revision 1.33
diff -u -r1.33 connecthand.c
--- server/connecthand.c        17 Sep 2004 19:04:21 -0000      1.33
+++ server/connecthand.c        26 Sep 2004 15:02:08 -0000
@@ -31,6 +31,7 @@
 #include "user_db.h"
 #include "diplhand.h"
 #include "gamehand.h"
+#include "gamelog.h"
 #include "maphand.h"
 #include "meta.h"
 #include "plrhand.h"
@@ -115,6 +116,10 @@
   if ((pplayer = find_player_by_user(pconn->username))) {
     attach_connection_to_player(pconn, pplayer);
 
+    if (game.auto_ai_toggle && pplayer->ai.control) {
+      toggle_ai_player_direct(NULL, pplayer);
+    }
+
     if (server_state == RUN_GAME_STATE) {
       /* Player and other info is only updated when the game is running.
        * See the comment in lost_connection_to_client(). */
@@ -126,11 +131,11 @@
       send_diplomatic_meetings(pconn);
       send_packet_thaw_hint(pconn);
       send_packet_start_turn(pconn);
-    }
+      gamelog(GAMELOG_USER, "%d,%s,1,%d,%s", pplayer->player_no,
+              pplayer->username, pplayer->ai.control, pplayer->name);
 
-    if (game.auto_ai_toggle && pplayer->ai.control) {
-      toggle_ai_player_direct(NULL, pplayer);
     }
+
   } else if (server_state == PRE_GAME_STATE && game.is_new_game) {
     if (!attach_connection_to_player(pconn, NULL)) {
       notify_conn(dest, _("Couldn't attach your connection to new player."));
@@ -583,6 +588,11 @@
         && !pplayer->is_connected /* eg multiple controllers */) {
       toggle_ai_player_direct(NULL, pplayer);
     }
+
+    /* notify gamelog that this player is no longer controlled by this conn */
+    gamelog(GAMELOG_USER, "%d,%s,0,%d,%s", pplayer->player_no, 
+             pplayer->username, pplayer->ai.control, pplayer->name);
+
     check_for_full_turn_done();
   }
 
Index: server/gamelog.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gamelog.c,v
retrieving revision 1.37
diff -u -r1.37 gamelog.c
--- server/gamelog.c    17 Sep 2004 08:35:14 -0000      1.37
+++ server/gamelog.c    26 Sep 2004 15:02:08 -0000
@@ -68,6 +68,7 @@
   va_list args;
   char buf[512];
   FILE *fs;
+  static bool did_first_line;
 
   if (!gamelog_filename) {
     return;
@@ -83,6 +84,11 @@
     exit(EXIT_FAILURE);
   }
 
+  if (!did_first_line) {
+    fprintf(fs,"Freeciv Gamelog - v2.0\n"); /* somewhat arbitrary version # */
+    did_first_line = TRUE;
+  }
+
   va_start(args, message);
   my_vsnprintf(buf, sizeof(buf), message, args);
   if (level == GAMELOG_MAP) {
@@ -100,6 +106,10 @@
     fprintf(fs,"%s\n", buf);
   } else if (level == GAMELOG_STATUS) {
     fprintf(fs, "STATUS %s\n", buf);
+  } else if (level == GAMELOG_USER) {
+    fprintf(fs, "%i USER %s\n", game.year, buf);
+  } else if (level == GAMELOG_NATION) {
+    fprintf(fs, "NATION %s\n", buf);
   } else {
     fprintf(fs, "%i %s\n", game.year,buf);
   }
@@ -186,16 +196,17 @@
   buffer[0] = 0;
   for (i = 0; i < count; i++) {
     cat_snprintf(buffer, sizeof(buffer),
-                "%s,%i|",
-                game.players[rank[i].idx].name,
+                "%d,%i|",
+                game.players[rank[i].idx].player_no,
                 rank[i].value);
   }
   gamelog(GAMELOG_RANK,buffer);
   buffer[0] = 0;
   for (i = 0; i < count; i++) {
     cat_snprintf(buffer, sizeof(buffer),
-                "%s,%i,%i,%i|",
-                game.players[rank[i].idx].name,
+                "%d,%s,%i,%i,%i|",
+                game.players[rank[i].idx].player_no,
+                game.players[rank[i].idx].username,
                 game.players[rank[i].idx].ai.control ? 1 : 0 *
                 game.players[rank[i].idx].ai.skill_level,
                 game.players[rank[i].idx].is_connected, rank[i].value);
Index: server/gamelog.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gamelog.h,v
retrieving revision 1.9
diff -u -r1.9 gamelog.h
--- server/gamelog.h    7 Nov 2002 18:55:25 -0000       1.9
+++ server/gamelog.h    26 Sep 2004 15:02:08 -0000
@@ -16,42 +16,39 @@
 
 #include "shared.h"            /* fc__attribute */
 
-#define GAMELOG_FATAL  0
-#define GAMELOG_NORMAL 1
-#define GAMELOG_INIT  2
-#define GAMELOG_MAP 3
-#define GAMELOG_WONDER 4
-#define GAMELOG_FOUNDC 5 
-#define GAMELOG_LOSEC 6
-#define GAMELOG_TECH 7
-#define GAMELOG_EMBASSY 8
-#define GAMELOG_GOVERNMENT 9
-#define GAMELOG_CONQ 10
-#define GAMELOG_REVOLT 11
-#define GAMELOG_GENO 12
-#define GAMELOG_TREATY 13
-#define GAMELOG_TEAM 15
-#define GAMELOG_STATUS 16
-#define GAMELOG_RANK 17
-#define GAMELOG_LAST 18
-#define GAMELOG_EOT 19
-#define GAMELOG_FULL 20
-/*Unit created*/
-#define GAMELOG_UNIT 21
-/*Unit destroyed*/
-#define GAMELOG_UNITL 22
-/*Unit  lost due to fuel*/
-#define GAMELOG_UNITF 23
-/*Trireme lost at sea*/
-#define GAMELOG_UNITTRI 24
-/*Settlers lost to famine*/
-#define GAMELOG_UNITFS 25
-/*Improvements*/
-#define GAMELOG_IMP 28
-/*Taxation rate change*/
-#define GAMELOG_RATE 29
-#define GAMELOG_EVERYTHING 30
-#define GAMELOG_DEBUG 40
+enum {
+  GAMELOG_FATAL,
+  GAMELOG_NORMAL,
+  GAMELOG_INIT,
+  GAMELOG_MAP,
+  GAMELOG_WONDER,
+  GAMELOG_FOUNDC,
+  GAMELOG_LOSEC,
+  GAMELOG_TECH,
+  GAMELOG_EMBASSY,
+  GAMELOG_GOVERNMENT,
+  GAMELOG_CONQ,
+  GAMELOG_REVOLT,
+  GAMELOG_GENO,
+  GAMELOG_TREATY,
+  GAMELOG_TEAM,
+  GAMELOG_USER,                /* User changed or announced */
+  GAMELOG_NATION,      /* Announce which player have which nation */
+  GAMELOG_STATUS,
+  GAMELOG_RANK,
+  GAMELOG_LAST,
+  GAMELOG_EOT,
+  GAMELOG_FULL,
+  GAMELOG_UNIT,                /* Unit created */
+  GAMELOG_UNITL,       /* Unit destroyed */
+  GAMELOG_UNITF,       /* Unit lost due to fuel */
+  GAMELOG_UNITTRI,     /* Trireme lost at sea */
+  GAMELOG_UNITFS,      /* Settlers lost to famine */
+  GAMELOG_IMP,         /* Improvements */
+  GAMELOG_RATE,                /* Taxation rate change */
+  GAMELOG_EVERYTHING,
+  GAMELOG_DEBUG
+};
 
 void gamelog_init(char *filename);
 void gamelog_set_level(int level);
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.198
diff -u -r1.198 srv_main.c
--- server/srv_main.c   21 Sep 2004 05:51:12 -0000      1.198
+++ server/srv_main.c   26 Sep 2004 15:02:09 -0000
@@ -1801,13 +1801,25 @@
       init_tech(pplayer, game.tech);
       player_limit_to_government_rates(pplayer);
       pplayer->economic.gold = game.gold;
+
     } players_iterate_end;
-    if(game.is_new_game) {
-      /* If we're starting a new game, reset the max_players to be the
-       * number of players currently in the game.  But when loading a game
-       * we don't want to change it. */
-      game.max_players = game.nplayers;
-    }
+
+    /* some logging */
+    players_iterate(pplayer) {
+      gamelog(GAMELOG_NATION, "%d,%s", pplayer->player_no, 
+              get_nation_name_plural(pplayer->nation));
+    } players_iterate_end;
+
+    /* more logging */
+    players_iterate(pplayer) {
+      gamelog(GAMELOG_USER, "%d,%s,1,%d,%s", pplayer->player_no, 
+              pplayer->username, pplayer->ai.control, pplayer->name);
+    } players_iterate_end;
+
+    /* If we're starting a new game, reset the max_players to be the
+     * number of players currently in the game.  But when loading a game
+     * we don't want to change it. */
+    game.max_players = game.nplayers;
 
     /* we don't want random start positions in a scenario which already
        provides them. -- Gudy */
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.351
diff -u -r1.351 stdinhand.c
--- server/stdinhand.c  20 Sep 2004 22:06:52 -0000      1.351
+++ server/stdinhand.c  26 Sep 2004 15:02:10 -0000
@@ -2787,6 +2787,11 @@
     sz_strlcpy(pplayer->name, pconn->username);
   }
 
+  /* aitoggle the player back to human if necessary. */
+  if (pplayer->ai.control && game.auto_ai_toggle) {
+    toggle_ai_player_direct(NULL, pplayer);
+  }
+
   if (server_state == RUN_GAME_STATE) {
     send_packet_freeze_hint(pconn);
     send_rulesets(&pconn->self);
@@ -2796,11 +2801,8 @@
     send_diplomatic_meetings(pconn);
     send_packet_thaw_hint(pconn);
     send_packet_start_turn(pconn);
-  }
-
-  /* aitoggle the player back to human if necessary. */
-  if (pplayer->ai.control && game.auto_ai_toggle) {
-    toggle_ai_player_direct(NULL, pplayer);
+    gamelog(GAMELOG_USER, "%d,%s,1,%d,%s", pplayer->player_no,
+            pplayer->username, pplayer->ai.control, pplayer->name);
   }
 
   cmd_reply(CMD_TAKE, caller, C_OK, _("%s now controls %s (%s, %s)"), 

[Prev in Thread] Current Thread [Next in Thread]