From 08b9469e2c71e06fdd70d607f281686746755073 Mon Sep 17 00:00:00 2001 From: Satya Ortiz-Gagne Date: Mon, 10 Jun 2019 10:20:39 -0400 Subject: DAIDE - Added connection_handler and server - Ability to open and close port when DAIDE games are started and stopped - Can get the DAIDE port using a request --- diplomacy/server/connection_handler.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'diplomacy/server/connection_handler.py') diff --git a/diplomacy/server/connection_handler.py b/diplomacy/server/connection_handler.py index 0089db3..6c1351f 100644 --- a/diplomacy/server/connection_handler.py +++ b/diplomacy/server/connection_handler.py @@ -26,6 +26,7 @@ import ujson as json from diplomacy.communication import responses, requests from diplomacy.server import request_managers from diplomacy.utils import exceptions, strings +from diplomacy.utils.network_data import NetworkData LOGGER = logging.getLogger(__name__) @@ -79,6 +80,21 @@ class ConnectionHandler(WebSocketHandler): self.server.users.remove_connection(self, remove_tokens=False) LOGGER.info("Removed connection. Remaining %d connection(s).", self.server.users.count_connections()) + def write_message(self, message, binary=False): + """ Sends the given message to the client of this Web Socket. """ + if isinstance(message, NetworkData): + message = message.json() + return super(ConnectionHandler, self).write_message(message, binary) + + @staticmethod + def translate_notification(notification): + """ Translate a notification to an array of notifications. + :param notification: a notification object to pass to handler function. + See diplomacy.communication.notifications for possible notifications. + :return: An array of notifications containing a single notification. + """ + return [notification] + @gen.coroutine def on_message(self, message): """ Parse given message and manage parsed data (expected a string representation of a request). """ -- cgit v1.2.3