From 5862e6964f0ce6e7139862e8b1de3b1cca0a306f Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Mon, 28 Dec 2020 17:13:01 +0100
Subject: [PATCH] Control login limit from optional file to be changed during
 server run.

---
 plomrogue/game.py | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/plomrogue/game.py b/plomrogue/game.py
index 8fcb430..b76860a 100755
--- a/plomrogue/game.py
+++ b/plomrogue/game.py
@@ -349,11 +349,17 @@ class Game(GameBase):
         self.changed = True
 
     def login(self, nick, connection_id):
-        if len(self.sessions) > 200:
-            print('DEBUG LOGIN TOO MANY FOR', connection_id)
-            self.io.send('CHAT "sorry, too many users currenty '
-                         'logged in, try again later"', connection_id)
-            return
+        login_limit_filename = 'login_limit'
+        if os.path.exists(login_limit_filename):
+            with open(login_limit_filename, 'r') as f:
+                lines = f.readlines()
+                login_limit = int(lines[0])
+                if len(self.sessions) > login_limit - 1:
+                    print('DEBUG LOGIN TOO MANY FOR', nick, connection_id)
+                    self.io.send('CHAT "sorry, too many users currently '
+                                 'logged in, try again later '
+                                 'by re-entering your name"', connection_id)
+                    return
         for t in [t for t in self.things
                   if t.type_ == 'Player' and t.name == nick]:
             self.io.send('GAME_ERROR ' + quote('name already in use'),
-- 
2.30.2