diff --git a/src/net/common/servergame.cpp b/src/net/common/servergame.cpp index b70bb5ea..25246422 100644 --- a/src/net/common/servergame.cpp +++ b/src/net/common/servergame.cpp @@ -984,7 +984,7 @@ ServerGame::CheckPassword(const string &password) const } bool -ServerGame::CheckSettings(const GameData &data) +ServerGame::CheckSettings(const GameData &data, const string &password) { bool retVal = true; if (data.gameType == GAME_TYPE_RANKING) @@ -994,7 +994,8 @@ ServerGame::CheckSettings(const GameData &data) || (data.firstSmallBlind != RANKING_GAME_START_SBLIND) || (data.raiseIntervalMode != RAISE_ON_HANDNUMBER) || (data.raiseMode != DOUBLE_BLINDS) - || (data.raiseSmallBlindEveryHandsValue != RANKING_GAME_RAISE_EVERY_HAND)) + || (data.raiseSmallBlindEveryHandsValue != RANKING_GAME_RAISE_EVERY_HAND) + || (!password.empty())) { retVal = false; } diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 8cb7ac63..853feebf 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -1349,7 +1349,7 @@ ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const std:: { SendJoinGameFailed(session.sessionData, gameId, NTF_NET_JOIN_GUEST_FORBIDDEN); } - else if (!ServerGame::CheckSettings(tmpData)) + else if (!ServerGame::CheckSettings(tmpData, password)) { SendJoinGameFailed(session.sessionData, gameId, NTF_NET_JOIN_INVALID_SETTINGS); } diff --git a/src/net/servergame.h b/src/net/servergame.h index eff6e23e..89e4ad5a 100644 --- a/src/net/servergame.h +++ b/src/net/servergame.h @@ -69,7 +69,7 @@ public: bool IsPasswordProtected() const; bool CheckPassword(const std::string &password) const; - static bool CheckSettings(const GameData &data); + static bool CheckSettings(const GameData &data, const std::string &password); const GameData &GetGameData() const; boost::shared_ptr GetPlayerDataByUniqueId(unsigned playerId) const; diff --git a/tests/src/pokerth_protocol/ChatRequestMessage.java b/tests/src/pokerth_protocol/ChatRequestMessage.java index caea3b7c..48e5a398 100644 --- a/tests/src/pokerth_protocol/ChatRequestMessage.java +++ b/tests/src/pokerth_protocol/ChatRequestMessage.java @@ -40,6 +40,11 @@ import org.bn.types.*; private ChatRequestTypeGame chatRequestTypeGame = null; + @ASN1Element ( name = "chatRequestTypePrivate", isOptional = false , hasTag = true, tag = 2 , hasDefaultValue = false ) + + private ChatRequestTypePrivate chatRequestTypePrivate = null; + + public ChatRequestTypeLobby getChatRequestTypeLobby () { return this.chatRequestTypeLobby; @@ -58,6 +63,8 @@ import org.bn.types.*; this.chatRequestTypeLobby = value; setChatRequestTypeGame(null); + + setChatRequestTypePrivate(null); } @@ -81,6 +88,33 @@ import org.bn.types.*; this.chatRequestTypeGame = value; setChatRequestTypeLobby(null); + + setChatRequestTypePrivate(null); + + } + + + + + public ChatRequestTypePrivate getChatRequestTypePrivate () { + return this.chatRequestTypePrivate; + } + + public boolean isChatRequestTypePrivateSelected () { + return this.chatRequestTypePrivate != null; + } + + private void setChatRequestTypePrivate (ChatRequestTypePrivate value) { + this.chatRequestTypePrivate = value; + } + + + public void selectChatRequestTypePrivate (ChatRequestTypePrivate value) { + this.chatRequestTypePrivate = value; + + setChatRequestTypeLobby(null); + + setChatRequestTypeGame(null); } diff --git a/tests/src/pokerth_protocol/NetGameInfo.java b/tests/src/pokerth_protocol/NetGameInfo.java index 68dfc22c..dff374f5 100644 --- a/tests/src/pokerth_protocol/NetGameInfo.java +++ b/tests/src/pokerth_protocol/NetGameInfo.java @@ -322,16 +322,17 @@ import org.bn.types.*; private Integer startMoney = null; @ASN1Integer( name = "" ) - @ASN1ValueRangeConstraint ( - - min = 1L, - - max = 1000000L - - ) @ASN1SequenceOf( name = "manualBlinds", isSetOf = false ) + @ASN1ValueRangeConstraint ( + + min = 0L, + + max = 30L + + ) + @ASN1Element ( name = "manualBlinds", isOptional = false , hasTag = false , hasDefaultValue = false ) private java.util.Collection manualBlinds = null; diff --git a/tests/src/pokerth_test/AllTests.java b/tests/src/pokerth_test/AllTests.java index 692589d9..fcc30335 100644 --- a/tests/src/pokerth_test/AllTests.java +++ b/tests/src/pokerth_test/AllTests.java @@ -26,7 +26,8 @@ import org.junit.runners.Suite; @Suite.SuiteClasses( { GuestLoginTest.class, AuthLoginTest.class, - CreateGameTest.class + CreateGameTest.class, + CreateRankingGameTest.class }) public class AllTests { public static void main(String[] args) diff --git a/tests/src/pokerth_test/AuthLoginTest.java b/tests/src/pokerth_test/AuthLoginTest.java index 30c8d99e..c12a4455 100644 --- a/tests/src/pokerth_test/AuthLoginTest.java +++ b/tests/src/pokerth_test/AuthLoginTest.java @@ -30,82 +30,6 @@ public class AuthLoginTest extends TestBase { @Test public void testAuthLogin() throws Exception { - PokerTHMessage msg = receiveMessage(); - AnnounceMessage announce = msg.getAnnounceMessage(); - assertTrue(announce.getValue().getServerType().getValue() == ServerTypeEnumType.EnumType.serverTypeInternetAuth); - - ScramSha1 scramAuth = new ScramSha1(); - - // Send challenge. - Version requestedVersion = new Version(); - requestedVersion.setMajor(PROTOCOL_VERSION_MAJOR); - requestedVersion.setMinor(PROTOCOL_VERSION_MINOR); - AuthenticatedLogin authLogin = new AuthenticatedLogin(); - authLogin.setClientUserData(scramAuth.executeStep1(AuthUser).getBytes()); - LoginChoiceType loginType = new LoginChoiceType(); - loginType.selectAuthenticatedLogin(authLogin); - InitMessageSequenceType msgType = new InitMessageSequenceType(); - msgType.setBuildId(0L); - msgType.setLogin(loginType); - msgType.setRequestedVersion(requestedVersion); - InitMessage init = new InitMessage(); - init.setValue(msgType); - msg = new PokerTHMessage(); - msg.selectInitMessage(init); - sendMessage(msg); - - msg = receiveMessage(); - - if (msg.isAuthMessageSelected() && msg.getAuthMessage().getValue().isAuthServerChallengeSelected()) - { - String serverFirstMessage = new String(msg.getAuthMessage().getValue().getAuthServerChallenge().getServerChallenge()); - AuthClientResponse authClient = new AuthClientResponse(); - authClient.setClientResponse(scramAuth.executeStep2(AuthPassword, serverFirstMessage).getBytes()); - AuthMessageChoiceType authChoice = new AuthMessageChoiceType(); - authChoice.selectAuthClientResponse(authClient); - AuthMessage authResponse = new AuthMessage(); - authResponse.setValue(authChoice); - - msg = new PokerTHMessage(); - msg.selectAuthMessage(authResponse); - sendMessage(msg); - } - else if (msg.isErrorMessageSelected()) - { - ErrorMessage error = msg.getErrorMessage(); - fail("Received error: " + error.getValue().getErrorReason().getValue().toString()); - } - else - { - fail("Invalid auth message."); - } - - msg = receiveMessage(); - if (msg.isErrorMessageSelected()) - { - ErrorMessage error = msg.getErrorMessage(); - fail("Received error: " + error.getValue().getErrorReason().getValue().toString()); - } - else if (!msg.isAuthMessageSelected() || !msg.getAuthMessage().getValue().isAuthServerVerificationSelected()) - { - fail("Invalid auth message."); - } - - msg = receiveMessage(); - if (msg.isInitAckMessageSelected()) - { - InitAckMessage initAck = msg.getInitAckMessage(); - assertTrue(initAck.getValue().getYourPlayerId().getValue() != 0L); - assertTrue(!initAck.getValue().isYourAvatarPresent()); - } - else if (msg.isErrorMessageSelected()) - { - ErrorMessage error = msg.getErrorMessage(); - fail("Received error: " + error.getValue().getErrorReason().getValue().toString()); - } - else - { - fail("Invalid response message."); - } + userInit(); } } diff --git a/tests/src/pokerth_test/CreateGameTest.java b/tests/src/pokerth_test/CreateGameTest.java index c25d775d..f822820b 100644 --- a/tests/src/pokerth_test/CreateGameTest.java +++ b/tests/src/pokerth_test/CreateGameTest.java @@ -25,11 +25,8 @@ import java.util.Collection; import org.junit.Test; import pokerth_protocol.*; -import pokerth_protocol.JoinGameRequestMessage.JoinGameRequestMessageSequenceType; -import pokerth_protocol.JoinGameRequestMessage.JoinGameRequestMessageSequenceType.JoinGameActionChoiceType; import pokerth_protocol.NetGameInfo.EndRaiseModeEnumType; import pokerth_protocol.NetGameInfo.NetGameTypeEnumType; -import pokerth_protocol.NetGameInfo.RaiseIntervalModeChoiceType; public class CreateGameTest extends TestBase { diff --git a/tests/src/pokerth_test/TestBase.java b/tests/src/pokerth_test/TestBase.java index 656e3932..be485838 100644 --- a/tests/src/pokerth_test/TestBase.java +++ b/tests/src/pokerth_test/TestBase.java @@ -26,6 +26,7 @@ import org.junit.Test; import pokerth_protocol.*; import pokerth_protocol.AnnounceMessage.AnnounceMessageSequenceType.ServerTypeEnumType; +import pokerth_protocol.AuthMessage.AuthMessageChoiceType; import pokerth_protocol.InitMessage.InitMessageSequenceType; import pokerth_protocol.InitMessage.InitMessageSequenceType.LoginChoiceType; import pokerth_protocol.JoinGameRequestMessage.JoinGameRequestMessageSequenceType; @@ -125,6 +126,90 @@ public abstract class TestBase { } } + public void userInit() throws Exception { + userInit(sock); + } + + public void userInit(Socket s) throws Exception { + PokerTHMessage msg = receiveMessage(s); + AnnounceMessage announce = msg.getAnnounceMessage(); + assertTrue(announce.getValue().getServerType().getValue() == ServerTypeEnumType.EnumType.serverTypeInternetAuth); + + ScramSha1 scramAuth = new ScramSha1(); + + // Send challenge. + Version requestedVersion = new Version(); + requestedVersion.setMajor(PROTOCOL_VERSION_MAJOR); + requestedVersion.setMinor(PROTOCOL_VERSION_MINOR); + AuthenticatedLogin authLogin = new AuthenticatedLogin(); + authLogin.setClientUserData(scramAuth.executeStep1(AuthUser).getBytes()); + LoginChoiceType loginType = new LoginChoiceType(); + loginType.selectAuthenticatedLogin(authLogin); + InitMessageSequenceType msgType = new InitMessageSequenceType(); + msgType.setBuildId(0L); + msgType.setLogin(loginType); + msgType.setRequestedVersion(requestedVersion); + InitMessage init = new InitMessage(); + init.setValue(msgType); + msg = new PokerTHMessage(); + msg.selectInitMessage(init); + sendMessage(msg, s); + + msg = receiveMessage(s); + + if (msg.isAuthMessageSelected() && msg.getAuthMessage().getValue().isAuthServerChallengeSelected()) + { + String serverFirstMessage = new String(msg.getAuthMessage().getValue().getAuthServerChallenge().getServerChallenge()); + AuthClientResponse authClient = new AuthClientResponse(); + authClient.setClientResponse(scramAuth.executeStep2(AuthPassword, serverFirstMessage).getBytes()); + AuthMessageChoiceType authChoice = new AuthMessageChoiceType(); + authChoice.selectAuthClientResponse(authClient); + AuthMessage authResponse = new AuthMessage(); + authResponse.setValue(authChoice); + + msg = new PokerTHMessage(); + msg.selectAuthMessage(authResponse); + sendMessage(msg, s); + } + else if (msg.isErrorMessageSelected()) + { + ErrorMessage error = msg.getErrorMessage(); + fail("Received error: " + error.getValue().getErrorReason().getValue().toString()); + } + else + { + fail("Invalid auth message."); + } + + msg = receiveMessage(s); + if (msg.isErrorMessageSelected()) + { + ErrorMessage error = msg.getErrorMessage(); + fail("Received error: " + error.getValue().getErrorReason().getValue().toString()); + } + else if (!msg.isAuthMessageSelected() || !msg.getAuthMessage().getValue().isAuthServerVerificationSelected()) + { + fail("Invalid auth message."); + } + + msg = receiveMessage(s); + if (msg.isInitAckMessageSelected()) + { + InitAckMessage initAck = msg.getInitAckMessage(); + assertTrue(initAck.getValue().getYourPlayerId().getValue() != 0L); + assertTrue(!initAck.getValue().isYourAvatarPresent()); + } + else if (msg.isErrorMessageSelected()) + { + ErrorMessage error = msg.getErrorMessage(); + fail("Received error: " + error.getValue().getErrorReason().getValue().toString()); + } + else + { + fail("Invalid response message."); + } + } + public PokerTHMessage createJoinGameRequestMsg(NetGameInfo gameInfo, NetGameTypeEnumType.EnumType type, int playerActionTimeout, int guiSpeed, String password) { NetGameTypeEnumType gameType = new NetGameTypeEnumType(); gameType.setValue(type); @@ -137,7 +222,9 @@ public abstract class TestBase { joinAction.selectJoinNewGame(joinNew); JoinGameRequestMessageSequenceType joinType = new JoinGameRequestMessageSequenceType(); joinType.setJoinGameAction(joinAction); - joinType.setPassword(password); + if (!password.isEmpty()) { + joinType.setPassword(password); + } JoinGameRequestMessage joinRequest = new JoinGameRequestMessage(); joinRequest.setValue(joinType); @@ -167,6 +254,7 @@ public abstract class TestBase { } gameInfo.setRaiseIntervalMode(raiseInterval); gameInfo.setStartMoney(startMoney); + return gameInfo; } }