Пример #1
0
        public async Task AppendMatchStats(GameServerIdentityContainer apiUserIdentity, MatchStatsBody matchStats)
        {
            await this.dbContext.ValidateGameServerIdentity(apiUserIdentity);

            await this.dbContext.ValidateMatchNotEnded(matchStats.MatchId);

            if (matchStats.Players == null || matchStats.Players.Length == 0)
            {
                return;
            }

            try
            {
                using (var dbTransaction = await this.dbContext.Database.BeginTransactionAsync())
                {
                    var updatedMatchPlayers = await GetMatchPlayersToUpdate(matchStats);

                    foreach (var updatedMatchPlayer in updatedMatchPlayers)
                    {
                        await AppendMatchPlayerWeaponTargets(updatedMatchPlayer);
                    }

                    await this.dbContext.SaveChangesAsync();

                    dbTransaction.Commit();
                }
            }
            catch (Exception e)
            {
                throw new DataException("Failed appending match statistics.");
            }
        }
Пример #2
0
        public async Task <MatchStartedResult> StartMatch(GameServerIdentityContainer apiUserIdentity, MatchStartBody matchStart)
        {
            await this.dbContext.ValidateGameServerIdentity(apiUserIdentity);

            var matchModel = new MatchModel
            {
                GameServerId = apiUserIdentity.GameServerIdentifier,
                GameName     = matchStart.GameName,
                MapName      = matchStart.MapName,
                Type         = matchStart.MatchType
            };

            var matchesToEnd = await this.dbContext.Match
                               .Where(m => !m.HasEnded &&
                                      m.GameServerId == apiUserIdentity.GameServerIdentifier &&
                                      m.GameServer.GroupId == apiUserIdentity.GameServerGroupIdentifier)
                               .ToListAsync();

            matchesToEnd.ForEach(m => m.HasEnded = true);

            await this.dbContext.Match.AddAsync(matchModel);

            await this.dbContext.SaveChangesAsync();

            return(new MatchStartedResult
            {
                MatchId = matchModel.Id
            });
        }
Пример #3
0
        public async Task EndMatch(GameServerIdentityContainer apiUserIdentity, MatchEndBody matchEnd)
        {
            await this.dbContext.ValidateGameServerIdentity(apiUserIdentity);

            var match = await this.dbContext.ValidateMatchNotEnded(matchEnd.MatchId);

            match.HasEnded      = true;
            match.SecondsPlayed = matchEnd.SecondsPlayed;

            await this.dbContext.SaveChangesAsync();
        }
Пример #4
0
        public async Task ValidateGameServerIdentity(GameServerIdentityContainer apiUserIdentity)
        {
            bool isValid =
                await(from gs in GameServer
                      join gsg in GameServerGroup
                      on gs.GroupId equals gsg.Id
                      where gs.Id == apiUserIdentity.GameServerIdentifier &&
                      gsg.Id == apiUserIdentity.GameServerGroupIdentifier &&
                      gs.IsActive && gs.IsValid &&
                      gsg.IsActive && gsg.IsActive
                      select gs).AnyAsync();

            if (!isValid)
            {
                throw new UnauthorizedAccessException("Invalid API user identity.");
            }
        }