tUpdateConfigFile() now returns FALSE if it failed to write the config file; a new server command "save" can now be used to save the current configuration to a named file. - vaccinewars - be a doctor and try to vaccinate the world
 (HTM) git clone git://src.adamsgaard.dk/vaccinewars
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit d5e203347aa5c6bf3cc11244f826d4b77a848535
 (DIR) parent d8129b26f75227b30e263238fae55e9cab967cec
 (HTM) Author: Ben Webb <ben@salilab.org>
       Date:   Mon, 24 Jun 2002 11:36:53 +0000
       
       UpdateConfigFile() now returns FALSE if it failed to write the config file;
       a new server command "save" can now be used to save the current configuration
       tto a named file.
       
       
       Diffstat:
         M ChangeLog                           |       2 ++
         M TODO                                |       2 --
         M doc/servercommands.html             |       8 +++++++-
         M src/configfile.c                    |      17 ++++++++++-------
         M src/configfile.h                    |       2 +-
         M src/serverside.c                    |      42 +++++++++++++++++++++++--------
       
       6 files changed, 51 insertions(+), 22 deletions(-)
       ---
 (DIR) diff --git a/ChangeLog b/ChangeLog
       t@@ -17,6 +17,8 @@ cvs
              a user-specified high score file with privilege
            - It is no longer necessary to run "dopewars -C" on a zero-byte high
              score file; it will be converted automatically
       +    - A new server command "save" can be used to save the current configuration
       +      to a named config file
        
        1.5.6   29-04-2002
            - Bug fix: the server will only let you pay back loans or deal with the
 (DIR) diff --git a/TODO b/TODO
       t@@ -1,5 +1,3 @@
       -- Have an option in the graphical server to save the current configuration
       -  (wishlist item from SourceForge)
        - Startscreen
        - Track down server memory corruption bug!
        - Implement server option to buy more than one bitch at a time in the Pub.
 (DIR) diff --git a/doc/servercommands.html b/doc/servercommands.html
       t@@ -44,6 +44,12 @@ This is necessary if, for example, the client refuses to acknowledge a
        <dd>Broadcasts the message <i>Hi all!</i> to all players currently connected
        to this server.</dd>
        
       +<dt><b>save <i>my-conf</i></b></dt>
       +<dd>Saves the current configuration (names of drugs, locations, etc.) to
       +the file <i>my-conf</i>. If no file name is given, the configuration is
       +written to the local configuration file - usually <tt>~/.dopewars</tt> on
       +Unix systems and <tt>dopewars-config.txt</tt> on Windows.</dd>
       +
        <dt><b>quit</b></dt>
        <dd>Politely quit, by asking all clients to leave, and then terminating once
        they have done so. An "impolite" quit, which is necessary if the clients fail
       t@@ -60,6 +66,6 @@ command).</dd>
           </ul>
        </li>
        </ul>
       -<p>Last update: <b>13-05-2001</b></p>
       +<p>Last update: <b>23-06-2002</b></p>
        </body>
        </html>
 (DIR) diff --git a/src/configfile.c b/src/configfile.c
       t@@ -195,19 +195,21 @@ static void WriteConfigFile(FILE *fp)
          }
        }
        
       -void UpdateConfigFile(gchar *cfgfile)
       +gboolean UpdateConfigFile(const gchar *cfgfile)
        {
          FILE *fp;
       +  gchar *defaultfile;
          static gchar *header =
              "\n### Everything from here on is written automatically by\n"
              "### the dopewars program; you can edit it manually, but any\n"
              "### formatting (comments, etc.) will be lost at the next rewrite.\n\n";
        
       -  if (!cfgfile) {
       -    cfgfile = GetLocalConfigFile();
       +  defaultfile = GetLocalConfigFile();
       +  if (!cfgfile || !cfgfile[0]) {
       +    cfgfile = defaultfile;
            if (!cfgfile) {
              g_warning(_("Could not determine local config file to write to"));
       -      return;
       +      return FALSE;
            }
          }
        
       t@@ -220,13 +222,14 @@ void UpdateConfigFile(gchar *cfgfile)
            gchar *errstr = ErrStrFromErrno(errno);
            g_warning(_("Could not open file %s: %s"), cfgfile, errstr);
            g_free(errstr);
       -    g_free(cfgfile);
       -    return;
       +    g_free(defaultfile);
       +    return FALSE;
          }
        
          ReadFileToString(fp, header, 50);
          WriteConfigFile(fp);
        
          fclose(fp);
       -  g_free(cfgfile);
       +  g_free(defaultfile);
       +  return TRUE;
        }
 (DIR) diff --git a/src/configfile.h b/src/configfile.h
       t@@ -25,6 +25,6 @@
        
        #include <glib.h>
        
       -void UpdateConfigFile(const gchar *cfgfile);
       +gboolean UpdateConfigFile(const gchar *cfgfile);
        
        #endif /* __DP_CONFIGFILE_H__ */
 (DIR) diff --git a/src/serverside.c b/src/serverside.c
       t@@ -47,6 +47,7 @@
        #include <errno.h>
        #include <stdlib.h>
        #include <glib.h>
       +#include "configfile.h"         /* For UpdateConfigFile */
        #include "dopewars.h"
        #include "log.h"
        #include "message.h"
       t@@ -118,18 +119,19 @@ char *PidFile;
        static char HelpText[] = {
          /* Help on various general server commands */
          N_("dopewars server version %s commands and settings\n\n"
       -     "help                       Displays this help screen\n"
       -     "list                       Lists all players logged on\n"
       -     "push <player>              Politely asks the named player to leave\n"
       -     "kill <player>              Abruptly breaks the connection with the "
       +     "help                     Displays this help screen\n"
       +     "list                     Lists all players logged on\n"
       +     "push <player>            Politely asks the named player to leave\n"
       +     "kill <player>            Abruptly breaks the connection with the "
             "named player\n"
       -     "msg:<mesg>                 Send message to all players\n"
       -     "quit                       Gracefully quit, after notifying all players\n"
       -     "<variable>=<value>         Sets the named variable to the given value\n"
       -     "<variable>                 Displays the value of the named variable\n"
       -     "<list>[x].<var>=<value>    Sets the named variable in the given list,\n"
       -     "                           index x, to the given value\n"
       -     "<list>[x].<var>            Displays the value of the named list variable\n"
       +     "msg:<mesg>               Send message to all players\n"
       +     "save <file>              Save current configuration to the named file\n"
       +     "quit                     Gracefully quit, after notifying all players\n"
       +     "<variable>=<value>       Sets the named variable to the given value\n"
       +     "<variable>               Displays the value of the named variable\n"
       +     "<list>[x].<var>=<value>  Sets the named variable in the given list,\n"
       +     "                         index x, to the given value\n"
       +     "<list>[x].<var>          Displays the value of the named list variable\n"
             "\nValid variables are listed below:-\n\n")
        };
        
       t@@ -956,6 +958,20 @@ static void FinishServerReply(GPrintFunc oldprint)
            g_set_print_handler(oldprint);
        }
        
       +static void ServerSaveConfigFile(const char *string)
       +{
       +  gchar *file = NULL;
       +
       +  if (!string) {
       +    file = GetLocalConfigFile();
       +    string = file;
       +  }
       +  if (UpdateConfigFile(file)) {
       +    g_print(_("Configuration file saved OK as %s\n"), string);
       +  }
       +  g_free(file);
       +}
       +
        static void HandleServerCommand(char *string, NetworkBuffer *netbuf)
        {
          GSList *list;
       t@@ -973,6 +989,10 @@ static void HandleServerCommand(char *string, NetworkBuffer *netbuf)
              RequestServerShutdown();
            } else if (g_strncasecmp(string, "msg:", 4) == 0) {
              BroadcastToClients(C_NONE, C_MSG, string + 4, NULL, NULL);
       +    } else if (g_strncasecmp(string, "save ", 5) == 0) {
       +      ServerSaveConfigFile(string + 5);
       +    } else if (g_strcasecmp(string, "save") == 0) {
       +      ServerSaveConfigFile(NULL);
            } else if (g_strcasecmp(string, "list") == 0) {
              if (FirstServer) {
                g_print(_("Users currently logged on:-\n"));