Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2006:
[Freeciv-Dev] (PR#15105) /list scenarios command
Home

[Freeciv-Dev] (PR#15105) /list scenarios command

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#15105) /list scenarios command
From: "Mike Kaufman" <kaufman@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 8 Jan 2006 14:48:29 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=15105 >

attached is a patch to list scenarios available to load without HACK.

-mike

Index: server/commands.c
===================================================================
--- server/commands.c   (revision 11429)
+++ server/commands.c   (working copy)
@@ -58,10 +58,12 @@
    "list\n"
    "list players\n"
    "list teams\n"
-   "list connections",
-   N_("Show a list of players, teams, or connections."),
-   N_("Show a list of players, of teams, or of connections to the server.  "
-      "The argument may be abbreviated, and defaults to 'players' if absent.")
+   "list connections\n"
+   "list scenarios",
+   N_("Show a list of players, teams, connections, or scenarios."),
+   N_("Show a list of players, teams, connections, or scenarios "
+      "to the server.  The argument may be abbreviated, and defaults "
+      "to 'players' if absent.")
   },
   {"quit",     ALLOW_HACK,
    "quit",
Index: server/stdinhand.c
===================================================================
--- server/stdinhand.c  (revision 11429)
+++ server/stdinhand.c  (working copy)
@@ -84,6 +84,7 @@
 static bool show_list(struct connection *caller, char *arg);
 static void show_teams(struct connection *caller);
 static void show_connections(struct connection *caller);
+static void show_scenarios(struct connection *caller);
 static bool set_ai_level(struct connection *caller, char *name, int level, 
                          bool check);
 static bool set_away(struct connection *caller, char *name, bool check);
@@ -3955,10 +3956,11 @@
   LIST_PLAYERS,
   LIST_TEAMS,
   LIST_CONNECTIONS,
+  LIST_SCENARIOS,
   LIST_ARG_NUM /* Must be last */
 };
 static const char * const list_args[] = {
-  "players", "teams", "connections", NULL
+  "players", "teams", "connections", "scenarios", NULL
 };
 static const char *listarg_accessor(int i) {
   return list_args[i];
@@ -3999,6 +4001,9 @@
   case LIST_CONNECTIONS:
     show_connections(caller);
     return TRUE;
+  case LIST_SCENARIOS:
+    show_scenarios(caller);
+    return TRUE;
   case LIST_ARG_NUM:
     break;
   }
@@ -4170,6 +4175,48 @@
   cmd_reply(CMD_LIST, caller, C_COMMENT, horiz_line);
 }
 
+/**************************************************************************
+  List scenarios. We look both in the DATA_PATH and DATA_PATH/scenario
+**************************************************************************/
+static void show_scenarios(struct connection *caller)
+{
+  char buf[MAX_LEN_CONSOLE_LINE];
+  struct datafile_list *files;
+
+  cmd_reply(CMD_LIST, caller, C_COMMENT, _("List of scenarios available:"));
+  cmd_reply(CMD_LIST, caller, C_COMMENT, horiz_line);
+
+  files = datafilelist_infix("scenario", ".sav", TRUE);
+  
+  datafile_list_iterate(files, pfile) {
+    my_snprintf(buf, sizeof(buf), "%s", pfile->name);
+    cmd_reply(CMD_LIST, caller, C_COMMENT, "%s", buf);
+
+    free(pfile->name);
+    free(pfile->fullname);
+    free(pfile);
+  } datafile_list_iterate_end;
+
+  datafile_list_unlink_all(files);
+  datafile_list_free(files);
+
+  files = datafilelist_infix(NULL, ".sav", TRUE);
+
+  datafile_list_iterate(files, pfile) {
+    my_snprintf(buf, sizeof(buf), "%s", pfile->name);
+    cmd_reply(CMD_LIST, caller, C_COMMENT, "%s", buf);
+
+    free(pfile->name);
+    free(pfile->fullname);
+    free(pfile); 
+  } datafile_list_iterate_end;
+
+  datafile_list_unlink_all(files);
+  datafile_list_free(files);
+
+  cmd_reply(CMD_LIST, caller, C_COMMENT, horiz_line);
+}
+
 #ifdef HAVE_LIBREADLINE
 /********************* RL completion functions ***************************/
 /* To properly complete both commands, player names, options and filenames

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