Adding support for custom delay between hands in protocol.
This commit is contained in:
@@ -674,31 +674,45 @@ ClientStateStartSession::Enter(boost::shared_ptr<ClientThread> client)
|
||||
InitMessage_t *netInit = &init->GetMsg()->choice.initMessage;
|
||||
netInit->requestedVersion.major = NET_VERSION_MAJOR;
|
||||
netInit->requestedVersion.minor = NET_VERSION_MINOR;
|
||||
netInit->login.present = login_PR_authenticatedLogin;
|
||||
AuthenticatedLogin_t *authLogin = &netInit->login.choice.authenticatedLogin;
|
||||
// Send authentication user data for challenge/response in init.
|
||||
boost::shared_ptr<SessionData> tmpSession = context.GetSessionData();
|
||||
tmpSession->CreateClientAuthSession(client->GetAuthContext(), context.GetPlayerName(), context.GetPassword());
|
||||
if (!tmpSession->AuthStep(1, ""))
|
||||
throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PASSWORD, 0);
|
||||
string outUserData(tmpSession->AuthGetNextOutMsg());
|
||||
OCTET_STRING_fromBuf(&authLogin->clientUserData,
|
||||
outUserData.c_str(),
|
||||
outUserData.length());
|
||||
string avatarFile = client->GetQtToolsInterface().stringFromUtf8(context.GetAvatarFile());
|
||||
if (!avatarFile.empty())
|
||||
|
||||
// CASE 1: Authenticated login (username, challenge/response for password).
|
||||
if (!context.GetPassword().empty())
|
||||
{
|
||||
MD5Buf tmpMD5;
|
||||
if (client->GetAvatarManager().GetHashForAvatar(avatarFile, tmpMD5))
|
||||
netInit->login.present = login_PR_authenticatedLogin;
|
||||
AuthenticatedLogin_t *authLogin = &netInit->login.choice.authenticatedLogin;
|
||||
// Send authentication user data for challenge/response in init.
|
||||
boost::shared_ptr<SessionData> tmpSession = context.GetSessionData();
|
||||
tmpSession->CreateClientAuthSession(client->GetAuthContext(), context.GetPlayerName(), context.GetPassword());
|
||||
if (!tmpSession->AuthStep(1, ""))
|
||||
throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PASSWORD, 0);
|
||||
string outUserData(tmpSession->AuthGetNextOutMsg());
|
||||
OCTET_STRING_fromBuf(&authLogin->clientUserData,
|
||||
outUserData.c_str(),
|
||||
outUserData.length());
|
||||
string avatarFile = client->GetQtToolsInterface().stringFromUtf8(context.GetAvatarFile());
|
||||
if (!avatarFile.empty())
|
||||
{
|
||||
// TODO: use sha1.
|
||||
authLogin->avatar =
|
||||
OCTET_STRING_new_fromBuf(
|
||||
&asn_DEF_OCTET_STRING,
|
||||
(const char *)tmpMD5.data,
|
||||
MD5_DATA_SIZE);
|
||||
MD5Buf tmpMD5;
|
||||
if (client->GetAvatarManager().GetHashForAvatar(avatarFile, tmpMD5))
|
||||
{
|
||||
// TODO: use sha1.
|
||||
authLogin->avatar =
|
||||
OCTET_STRING_new_fromBuf(
|
||||
&asn_DEF_OCTET_STRING,
|
||||
(const char *)tmpMD5.data,
|
||||
MD5_DATA_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
// CASE 2: Guest login (no password, but restrictions may apply).
|
||||
else
|
||||
{
|
||||
netInit->login.present = login_PR_guestLogin;
|
||||
GuestLogin_t *guestLogin = &netInit->login.choice.guestLogin;
|
||||
OCTET_STRING_fromBuf(&guestLogin->nickName,
|
||||
context.GetPlayerName().c_str(),
|
||||
context.GetPlayerName().length());
|
||||
}
|
||||
client->GetSender().Send(context.GetSessionData(), init);
|
||||
|
||||
client->SetState(ClientStateWaitAuthChallenge::Instance());
|
||||
@@ -1046,7 +1060,7 @@ ClientStateWaitAuthChallenge::InternalHandlePacket(boost::shared_ptr<ClientThrea
|
||||
if (netAuth->present == AuthMessage_PR_authServerChallenge)
|
||||
{
|
||||
AuthServerChallenge_t *netChallenge = &netAuth->choice.authServerChallenge;
|
||||
string challengeStr((const char *)netChallenge->serverChallenge.buf, netChallenge->serverChallenge.size);
|
||||
string challengeStr = STL_STRING_FROM_OCTET_STRING(netChallenge->serverChallenge);
|
||||
boost::shared_ptr<SessionData> tmpSession = client->GetContext().GetSessionData();
|
||||
if (!tmpSession->AuthStep(2, challengeStr.c_str()))
|
||||
throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PASSWORD, 0);
|
||||
@@ -1107,7 +1121,7 @@ ClientStateWaitAuthVerify::InternalHandlePacket(boost::shared_ptr<ClientThread>
|
||||
if (netAuth->present == AuthMessage_PR_authServerVerification)
|
||||
{
|
||||
AuthServerVerification_t *netVerification = &netAuth->choice.authServerVerification;
|
||||
string verificationStr((const char *)netVerification->serverVerification.buf, netVerification->serverVerification.size);
|
||||
string verificationStr = STL_STRING_FROM_OCTET_STRING(netVerification->serverVerification);
|
||||
boost::shared_ptr<SessionData> tmpSession = client->GetContext().GetSessionData();
|
||||
if (!tmpSession->AuthStep(3, verificationStr.c_str()))
|
||||
throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PASSWORD, 0);
|
||||
|
||||
@@ -123,6 +123,7 @@ NetPacket::SetGameData(const GameData &inData, NetGameInfo_t *outData)
|
||||
}
|
||||
outData->endRaiseMode = inData.afterManualBlindsMode;
|
||||
outData->proposedGuiSpeed = inData.guiSpeed;
|
||||
outData->delayBetweenHands = inData.delayBetweenHandsSec;
|
||||
outData->playerActionTimeout = inData.playerActionTimeoutSec;
|
||||
outData->endRaiseSmallBlindValue = inData.afterMBAlwaysRaiseValue;
|
||||
outData->firstSmallBlind = inData.firstSmallBlind;
|
||||
@@ -159,6 +160,7 @@ NetPacket::GetGameData(const NetGameInfo_t *inData, GameData &outData)
|
||||
outData.raiseMode = numManualBlinds > 0 ? MANUAL_BLINDS_ORDER : DOUBLE_BLINDS;
|
||||
outData.afterManualBlindsMode = static_cast<AfterManualBlindsMode>(inData->endRaiseMode);
|
||||
outData.guiSpeed = inData->proposedGuiSpeed;
|
||||
outData.delayBetweenHandsSec = inData->delayBetweenHands;
|
||||
outData.playerActionTimeoutSec = inData->playerActionTimeout;
|
||||
outData.firstSmallBlind = inData->firstSmallBlind;
|
||||
outData.afterMBAlwaysRaiseValue = inData->endRaiseSmallBlindValue;
|
||||
|
||||
@@ -40,7 +40,6 @@ using namespace std;
|
||||
//#define SERVER_TEST
|
||||
|
||||
#ifdef SERVER_TEST
|
||||
#define SERVER_DELAY_NEXT_HAND_SEC 0
|
||||
#define SERVER_DELAY_NEXT_GAME_SEC 0
|
||||
#define SERVER_DEAL_FLOP_CARDS_DELAY_SEC 0
|
||||
#define SERVER_DEAL_TURN_CARD_DELAY_SEC 0
|
||||
@@ -50,7 +49,6 @@ using namespace std;
|
||||
#define SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC 0
|
||||
#define SERVER_COMPUTER_ACTION_DELAY_SEC 0
|
||||
#else
|
||||
#define SERVER_DELAY_NEXT_HAND_SEC 10
|
||||
#define SERVER_DELAY_NEXT_GAME_SEC 10
|
||||
#define SERVER_DEAL_FLOP_CARDS_DELAY_SEC 5
|
||||
#define SERVER_DEAL_TURN_CARD_DELAY_SEC 2
|
||||
@@ -875,8 +873,13 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef POKERTH_TEST
|
||||
server->GetStateTimer().expires_from_now(
|
||||
boost::posix_time::seconds(SERVER_DELAY_NEXT_HAND_SEC));
|
||||
boost::posix_time::seconds(0));
|
||||
#else
|
||||
server->GetStateTimer().expires_from_now(
|
||||
boost::posix_time::seconds(server->GetGameData().delayBetweenHandsSec));
|
||||
#endif
|
||||
server->GetStateTimer().async_wait(
|
||||
boost::bind(
|
||||
&ServerGameStateHand::TimerNextHand, this, boost::asio::placeholders::error, server));
|
||||
|
||||
@@ -99,16 +99,17 @@ public:
|
||||
|
||||
virtual void ConnectSuccess()
|
||||
{
|
||||
LOG_MSG("Successfully connected to database.");
|
||||
}
|
||||
|
||||
virtual void ConnectFailed(const string &error)
|
||||
{
|
||||
// TODO
|
||||
LOG_ERROR("DB connect error: " << error);
|
||||
}
|
||||
|
||||
virtual void QueryError(const std::string &error)
|
||||
{
|
||||
// TODO
|
||||
LOG_ERROR("DB query error: " << error);
|
||||
}
|
||||
|
||||
virtual void PlayerLoginSuccess(unsigned requestId, DB_id dbPlayerId, const std::string &secret)
|
||||
@@ -128,6 +129,8 @@ public:
|
||||
|
||||
virtual void CreateGameFailed(unsigned requestId)
|
||||
{
|
||||
// TODO maybe handle request id.
|
||||
LOG_ERROR("DB create game failed for request " << requestId);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -919,7 +922,7 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const InitMessage
|
||||
if (initMessage.login.present == login_PR_guestLogin)
|
||||
{
|
||||
const GuestLogin_t *guestLogin = &initMessage.login.choice.guestLogin;
|
||||
playerName = string((const char *)guestLogin->nickName.buf, guestLogin->nickName.size);
|
||||
playerName = STL_STRING_FROM_OCTET_STRING(guestLogin->nickName);
|
||||
guestUser = true;
|
||||
}
|
||||
else if (initMessage.login.present == login_PR_authenticatedLogin)
|
||||
@@ -989,7 +992,7 @@ ServerLobbyThread::HandleNetPacketAuthClientResponse(SessionWrapper session, con
|
||||
{
|
||||
if (session.sessionData && session.playerData && session.sessionData->AuthGetCurStepNum() == 1)
|
||||
{
|
||||
string authData((const char *)clientResponse.clientResponse.buf, clientResponse.clientResponse.size);
|
||||
string authData = STL_STRING_FROM_OCTET_STRING(clientResponse.clientResponse);
|
||||
if (session.sessionData->AuthStep(2, authData))
|
||||
{
|
||||
string outVerification(session.sessionData->AuthGetNextOutMsg());
|
||||
@@ -1191,7 +1194,7 @@ ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const std::
|
||||
new ServerGame(
|
||||
shared_from_this(),
|
||||
GetNextGameId(),
|
||||
string((char *)newGame.gameInfo.gameName.buf, newGame.gameInfo.gameName.size),
|
||||
STL_STRING_FROM_OCTET_STRING(newGame.gameInfo.gameName),
|
||||
password,
|
||||
tmpData,
|
||||
session.playerData->GetUniqueId(),
|
||||
@@ -1360,7 +1363,9 @@ ServerLobbyThread::AuthenticatePlayer(SessionWrapper session)
|
||||
void
|
||||
ServerLobbyThread::UserValid(unsigned playerId, DB_id dbPlayerId, const string &dbSecret)
|
||||
{
|
||||
this->AuthChallenge(m_sessionManager.GetSessionByUniquePlayerId(playerId, true), dbSecret);
|
||||
SessionWrapper tmpSession = m_sessionManager.GetSessionByUniquePlayerId(playerId, true);
|
||||
tmpSession.playerData->SetDBId(dbPlayerId);
|
||||
this->AuthChallenge(tmpSession, dbSecret);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user