Skip to content

Commit

Permalink
Merge pull request #68 from cmu-sei/next
Browse files Browse the repository at this point in the history
3.6.4
  • Loading branch information
sei-mkaar authored Nov 14, 2022
2 parents 372e8ed + 41be6ee commit 8d8813b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
19 changes: 7 additions & 12 deletions src/Gameboard.Api/Features/UnityGames/UnityGameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public async Task<IActionResult> GetGamespace([FromRoute] string gid, [FromRoute
public async Task<string> DeployUnitySpace([FromRoute] string gid, [FromRoute] string tid)
{
AuthorizeAny(
() => Actor.IsDirector,
() => _gameService.UserIsTeamPlayer(Actor.Id, gid, tid).Result
);

Expand All @@ -103,6 +102,7 @@ public async Task<string> UndeployUnitySpace([FromQuery] string gid, [FromRoute]
{
AuthorizeAny(
() => Actor.IsAdmin,
() => Actor.IsSupport,
() => _gameService.UserIsTeamPlayer(Actor.Id, gid, tid).Result
);

Expand Down Expand Up @@ -153,13 +153,11 @@ public async Task<string> UndeployUnitySpace([FromQuery] string gid, [FromRoute]
{
Console.Write("Calling gamebrain failed with", ex);
}
finally
{
// notify the hub (if there is one)
await _hub.Clients
.Group(model.TeamId)
.ChallengeEvent(new HubEvent<Challenge>(_mapper.Map<Challenge>(result), EventAction.Updated));
}

// notify the hub (if there is one)
await _hub.Clients
.Group(model.TeamId)
.ChallengeEvent(new HubEvent<Challenge>(_mapper.Map<Challenge>(result), EventAction.Updated));

return result;
}
Expand Down Expand Up @@ -188,13 +186,10 @@ await _hub.Clients
public async Task CreateMissionEvent([FromBody] UnityMissionUpdate model)
{
AuthorizeAny(
() => Actor.IsDirector,
() => Actor.IsAdmin,
() => Actor.IsDesigner
() => Actor.IsAdmin
);

await Validate(model);

await _unityGameService.CreateMissionEvent(model, Actor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class TeamHasNoPlayersException : Exception { }

internal class ChallengeResolutionFailure : GameboardException
{
public ChallengeResolutionFailure(string teamId) : base($"Couldn't resolve the challenge for team ${teamId}.") { }
public ChallengeResolutionFailure(string teamId) : base($"Couldn't resolve a Unity challenge for team {teamId}") { }
}

internal class SemaphoreLockFailure : GameboardException
Expand Down
31 changes: 18 additions & 13 deletions src/Gameboard.Api/Features/UnityGames/UnityGameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,30 +194,35 @@ public async Task DeleteChallengeData(string gameId)

public async Task CreateMissionEvent(UnityMissionUpdate model, Api.User actor)
{
var player = await Store.DbContext
.Players
.Include(p => p.Challenges)
// TODO: need to think about how we ensure, across this service, that
// we're loading the unity game (or the right one when we get more than one)
.Include(p => p.Game)
.FirstOrDefaultAsync(p => p.Game.Mode == "unity" && p.TeamId == model.TeamId);
var challenge = await Store.DbContext
.Challenges
.Include(c => c.Game)
.Include(c => c.Events)
.Include(c => c.Player)
.Where(c => c.TeamId == model.TeamId && c.Game.Mode.ToLower() == "unity")
.FirstOrDefaultAsync();

if (player.Challenges.Count() != 1)
if (challenge == null)
{
throw new ChallengeResolutionFailure(model.TeamId);
}

var challengeEvent = new Data.ChallengeEvent()
// record an event for this challenge
challenge.Events.Add(new Data.ChallengeEvent
{
ChallengeId = player.Challenges.First().Id,
Id = Guid.NewGuid().ToString("n"),
ChallengeId = challenge.Id,
UserId = actor.Id,
TeamId = model.TeamId,
Text = $"{player.ApprovedName} has found the codex for {model.MissionName}!",
Text = $"{challenge.Player} has found the codex for {model.MissionName}!",
Type = ChallengeEventType.Submission,
Timestamp = DateTimeOffset.UtcNow
};
});

// also update the score of the challenge
challenge.Score += model.PointsScored;

await Store.DbContext.ChallengeEvents.AddAsync(challengeEvent);
// save it up
await Store.DbContext.SaveChangesAsync();
}

Expand Down

0 comments on commit 8d8813b

Please sign in to comment.