home · contact · privacy
Lower volume of messages by obfuscating them.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 12 Nov 2020 19:12:43 +0000 (20:12 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 12 Nov 2020 19:12:43 +0000 (20:12 +0100)
plomrogue/commands.py

index e62d6639468d0e5606bd0bec4cbfcf77cc396a37..9c0111c46dcd394bd9e7e9b7baf285f523f93734 100644 (file)
@@ -10,7 +10,22 @@ def cmd_TASKS(game, connection_id):
 cmd_TASKS.argtypes = ''
 
 def cmd_ALL(game, msg, connection_id):
-    import math
+
+    def lower_msg_by_volume(msg, volume):
+        lowered_msg = ''
+        for c in msg:
+            c = c
+            while random.random() > volume * 4:
+                if c.isupper():
+                    c = c.lower()
+                elif c != '.':
+                    c = '.'
+                else:
+                    c = ' '
+            lowered_msg += c
+        return lowered_msg
+
+    import random
     if not connection_id in game.sessions:
         raise GameError('need to be logged in for this')
     speaker = game.get_thing(game.sessions[connection_id], False)
@@ -33,8 +48,11 @@ def cmd_ALL(game, msg, connection_id):
     for c_id in game.sessions:
         listener = game.get_thing(game.sessions[c_id], create_unfound=False)
         volume = 1 / max(1, dijkstra_map[listener.position])
+        lowered_msg = lower_msg_by_volume(msg, volume)
+        lowered_nick = lower_msg_by_volume(speaker.nickname, volume)
         game.io.send('CHAT ' +
-                     quote('(volume: %.3f) %s: %s' % (volume, speaker.nickname, msg)),
+                     quote('(volume: %.2f) %s: %s' % (volume, lowered_nick,
+                                                      lowered_msg)),
                      c_id)
 cmd_ALL.argtypes = 'string'