Exemplo n.º 1
0
        public async Task CreateLobby(PlayerData playerData)
        {
            try
            {
                if (Context.UserIdentifier != null)
                {
                    var user = await _userRepository.GetUserByIdentityId(Context.UserIdentifier);

                    user.Name       = playerData.Name;
                    user.AvatarJson = playerData.AvatarJson;
                    await _userRepository.UpdateUser(user);

                    _playerManager.AddPlayer(playerData, Context.ConnectionId, user.Id);
                }
                else
                {
                    _playerManager.AddPlayer(playerData, Context.ConnectionId);
                }

                var lobby = await _lobbyManager.CreateLobbyAsync(playerData);

                _logger.LogDebug("{username} created lobby {lobbyId}", playerData.Id, lobby.Id);

                await _lobbyManager.JoinLobbyAsync(lobby.Id, playerData, Context.ConnectionId);

                await Groups.AddToGroupAsync(Context.ConnectionId, lobby.Id);
            }
            catch (Exception e)
            {
                await HandleException(e);
            }
        }