Index: utility/log.c
===================================================================
--- utility/log.c	(revision 6242)
+++ utility/log.c	(working copy)
@@ -342,3 +342,13 @@
   vreal_freelog(level, message, ap);
   va_end(ap);
 }
+
+void im_freelog(FILE *pipe, const char *message, ...)
+{
+  if (pipe) {
+    va_list ap;
+    va_start(ap, message);
+    vfprintf(pipe, message, ap);
+    va_end(ap);
+  }
+}
Index: utility/log.h
===================================================================
--- utility/log.h	(revision 6242)
+++ utility/log.h	(working copy)
@@ -64,6 +64,7 @@
 void real_freelog(int level, const char *message, ...)
                   fc__attribute((__format__ (__printf__, 2, 3)));
 void vreal_freelog(int level, const char *message, va_list ap);
+void im_freelog(FILE *pipe, const char *message, ...);
 
 
 #ifdef DEBUG
Index: server/civserver.c
===================================================================
--- server/civserver.c	(revision 6242)
+++ server/civserver.c	(working copy)
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <err.h>
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
@@ -139,6 +140,7 @@
   bool showhelp = FALSE;
   bool showvers = FALSE;
   char *option = NULL;
+  pid_t pid;
 
   /* Load win32 post-crash debugger */
 #ifdef WIN32_NATIVE
@@ -203,6 +205,10 @@
     } else if (is_option("--help", argv[inx])) {
       showhelp = TRUE;
       break;
+    } else if ((option = get_option_malloc("--name", argv, &inx, argc))) {
+      srvarg.gamename = option; /* Never freed. */
+    } else if ((option = get_option_malloc("--im", argv, &inx, argc))) {
+      srvarg.im_filename = option; /* Never freed. */
     } else if ((option = get_option_malloc("--log", argv, &inx, argc))) {
       srvarg.log_filename = option; /* Never freed. */
     } else if ((option = get_option_malloc("--Ranklog", argv, &inx, argc))) {
@@ -352,6 +358,26 @@
   /* disallow running as root -- too dangerous */
   dont_run_as_root(argv[0], "freeciv_server");
 
+  if (srvarg.im_filename) {
+    if (pipe(im_des)) {
+      err(EXIT_FAILURE, "pipe()");
+    }
+    if ((pid = fork()) == -1) {
+      err(EXIT_FAILURE, "fork()");
+    } else if (pid == 0) {
+      close(im_des[1]);
+      dup2(im_des[0], STDIN_FILENO);
+      execl(srvarg.im_filename, srvarg.im_filename, srvarg.gamename, NULL);
+      err(EXIT_FAILURE, "execl()");
+    } else {
+      close(im_des[0]);
+      if ((im_pipe = fdopen(im_des[1], "w")) == NULL) {
+	err(EXIT_FAILURE, "fdopen()");
+      }
+      setbuf(im_pipe, NULL);
+    }
+  }
+
   ggz_initialize();
   init_our_capability();
 
Index: server/srv_main.c
===================================================================
--- server/srv_main.c	(revision 6242)
+++ server/srv_main.c	(working copy)
@@ -2040,6 +2040,8 @@
       /* Before sniff (human player activites), report time to now: */
       freelog(LOG_VERBOSE, "End/start-turn server/ai activities: %g seconds",
 	      read_timer_seconds(eot_timer));
+      im_freelog(im_pipe, "End/start-turn server/ai activities: %g seconds. Turn T%d\n",
+	      read_timer_seconds(eot_timer), game.info.turn);
 
       /* Do auto-saves just before starting server_sniff_all_input(), so that
        * autosave happens effectively "at the same time" as manual
Index: server/srv_main.h
===================================================================
--- server/srv_main.h	(revision 6242)
+++ server/srv_main.h	(working copy)
@@ -13,6 +13,9 @@
 #ifndef FC__SRV_MAIN_H
 #define FC__SRV_MAIN_H
 
+int im_des[2];
+FILE *im_pipe;
+
 /* utility */
 #include "netintf.h"
 
@@ -35,6 +38,8 @@
   int loglevel;
   /* filenames */
   char *log_filename;
+  char *im_filename;
+  char *gamename;
   char *ranklog_filename;
   char load_filename[512]; /* FIXME: may not be long enough? use MAX_PATH? */
   char *script_filename;
Index: server/connecthand.c
===================================================================
--- server/connecthand.c	(revision 6242)
+++ server/connecthand.c	(working copy)
@@ -273,6 +273,7 @@
   packet.conn_id = -1;
   send_packet_server_join_reply(pconn, &packet);
   freelog(LOG_NORMAL, _("Client rejected: %s."), conn_description(pconn));
+  im_freelog(im_pipe, "Client rejected: %s.\n", conn_description(pconn));
   flush_connection_send_buffer_all(pconn);
 }
 
@@ -287,6 +288,8 @@
   
   freelog(LOG_NORMAL, _("Connection request from %s from %s"),
           req->username, pconn->addr);
+  im_freelog(im_pipe, "Connection request from %s from %s\n",
+          req->username, pconn->addr);
   
   /* print server and client capabilities to console */
   freelog(LOG_NORMAL, _("%s has client version %d.%d.%d%s"),
@@ -378,6 +381,7 @@
   const char *desc = conn_description(pconn);
 
   freelog(LOG_NORMAL, _("Lost connection: %s."), desc);
+  im_freelog(im_pipe, "Lost connection: %s.\n", desc);
 
   /* _Must_ avoid sending to pconn, in case pconn connection is
    * really lost (as opposed to server shutting it down) which would
Index: server/plrhand.c
===================================================================
--- server/plrhand.c	(revision 6242)
+++ server/plrhand.c	(working copy)
@@ -1727,6 +1727,7 @@
     return;
   }
   pplayer->phase_done = TRUE;
+  im_freelog(im_pipe, "Player %s has finished his turn\n", pplayer->username);
 
   check_for_full_turn_done();
 
