diff options
author | Satya Ortiz-Gagne <satya.ortiz-gagne@mila.quebec> | 2019-06-10 10:12:45 -0400 |
---|---|---|
committer | Philip Paquette <pcpaquette@gmail.com> | 2019-06-14 15:08:29 -0400 |
commit | 4979f43baba8c7377471bbf65e7b5c003bf65406 (patch) | |
tree | c7c188edfbbb2a061a50ce0ec976b86d079e0dff /diplomacy/daide/utils.py | |
parent | a47a787bbc15fc01a20fef7df05437fd3ce7eae8 (diff) |
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
Diffstat (limited to 'diplomacy/daide/utils.py')
-rw-r--r-- | diplomacy/daide/utils.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/diplomacy/daide/utils.py b/diplomacy/daide/utils.py index b6ef60d..e300071 100644 --- a/diplomacy/daide/utils.py +++ b/diplomacy/daide/utils.py @@ -15,8 +15,27 @@ # with this program. If not, see <https://www.gnu.org/licenses/>. # ============================================================================== """ Settings - Contains a list of utils to help handle DAIDE communication """ +from collections import namedtuple from diplomacy.daide.tokens import is_integer_token, Token +ClientConnection = namedtuple('ClientConnection', ['username', 'daide_user', 'token', 'power_name']) + +def get_user_connection(server_users, game, connection_handler): + """ Get the DAIDE user connection informations + :param server_users: The instance of `diplomacy.server.users` of the game's server + :param game: The game the user has joined + :param connection_handler: The connection_handler of the user + :return: A tuple of username, daide_user, token, power_name + """ + token = connection_handler.token + username = server_users.get_name(token) if server_users.has_token(token) else None + daide_user = server_users.users.get(username, None) + + # Assumed to be only one power name in the list + user_powers = [power_name for power_name, power in game.powers.items() if power.is_controlled_by(username)] + power_name = user_powers[0] if user_powers else None + return ClientConnection(username, daide_user, token, power_name) + def str_to_bytes(daide_str): """ Converts a str into its bytes representation :param daide_str: A DAIDE string with tokens separated by spaces |