示例#1
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;
  }
示例#2
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;
  }