Esempio n. 1
0
        protected override void DoHandle([NotNull] GameHttpContext context, [NotNull] IDebugger debugger)
        {
            if (!context.GodMode && !arenaState.EnableDeepNavigation)
            {
                throw new HttpException(HttpStatusCode.Forbidden, "This operation is only allowed in god mode :-)");
            }

            var playerName1       = context.GetStringParam("player1Result[player][name]");
            var playerVersion1    = context.GetIntParam("player1Result[player][version]");
            var playerName2       = context.GetStringParam("player2Result[player][name]");
            var playerVersion2    = context.GetIntParam("player2Result[player][version]");
            var programStartInfos = new[]
            {
                new DebuggerProgramStartInfo
                {
                    Program      = GetBotProgram(playerName1, playerVersion1),
                    StartAddress = context.GetIntParam("player1Result[startAddress]"),
                },
                new DebuggerProgramStartInfo
                {
                    Program      = GetBotProgram(playerName2, playerVersion2),
                    StartAddress = context.GetIntParam("player2Result[startAddress]"),
                }
            };

            debugger.StartNewGame(programStartInfos);
            context.Redirect(context.BasePath + "debugger.html");
        }
Esempio n. 2
0
 public bool CanHandle([NotNull] GameHttpContext context)
 {
     if (string.IsNullOrEmpty(path))
     {
         return(context.IsRootPathRequested());
     }
     return(context.Request.Url.AbsolutePath.Equals(context.BasePath + path, StringComparison.OrdinalIgnoreCase));
 }
Esempio n. 3
0
        public override void Handle([NotNull] GameHttpContext context)
        {
            var response = new IndexResponse
            {
                NavigationIsDisabled = arenaState.GodAccessOnly && !context.GodMode,
            };

            context.SendResponse(response);
        }
Esempio n. 4
0
        public void Handle([NotNull] GameHttpContext context)
        {
            var localPath = TryGetLocalPath(context);

            if (localPath == null)
            {
                throw new HttpException(HttpStatusCode.NotFound, string.Format("Static resource '{0}' is not found", context.Request.RawUrl));
            }
            context.SendStaticFile(Path.Combine(staticContentPath, "StaticContent", localPath));
        }
Esempio n. 5
0
        private static string TryGetLocalPath([NotNull] GameHttpContext context)
        {
            var relPath = context.Request.Url.LocalPath;

            if (!relPath.Contains("..") && relPath.StartsWith(context.BasePath, StringComparison.OrdinalIgnoreCase))
            {
                return(relPath.Substring(context.BasePath.Length));
            }
            return(null);
        }
Esempio n. 6
0
        public override void Handle([NotNull] GameHttpContext context)
        {
            var response = new ArenaSubmitFormResponse
            {
                SubmitIsAllowed = arenaState.SubmitIsAllowed,
                GodMode         = context.GodMode,
            };

            context.SendResponse(response);
        }
        public override void Handle([NotNull] GameHttpContext context)
        {
            if (!context.GodMode)
            {
                throw new HttpException(HttpStatusCode.Forbidden, "This operation is only allowed in god mode :-)");
            }

            arenaState.SubmitIsAllowed = context.GetBoolParam("value");
            context.Redirect(context.BasePath + "submit.html");
        }
        protected override void DoHandle([NotNull] GameHttpContext context, [NotNull] IDebugger debugger)
        {
            var gameStepResult = debugger.StepToEnd();
            var response       = new DebuggerStepResponse
            {
                StoppedOnBreakpoint = gameStepResult.StoppedInBreakpoint,
                GameState           = debugger.State.GameState
            };

            context.SendResponse(response);
        }
        public override void Handle([NotNull] GameHttpContext context)
        {
            var timeToContestStart = arenaState.CountdownProvider.GetTimeToContestStart();
            var contestTimeLeft    = arenaState.CountdownProvider.GetContestTimeLeft();
            var response           = new NavPanelResponse
            {
                NavigationIsDisabled = arenaState.GodAccessOnly && !context.GodMode,
                TimeToContestStart   = !timeToContestStart.HasValue ? null : timeToContestStart.Value.DropMillis().ToString("c"),
                ContestTimeLeft      = !contestTimeLeft.HasValue ? null : contestTimeLeft.Value.DropMillis().ToString("c"),
            };

            context.SendResponse(response);
        }
Esempio n. 10
0
        public override void Handle([NotNull] GameHttpContext context)
        {
            var playerName      = context.GetStringParam("name");
            var version         = context.GetOptionalIntParam("version");
            var playerVersions  = arenaState.PlayersRepo.LoadPlayerVersions(playerName);
            var botVersionInfos = playerVersions.Select(p => new BotVersionInfo
            {
                Name      = p.Name,
                Version   = p.Version,
                Timestamp = p.Timestamp
            })
                                  .OrderByDescending(x => x.Version)
                                  .ToArray();
            TournamentRanking ranking = null;
            var playerInfo            = new PlayerInfo();
            var lastVersion           = playerVersions.TryGetLastVersion();

            if (lastVersion != null)
            {
                ArenaPlayer arenaPlayer;
                if (version.HasValue)
                {
                    arenaPlayer = playerVersions.FirstOrDefault(p => p.Version == version.Value);
                    if (arenaPlayer != null)
                    {
                        arenaPlayer.Authors = lastVersion.Authors;
                        var tournamentId = "last";
                        if (arenaPlayer.Version != lastVersion.Version)
                        {
                            var nextVersion = playerVersions.First(p => p.Version > version.Value);
                            tournamentId = arenaState.GamesRepo.GetAllTournamentIds()
                                           .Select(id => new DateTime(long.Parse(id), DateTimeKind.Utc))
                                           .OrderBy(ts => ts)
                                           .LastOrDefault(ts => ts < nextVersion.Timestamp)
                                           .Ticks.ToString();
                        }
                        ranking = arenaState.GamesRepo.TryLoadRanking(tournamentId);
                    }
                }
                else
                {
                    arenaPlayer = lastVersion;
                    ranking     = arenaState.GamesRepo.TryLoadRanking("last");
                }
                if (ranking != null)
                {
                    playerInfo = CreatePlayerInfo(arenaPlayer, ranking, botVersionInfos, context.GodMode || arenaState.EnableDeepNavigation);
                }
            }
            context.SendResponse(playerInfo);
        }
Esempio n. 11
0
        public override void Handle([NotNull] GameHttpContext context)
        {
            if (!context.GodMode)
            {
                throw new HttpException(HttpStatusCode.Forbidden, "This operation is only allowed in god mode :-)");
            }

            var playerName = context.GetStringParam("name");

            arenaState.GamesRepo.RemovePlayer(playerName);
            arenaState.PlayersRepo.Remove(playerName);

            context.Redirect(context.BasePath + "ranking.html");
        }
        protected override void DoHandle([NotNull] GameHttpContext context, [NotNull] IDebugger debugger)
        {
            var programStartInfos = context.GetRequest <DebuggerProgramStartInfo[]>();

            try
            {
                debugger.StartNewGame(programStartInfos);
            }
            catch (CompilationException e)
            {
                throw new HttpException(HttpStatusCode.BadRequest, string.Format("В программе есть ошибки:\r\n{0}", e.Message), e);
            }
            context.SendResponse(debugger.State.GameState);
        }
        public override void Handle([NotNull] GameHttpContext context)
        {
            var tournamentId           = context.GetOptionalStringParam("tournamentId");
            var ranking                = arenaState.GamesRepo.TryLoadRanking(tournamentId ?? "last");
            var tournamentHistoryItems = arenaState.GamesRepo.GetAllTournamentIds().Select(id => new TournamentHistoryItem
            {
                TournamentId      = id,
                CreationTimestamp = new DateTime(long.Parse(id), DateTimeKind.Utc),
            }).OrderByDescending(x => x.CreationTimestamp).Take(20).ToArray();
            var response = new ArenaRankingResponse
            {
                Ranking             = ranking,
                HistoryItems        = tournamentHistoryItems,
                TournamentIsRunning = arenaState.TournamentIsRunning,
                GodMode             = context.GodMode,
            };

            context.SendResponse(response);
        }
Esempio n. 14
0
        protected override void DoHandle([NotNull] GameHttpContext context, [NotNull] IDebugger debugger)
        {
            var stepCount      = context.GetOptionalIntParam("count") ?? 1;
            var currentStep    = context.GetOptionalIntParam("currentStep");
            var gameStepResult = debugger.Step(stepCount, currentStep);
            var response       = new DebuggerStepResponse {
                StoppedOnBreakpoint = gameStepResult.StoppedInBreakpoint
            };

            if (gameStepResult.Diff == null || DiffIsTooBig(gameStepResult.Diff))
            {
                response.GameState = debugger.State.GameState;
            }
            else
            {
                response.Diff = gameStepResult.Diff;
            }
            context.SendResponse(response);
        }
        public override void Handle([NotNull] GameHttpContext context)
        {
            if (!arenaState.SubmitIsAllowed)
            {
                throw new HttpException(HttpStatusCode.Forbidden, "Bot submission is disabled");
            }

            var arenaPlayer = context.GetRequest <ArenaPlayer>();

            try
            {
                if (arenaState.PlayersRepo.CreateOrUpdate(arenaPlayer))
                {
                    Log.For(this).Info(string.Format("New bot submitted: {0}", arenaPlayer));
                    tournamentRunner.SignalBotSubmission();
                }
            }
            catch (BadBotException e)
            {
                Log.For(this).Warn(string.Format("Bot submission failed: {0}", arenaPlayer), e);
                throw new HttpException(HttpStatusCode.BadRequest, e.Message, e);
            }
        }
 protected override void DoHandle([NotNull] GameHttpContext context, [NotNull] IDebugger debugger)
 {
     debugger.Reset();
 }
 protected override void DoHandle([NotNull] GameHttpContext context, [NotNull] IDebugger debugger)
 {
     debugger.RemoveBreakpoint(new Breakpoint(context.GetUIntParam("address"), context.GetIntParam("program"), context.GetEnumParam <BreakpointType>("breakpointType")));
 }
Esempio n. 18
0
 protected override void DoHandle([NotNull] GameHttpContext context, [NotNull] IDebugger debugger)
 {
     debugger.ClearBreakpoints();
 }
Esempio n. 19
0
 public override void Handle([NotNull] GameHttpContext context)
 {
     context.Redirect(context.BasePath + "index.html");
 }
Esempio n. 20
0
        public override sealed void Handle([NotNull] GameHttpContext context)
        {
            var debugger = debuggerManager.GetDebugger(context.Session);

            DoHandle(context, debugger);
        }
Esempio n. 21
0
 public bool CanHandle([NotNull] GameHttpContext context)
 {
     return(GameHttpContextExtensions.TryGetContentType(context.Request.Url.AbsolutePath) != null);
 }
Esempio n. 22
0
 protected abstract void DoHandle([NotNull] GameHttpContext context, [NotNull] IDebugger debugger);
Esempio n. 23
0
 public abstract void Handle([NotNull] GameHttpContext context);
 protected override void DoHandle([NotNull] GameHttpContext context, [NotNull] IDebugger debugger)
 {
     context.SendResponse(debugger.State);
 }