public override async Task <GetGameRoomEventsResponse> GetGameRoomEvents(GetGameRoomEventsRequest request, ServerCallContext context) { RedisUserModel user = context.UserState["user"] as RedisUserModel; if (user == null) { return new GetGameRoomEventsResponse() { Status = ResponseFactory.createResponse(ResponseType.UNAUTHORIZED) } } ; RedisRoomModel room = await RedisRoomModel.GetRoomFromGuid(request.RoomId); if (room == null) { return new GetGameRoomEventsResponse() { Status = ResponseFactory.createResponse(ResponseType.ROOM_DOES_NOT_EXIST) } } ; List <RedisUserModel> playersInGame = await room.GetPlayersInGame(); if (playersInGame.All(it => it.UserModel.Id != user.UserModel.Id) && !user.HasClaim(UserClaim.Admin)) { return new GetGameRoomEventsResponse() { Status = ResponseFactory.createResponse(ResponseType.PERMISSION_DENIED) } } ; List <GameEventModel> events = await room.GetAllGameEvents(); // Filter out only the player's events and events that have occurred in the past. // Get current tick to determine events in the past. GameTick currentTick = new GameTick(DateTime.FromFileTimeUtc(room.RoomModel.UnixTimeStarted), DateTime.UtcNow); // Admins see all events :) if (!user.HasClaim(UserClaim.Admin)) { events = events.FindAll(it => it.OccursAtTick <= currentTick.GetTick() || it.IssuedBy == user.UserModel.Id); } GetGameRoomEventsResponse response = new GetGameRoomEventsResponse(); response.GameEvents.AddRange(events); response.Status = ResponseFactory.createResponse(ResponseType.SUCCESS); return(response); }
public void SuperUserAccountHasAdminClaims() { SuperUser superUser = RedisUserModel.CreateSuperUser().Result; // Fetch the user from the database. RedisUserModel user = RedisUserModel.GetUserFromGuid(superUser.userModel.UserModel.Id).Result; // Ensure the user has admin power Assert.IsTrue(user.HasClaim(UserClaim.Admin)); Assert.IsTrue(user.HasClaim(UserClaim.Dev)); Assert.IsTrue(user.HasClaim(UserClaim.EmailVerified)); }