Exemplo n.º 1
0
  public PokerTHMessage rejoinGameRequestMsg(int gameId, boolean autoLeave) {
    RejoinGameMessage rejoinRequest =
        RejoinGameMessage.newBuilder().setGameId(gameId).setAutoLeave(autoLeave).build();

    LobbyMessage lobby =
        LobbyMessage.newBuilder()
            .setMessageType(LobbyMessageType.Type_RejoinGameMessage)
            .setRejoinGameMessage(rejoinRequest)
            .build();

    PokerTHMessage msg =
        PokerTHMessage.newBuilder()
            .setMessageType(PokerTHMessageType.Type_LobbyMessage)
            .setLobbyMessage(lobby)
            .build();
    return msg;
  }
Exemplo n.º 2
0
  public int guestInit(Socket s) throws Exception {
    int playerId = 0;
    PokerTHMessage msg = receiveMessage(s);
    assertTrue(msg.hasAnnounceMessage());

    AnnounceMessage.Version requestedVersion =
        AnnounceMessage.Version.newBuilder()
            .setMajorVersion(PROTOCOL_VERSION_MAJOR)
            .setMinorVersion(PROTOCOL_VERSION_MINOR)
            .build();
    AuthClientRequestMessage init =
        AuthClientRequestMessage.newBuilder()
            .setBuildId(0)
            .setLogin(AuthClientRequestMessage.LoginType.guestLogin)
            .setRequestedVersion(requestedVersion)
            .setNickName(GuestUser)
            .build();
    AuthMessage auth =
        AuthMessage.newBuilder()
            .setMessageType(AuthMessageType.Type_AuthClientRequestMessage)
            .setAuthClientRequestMessage(init)
            .build();
    msg =
        PokerTHMessage.newBuilder()
            .setMessageType(PokerTHMessageType.Type_AuthMessage)
            .setAuthMessage(auth)
            .build();
    sendMessage(msg, s);

    msg = receiveMessage(s);
    if (msg.hasLobbyMessage()
        && msg.getMessageType() == PokerTHMessageType.Type_LobbyMessage
        && msg.getLobbyMessage().hasInitDoneMessage()
        && msg.getLobbyMessage().getMessageType() == LobbyMessageType.Type_InitDoneMessage) {
      InitDoneMessage initDone = msg.getLobbyMessage().getInitDoneMessage();
      assertTrue(initDone.getYourPlayerId() != 0L);
      assertTrue(!initDone.hasYourAvatarHash());
      playerId = initDone.getYourPlayerId();
    } else {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }
    return playerId;
  }
Exemplo n.º 3
0
  public PokerTHMessage leaveGameRequestMsg(int gameId) {
    LeaveGameRequestMessage leaveRequest = LeaveGameRequestMessage.newBuilder().build();
    GameManagementMessage gameManagement =
        GameManagementMessage.newBuilder()
            .setMessageType(GameManagementMessageType.Type_LeaveGameRequestMessage)
            .setLeaveGameRequestMessage(leaveRequest)
            .build();
    GameMessage game =
        GameMessage.newBuilder()
            .setMessageType(GameMessageType.Type_GameManagementMessage)
            .setGameManagementMessage(gameManagement)
            .setGameId(gameId)
            .build();

    PokerTHMessage msg =
        PokerTHMessage.newBuilder()
            .setMessageType(PokerTHMessageType.Type_GameMessage)
            .setGameMessage(game)
            .build();
    return msg;
  }
Exemplo n.º 4
0
  public PokerTHMessage joinGameRequestMsg(
      int gameId, String password, boolean autoLeave, boolean spectateOnly) {
    JoinGameMessage.Builder joinBuilder = JoinGameMessage.newBuilder();
    joinBuilder.setGameId(gameId);
    joinBuilder.setAutoLeave(autoLeave);
    joinBuilder.setSpectateOnly(spectateOnly);
    if (!password.isEmpty()) {
      joinBuilder.setPassword(password);
    }
    JoinGameMessage joinExisting = joinBuilder.build();

    LobbyMessage lobby =
        LobbyMessage.newBuilder()
            .setMessageType(LobbyMessageType.Type_JoinGameMessage)
            .setJoinGameMessage(joinExisting)
            .build();

    PokerTHMessage msg =
        PokerTHMessage.newBuilder()
            .setMessageType(PokerTHMessageType.Type_LobbyMessage)
            .setLobbyMessage(lobby)
            .build();
    return msg;
  }
Exemplo n.º 5
0
  public PokerTHMessage createGameRequestMsg(
      NetGameInfo gameInfo, String password, boolean autoLeave) {
    CreateGameMessage.Builder createBuilder = CreateGameMessage.newBuilder();
    createBuilder.setRequestId(1);
    createBuilder.setGameInfo(gameInfo);
    createBuilder.setAutoLeave(autoLeave);
    if (!password.isEmpty()) {
      createBuilder.setPassword(password);
    }
    CreateGameMessage createNew = createBuilder.build();

    LobbyMessage lobby =
        LobbyMessage.newBuilder()
            .setMessageType(LobbyMessageType.Type_CreateGameMessage)
            .setCreateGameMessage(createNew)
            .build();

    PokerTHMessage msg =
        PokerTHMessage.newBuilder()
            .setMessageType(PokerTHMessageType.Type_LobbyMessage)
            .setLobbyMessage(lobby)
            .build();
    return msg;
  }
Exemplo n.º 6
0
  public int userInit(Socket s, String user, String password, byte[] avatarData, Guid lastSessionId)
      throws Exception {
    int playerId = 0;
    PokerTHMessage msg = receiveMessage(s);
    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();
    AuthClientRequestMessage.Builder initBuilder =
        AuthClientRequestMessage.newBuilder()
            .setBuildId(0)
            .setLogin(AuthClientRequestMessage.LoginType.authenticatedLogin)
            .setRequestedVersion(requestedVersion)
            .setClientUserData(ByteString.copyFromUtf8(scramAuth.executeStep1(user)));
    if (avatarData != null) {
      initBuilder.setAvatarHash(ByteString.copyFrom(avatarData));
    }
    if (lastSessionId != null && lastSessionId.value != null) {
      initBuilder.setMyLastSessionId(ByteString.copyFrom(lastSessionId.value));
    }
    AuthClientRequestMessage init = initBuilder.build();

    AuthMessage authRequest =
        AuthMessage.newBuilder()
            .setMessageType(AuthMessageType.Type_AuthClientRequestMessage)
            .setAuthClientRequestMessage(init)
            .build();
    msg =
        PokerTHMessage.newBuilder()
            .setMessageType(PokerTHMessageType.Type_AuthMessage)
            .setAuthMessage(authRequest)
            .build();
    sendMessage(msg, s);

    msg = receiveMessage(s);

    if (msg.hasAuthMessage()
        && msg.getMessageType() == PokerTHMessageType.Type_AuthMessage
        && msg.getAuthMessage().hasAuthServerChallengeMessage()
        && msg.getAuthMessage().getMessageType()
            == AuthMessageType.Type_AuthServerChallengeMessage) {
      String serverFirstMessage =
          new String(
              msg.getAuthMessage()
                  .getAuthServerChallengeMessage()
                  .getServerChallenge()
                  .toStringUtf8());
      AuthClientResponseMessage authClient =
          AuthClientResponseMessage.newBuilder()
              .setClientResponse(
                  ByteString.copyFromUtf8(scramAuth.executeStep2(password, serverFirstMessage)))
              .build();

      AuthMessage authResponse =
          AuthMessage.newBuilder()
              .setMessageType(AuthMessageType.Type_AuthClientResponseMessage)
              .setAuthClientResponseMessage(authClient)
              .build();

      msg =
          PokerTHMessage.newBuilder()
              .setMessageType(PokerTHMessageType.Type_AuthMessage)
              .setAuthMessage(authResponse)
              .build();
      sendMessage(msg, s);
    }
    failOnErrorMessage(msg);

    msg = receiveMessage(s);
    failOnErrorMessage(msg);

    msg = receiveMessage(s);
    if (msg.hasLobbyMessage()
        && msg.getMessageType() == PokerTHMessageType.Type_LobbyMessage
        && msg.getLobbyMessage().hasInitDoneMessage()
        && msg.getLobbyMessage().getMessageType() == LobbyMessageType.Type_InitDoneMessage) {
      InitDoneMessage initDone = msg.getLobbyMessage().getInitDoneMessage();
      assertTrue(initDone.getYourPlayerId() != 0L);
      assertTrue(!initDone.hasYourAvatarHash());
      playerId = initDone.getYourPlayerId();
      if (lastSessionId != null) {
        lastSessionId.value = initDone.getYourSessionId().toByteArray();
      }
      if (initDone.hasRejoinGameId()) {
        lastRejoinGameId = initDone.getRejoinGameId();
      } else {
        lastRejoinGameId = 0;
      }
    } else {
      failOnErrorMessage(msg);
      fail("Invalid message.");
    }
    return playerId;
  }