From 4979f43baba8c7377471bbf65e7b5c003bf65406 Mon Sep 17 00:00:00 2001 From: Satya Ortiz-Gagne Date: Mon, 10 Jun 2019 10:12:45 -0400 Subject: DAIDE - Implemented notifications and notification_managers - MAP = MapNameNotification - HLO = HelloNotification - SCO = SupplyCenterNotification - NOW = CurrentPositionNotification - MIS = MissingOrdersNotification - ORD = OrderResultNotification - TME = TimeToDeadlineNotification - CCD = PowerInCivilDisorderNotification - OUT = PowerIsEliminatedNotification - DRW = DrawNotification - FRM = MessageFromNotification - SLO = SoloNotification - SMR = SummaryNotification - OFF = TurnOffNotification --- diplomacy/server/user.py | 17 ++++++++++++++++- diplomacy/server/users.py | 8 ++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'diplomacy/server') diff --git a/diplomacy/server/user.py b/diplomacy/server/user.py index cfb6ad4..11cca15 100644 --- a/diplomacy/server/user.py +++ b/diplomacy/server/user.py @@ -15,7 +15,7 @@ # with this program. If not, see . # ============================================================================== """ User object, defined with a username and a hashed password. """ -from diplomacy.utils import strings +from diplomacy.utils import strings, parsing from diplomacy.utils.common import is_valid_password from diplomacy.utils.jsonable import Jsonable @@ -35,3 +35,18 @@ class User(Jsonable): def is_valid_password(self, password): """ Return True if given password matches user hashed password. """ return is_valid_password(password, self.password_hash) + +class DaideUser(User): + """ DAIDE user class """ + __slots__ = ['username', 'password_hash', 'client_name', 'client_version', 'passcode'] + model = parsing.extend_model(User.model, { + strings.CLIENT_NAME: str, + strings.CLIENT_VERSION: str, + strings.PASSCODE: parsing.OptionalValueType(int) + }) + + def __init__(self, **kwargs): + self.client_name = '' + self.client_version = '' + self.passcode = 0 + super(DaideUser, self).__init__(**kwargs) diff --git a/diplomacy/server/users.py b/diplomacy/server/users.py index d1c8ca0..d63df3e 100644 --- a/diplomacy/server/users.py +++ b/diplomacy/server/users.py @@ -116,6 +116,10 @@ class Users(Jsonable): """ Return username of given token. """ return self.token_to_username[token] + def get_user(self, username): + """ Returns user linked to username """ + return self.users.get(username, None) + def get_connection_handler(self, token): """ Return connection handler associated to given token, or None if no handler currently associated. """ return self.token_to_connection_handler.get(token, None) @@ -145,6 +149,10 @@ class Users(Jsonable): self.users[username] = user return user + def replace_user(self, username, new_user): + """ Replaces user object with a new user """ + self.users[username] = new_user + def remove_user(self, username): """ Remove user related to given username. """ user = self.users.pop(username) -- cgit v1.2.3