private void HandleMessage(string message) { try { lock (MessageTasks) { ErrorResponse errorResponse = JsonConvert.DeserializeObject <ErrorResponse>(message); if (errorResponse.IsValid()) { Debug.Log("ErrorResponse: " + errorResponse.ErrorMessage); return; } DisconnectMessage disconnectMessage = JsonConvert.DeserializeObject <DisconnectMessage>(message); if (disconnectMessage.IsValid()) { HandleDisconnect(disconnectMessage); return; } RestartMessage restartMessage = JsonConvert.DeserializeObject <RestartMessage>(message); if (restartMessage.IsValid()) { HandleRestart(restartMessage); return; } GameTypeMessage gameTypeMessage = JsonConvert.DeserializeObject <GameTypeMessage>(message); if (gameTypeMessage.IsValid()) { ViewController.Instance.UpdateGameTypes(gameTypeMessage.GameTypes); return; } JoinResponse joinResponse = JsonConvert.DeserializeObject <JoinResponse>(message); if (joinResponse.IsValid()) { HandleJoinResponse(joinResponse); return; } AvailableGamesMessage gamesMessage = JsonConvert.DeserializeObject <AvailableGamesMessage>(message); if (gamesMessage.IsValid()) { ViewController.Instance.UpdateAvailableGames(gamesMessage.AvailableGames); return; } JoinMessage joinMessage = JsonConvert.DeserializeObject <JoinMessage>(message); if (joinMessage.IsValid()) { HandleJoin(joinMessage); return; } StartMessage startMessage = JsonConvert.DeserializeObject <StartMessage>(message); if (startMessage.IsValid()) { HandleStart(startMessage); return; } BidMessage bidMessage = JsonConvert.DeserializeObject <BidMessage>(message); if (bidMessage.IsValid()) { HandleBid(bidMessage); return; } KittyMessage kittyMessage = JsonConvert.DeserializeObject <KittyMessage>(message); if (kittyMessage.IsValid()) { HandleKitty(kittyMessage); return; } TrumpMessage trumpMessage = JsonConvert.DeserializeObject <TrumpMessage>(message); if (trumpMessage.IsValid()) { HandleTrump(trumpMessage); return; } MeldPointsMessage meldPointsMessage = JsonConvert.DeserializeObject <MeldPointsMessage>(message); if (meldPointsMessage.IsValid()) { HandleMeldPoints(meldPointsMessage); return; } MeldMessage meldMessage = JsonConvert.DeserializeObject <MeldMessage>(message); if (meldMessage.IsValid()) { HandleMeld(meldMessage); return; } PassMessage passMessage = JsonConvert.DeserializeObject <PassMessage>(message); if (passMessage.IsValid()) { HandlePass(passMessage); return; } ScoreMessage scoreMessage = JsonConvert.DeserializeObject <ScoreMessage>(message); if (scoreMessage.IsValid()) { HandleScore(scoreMessage); return; } TurnMessage turnMessage = JsonConvert.DeserializeObject <TurnMessage>(message); if (turnMessage.IsValid()) { HandleTurn(turnMessage); return; } TrickMessage trickMessage = JsonConvert.DeserializeObject <TrickMessage>(message); if (trickMessage.IsValid()) { HandleTrick(trickMessage); return; } TrickInfoMessage trickInfoMessage = JsonConvert.DeserializeObject <TrickInfoMessage>(message); if (trickInfoMessage.IsValid()) { HandleTrickInfo(trickInfoMessage); return; } GameOverMessage gameOverMessage = JsonConvert.DeserializeObject <GameOverMessage>(message); if (gameOverMessage.IsValid()) { HandleGameOver(gameOverMessage); return; } } } catch (Exception err) { Debug.Log("OnMessage error: " + err.Message); Debug.Log("OnMessage stack trace: " + err.StackTrace); } }
private MessagePackets HandleMessage(string message) { RestartMessage restartMessage = JsonConvert.DeserializeObject <RestartMessage>(message); if (restartMessage.IsValid()) { return(GamesManager.Get().HandleRestart(ID, restartMessage)); } GameTypeMessage gameTypeMessage = JsonConvert.DeserializeObject <GameTypeMessage>(message); if (gameTypeMessage.IsValid()) { return(GamesManager.Get().HandleGameTypes(ID, gameTypeMessage)); } JoinMessage joinMessage = JsonConvert.DeserializeObject <JoinMessage>(message); if (joinMessage.IsValid()) { return(GamesManager.Get().HandleJoin(ID, joinMessage)); } BidMessage bidMessage = JsonConvert.DeserializeObject <BidMessage>(message); if (bidMessage.IsValid()) { return(GamesManager.Get().HandleBid(ID, bidMessage)); } KittyMessage kittyMessage = JsonConvert.DeserializeObject <KittyMessage>(message); if (kittyMessage.IsValid()) { return(GamesManager.Get().HandleKitty(ID, kittyMessage)); } TrumpMessage trumpMessage = JsonConvert.DeserializeObject <TrumpMessage>(message); if (trumpMessage.IsValid()) { return(GamesManager.Get().HandleTrump(ID, trumpMessage)); } MeldMessage meldMessage = JsonConvert.DeserializeObject <MeldMessage>(message); if (meldMessage.IsValid()) { return(GamesManager.Get().HandleMeld(ID, meldMessage)); } PassMessage passMessage = JsonConvert.DeserializeObject <PassMessage>(message); if (passMessage.IsValid()) { return(GamesManager.Get().HandlePass(ID, passMessage)); } TurnMessage turnMessage = JsonConvert.DeserializeObject <TurnMessage>(message); if (turnMessage.IsValid()) { return(GamesManager.Get().HandleTurn(ID, turnMessage)); } return(new MessagePackets()); }