import queue
import threading
+import inspect
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()
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
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)
class PlomSocketSSL(PlomSocket):
- def __init__(self, *args, server_side=False, **kwargs):
+ def __init__(self, *args, server_side=False, certfile=None, keyfile=None, **kwargs):
import ssl
- print('DEBUG', args, kwargs)
super().__init__(*args, **kwargs)
if server_side:
self.socket = ssl.wrap_socket(self.socket, server_side=True,
- certfile="server.pem",
- keyfile="key.pem")
+ certfile=certfile, keyfile=keyfile)
else:
self.socket = ssl.wrap_socket(self.socket)
import queue
import threading
if self.socket_class == PlomSocketSSL:
- plom_socket = self.socket_class(self.request, server_side=True)
+ plom_socket = self.socket_class(self.request, server_side=True,
+ certfile=self.server.certfile,
+ keyfile=self.server.keyfile)
else:
plom_socket = self.socket_class(self.request)
print('CONNECTION FROM:', str(self.client_address))
class PlomTCPServerSSL(PlomTCPServer):
- def __init__(self, *args, **kwargs):
+ def __init__(self, *args, certfile=None, keyfile=None, **kwargs):
+ self.certfile = certfile
+ self.keyfile = keyfile
super().__init__(*args, host='0.0.0.0', io_handler=IO_HandlerSSL, **kwargs)