home · contact · privacy
Client: Minor variable renaming.
[plomrogue] / src / server / io.c
index 8f8f738b46533dcbf099e08948f7524dc650e163..c2a3354fd8f9c63d5b689fc9b3369f0ec822ce63 100644 (file)
@@ -1,4 +1,9 @@
-/* src/server/io.c */
+/* src/server/io.c
+ *
+ * This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
+ * or any later version. For details on its copyright, license, and warranties,
+ * see the file NOTICE in the root directory of the PlomRogue source package.
+ */
 
 #define _POSIX_C_SOURCE 200112L /* snrpintf() */
 #include "io.h"
@@ -38,12 +43,12 @@ static void write_thing(FILE * file, struct Thing * t);
 /* Cut out and return first \0-terminated string from world.queue and
  * appropriately reduce world.queue_size. Return NULL if queue is empty.
  * Superfluous \0 bytes after the string are also cut out. Should the queue
- * start with \0 bytes, those are cut out, but NULL is returned instead of "".
-*/
+ * start with \0 bytes, those are cut out before returning anything after them.
+ */
 static char * get_message_from_queue();
 
 /* Poll input file for world.queue input. Wait a few seconds until giving up;
- * poll only every 0.03 seconds.. Translate '\n' chars in input file into '\0'.
+ * poll only every 0.03 seconds. Translate '\n' chars in input file into '\0'.
  */
 static void read_file_into_queue();
 
@@ -188,6 +193,7 @@ static char * get_message_from_queue()
     if (world.queue_size)
     {
         size_t cutout_len = strlen(world.queue);
+        uint8_t is_nullbyte_chunk = !cutout_len;
         if (0 < cutout_len)
         {
             cutout_len++;
@@ -209,6 +215,10 @@ static char * get_message_from_queue()
             memcpy(new_queue, &(world.queue[cutout_len]), world.queue_size);
             free(world.queue);
             world.queue = new_queue;
+            if (is_nullbyte_chunk)
+            {
+                return get_message_from_queue();
+            }
         }
     }
     return message;
@@ -289,7 +299,7 @@ static void write_value_as_line(uint32_t value, FILE * file)
 static void write_inventory(struct Thing * player, FILE * file)
 {
     struct Thing * owned = player->owns;
-    if (NULL == owned)
+    if (!owned)
     {
         char * empty = "(none)\n";
         try_fwrite(empty, strlen(empty), 1, file, __func__);
@@ -297,7 +307,7 @@ static void write_inventory(struct Thing * player, FILE * file)
     else
     {
         uint8_t q;
-        for (q = 0; NULL != owned; q++)
+        for (q = 0; owned; q++)
         {
             struct ThingType * tt = get_thing_type(owned->type);
             try_fwrite(tt->name, strlen(tt->name), 1, file, __func__);
@@ -372,7 +382,7 @@ static void write_map(struct Thing * player, FILE * file)
     struct ThingInMemory * tm;
     for (i = 0; i < 2; i++)
     {
-        for (tm = player->t_mem; tm != NULL; tm = tm->next)
+        for (tm = player->t_mem; tm; tm = tm->next)
         {
             if (' ' != player->mem_map[tm->pos.y*world.map.length+tm->pos.x])
             {
@@ -450,6 +460,7 @@ extern void save_world()
         exit_trouble(test < 0, __func__, "fprintf");
         write_key_space_string(file, s[S_CMD_TT_NAME], tt->name);
         write_key_space_value(file, s[S_CMD_TT_CONSUM], tt->consumable);
+        write_key_space_value(file, s[S_CMD_TT_PROL], tt->proliferate);
         try_fputc('\n', file, __func__);
     }
     for (tt = world.thing_types; tt; tt = tt->next)