From cf8ab4843ff083bd174a30a5bb148ed3a9c531e2 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Thu, 12 Nov 2020 20:12:43 +0100
Subject: [PATCH] Lower volume of messages by obfuscating them.

---
 plomrogue/commands.py | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/plomrogue/commands.py b/plomrogue/commands.py
index e62d663..9c0111c 100644
--- a/plomrogue/commands.py
+++ b/plomrogue/commands.py
@@ -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'
 
-- 
2.30.2