public override async Task SendMatchRequest(MatchUserRequest request) { Debug.Assert(Room != null); Debug.Assert(LocalUser != null); switch (request) { case StartMatchCountdownRequest matchCountdownRequest: startCountdown(new MatchStartCountdown { TimeRemaining = matchCountdownRequest.Duration }, StartMatch); break; case StopCountdownRequest _: stopCountdown(); break; case ChangeTeamRequest changeTeam: TeamVersusRoomState roomState = (TeamVersusRoomState)Room.MatchState !; TeamVersusUserState userState = (TeamVersusUserState)LocalUser.MatchState !; var targetTeam = roomState.Teams.FirstOrDefault(t => t.ID == changeTeam.TeamID); if (targetTeam != null) { userState.TeamID = targetTeam.ID; await((IMultiplayerClient)this).MatchUserStateChanged(LocalUser.UserID, userState).ConfigureAwait(false); } break; } }
public void TestSerialiseUserStateExpected() { var state = new TeamVersusUserState(); byte[] serialized = MessagePackSerializer.Serialize(typeof(MatchUserState), state); var deserialized = MessagePackSerializer.Deserialize <MatchUserState>(serialized); Assert.IsTrue(deserialized is TeamVersusUserState); }
public void TestSerialiseUnionFailsWithSingalR() { var state = new TeamVersusUserState(); // SignalR serialises using the actual type, rather than a base specification. byte[] serialized = MessagePackSerializer.Serialize(typeof(TeamVersusUserState), state); // works with explicit type specified. MessagePackSerializer.Deserialize <TeamVersusUserState>(serialized); // fails with base (union) type. Assert.Throws <MessagePackSerializationException>(() => MessagePackSerializer.Deserialize <MatchUserState>(serialized)); }
public void TestSerialiseUnionSucceedsWithWorkaround() { var state = new TeamVersusUserState(); // SignalR serialises using the actual type, rather than a base specification. byte[] serialized = MessagePackSerializer.Serialize(typeof(TeamVersusUserState), state, SignalRUnionWorkaroundResolver.OPTIONS); // works with explicit type specified. MessagePackSerializer.Deserialize <TeamVersusUserState>(serialized); // works with custom resolver. var deserialized = MessagePackSerializer.Deserialize <MatchUserState>(serialized, SignalRUnionWorkaroundResolver.OPTIONS); Assert.IsTrue(deserialized is TeamVersusUserState); }
public override async Task SendMatchRequest(MatchUserRequest request) { Debug.Assert(Room != null); Debug.Assert(LocalUser != null); switch (request) { case ChangeTeamRequest changeTeam: TeamVersusRoomState roomState = (TeamVersusRoomState)Room.MatchState !; TeamVersusUserState userState = (TeamVersusUserState)LocalUser.MatchState !; var targetTeam = roomState.Teams.FirstOrDefault(t => t.ID == changeTeam.TeamID); if (targetTeam != null) { userState.TeamID = targetTeam.ID; await((IMultiplayerClient)this).MatchUserStateChanged(LocalUser.UserID, userState).ConfigureAwait(false); } break; } }