public Task Spawn(Problem problem) { if (Cache.TryGetValue(Key(problem.Id), out ProblemState existing)) { existing.GamespaceReady = true; existing.Status = ProblemStatus.Ready; Task.WaitAll(Handler.Update(existing)); return(Task.FromResult(existing)); } int i = new Random().Next(4, 12); var state = new ProblemState { Id = problem.Id, ChallengeLink = problem.ChallengeLink, TeamId = problem.Team.Id, Status = ProblemStatus.Registered, Start = DateTime.UtcNow, EstimatedReadySeconds = i, Text = $"Preparing...estimated wait time: {i} seconds" }; Task.WaitAll(Handler.Update(state)); Logger.LogDebug("generating flag"); string flag = new Random().Next().ToString("x"); Cache.Set(FlagKey(problem.Id), flag); state.Text = $"> Download Resources: [PDF Instructions](#) | [ISO File](#)\n\n> Gamespace Resources: [windows10](/console/#) | [kali](/console/#)\n\n(flag: `{flag}`, for testing)\n\n## Demo Instructions\n\nIn this challenge you will find the flag using tools and procedures you are most likely familiar with as a cybersecurity operator.\n\n#### Concept\n\nContinue to work through this..."; Cache.Set(Key(problem.Id), state); Logger.LogDebug("updating state"); state.Start = DateTime.UtcNow; state.Status = ProblemStatus.Ready; state.EstimatedReadySeconds = 0; state.HasGamespace = true; state.GamespaceReady = true; Logger.LogDebug("mock delay"); Task.Delay(i * 1000).Wait(); Task.WaitAll(Handler.Update(state)); Logger.LogDebug("done"); return(Task.CompletedTask); }
public static void Log(this ProblemState state, ILogger logger) { logger.LogInformation(EngineEvent.ProblemStarted, "{ProblemId} {ChallengeId} {ChallengeSlug} {TeamId} {Status} {StartedAt} {StoppedAt}", state.Id, state.ChallengeLink.Id, state.ChallengeLink.Slug, state.TeamId, state.Status, state.Start, state.End ); }
//Changes problem's state public void ChangeState() { if (problemState == ProblemState.WORDING) { problemState = ProblemState.ANSWERS; wordingState = TextState.NONE; answersState = TextState.IN; } else { problemState = ProblemState.WORDING; answersState = TextState.NONE; wordingState = TextState.IN; } }
public override bool Equals(object obj) { if (obj == null || obj.GetType() != GetType()) { return(false); } if (ReferenceEquals(this, obj)) { return(true); } ProblemState otherState = (ProblemState)obj; return (Equals(SmallBucket, otherState.SmallBucket) && Equals(BigBucket, otherState.BigBucket)); }
protected override bool Validate(ClientProblem wrapper) { int eta = Stats.ChallengeWaitSeconds(wrapper.Problem.ChallengeLink.Id); var state = new ProblemState { Id = wrapper.Id, ChallengeLink = wrapper.Problem.ChallengeLink, TeamId = wrapper.Problem.Team?.Id, Status = ProblemStatus.Registered, EstimatedReadySeconds = eta, Text = (eta > 0) ? $"Average wait time is {eta} seconds" : "Challenge is initializing..." }; _ = FireCallback(wrapper, state, "updated"); return(true); }
protected override void ProcessItem(ClientProblem wrapper) { var state = new ProblemState(); try { wrapper.LogStart(Logger); state = Service.Spawn(wrapper.Problem); Task.Delay(2000).Wait(); _ = FireCallback(wrapper, state, "updated"); state.Log(Logger); } finally { ActiveIds.Remove(wrapper.Id); } }
public IActionResult Updated([FromBody] ProblemState model) { model.Log(Logger); return(Ok()); }
public async Task Update(ProblemState state) { Logger.LogInformation(JsonConvert.SerializeObject(state)); await Task.Delay(0); }
public ProblemState(ProblemState state) { SmallBucket = state.SmallBucket.Clone(); BigBucket = state.BigBucket.Clone(); }