Adding tests for ranking games, fixing small issue when creating ranking games.
This commit is contained in:
@@ -984,7 +984,7 @@ ServerGame::CheckPassword(const string &password) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ServerGame::CheckSettings(const GameData &data)
|
ServerGame::CheckSettings(const GameData &data, const string &password)
|
||||||
{
|
{
|
||||||
bool retVal = true;
|
bool retVal = true;
|
||||||
if (data.gameType == GAME_TYPE_RANKING)
|
if (data.gameType == GAME_TYPE_RANKING)
|
||||||
@@ -994,7 +994,8 @@ ServerGame::CheckSettings(const GameData &data)
|
|||||||
|| (data.firstSmallBlind != RANKING_GAME_START_SBLIND)
|
|| (data.firstSmallBlind != RANKING_GAME_START_SBLIND)
|
||||||
|| (data.raiseIntervalMode != RAISE_ON_HANDNUMBER)
|
|| (data.raiseIntervalMode != RAISE_ON_HANDNUMBER)
|
||||||
|| (data.raiseMode != DOUBLE_BLINDS)
|
|| (data.raiseMode != DOUBLE_BLINDS)
|
||||||
|| (data.raiseSmallBlindEveryHandsValue != RANKING_GAME_RAISE_EVERY_HAND))
|
|| (data.raiseSmallBlindEveryHandsValue != RANKING_GAME_RAISE_EVERY_HAND)
|
||||||
|
|| (!password.empty()))
|
||||||
{
|
{
|
||||||
retVal = false;
|
retVal = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1349,7 +1349,7 @@ ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const std::
|
|||||||
{
|
{
|
||||||
SendJoinGameFailed(session.sessionData, gameId, NTF_NET_JOIN_GUEST_FORBIDDEN);
|
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);
|
SendJoinGameFailed(session.sessionData, gameId, NTF_NET_JOIN_INVALID_SETTINGS);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public:
|
|||||||
|
|
||||||
bool IsPasswordProtected() const;
|
bool IsPasswordProtected() const;
|
||||||
bool CheckPassword(const std::string &password) 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;
|
const GameData &GetGameData() const;
|
||||||
|
|
||||||
boost::shared_ptr<PlayerData> GetPlayerDataByUniqueId(unsigned playerId) const;
|
boost::shared_ptr<PlayerData> GetPlayerDataByUniqueId(unsigned playerId) const;
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ import org.bn.types.*;
|
|||||||
private ChatRequestTypeGame chatRequestTypeGame = null;
|
private ChatRequestTypeGame chatRequestTypeGame = null;
|
||||||
|
|
||||||
|
|
||||||
|
@ASN1Element ( name = "chatRequestTypePrivate", isOptional = false , hasTag = true, tag = 2 , hasDefaultValue = false )
|
||||||
|
|
||||||
|
private ChatRequestTypePrivate chatRequestTypePrivate = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ChatRequestTypeLobby getChatRequestTypeLobby () {
|
public ChatRequestTypeLobby getChatRequestTypeLobby () {
|
||||||
return this.chatRequestTypeLobby;
|
return this.chatRequestTypeLobby;
|
||||||
@@ -58,6 +63,8 @@ import org.bn.types.*;
|
|||||||
this.chatRequestTypeLobby = value;
|
this.chatRequestTypeLobby = value;
|
||||||
|
|
||||||
setChatRequestTypeGame(null);
|
setChatRequestTypeGame(null);
|
||||||
|
|
||||||
|
setChatRequestTypePrivate(null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,6 +88,33 @@ import org.bn.types.*;
|
|||||||
this.chatRequestTypeGame = value;
|
this.chatRequestTypeGame = value;
|
||||||
|
|
||||||
setChatRequestTypeLobby(null);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -322,16 +322,17 @@ import org.bn.types.*;
|
|||||||
private Integer startMoney = null;
|
private Integer startMoney = null;
|
||||||
|
|
||||||
@ASN1Integer( name = "" )
|
@ASN1Integer( name = "" )
|
||||||
@ASN1ValueRangeConstraint (
|
|
||||||
|
|
||||||
min = 1L,
|
|
||||||
|
|
||||||
max = 1000000L
|
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
@ASN1SequenceOf( name = "manualBlinds", isSetOf = false )
|
@ASN1SequenceOf( name = "manualBlinds", isSetOf = false )
|
||||||
|
|
||||||
|
@ASN1ValueRangeConstraint (
|
||||||
|
|
||||||
|
min = 0L,
|
||||||
|
|
||||||
|
max = 30L
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
@ASN1Element ( name = "manualBlinds", isOptional = false , hasTag = false , hasDefaultValue = false )
|
@ASN1Element ( name = "manualBlinds", isOptional = false , hasTag = false , hasDefaultValue = false )
|
||||||
|
|
||||||
private java.util.Collection<Integer> manualBlinds = null;
|
private java.util.Collection<Integer> manualBlinds = null;
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ import org.junit.runners.Suite;
|
|||||||
@Suite.SuiteClasses( {
|
@Suite.SuiteClasses( {
|
||||||
GuestLoginTest.class,
|
GuestLoginTest.class,
|
||||||
AuthLoginTest.class,
|
AuthLoginTest.class,
|
||||||
CreateGameTest.class
|
CreateGameTest.class,
|
||||||
|
CreateRankingGameTest.class
|
||||||
})
|
})
|
||||||
public class AllTests {
|
public class AllTests {
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
|
|||||||
@@ -30,82 +30,6 @@ public class AuthLoginTest extends TestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthLogin() throws Exception {
|
public void testAuthLogin() throws Exception {
|
||||||
PokerTHMessage msg = receiveMessage();
|
userInit();
|
||||||
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.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,11 +25,8 @@ import java.util.Collection;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import pokerth_protocol.*;
|
import pokerth_protocol.*;
|
||||||
import pokerth_protocol.JoinGameRequestMessage.JoinGameRequestMessageSequenceType;
|
|
||||||
import pokerth_protocol.JoinGameRequestMessage.JoinGameRequestMessageSequenceType.JoinGameActionChoiceType;
|
|
||||||
import pokerth_protocol.NetGameInfo.EndRaiseModeEnumType;
|
import pokerth_protocol.NetGameInfo.EndRaiseModeEnumType;
|
||||||
import pokerth_protocol.NetGameInfo.NetGameTypeEnumType;
|
import pokerth_protocol.NetGameInfo.NetGameTypeEnumType;
|
||||||
import pokerth_protocol.NetGameInfo.RaiseIntervalModeChoiceType;
|
|
||||||
|
|
||||||
public class CreateGameTest extends TestBase {
|
public class CreateGameTest extends TestBase {
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import pokerth_protocol.*;
|
import pokerth_protocol.*;
|
||||||
import pokerth_protocol.AnnounceMessage.AnnounceMessageSequenceType.ServerTypeEnumType;
|
import pokerth_protocol.AnnounceMessage.AnnounceMessageSequenceType.ServerTypeEnumType;
|
||||||
|
import pokerth_protocol.AuthMessage.AuthMessageChoiceType;
|
||||||
import pokerth_protocol.InitMessage.InitMessageSequenceType;
|
import pokerth_protocol.InitMessage.InitMessageSequenceType;
|
||||||
import pokerth_protocol.InitMessage.InitMessageSequenceType.LoginChoiceType;
|
import pokerth_protocol.InitMessage.InitMessageSequenceType.LoginChoiceType;
|
||||||
import pokerth_protocol.JoinGameRequestMessage.JoinGameRequestMessageSequenceType;
|
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) {
|
public PokerTHMessage createJoinGameRequestMsg(NetGameInfo gameInfo, NetGameTypeEnumType.EnumType type, int playerActionTimeout, int guiSpeed, String password) {
|
||||||
NetGameTypeEnumType gameType = new NetGameTypeEnumType();
|
NetGameTypeEnumType gameType = new NetGameTypeEnumType();
|
||||||
gameType.setValue(type);
|
gameType.setValue(type);
|
||||||
@@ -137,7 +222,9 @@ public abstract class TestBase {
|
|||||||
joinAction.selectJoinNewGame(joinNew);
|
joinAction.selectJoinNewGame(joinNew);
|
||||||
JoinGameRequestMessageSequenceType joinType = new JoinGameRequestMessageSequenceType();
|
JoinGameRequestMessageSequenceType joinType = new JoinGameRequestMessageSequenceType();
|
||||||
joinType.setJoinGameAction(joinAction);
|
joinType.setJoinGameAction(joinAction);
|
||||||
joinType.setPassword(password);
|
if (!password.isEmpty()) {
|
||||||
|
joinType.setPassword(password);
|
||||||
|
}
|
||||||
JoinGameRequestMessage joinRequest = new JoinGameRequestMessage();
|
JoinGameRequestMessage joinRequest = new JoinGameRequestMessage();
|
||||||
joinRequest.setValue(joinType);
|
joinRequest.setValue(joinType);
|
||||||
|
|
||||||
@@ -167,6 +254,7 @@ public abstract class TestBase {
|
|||||||
}
|
}
|
||||||
gameInfo.setRaiseIntervalMode(raiseInterval);
|
gameInfo.setRaiseIntervalMode(raiseInterval);
|
||||||
gameInfo.setStartMoney(startMoney);
|
gameInfo.setStartMoney(startMoney);
|
||||||
|
|
||||||
return gameInfo;
|
return gameInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user