Examples of PokerTHMessage


Examples of de.pokerth.protocol.ProtoBuf.PokerTHMessage

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

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

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

    msg = receiveMessage();
    if (msg.hasJoinGameAckMessage() && msg.getMessageType() == PokerTHMessageType.Type_JoinGameAckMessage)
    {
      assertTrue(msg.getJoinGameAckMessage().getGameId() != 0);
      NetGameInfo receivedGameInfo = msg.getJoinGameAckMessage().getGameInfo();
      assertEquals(receivedGameInfo.getDelayBetweenHands(), gameInfo.getDelayBetweenHands());
      assertEquals(receivedGameInfo.getEndRaiseMode(), gameInfo.getEndRaiseMode());
      assertEquals(receivedGameInfo.getEndRaiseSmallBlindValue(), gameInfo.getEndRaiseSmallBlindValue());
      assertEquals(receivedGameInfo.getFirstSmallBlind(), gameInfo.getFirstSmallBlind());
      assertEquals(receivedGameInfo.getGameName(), gameInfo.getGameName());
View Full Code Here

Examples of de.pokerth.protocol.ProtoBuf.PokerTHMessage

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

    PokerTHMessage msg;

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

    // Game list update (new game)
    msg = receiveMessage();
    if (!msg.hasGameListNewMessage() || msg.getMessageType() != PokerTHMessageType.Type_GameListNewMessage) {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }

    // Join game ack.
    msg = receiveMessage();
    if (!msg.hasJoinGameAckMessage() || msg.getMessageType() != PokerTHMessageType.Type_JoinGameAckMessage) {
      failOnErrorMessage(msg);
      fail("Could not create game!");
    }
    int gameId = msg.getJoinGameAckMessage().getGameId();

    // Game list update (player joined).
    msg = receiveMessage();
    if (!msg.hasGameListPlayerJoinedMessage() || msg.getMessageType() != PokerTHMessageType.Type_GameListPlayerJoinedMessage) {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }

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

    // Now the computer players should join.
    for (int i = 0; i < 9; i++) {
      msg = receiveMessage();
      if (!msg.hasGamePlayerJoinedMessage() || msg.getMessageType() != PokerTHMessageType.Type_GamePlayerJoinedMessage) {
        failOnErrorMessage(msg);
        fail("Invalid message.");
      }
      msg = receiveMessage();
      if (!msg.hasGameListPlayerJoinedMessage() || msg.getMessageType() != PokerTHMessageType.Type_GameListPlayerJoinedMessage) {
        failOnErrorMessage(msg);
        fail("Invalid message.");
      }
    }

    // Server should confirm start event.
    msg = receiveMessage();
    if (!msg.hasStartEventMessage() || msg.getMessageType() != PokerTHMessageType.Type_StartEventMessage) {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }
    // Acknowledge start event.
    StartEventAckMessage startAck = StartEventAckMessage.newBuilder()
      .setGameId(gameId)
      .build();
    msg = PokerTHMessage.newBuilder()
      .setMessageType(PokerTHMessageType.Type_StartEventAckMessage)
      .setStartEventAckMessage(startAck)
      .build();
    sendMessage(msg);

    // Game list update (game now running).
    msg = receiveMessage();
    if (!msg.hasGameListUpdateMessage() || msg.getMessageType() != PokerTHMessageType.Type_GameListUpdateMessage) {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }

    msg = receiveMessage();
    if (!msg.hasGameStartInitialMessage() || msg.getMessageType() != PokerTHMessageType.Type_GameStartInitialMessage) {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }

    long lastPlayerMoney = 0;
    do {
      msg = receiveMessage();
      if (msg.hasEndOfHandHideCardsMessage()) {
        lastPlayerMoney = msg.getEndOfHandHideCardsMessage().getPlayerMoney();
      } else if (msg.hasEndOfHandShowCardsMessage()) {
        Collection<PlayerResult> result = msg.getEndOfHandShowCardsMessage().getPlayerResultsList();
        assertFalse(result.isEmpty());
        long maxPlayerMoney = 0;
        for (Iterator<PlayerResult> it = result.iterator(); it.hasNext(); ) {
          PlayerResult r = it.next();
          int curMoney = r.getPlayerMoney();
          if (curMoney > maxPlayerMoney) {
            maxPlayerMoney = curMoney;
          }
        }
        lastPlayerMoney = maxPlayerMoney;
      }
    } while (
        msg.hasHandStartMessage()
        || msg.hasDealFlopCardsMessage()
        || msg.hasDealRiverCardMessage()
        || msg.hasDealTurnCardMessage()
        || msg.hasPlayersTurnMessage()
        || msg.hasPlayersActionDoneMessage()
        || msg.hasEndOfHandHideCardsMessage()
        || msg.hasEndOfHandShowCardsMessage()
        || msg.hasAllInShowCardsMessage()
        || msg.hasTimeoutWarningMessage()
        );
    if (!msg.hasEndOfGameMessage() || msg.getMessageType() != PokerTHMessageType.Type_EndOfGameMessage) {
      fail("No end of game received.");
    }
    // Last player money should be sum of all money.
    assertEquals(2000 * 10, lastPlayerMoney);

    // Now the computer players should leave.
    for (int i = 0; i < 9; i++) {
      msg = receiveMessage();
      if (!msg.hasGamePlayerLeftMessage()) {
        failOnErrorMessage(msg);
        fail("Invalid message.");
      }
      msg = receiveMessage();
      if (!msg.hasGameListPlayerLeftMessage()) {
        failOnErrorMessage(msg);
        fail("Invalid message.");
      }
    }
  }
View Full Code Here

Examples of de.pokerth.protocol.ProtoBuf.PokerTHMessage

    Guid firstPlayerSession = new Guid();
    int firstPlayerId = userInit(sock, AuthUser, AuthPassword, null, firstPlayerSession);

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

    Collection<Integer> l = new ArrayList<Integer>();
    String gameName = AuthUser + " rejoin game";
    NetGameInfo gameInfo = createGameInfo(NetGameType.normalGame, 5, 7, 5, EndRaiseMode.doubleBlinds, 0, 50, gameName, l, 10, 0, 11, 10000);
    sendMessage(createGameRequestMsg(
        gameInfo,
        "",
        false));

    // Game list update (new game)
    msg = receiveMessage();
    if (!msg.hasGameListNewMessage()) {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }

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

    // Game list update (player joined).
    msg = receiveMessage();
    if (!msg.hasGameListPlayerJoinedMessage()) {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }

    // 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);
      // Waiting for player list update.
      do {
        msg = receiveMessage(s[i]);
      } while (msg.hasGameListNewMessage() || msg.hasGameListPlayerJoinedMessage() || msg.hasGamePlayerJoinedMessage());
      if (!msg.hasPlayerListMessage()) {
        failOnErrorMessage(msg);
        fail("Invalid message.");
      }
      sendMessage(joinGameRequestMsg(gameId, "", false), s[i]);
      do {
        msg = receiveMessage(s[i]);
        failOnErrorMessage(msg);
      } while (!msg.hasJoinGameAckMessage() && !msg.hasJoinGameFailedMessage());
      if (!msg.hasJoinGameAckMessage()) {
        fail("User " + username + " could not join ranking game.");
      }

      // The player should have joined the game.
      msg = receiveMessage();
      if (!msg.hasPlayerListMessage()) {
        failOnErrorMessage(msg);
        fail("Invalid message.");
      }
      msg = receiveMessage();
      if (!msg.hasGamePlayerJoinedMessage()) {
        failOnErrorMessage(msg);
        fail("Invalid message.");
      }
      msg = receiveMessage();
      if (!msg.hasGameListPlayerJoinedMessage()) {
        failOnErrorMessage(msg);
        fail("Invalid message.");
      }
    }

    // Server should automatically send start event.
    msg = receiveMessage();
    if (!msg.hasStartEventMessage()) {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }
    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]);
    }

    // Game list update (game now running).
    msg = receiveMessage();
    if (!msg.hasGameListUpdateMessage()) {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }

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

    // Wait for start of hand.
    do {
      msg = receiveMessage();
      failOnErrorMessage(msg);
      for (int i = 0; i < 9; i++) {
        while (s[i].getInputStream().available() > 0) {
          PokerTHMessage inMsg = receiveMessage(s[i]);
          failOnErrorMessage(inMsg);
        }
      }
    } while (!msg.hasHandStartMessage());
View Full Code Here

Examples of de.pokerth.protocol.ProtoBuf.PokerTHMessage

  public void testPlayerList() throws Exception {

    int myId = guestInit();

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

    // This should be a "player list new" notification with correct player id.
    PlayerListMessage listMsg = msg.getPlayerListMessage();
    assertEquals(myId, listMsg.getPlayerId());
    assertEquals(PlayerListNotification.playerListNew, listMsg.getPlayerListNotification());

    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());
      listMsg = msg.getPlayerListMessage();
      // Id should be different from first id.
      assertTrue(myId != playerId[i]);
      // This should be a "player list new" notification with correct player id.
      assertEquals(playerId[i], listMsg.getPlayerId());
      assertEquals(PlayerListNotification.playerListNew, listMsg.getPlayerListNotification());

      s[i].close();

      // After the connection is closed, a "player list left" notification should be received.
      msg = receiveMessage();
      assertTrue(msg.hasPlayerListMessage());
      listMsg = msg.getPlayerListMessage();
      assertEquals(playerId[i], listMsg.getPlayerId());
      assertEquals(PlayerListNotification.playerListLeft, listMsg.getPlayerListNotification());
    }
  }
View Full Code Here

Examples of de.pokerth.protocol.ProtoBuf.PokerTHMessage

    long countBefore = countBeforeResult.getLong(1);

    userInit();

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

    Collection<Integer> l = new ArrayList<Integer>();
    String gameName = AuthUser + " rejoin game";
    NetGameInfo gameInfo = createGameInfo(NetGameType.rankingGame, 5, 7, 5, EndRaiseMode.doubleBlinds, 0, 50, gameName, l, 10, 0, 11, 10000);
    sendMessage(createGameRequestMsg(
        gameInfo,
        "",
        false));

    // Game list update (new game)
    msg = receiveMessage();
    if (!msg.hasGameListNewMessage()) {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }

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

    // Game list update (player joined).
    msg = receiveMessage();
    if (!msg.hasGameListPlayerJoinedMessage()) {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }

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

      // The player should have joined the game.
      msg = receiveMessage();
      if (!msg.hasPlayerListMessage()) {
        failOnErrorMessage(msg);
        fail("Invalid message.");
      }
      msg = receiveMessage();
      if (!msg.hasGamePlayerJoinedMessage()) {
        failOnErrorMessage(msg);
        fail("Invalid message.");
      }
      msg = receiveMessage();
      if (!msg.hasGameListPlayerJoinedMessage()) {
        failOnErrorMessage(msg);
        fail("Invalid message.");
      }
    }

    // Server should automatically send start event.
    msg = receiveMessage();
    if (!msg.hasStartEventMessage()) {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }
    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]);
    }

    // Game list update (game now running).
    msg = receiveMessage();
    if (!msg.hasGameListUpdateMessage()) {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }

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

    // Wait for start of hand.
    do {
      msg = receiveMessage();
      failOnErrorMessage(msg);
      for (int i = 0; i < 9; i++) {
        while (s[i].getInputStream().available() > 0) {
          PokerTHMessage inMsg = receiveMessage(s[i]);
          failOnErrorMessage(inMsg);
        }
      }
    } while (!msg.hasHandStartMessage());
View Full Code Here

Examples of de.pokerth.protocol.ProtoBuf.PokerTHMessage

  PokerTHMessage createLobbyChatMsg(String chatText) {
    ChatRequestMessage chatLobby = ChatRequestMessage.newBuilder()
      .setChatText(chatText)
      .build();
    PokerTHMessage msg = PokerTHMessage.newBuilder()
        .setMessageType(PokerTHMessageType.Type_ChatRequestMessage)
        .setChatRequestMessage(chatLobby)
        .build();
    return msg;
  }
View Full Code Here

Examples of de.pokerth.protocol.ProtoBuf.PokerTHMessage

  PokerTHMessage createGameChatMsg(String chatText, int gameId) {
    ChatRequestMessage chatGame = ChatRequestMessage.newBuilder()
        .setChatText(chatText)
        .setTargetGameId(gameId)
        .build();
    PokerTHMessage msg = PokerTHMessage.newBuilder()
        .setMessageType(PokerTHMessageType.Type_ChatRequestMessage)
        .setChatRequestMessage(chatGame)
        .build();
    return msg;
  }
View Full Code Here

Examples of de.pokerth.protocol.ProtoBuf.PokerTHMessage

  PokerTHMessage createPrivateChatMsg(String chatText, int playerId) {
    ChatRequestMessage chatPrivate = ChatRequestMessage.newBuilder()
        .setChatText(chatText)
        .setTargetPlayerId(playerId)
        .build();
    PokerTHMessage msg = PokerTHMessage.newBuilder()
        .setMessageType(PokerTHMessageType.Type_ChatRequestMessage)
        .setChatRequestMessage(chatPrivate)
        .build();
    return msg;
  }
View Full Code Here

Examples of de.pokerth.protocol.ProtoBuf.PokerTHMessage

      String username = "test" + (i+1);
      String password = username;
      playerId[i] = userInit(s[i], username, password);
    }

    PokerTHMessage msg = createLobbyChatMsg(ChatText + 1);
    // Message as guest user should be rejected.
    sendMessage(msg);
    do {
      msg = receiveMessage();
    } while (msg.hasPlayerListMessage());
    assertTrue(msg.hasChatRejectMessage());
    assertEquals(ChatText + 1, msg.getChatRejectMessage().getChatText());

    // Message as registered user should be sent to other users and guests.
    msg = createLobbyChatMsg(ChatText + 2);
    sendMessage(msg, s[0]);

    msg = receiveMessage();
    assertTrue(msg.hasChatMessage() && msg.getMessageType() == PokerTHMessageType.Type_ChatMessage);
    assertEquals(ChatText + 2, msg.getChatMessage().getChatText());
    assertEquals(ChatType.chatTypeLobby, msg.getChatMessage().getChatType());
    assertEquals(playerId[0], msg.getChatMessage().getPlayerId());

    for (int i = 0; i < 8; i++) {
      do {
        msg = receiveMessage(s[i]);
      } while (msg.hasPlayerListMessage());
      assertTrue(msg.hasChatMessage() && msg.getMessageType() == PokerTHMessageType.Type_ChatMessage);
      assertEquals(ChatText + 2, msg.getChatMessage().getChatText());
      assertEquals(ChatType.chatTypeLobby, msg.getChatMessage().getChatType());
      assertEquals(playerId[0], msg.getChatMessage().getPlayerId());
    }

    // A game chat message, if not within a game, should be rejected.
    msg = createGameChatMsg(ChatText + 3, 1);
    sendMessage(msg);

    msg = receiveMessage();
    assertTrue(msg.hasChatRejectMessage() && msg.getMessageType() == PokerTHMessageType.Type_ChatRejectMessage);
    assertEquals(ChatText + 3, msg.getChatRejectMessage().getChatText());

    msg = createGameChatMsg(ChatText + 4, 1);
    sendMessage(msg, s[0]);

    msg = receiveMessage(s[0]);
    assertTrue(msg.hasChatRejectMessage() && msg.getMessageType() == PokerTHMessageType.Type_ChatRejectMessage);
    assertEquals(ChatText + 4, msg.getChatRejectMessage().getChatText());

    // Guests are not allowed to send private messages in the lobby.
    msg = createPrivateChatMsg(ChatText + 5, playerId[1]);
    sendMessage(msg);

    msg = receiveMessage();
    assertTrue(msg.hasChatRejectMessage() && msg.getMessageType() == PokerTHMessageType.Type_ChatRejectMessage);
    assertEquals(ChatText + 5, msg.getChatRejectMessage().getChatText());

    // Registered users are allowed to send private messages in the lobby.
    msg = createPrivateChatMsg(ChatText + 6, playerId[1]);
    sendMessage(msg, s[0]);

    msg = receiveMessage(s[1]);
    assertTrue(msg.hasChatMessage() && msg.getMessageType() == PokerTHMessageType.Type_ChatMessage);
    assertEquals(ChatText + 6, msg.getChatMessage().getChatText());
    assertEquals(ChatType.chatTypePrivate, msg.getChatMessage().getChatType());
    assertEquals(playerId[0], msg.getChatMessage().getPlayerId());

    // Game messages can be sent by registered users within a 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));
    do {
      msg = receiveMessage();
      failOnErrorMessage(msg);
    } while (!msg.hasJoinGameAckMessage() && !msg.hasJoinGameFailedMessage());
    assertTrue(msg.hasJoinGameAckMessage() && msg.getMessageType() == PokerTHMessageType.Type_JoinGameAckMessage);
    int gameId = msg.getJoinGameAckMessage().getGameId();

    // Let 8 players join the game, and test game chat.
    for (int i = 0; i < 8; i++) {
      sendMessage(joinGameRequestMsg(gameId, "", false), s[i]);
      do {
        msg = receiveMessage(s[i]);
        failOnErrorMessage(msg);
      } while (!msg.hasJoinGameAckMessage() && !msg.hasJoinGameFailedMessage());
      assertTrue(msg.hasJoinGameAckMessage() && msg.getMessageType() == PokerTHMessageType.Type_JoinGameAckMessage);
    }

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

    // Server should confirm start event.
    do {
      msg = receiveMessage();
      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 < 8; i++) {
      sendMessage(msg, s[i]);
    }

    // Server should game start.
    do {
      msg = receiveMessage();
      failOnErrorMessage(msg);
    } while (!msg.hasGameStartInitialMessage());


    // Guest user: not allowed.
    msg = createGameChatMsg(ChatText + 7, gameId);
    sendMessage(msg);
    do {
      msg = receiveMessage();
      failOnErrorMessage(msg);
      assertFalse(msg.hasChatMessage());
    } while (!msg.hasChatRejectMessage());
    assertEquals(ChatText + 7, msg.getChatRejectMessage().getChatText());

    // Other users: allowed.
    for (int c = 0; c < 8; c++) {
      msg = createGameChatMsg(ChatText + "c" + c, gameId);
      sendMessage(msg, s[c]);
      do {
        msg = receiveMessage(s[c]);
        failOnErrorMessage(msg);
        assertFalse(msg.hasChatRejectMessage() || msg.getMessageType() == PokerTHMessageType.Type_ChatRejectMessage);
      } while (!msg.hasChatMessage());
 
      assertEquals(ChatText + "c" + c, msg.getChatMessage().getChatText());
      assertEquals(ChatType.chatTypeGame, msg.getChatMessage().getChatType());
      assertEquals(playerId[c], msg.getChatMessage().getPlayerId());
      assertEquals(gameId, msg.getChatMessage().getGameId());

      for (int i = 0; i < 8; i++) {
        if (i != c) {
          do {
            msg = receiveMessage(s[i]);
            failOnErrorMessage(msg);
            assertFalse(msg.hasChatRejectMessage() || msg.getMessageType() == PokerTHMessageType.Type_ChatRejectMessage);
          } while (!msg.hasChatMessage());
          assertEquals(ChatText + "c" + c, msg.getChatMessage().getChatText());
          assertEquals(ChatType.chatTypeGame, msg.getChatMessage().getChatType());
          assertEquals(playerId[c], msg.getChatMessage().getPlayerId());
          assertEquals(gameId, msg.getChatMessage().getGameId());
        }
      }
    }

    // Private chat message should now be rejected.
    msg = createPrivateChatMsg(ChatText + 8, playerId[1]);
    sendMessage(msg, s[0]);
    do {
      msg = receiveMessage(s[0]);
      failOnErrorMessage(msg);
      assertFalse(msg.hasChatMessage() || msg.getMessageType() == PokerTHMessageType.Type_ChatMessage);
    } while (!msg.hasChatRejectMessage());

    for (int i = 0; i < 8; i++) {
      s[i].close();
    }
  }
View Full Code Here

Examples of de.pokerth.protocol.ProtoBuf.PokerTHMessage

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

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

    SubscriptionRequestMessage subscriptionRequest = SubscriptionRequestMessage.newBuilder()
      .setSubscriptionAction(SubscriptionAction.unsubscribeGameList)
      .build();
    msg = PokerTHMessage.newBuilder()
        .setMessageType(PokerTHMessageType.Type_SubscriptionRequestMessage)
        .setSubscriptionRequestMessage(subscriptionRequest)
        .build();
    sendMessage(msg);

    // 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));

    // No game list message should be sent by the server.
    // Next message is join game ack.
    msg = receiveMessage();
    assertTrue(msg.hasJoinGameAckMessage());
    int gameId = msg.getJoinGameAckMessage().getGameId();

    Socket s[] = new Socket[9];
    for (int i = 0; i < 9; i++) {
      s[i] = new Socket("localhost", 7234);
      String username = "test" + (i+1);
      String password = username;
      userInit(s[i], username, password);
      sendMessage(joinGameRequestMsg(gameId, "", false), s[i]);
    }

    // No game list message should be received.
    do {
      msg = receiveMessage();
      if (msg.hasGameListNewMessage() || msg.hasPlayerListMessage()) {
        fail("Game/player list messages are switched off!");
      }
    } while (!msg.hasStartEventMessage());

    // Resubscribe game list
    subscriptionRequest = SubscriptionRequestMessage.newBuilder()
        .setSubscriptionAction(SubscriptionAction.resubscribeGameList)
        .build();
    msg = PokerTHMessage.newBuilder()
        .setMessageType(PokerTHMessageType.Type_SubscriptionRequestMessage)
        .setSubscriptionRequestMessage(subscriptionRequest)
        .build();
    sendMessage(msg);

    // Next messages should player list messages for all 10 players.
    for (int i = 0; i < 10; i++) {
      msg = receiveMessage();
      assertTrue(msg.hasPlayerListMessage());
    }
    // Now there should be one game list message.
    msg = receiveMessage();
    assertTrue(msg.hasGameListNewMessage());

    for (int i = 0; i < 9; i++) {
      s[i].close();
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.