aboutsummaryrefslogtreecommitdiff
path: root/diplomacy/server/connection_handler.py
diff options
context:
space:
mode:
authorSatya Ortiz-Gagne <satya.ortiz-gagne@mila.quebec>2019-06-10 10:20:39 -0400
committerPhilip Paquette <pcpaquette@gmail.com>2019-06-14 15:08:29 -0400
commit08b9469e2c71e06fdd70d607f281686746755073 (patch)
tree72066b7920e1c6aa0c8a0b390418c25a1afec1ad /diplomacy/server/connection_handler.py
parent9628cdadbf5a6380098168846dc51e4feadef6ad (diff)
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
Diffstat (limited to 'diplomacy/server/connection_handler.py')
-rw-r--r--diplomacy/server/connection_handler.py16
1 files changed, 16 insertions, 0 deletions
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). """