home · contact · privacy
Ignore success messages, properly quote messages.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 14 Jan 2019 17:01:19 +0000 (18:01 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 14 Jan 2019 17:01:19 +0000 (18:01 +0100)
client.py
server.py
server_/game.py

index 80cac96aab380849a29c4e54edb6cb5c5bc86579..dd40323fca7038e45f8684bd1f34bd086e96523d 100755 (executable)
--- a/client.py
+++ b/client.py
@@ -23,6 +23,11 @@ class Game(Commander):
             symbol = 'm'
         return symbol
 
+    def cmd_LAST_PLAYER_TASK_RESULT(self, msg):
+        if msg != "success":
+            self.log_text = msg + '\n' + self.log_text
+    cmd_LAST_PLAYER_TASK_RESULT.argtypes = 'string'
+
     def cmd_TURN_FINISHED(self, n):
         """Do nothing. (This may be extended later.)"""
         pass
index cf706994feab1e079dea4b5281f79ea524d5951d..3028b832b29f419f7dabdcd3b2ce79d8d3bd2003 100755 (executable)
--- a/server.py
+++ b/server.py
@@ -133,6 +133,17 @@ class CommandHandler(game_common.Commander, server_.game.Commander):
         except server_.game.GameError as e:
             answer(connection_id, 'GAME ERROR: ' + str(e))
 
+    def quote(self, string):
+        """Quote & escape string so client interprets it as single token."""
+        quoted = []
+        quoted += ['"']
+        for c in string:
+            if c in {'"', '\\'}:
+                quoted += ['\\']
+            quoted += [c]
+        quoted += ['"']
+        return ''.join(quoted)
+
     def send(self, msg, connection_id=None):
         if connection_id:
             self.queues_out[connection_id].put(msg)
@@ -147,22 +158,12 @@ class CommandHandler(game_common.Commander, server_.game.Commander):
             """Transform tuple (y,x) into string 'Y:'+str(y)+',X:'+str(x)."""
             return 'Y:' + str(tuple_[0]) + ',X:' + str(tuple_[1])
 
-        def quoted(string):
-            """Quote & escape string so client interprets it as single token."""
-            quoted = []
-            quoted += ['"']
-            for c in string:
-                if c in {'"', '\\'}:
-                    quoted += ['\\']
-                quoted += [c]
-            quoted += ['"']
-            return ''.join(quoted)
-
         self.send('NEW_TURN ' + str(self.world.turn))
         self.send('MAP_SIZE ' + stringify_yx(self.world.map_.size))
         visible_map = self.world.get_player().get_visible_map()
         for y in range(self.world.map_.size[0]):
-            self.send('VISIBLE_MAP_LINE %5s "%s"' % (y, visible_map.get_line(y)))
+            self.send('VISIBLE_MAP_LINE %5s %s' %
+                      (y, self.quote(visible_map.get_line(y))))
         visible_things = self.world.get_player().get_visible_things()
         for thing in visible_things:
             self.send('THING_TYPE %s %s' % (thing.id_, thing.type_))
@@ -178,7 +179,7 @@ class CommandHandler(game_common.Commander, server_.game.Commander):
         self.send('TURN_FINISHED ' + str(self.world.turn))
         self.world.proceed_to_next_player_turn()
         msg = str(self.world.get_player().last_task_result)
-        self.send('LAST_PLAYER_TASK_RESULT ' + msg)
+        self.send('LAST_PLAYER_TASK_RESULT ' + self.quote(msg))
         self.send_gamestate()
 
     def cmd_FIB(self, numbers, connection_id):
index 910d60878c3426ddc7f402b82e847f8d204b5a27..59df5ae45c0b8939523c4dc3646b40a3d9986548 100644 (file)
@@ -179,7 +179,6 @@ class Thing(game_common.Thing):
         stencil = self.get_stencil()
         visible_things = []
         for thing in self.world.things:
-            print('DEBUG .....')
             width = self.world.map_.size[1]
             pos_i = thing.position[0] * width + thing.position[1]
             if stencil.terrain[pos_i] == '.':