public override Task <GameStartInformation> Initialize(PlayerInformation request, ServerCallContext context) { _logger.Info($"Client {request.Name} requested initialize."); bool connectionTest = request.Name.Contains("test"); GameStartInformation response; if (Player1 == null) { // First connection if (connectionTest) { Player1 = MockPlayer; } else { Player1 = new PlayerClass() { Information = request } }; response = new GameStartInformation() { WhitePlayer = true }; } else if (Player2 == null) { if (connectionTest) { Player2 = MockPlayer; } else { Player2 = new PlayerClass() { Information = request } }; response = new GameStartInformation() { WhitePlayer = false, OpponentMove = Player1.LatestMove.Move }; } else { throw new ArgumentException("Error: Can't have 3 clients playing."); } return(Task.FromResult(response)); }
public override Task <GameStartInformation> Initialize(GameInformation request, ServerCallContext context) { _logger.Info($"Client {request.Name} requested initialize."); GameStartInformation response; if (Player1 == null) { // First connection Player1 = new PlayerClient() { PlayerIndex = 0, RequestStream = null, ResponseStream = null, PeerName = context.Peer, Information = request }; response = new GameStartInformation() { Start = true }; } else if (Player2 == null) { Player2 = new PlayerClient() { PlayerIndex = 1, RequestStream = null, ResponseStream = null, PeerName = context.Peer, Information = request }; // TODO logic to wait p1 first move response = new GameStartInformation() { Start = false, ChessMove = Player1.LatestMove }; } else { throw new ArgumentException("Error: Can't have 3 clients playing."); } return(Task.FromResult(response)); }