示例#1
0
 public GameInfo(Guid id, DateTime created, GameOrigin origin, IEnumerable <GameUserInfo> users)
 {
     this.Id      = id;
     this.Created = created;
     this.Origin  = origin;
     this.Users   = users.ToList();
 }
        public Task AddGameTask(IReadOnlyCollection <User> users, GameOrigin origin)
        {
            Debug.Assert(users != null && users.Count == 4);

            // <gameOrigin>#<userGuid>:<userName>,<userGuid:userName>,<userGuid:userName>,<userGuid:userName>
            // 1#af05:askaiser,634b:xenure,7ccb:minty,133e:kalmera
            var data = ((int)origin) + "#" + string.Join(",", users.Select(u => $"{u.Id:D}:{u.UserName}"));

            return(this.AddTask(QueuedTaskType.Game, data));
        }
示例#3
0
        public async Task <Guid> AddGame(GameSummary gameSummary, GameOrigin origin, int seasonId)
        {
            var dbGame = new DbGame();

            dbGame.Errors       = gameSummary.Errors;
            dbGame.InitDuration = gameSummary.InitDuration;
            dbGame.GameDuration = gameSummary.GameDuration;
            dbGame.Stdout       = gameSummary.StandardOutput;
            dbGame.Stderr       = gameSummary.StandardError;
            dbGame.Origin       = origin;
            dbGame.SeasonId     = seasonId;

            this._dbContext.Games.Add(dbGame);

            foreach (var(_, playerSummary) in gameSummary.Players)
            {
                var userDbId = playerSummary.WebsiteId !.Value;
                var botDbId  = playerSummary.BotId !.Value;

                var dbGameUser = new DbGameUser
                {
                    Game        = dbGame,
                    UserId      = userDbId,
                    Score       = playerSummary.Score,
                    DeltaPoints = playerSummary.DeltaPoints ?? 0,
                    Rank        = playerSummary.Rank,
                    Errors      = playerSummary.Errors,
                    BotId       = botDbId
                };

                this._dbContext.GameUsers.Add(dbGameUser);

                if (playerSummary.Points.HasValue && playerSummary.Points.Value > 0)
                {
                    var dbUser = await this._dbContext.Users.SingleAsync(u => u.Id == userDbId).ConfigureAwait(false);

                    dbUser.Points = playerSummary.Points.Value;
                }
            }

            await this._dbContext.SaveChangesAsync().ConfigureAwait(false);

            return(dbGame.Id);
        }
示例#4
0
 public override void OnPositionChanged(ref GameOrigin origin)
 {
     base.OnPositionChanged(ref origin);
 }
示例#5
0
 public Task <Guid> AddGame(GameSummary gameSummary, GameOrigin origin, int seasonId)
 {
     this._objectCache.Remove(GetRankedUsersKeyFormat);
     return(this._underlyingRepository.AddGame(gameSummary, origin, seasonId));
 }
示例#6
0
 public Task AddGameTask(IReadOnlyCollection <User> users, GameOrigin origin)
 {
     return(this._underlyingRepository.AddGameTask(users, origin));
 }