static void TestRequestSerialization() { NetCom.ChallengeRequest request = new NetCom.ChallengeRequest(); request.OpponentName = "TestMe"; request.PlayerName = "TestYou"; string jsonRequest = JsonSerializer.SerializeToJSON(request); Console.WriteLine("Serialized Request: {0}", jsonRequest); NetCom.ChallengeRequest deserializedRequest = JsonSerializer.DeseriaizeFromJSON<NetCom.ChallengeRequest>(jsonRequest); Console.WriteLine("PlayerName: {0}", deserializedRequest.PlayerName); Console.WriteLine("OpponentName: {0}", deserializedRequest.OpponentName); Console.ReadKey(); }
void ICommunicationChannel.ChallengePlayer(int matchId) { using (IGameDataService dataService = new GameDataService()) { //We need to create a session even if the challenge isn't accepted. Match match = dataService.GetMatch(matchId, null); dataService.CreateCentralServerSession(match.CurrentGameId.Value); Player player = dataService.GetPlayer(match.PlayerOneId); Player opponent = dataService.GetPlayer(match.PlayerTwoId); Game game = dataService.GetGame(match.CurrentGameId.Value); var requestData = new ChallengeRequest(); requestData.PlayerName = player.PlayerName; requestData.OpponentName = opponent.PlayerName; string requestJSON = JsonSerializer.SerializeToJSON<ChallengeRequest>(requestData); var requestConfig = new ServerRequestConfig(); requestConfig.Url = string.Format("{0}/ServerPairing.php", ConfigurationManager.AppSettings["CentralServerUrl"]); requestConfig.RequestData = requestJSON; requestConfig.GameId = game.GameId; requestConfig.MatchId = game.MatchId; requestConfig.ResponseAction = new Action<string, int>(ChallengePlayerCompleted); this.PerformServerRequest(requestConfig); } }