home · contact · privacy
Server: Fix buggy handling of ID sizes in TT_ID/TA_ID/T_ID commands.
[plomrogue] / src / server / god_commands.c
index efb607d9083adb3767c28fbd05bf684959682a76..b0aa86aabf2d6e927065d486d7cd92ecb543107a 100644 (file)
@@ -53,6 +53,9 @@ static uint8_t parse_thing_manipulation(char * tok0, char * tok1);
 /* Performs parse_world_active()'s world activation legality tests. */
 static uint8_t world_may_be_set_active();
 
+/* Unlink worldstate file if it exists. */
+static void remove_worldstate_file();
+
 /* Parse/apply god command in "tok0"/"tok1" on toggling world.exists. Unset if
  * argument is 0 and unlink worldstate file, but only set it on positive
  * argument if it is not already set and a thing action of name S_CMD_WAIT, a
@@ -78,7 +81,7 @@ static uint8_t parse_thingtype_manipulation(char * tok0, char * tok1)
         err_line(1, "No thing type defined to manipulate yet.");
         return 1;
     }
-    uint8_t id;
+    int16_t id;
     if (   parse_val(tok0,tok1,s[S_CMD_TT_CONSUM],'8',(char *) &tt->consumable)
         || parse_val(tok0,tok1,s[S_CMD_TT_HP],'8',(char *) &tt->lifepoints)
         || parse_val(tok0,tok1,s[S_CMD_TT_STARTN],'8',(char *) &tt->start_n)
@@ -93,7 +96,7 @@ static uint8_t parse_thingtype_manipulation(char * tok0, char * tok1)
         }
         tt->corpse_id = id;
     }
-    else if (parse_val(tok0, tok1, s[S_CMD_THINGTYPE], '8', (char *) &id))
+    else if (parse_val(tok0, tok1, s[S_CMD_TT_ID], 'i', (char *) &id))
     {
         tt = get_thing_type(id);
         if (!tt)
@@ -132,9 +135,9 @@ static uint8_t parse_thingaction_manipulation(char * tok0, char * tok1)
         err_line(1, "No thing action defined to manipulate yet.");
         return 1;
     }
-    uint8_t id;
-    if      (parse_val(tok0, tok1, s[S_CMD_TA_EFFORT],'8',(char *) &ta->effort));
-    else if (parse_val(tok0, tok1, s[S_CMD_TA_NAME], 's', (char *) &ta->name))
+    int16_t id;
+    if      (parse_val(tok0, tok1, s[S_CMD_TA_EFFORT],'8',(char *)&ta->effort));
+    else if (parse_val(tok0, tok1, s[S_CMD_TA_NAME], 's', (char *)&ta->name))
     {
         if (!(   try_func_name(ta, s[S_CMD_MOVE], actor_move)
               || try_func_name(ta, s[S_CMD_PICKUP], actor_pick)
@@ -148,9 +151,13 @@ static uint8_t parse_thingaction_manipulation(char * tok0, char * tok1)
         if (world.exists)
         {
             world.exists = 0 != get_thing_action_id_by_name(s[S_CMD_WAIT]);
+            if (!world.exists)
+            {
+                remove_worldstate_file();
+            }
         }
     }
-    else if (parse_val(tok0, tok1, s[S_CMD_THINGACTION], '8', (char *) &id))
+    else if (parse_val(tok0, tok1, s[S_CMD_TA_ID], '8', (char *) &id))
     {
         ta = get_thing_action(id);
         if (!ta)
@@ -278,15 +285,15 @@ static uint8_t parse_thing_manipulation(char * tok0, char * tok1)
         err_line(1, "No thing defined to manipulate yet.");
         return 1;
     }
-    uint8_t id;
-    if (    parse_thing_type(tok0, tok1, t)
+    int16_t id;
+    if (   parse_thing_type(tok0, tok1, t)
         || parse_thing_command(tok0, tok1, t)
         || parse_val(tok0,tok1, s[S_CMD_T_ARGUMENT], '8', (char *)&t->arg)
         || parse_val(tok0,tok1, s[S_CMD_T_PROGRESS], '8', (char *)&t->progress)
         || parse_val(tok0,tok1, s[S_CMD_T_HP], '8', (char *) &t->lifepoints)
         || parse_position(tok0, tok1, t)
         || parse_carry(tok0, tok1, t));
-    else if (parse_val(tok0, tok1, s[S_CMD_THING], 'i', (char *) &id))
+    else if (parse_val(tok0, tok1, s[S_CMD_T_ID], 'i', (char *) &id))
     {
         t = get_thing(world.things, id, 1);
         char * err = "No thing type found to initialize new thing.";
@@ -330,9 +337,19 @@ static uint8_t world_may_be_set_active()
 
 
 
+static void remove_worldstate_file()
+{
+    if (!access(s[S_PATH_WORLDSTATE], F_OK))
+    {
+        int test = unlink(s[S_PATH_WORLDSTATE]);
+        exit_trouble(-1 == test, __func__, "unlink");
+    }
+}
+
+
+
 static uint8_t parse_world_active(char * tok0, char * tok1)
 {
-    char * f_name = "parse_world_active()";
     if (!strcmp(tok0, s[S_CMD_WORLD_ACTIVE]) && !parsetest_int(tok1, '8'))
     {
         if (!parsetest_int(tok1, '8'))
@@ -340,11 +357,7 @@ static uint8_t parse_world_active(char * tok0, char * tok1)
             uint8_t argument = atoi(tok1);
             if (!argument)
             {
-                if (!access(s[S_PATH_WORLDSTATE], F_OK))
-                {
-                    int test = unlink(s[S_PATH_WORLDSTATE]);
-                    exit_trouble(-1 == test, f_name, "unlink()");
-                }
+                remove_worldstate_file();
                 world.exists = 0;
             }
             else if (world.exists)
@@ -386,6 +399,7 @@ static uint8_t set_map_length(char * tok0, char * tok1)
             return 1;
         }
         world.exists = 0;
+        remove_worldstate_file();
         free_things(world.things);
         free(world.map.cells);
         world.map.cells = NULL;    /* Since remake_map() runs free() on this. */