home · contact · privacy
De-hardcode cert and key file for PlomSocketSSL.
[plomrogue2-experiments] / new2 / plomrogue / io.py
index 5450c343a031a721c64ae70289719f40729b1a7f..8e0f9bf530548572eb7c07d389d7188e19af47d1 100644 (file)
@@ -1,5 +1,6 @@
 import queue
 import threading
+import inspect
 
 
 
@@ -30,12 +31,15 @@ class GameIO():
         c = threading.Thread(target=self.loop, args=(self.queue,))
         c.start()
 
-    def start_server(self, port, server_class):
+    def start_server(self, port, server_class, certfile=None, keyfile=None):
         """Start server of server_class in talk with game loop.
 
         The server communicates with the game loop via self.queue.
         """
-        server = server_class(self.queue, port)
+        if 'certfile' in list(inspect.signature(server_class.__init__).parameters):
+            server = server_class(self.queue, port, certfile=certfile, keyfile=keyfile)
+        else:
+            server = server_class(self.queue, port)
         self.servers += [server]
         c = threading.Thread(target=server.serve_forever)
         c.start()
@@ -47,7 +51,6 @@ class GameIO():
         signature will only be called if god_mode is set.
 
         """
-        from inspect import signature
         from plomrogue.errors import GameError, ArgError, PlayError
         from plomrogue.misc import quote
 
@@ -62,7 +65,7 @@ class GameIO():
             if command is None:
                 answer(connection_id, 'UNHANDLED_INPUT')
             else:
-                if 'connection_id' in list(signature(command).parameters):
+                if 'connection_id' in list(inspect.signature(command).parameters):
                     command(*args, connection_id=connection_id)
                 elif god_mode:
                     command(*args)