//The below methods contain the actual client-server message-passing code. //The program flow is written to line up with the messaging code in GameMode_Networked.cs. private void SocketHandler_FindGame(Messages.FindGame msg, NetworkStream stream, BinaryReader streamReader, BinaryWriter streamWriter) { ulong playerID = nextPlayerID; nextPlayerID = unchecked (nextPlayerID + 1); var successMsg = new Messages.SuccessfullyInQueue(playerID); if (Try(() => Messages.Base.Write(successMsg, streamWriter), "Sending 'success' msg")) { playerMatcher.Push(new PlayerMatcher.Player(msg.ClientName, playerID, msg.GameID)); } }
public static Base Read(BinaryReader reader) { Base b = null; var type = (Types)reader.ReadByte(); switch (type) { case Types.Error: b = new Error(null); break; case Types.Acknowledge: b = new Acknowledge(); break; case Types.FindGame: b = new FindGame(null, 0); break; case Types.SuccessfullyInQueue: b = new SuccessfullyInQueue(0); break; case Types.CheckOpponentFound: b = new CheckOpponentFound(0); break; case Types.FoundOpponent: b = new FoundOpponent(null, 0, false); break; case Types.NewBoard: b = new NewBoard(null, MatchStates.Tie); break; case Types.GetGameState: b = new GetGameState(0, 0); break; case Types.GameState: b = new GameState(null, null, MatchStates.Tie, 0, 0); break; case Types.MakeMove: b = new MakeMove(0, null, null, MatchStates.Tie); break; case Types.ForfeitGame: b = new ForfeitGame(0); break; default: throw new NotImplementedException(type.ToString()); } b.Deserialize(reader); return(b); }