Package de.pokerth.protocol.ProtoBuf

Examples of de.pokerth.protocol.ProtoBuf.PokerTHMessage


  public void testGameList() throws Exception {

    int myId = guestInit();

    // Waiting for player list update.
    PokerTHMessage msg;
    msg = receiveMessage();
    assertTrue(msg.hasPlayerListMessage());

    // Create a new game.
    Collection<Integer> l = new ArrayList<Integer>();
    NetGameInfo gameInfo = createGameInfo(NetGameType.normalGame, 10, 5, 5, EndRaiseMode.doubleBlinds, 0, 100, GuestUser + " game list normal game", l, 10, 0, 2, 2000);
    sendMessage(createGameRequestMsg(
        gameInfo,
        "",
        false));

    // Game list message is sent before join game ack.
    msg = receiveMessage();
    assertTrue(msg.hasGameListNewMessage());
    GameListNewMessage gameListNewMsg = msg.getGameListNewMessage();
    int gameId = gameListNewMsg.getGameId();
    assertTrue(0 != gameListNewMsg.getGameId());
    checkGameListNewMsg(
        myId,
        gameListNewMsg,
        NetGameMode.netGameCreated,
        gameInfo);
    assertTrue(gameListNewMsg.getPlayerIdsCount() == 0);

    // Next message is join game ack.
    msg = receiveMessage();
    assertTrue(msg.hasJoinGameAckMessage() && msg.getMessageType() == PokerTHMessageType.Type_JoinGameAckMessage);
    // Make sure game list id equals join game ack id.
    assertEquals(gameId, msg.getJoinGameAckMessage().getGameId());

    // Next message is game list player joined.
    msg = receiveMessage();
    assertTrue(msg.hasGameListPlayerJoinedMessage());
    GameListPlayerJoinedMessage gameListJoinedMsg = msg.getGameListPlayerJoinedMessage();
    assertEquals(gameId, gameListJoinedMsg.getGameId());
    assertEquals(myId, gameListJoinedMsg.getPlayerId());

    // Check game list for newly connected players.
    Socket s[] = new Socket[9];
    long playerId[] = new long[9];
    for (int i = 0; i < 9; i++) {
      s[i] = new Socket("localhost", 7234);
      String username = "test" + (i+1);
      String password = username;
      playerId[i] = userInit(s[i], username, password);
      msg = receiveMessage();
      assertTrue(msg.hasPlayerListMessage());

      do {
        msg = receiveMessage(s[i]);
      } while (msg.hasPlayerListMessage());
      assertTrue(msg.hasGameListNewMessage());
      gameListNewMsg = msg.getGameListNewMessage();
      assertEquals(gameId, gameListNewMsg.getGameId());
      assertTrue(0 != gameListNewMsg.getGameId());
      checkGameListNewMsg(
          myId,
          gameListNewMsg,
          NetGameMode.netGameCreated,
          gameInfo);
      assertEquals(1, gameListNewMsg.getPlayerIdsCount());
      assertEquals(myId, gameListNewMsg.getPlayerIds(0));
    }

    // Let 9 players join the game.
    for (int i = 0; i < 9; i++) {
      sendMessage(joinGameRequestMsg(gameId, "", false), s[i]);
      do {
        msg = receiveMessage(s[i]);
      } while (msg.hasPlayerListMessage());
      for (int j = 0; j < i; j++) {
        assertTrue(msg.hasGameListPlayerJoinedMessage());
        gameListJoinedMsg = msg.getGameListPlayerJoinedMessage();
        assertEquals(gameId, gameListJoinedMsg.getGameId());
        assertEquals(playerId[j], gameListJoinedMsg.getPlayerId());
        msg = receiveMessage(s[i]);
      }
      failOnErrorMessage(msg);
      // Next message is join game ack.
      assertTrue(msg.hasJoinGameAckMessage());
      // Make sure game list id equals join game ack id.
      assertEquals(gameId, msg.getJoinGameAckMessage().getGameId());

      // Next message is game list player joined.
      do {
        msg = receiveMessage(s[i]);
      } while (msg.hasGamePlayerJoinedMessage());
      assertTrue(msg.hasGameListPlayerJoinedMessage());
      gameListJoinedMsg = msg.getGameListPlayerJoinedMessage();
      assertEquals(gameId, gameListJoinedMsg.getGameId());
      assertEquals(playerId[i], gameListJoinedMsg.getPlayerId());
    }

    // Wait for game list update which marks start of game.
    do {
      msg = receiveMessage();
      failOnErrorMessage(msg);
    } while (!(msg.hasGameListUpdateMessage()));

    assertEquals(NetGameMode.netGameStarted, msg.getGameListUpdateMessage().getGameMode());

    // Wait for player left messages.
    for (int i = 0; i < 9; i++) {
      s[i].close();
      do {
        msg = receiveMessage();
        failOnErrorMessage(msg);
      } while (!msg.hasGameListPlayerLeftMessage());
      GameListPlayerLeftMessage gameListLeftMsg = msg.getGameListPlayerLeftMessage();
      assertEquals(gameId, gameListLeftMsg.getGameId());
      assertEquals(playerId[i], gameListLeftMsg.getPlayerId());
    }

    // Wait for game list update which marks close of game.
    do {
      msg = receiveMessage();
      failOnErrorMessage(msg);
    } while (!(msg.hasGameListUpdateMessage()));

    assertEquals(NetGameMode.netGameClosed, msg.getGameListUpdateMessage().getGameMode());
  }
View Full Code Here


  @Test
  public void testCreateRankingGameAsGuest() throws Exception {
    guestInit();

    PokerTHMessage msg;
    msg = receiveMessage();
    if (!msg.hasPlayerListMessage()) {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }

    createRankingGame("");
    msg = receiveMessage();

    if (!msg.hasJoinGameFailedMessage())
    {
      failOnErrorMessage(msg);
      fail("Guest user could create ranking game!");
    }
  }
View Full Code Here

  @Test
  public void testCreateRankingGameNoPasswordAsUser() throws Exception {
    userInit();

    // Waiting for player list update.
    PokerTHMessage msg;
    msg = receiveMessage();
    if (!msg.hasPlayerListMessage()) {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }

    createRankingGame("");
    msg = receiveMessage();

    if (msg.hasGameListNewMessage())
    {
      msg = receiveMessage();
      if (msg.hasJoinGameFailedMessage())
      {
        fail("Registered user could not join ranking game!");
      }
    }
    else {
View Full Code Here

  @Test
  public void testCreateRankingGameWithPasswordAsUser() throws Exception {
    userInit();

    // Waiting for player list update.
    PokerTHMessage msg;
    msg = receiveMessage();
    if (!msg.hasPlayerListMessage()) {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }

    createRankingGame(GamePassword);
    msg = receiveMessage();

    if (!msg.hasJoinGameFailedMessage())
    {
      failOnErrorMessage(msg);
      fail("Registered user should not be allowed to create ranking game with password!");
    }
  }
View Full Code Here

        gameInfo,
        "",
        false));

    // Wait for join game ack.
    PokerTHMessage msg;
    do {
      msg = receiveMessage();
      failOnErrorMessage(msg);
    } while (!msg.hasJoinGameAckMessage() && !msg.hasJoinGameFailedMessage());
    if (!msg.hasJoinGameAckMessage()) {
      fail("Could not create game!");
    }
    int gameId = msg.getJoinGameAckMessage().getGameId();

    // Let 9 additional clients join.
    Socket s[] = new Socket[9];
    int playerId[] = new int[9];
    for (int i = 0; i < 9; i++) {
      s[i] = new Socket("localhost", 7234);
      String username = "test" + (i+1);
      String password = username;
      playerId[i] = userInit(s[i], username, password);
      sendMessage(joinGameRequestMsg(gameId, "", false), s[i]);
      do {
        msg = receiveMessage(s[i]);
        failOnErrorMessage(msg);
      } while (!msg.hasJoinGameAckMessage() && !msg.hasJoinGameFailedMessage());
      if (!msg.hasJoinGameAckMessage()) {
        fail("Could not join game!");
      }
    }

    // Server should automatically send start event.
    do {
      msg = receiveMessage();
      failOnErrorMessage(msg);
    } while (!msg.hasStartEventMessage());
    for (int i = 0; i < 9; i++) {
      do {
        msg = receiveMessage(s[i]);
        failOnErrorMessage(msg);
      } while (!msg.hasStartEventMessage());
    }
    // Acknowledge start event.
    StartEventAckMessage startAck = StartEventAckMessage.newBuilder()
        .setGameId(gameId)
        .build();
    msg = PokerTHMessage.newBuilder()
        .setMessageType(PokerTHMessageType.Type_StartEventAckMessage)
        .setStartEventAckMessage(startAck)
        .build();
    sendMessage(msg);
    for (int i = 0; i < 9; i++) {
      sendMessage(msg, s[i]);
    }

    // Wait for game start message.
    do {
      msg = receiveMessage();
      failOnErrorMessage(msg);
    } while (!msg.hasGameStartInitialMessage());
    assertEquals(gameId, msg.getGameStartInitialMessage().getGameId());
    Collection<Integer> seats = msg.getGameStartInitialMessage().getPlayerSeatsList();
    assertEquals(10, seats.size());
    int firstPlayerPos = 0;
    for (Iterator<Integer> it = seats.iterator(); it.hasNext(); ) {
      int seat = it.next();
      if (seat == firstPlayerId)
        break;
      firstPlayerPos++;
    }

    // Wait for first seat state list.
    do {
      msg = receiveMessage();
      failOnErrorMessage(msg);
    } while (!msg.hasHandStartMessage());
    Collection<NetPlayerState> seatStates = msg.getHandStartMessage().getSeatStatesList();

    // Check whether the correct default seat states are sent.
    assertEquals(10, seatStates.size());
    for (Iterator<NetPlayerState> it = seatStates.iterator(); it.hasNext(); ) {
      NetPlayerState state = it.next();
      assertEquals(NetPlayerState.netPlayerStateNormal, state);
    }
    // All other players leave (and are in autofold state then).
    for (int i = 0; i < 9; i++) {
      s[i].close();
    }
    // Wait for next seat state list.
    do {
      msg = receiveMessage();
      failOnErrorMessage(msg);
      assertTrue(!msg.hasEndOfGameMessage());
    } while (!msg.hasHandStartMessage());
    seatStates = msg.getHandStartMessage().getSeatStatesList();

    // Check whether the correct seat states are sent.
    assertEquals(10, seatStates.size());
    int stateNormalCounter = 0;
    int stateInactiveCounter = 0;
View Full Code Here

    sendMessage(createGameRequestMsg(
        gameInfo,
        "",
        false));

    PokerTHMessage msg;
    // Waiting for player list update.
    msg = receiveMessage();
    if (!msg.hasPlayerListMessage()) {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }

    msg = receiveMessage();
    if (!msg.hasGameListNewMessage()) {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }

    msg = receiveMessage();
    if (!msg.hasJoinGameAckMessage()) {
      failOnErrorMessage(msg);
      fail("Could not create game!");
    }
    int gameId = msg.getJoinGameAckMessage().getGameId();

    StartEventMessage startMsg = StartEventMessage.newBuilder()
      .setGameId(gameId)
      .setFillWithComputerPlayers(true)
      .setStartEventType(StartEventType.startEvent)
      .build();
    msg = PokerTHMessage.newBuilder()
      .setMessageType(PokerTHMessageType.Type_StartEventMessage)
      .setStartEventMessage(startMsg)
      .build();
    sendMessage(msg);

    do {
      msg = receiveMessage();
    } while (msg.hasGameListPlayerJoinedMessage() || msg.hasGamePlayerJoinedMessage());

    assertTrue(msg.hasStartEventMessage() && msg.getMessageType() == PokerTHMessageType.Type_StartEventMessage);

    StartEventAckMessage startAck = StartEventAckMessage.newBuilder()
      .setGameId(gameId)
      .build();
    msg = PokerTHMessage.newBuilder()
      .setMessageType(PokerTHMessageType.Type_StartEventAckMessage)
      .setStartEventAckMessage(startAck)
      .build();
    sendMessage(msg);

    do {
      msg = receiveMessage();
    } while (msg.hasGameListUpdateMessage());

    if (!msg.hasGameStartInitialMessage()) {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }
  }
View Full Code Here

    // We need a lot of sockets and player ids.
    Socket s[] = new Socket[NumGames * 10];
    int playerId[] = new int[NumGames * 10];
    int gameId[] = new int[NumGames];

    PokerTHMessage msg;
    // First players are game admins.
    // Create several games.
    for (int i = 0; i < NumGames; i++) {
      s[i * 10] = new Socket("localhost", 7234);
      String username = "test" + (i*10+1);
      String password = username;
      playerId[i * 10] = userInit(s[i * 10], username, password);

      do {
        msg = receiveMessage(s[i * 10]);
      } while (msg.hasGameListNewMessage() || msg.hasGameListPlayerJoinedMessage() || msg.hasGamePlayerJoinedMessage());
      if (!msg.hasPlayerListMessage()) {
        failOnErrorMessage(msg);
        fail("Invalid message.");
      }

      Collection<Integer> l = new ArrayList<Integer>();
      String gameName = AuthUser + " load game " + i;
      NetGameInfo gameInfo = createGameInfo(NetGameType.normalGame, 5, 7, 5, EndRaiseMode.doubleBlinds, 0, 200, gameName, l, 10, 0, 1, 10000);
      sendMessage(createGameRequestMsg(
          gameInfo,
          "",
          false),
          s[i * 10]);

      // Game list update (new game)
      do {
        msg = receiveMessage(s[i * 10]);
        failOnErrorMessage(msg);
      } while (msg.hasGameListNewMessage() || msg.hasGameListPlayerJoinedMessage() || msg.hasPlayerListMessage());

      // Join game ack.
      if (!msg.hasJoinGameAckMessage()) {
        failOnErrorMessage(msg);
        fail("Could not create game!");
      }
      gameId[i] = msg.getJoinGameAckMessage().getGameId();
    }


    // Let additional clients join.
    for (int i = 0; i < NumGames * 10; i++) {
      if (i % 10 == 0) {
        continue;
      }
      s[i] = new Socket("localhost", 7234);
      String username = "test" + (i+1);
      String password = username;
      playerId[i] = userInit(s[i], username, password);
      // Waiting for player list update.
      do {
        msg = receiveMessage(s[i]);
      } while (msg.hasGameListPlayerJoinedMessage() || msg.hasGamePlayerJoinedMessage());
      if (!msg.hasPlayerListMessage()) {
        failOnErrorMessage(msg);
        fail("Invalid message.");
      }
      sendMessage(joinGameRequestMsg(gameId[i/10], "", false), s[i]);
      do {
        msg = receiveMessage(s[i]);
        failOnErrorMessage(msg);
      } while (!msg.hasJoinGameAckMessage() && !msg.hasJoinGameFailedMessage());
      if (!msg.hasJoinGameAckMessage()) {
        fail("User " + username + " could not join normal game.");
      }
    }

    boolean abort = false;
    int handNum[] = new int[NumGames];
    do {
      for (int i = 0; i < NumGames * 10; i++) {
        while (s[i].getInputStream().available() > 0) {
          msg = receiveMessage(s[i]);
          failOnErrorMessage(msg);
          if (msg.hasHandStartMessage()) {
            handNum[i / 10]++;
          }
          else if (msg.hasPlayersTurnMessage()) {
            if (msg.getPlayersTurnMessage().getPlayerId() == playerId[i / 10]) {
              MyActionRequestMessage myRequest = MyActionRequestMessage.newBuilder()
                .setGameId(gameId[i / 10])
                .setGameState(msg.getPlayersTurnMessage().getGameState())
                .setHandNum(handNum[i / 10])
                .setMyAction(NetPlayerAction.netActionAllIn)
                .setMyRelativeBet(0)
                .build();
              PokerTHMessage outMsg = PokerTHMessage.newBuilder()
                  .setMessageType(PokerTHMessageType.Type_MyActionRequestMessage)
                  .setMyActionRequestMessage(myRequest)
                  .build();
              sendMessage(outMsg, s[i]);
            }
View Full Code Here


public class BlockedPlayerTest extends TestBase {

  void verifyLoginBlocked() throws Exception {
    PokerTHMessage msg = receiveMessage(sock);
    AnnounceMessage announce = msg.getAnnounceMessage();
    assertTrue(announce.getServerType() == ServerType.serverTypeInternetAuth);

    ScramSha1 scramAuth = new ScramSha1();

    // Send challenge.
    AnnounceMessage.Version requestedVersion = AnnounceMessage.Version.newBuilder()
        .setMajorVersion(PROTOCOL_VERSION_MAJOR)
        .setMinorVersion(PROTOCOL_VERSION_MINOR)
        .build();
    InitMessage init = InitMessage.newBuilder()
        .setBuildId(0)
        .setLogin(InitMessage.LoginType.authenticatedLogin)
        .setRequestedVersion(requestedVersion)
        .setClientUserData(ByteString.copyFromUtf8(scramAuth.executeStep1("test9999")))
        .build();

    msg = PokerTHMessage.newBuilder()
        .setMessageType(PokerTHMessageType.Type_InitMessage)
        .setInitMessage(init)
        .build();
    sendMessage(msg, sock);

    msg = receiveMessage(sock);
    assertTrue(msg.hasErrorMessage() && msg.getMessageType() == PokerTHMessageType.Type_ErrorMessage);
    assertEquals(ErrorReason.blockedByServer, msg.getErrorMessage().getErrorReason());
  }
View Full Code Here

TOP

Related Classes of de.pokerth.protocol.ProtoBuf.PokerTHMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.