public async Task <IActionResult> StartMatch([FromBody] MatchStartBody matchStart)
 {
     try
     {
         return(Ok(await service.StartMatch(GetApiUserIdentityContainer(), matchStart)));
     }
     catch (Exception)
     {
         return(Error(new ErrorResult
         {
             Classification = ErrorClassification.InternalError,
             Message = "Failed to start match"
         }));
     }
 }
Exemple #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
            });
        }