public async Task <IActionResult> RegisterSteamUser()
        {
            var authResult = await HttpContext.AuthenticateAsync(AuthenticationConfiguration.SteamCookieScheme);

            if (!authResult.Succeeded)
            {
                // TODO: Should probably add an error here
                return(RedirectToAction("Index", "Home"));
            }

            var steamId = authResult.Principal.FindFirstValue(ClaimTypes.NameIdentifier);
            var player  = await _repo.GetPlayer(steamId);

            if (player != null)
            {
                return(await SignInSteamUser(player));
            }

            player = new Player
            {
                SteamId  = steamId,
                PlayerId = Guid.NewGuid(),
                Name     = authResult.Principal.FindFirstValue(ClaimTypes.Name),
            };

            // TODO: Refactor this into a dedicated client for easier testing
            using (var client = new HttpClient())
            {
                try
                {
                    var key      = _configuration["Authentication:Steam:AppKey"];
                    var url      = $"api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={key}&steamids={steamId.Replace("https://steamcommunity.com/openid/id/", "")}";
                    var response = await client.GetAsync("https://" + url);

                    var body = await response.Content.ReadAsStringAsync();

                    var payload     = JsonConvert.DeserializeObject <SteamApiResponseWrapper <GetPlayerSummariesResponse> >(body);
                    var steamplayer = payload.Response.Players.FirstOrDefault();
                    player.ProfileURL   = steamplayer.ProfileURL;
                    player.Avatar       = steamplayer.Avatar;
                    player.AvatarFull   = steamplayer.AvatarFull;
                    player.AvatarMedium = steamplayer.AvatarMedium;
                }
                catch (Exception e)
                {
                    _logger.Error(e, $"Could not fetch player summary for player {steamId}! Error: {e.Message}");
                    // TODO: Should probably add an error response here
                    return(RedirectToAction("Index", "Home"));
                }
            }

            var evnt = new PlayerCreatedEvent(player);

            HttpContext.Items[nameof(IEvent)] = evnt;
            var result = await _eventStore.ProduceAsync(evnt);

            return(await SignInSteamUser(player));
        }
        public async Task SignUpPlayer(SignUpPlayerModel model)
        {
            var suModel = new SignUpModel()
            {
                Username = model.Username,
                Password = model.Password,
                Role     = Role.Player.ToString()
            };
            var id = await SignUp(suModel);

            var @event = new PlayerCreatedEvent()
            {
                PlayerId  = id,
                Name      = model.Name,
                Surname   = model.Surname,
                Age       = model.Age,
                LevelName = model.LevelName
            };

            await _publisher.PublishAsync(@event);
        }
Exemplo n.º 3
0
    private void CreateStartingEnemies(PlayerCreatedEvent e)
    {
        currentEnemies.Clear();

        currentSpawnableEnemyWeights = new float[spawnableEnemyWeights.Length];
        for (int i = 0; i < spawnableEnemyWeights.Length; i++)
        {
            currentSpawnableEnemyWeights[i] = spawnableEnemyWeights[i];
        }

        targetPlayer = e.transform;

        for (int i = 0; i < startingEnemyCount; i++)
        {
            GameObject obj = GetEnemyBasedOnWeight();
            obj.transform.position = enemySpawnPoints[UnityEngine.Random.Range(0, enemySpawnPoints.Length - 1)].position;
            obj.transform.LookAt(targetPlayer.position);
            obj.GetComponent <Enemy>().InitializeEnemy(targetPlayer.gameObject);
            currentEnemies.Add(obj);
        }

        enemyCreated     = true;
        enemyCreatedTime = DateTime.Now;
    }
Exemplo n.º 4
0
 private void InitializeCamera(PlayerCreatedEvent e)
 {
     playerTransform   = e.transform;
     playerMoveStarted = true;
 }