diff --git a/src/gui/generic/serverguiwrapper.cpp b/src/gui/generic/serverguiwrapper.cpp index 657cc349..b69af568 100644 --- a/src/gui/generic/serverguiwrapper.cpp +++ b/src/gui/generic/serverguiwrapper.cpp @@ -122,6 +122,8 @@ void ServerGuiWrapper::SignalNetClientServerListAdd(unsigned serverId) { if (myC void ServerGuiWrapper::SignalNetClientServerListClear() { if (myClientcb) myClientcb->SignalNetClientServerListClear(); } void ServerGuiWrapper::SignalNetClientServerListShow() { if (myClientcb) myClientcb->SignalNetClientServerListShow(); } +void ServerGuiWrapper::SignalNetClientLoginShow() { if (myClientcb) myClientcb->SignalNetClientLoginShow(); } + void ServerGuiWrapper::SignalNetClientConnect(int actionID) { if (myClientcb) myClientcb->SignalNetClientConnect(actionID); } void ServerGuiWrapper::SignalNetClientGameInfo(int actionID) { if (myClientcb) myClientcb->SignalNetClientGameInfo(actionID); } void ServerGuiWrapper::SignalNetClientError(int errorID, int osErrorID) { if (myClientcb) myClientcb->SignalNetClientError(errorID, osErrorID); } diff --git a/src/gui/generic/serverguiwrapper.h b/src/gui/generic/serverguiwrapper.h index 2edc0513..1c61c5b0 100644 --- a/src/gui/generic/serverguiwrapper.h +++ b/src/gui/generic/serverguiwrapper.h @@ -132,6 +132,8 @@ public: void SignalNetClientServerListClear(); void SignalNetClientServerListShow(); + void SignalNetClientLoginShow(); + void SignalNetServerSuccess(int actionID); void SignalNetServerError(int errorID, int osErrorID); diff --git a/src/gui/qt/startwindow/startwindowimpl.cpp b/src/gui/qt/startwindow/startwindowimpl.cpp index 7fc052f0..39b315dc 100644 --- a/src/gui/qt/startwindow/startwindowimpl.cpp +++ b/src/gui/qt/startwindow/startwindowimpl.cpp @@ -446,8 +446,7 @@ void startWindowImpl::callJoinNetworkGameDialog() { myJoinNetworkGameDialog->lineEdit_ipAddress->text().toUtf8().constData(), myJoinNetworkGameDialog->spinBox_port->value(), myJoinNetworkGameDialog->checkBox_ipv6->isChecked(), - myJoinNetworkGameDialog->checkBox_sctp->isChecked(), - myJoinNetworkGameDialog->lineEdit_password->text().toUtf8().constData()); + myJoinNetworkGameDialog->checkBox_sctp->isChecked()); //Dialog mit Statusbalken myConnectToServerDialog->exec(); diff --git a/src/net/clientcallback.h b/src/net/clientcallback.h index 8408b915..4abcc50d 100644 --- a/src/net/clientcallback.h +++ b/src/net/clientcallback.h @@ -62,9 +62,11 @@ public: virtual void SignalNetClientMsgBox(const std::string &msg) = 0; virtual void SignalNetClientWaitDialog() = 0; - virtual void SignalNetClientServerListAdd(unsigned serverId) =0; - virtual void SignalNetClientServerListClear() =0; - virtual void SignalNetClientServerListShow() =0; + virtual void SignalNetClientServerListAdd(unsigned serverId) = 0; + virtual void SignalNetClientServerListClear() = 0; + virtual void SignalNetClientServerListShow() = 0; + + virtual void SignalNetClientLoginShow() = 0; virtual void SignalLobbyPlayerJoined(unsigned playerId, const std::string &nickName) = 0; virtual void SignalLobbyPlayerKicked(const std::string &nickName, const std::string &byWhom, const std::string &reason) = 0; diff --git a/src/net/clientstate.h b/src/net/clientstate.h index faa67f94..3c91088a 100644 --- a/src/net/clientstate.h +++ b/src/net/clientstate.h @@ -234,24 +234,6 @@ private: boost::asio::ip::tcp::resolver::iterator m_remoteEndpointIterator; }; -// State: Session init. -class ClientStateStartSession : public ClientState -{ -public: - // Access the state singleton. - static ClientStateStartSession &Instance(); - virtual ~ClientStateStartSession(); - - virtual void Enter(boost::shared_ptr client); - virtual void Exit(boost::shared_ptr client); - - virtual void HandlePacket(boost::shared_ptr /*client*/, boost::shared_ptr /*tmpPacket*/) {} - -protected: - // Protected constructor - this is a singleton. - ClientStateStartSession(); -}; - // Abstract State: Receiving class AbstractClientStateReceiving : public ClientState { @@ -266,6 +248,44 @@ protected: virtual void InternalHandlePacket(boost::shared_ptr client, boost::shared_ptr tmpPacket) = 0; }; +// State: Session init. +class ClientStateStartSession : public AbstractClientStateReceiving +{ +public: + // Access the state singleton. + static ClientStateStartSession &Instance(); + virtual ~ClientStateStartSession(); + + virtual void Enter(boost::shared_ptr client); + virtual void Exit(boost::shared_ptr client); + +protected: + // Protected constructor - this is a singleton. + ClientStateStartSession(); + + virtual void InternalHandlePacket(boost::shared_ptr client, boost::shared_ptr tmpPacket); +}; + +// State: Waiting for the user to enter login data. +class ClientStateWaitEnterLogin : public ClientState +{ +public: + static ClientStateWaitEnterLogin &Instance(); + virtual ~ClientStateWaitEnterLogin(); + + virtual void Enter(boost::shared_ptr client); + virtual void Exit(boost::shared_ptr client); + + virtual void HandlePacket(boost::shared_ptr /*client*/, boost::shared_ptr /*tmpPacket*/) {} + +protected: + + // Protected constructor - this is a singleton. + ClientStateWaitEnterLogin(); + + void TimerLoop(const boost::system::error_code& ec, boost::shared_ptr client); +}; + // State: Wait for Authentication Challenge. class ClientStateWaitAuthChallenge : public AbstractClientStateReceiving { diff --git a/src/net/clientthread.h b/src/net/clientthread.h index 7a4a61a5..53010c22 100644 --- a/src/net/clientthread.h +++ b/src/net/clientthread.h @@ -62,7 +62,6 @@ public: bool sctp, const std::string &avatarServerAddress, const std::string &playerName, - const std::string &playerPwd, const std::string &avatarFile, const std::string &cacheDir); virtual void SignalTermination(); @@ -267,6 +266,7 @@ friend class ClientStateWaitChooseServer; friend class ClientStateStartConnect; friend class ClientStateConnecting; friend class ClientStateStartSession; +friend class ClientStateWaitEnterLogin; friend class ClientStateWaitAuthChallenge; friend class ClientStateWaitAuthVerify; friend class ClientStateWaitSession; diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 82ad477c..b4ccc1f3 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -649,82 +649,6 @@ ClientStateStartConnect::TimerTimeout(const boost::system::error_code& ec, boost //----------------------------------------------------------------------------- -ClientStateStartSession & -ClientStateStartSession::Instance() -{ - static ClientStateStartSession state; - return state; -} - -ClientStateStartSession::ClientStateStartSession() -{ -} - -ClientStateStartSession::~ClientStateStartSession() -{ -} - -void -ClientStateStartSession::Enter(boost::shared_ptr client) -{ - ClientContext &context = client->GetContext(); - - boost::shared_ptr init(new NetPacket(NetPacket::Alloc)); - init->GetMsg()->present = PokerTHMessage_PR_initMessage; - InitMessage_t *netInit = &init->GetMsg()->choice.initMessage; - netInit->requestedVersion.major = NET_VERSION_MAJOR; - netInit->requestedVersion.minor = NET_VERSION_MINOR; - - // CASE 1: Authenticated login (username, challenge/response for password). - if (!context.GetPassword().empty()) - { - 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 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()) - { - 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()); -} - -void -ClientStateStartSession::Exit(boost::shared_ptr /*client*/) -{ -} - -//----------------------------------------------------------------------------- - AbstractClientStateReceiving::AbstractClientStateReceiving() { } @@ -1023,6 +947,167 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr clien //----------------------------------------------------------------------------- +ClientStateStartSession & +ClientStateStartSession::Instance() +{ + static ClientStateStartSession state; + return state; +} + +ClientStateStartSession::ClientStateStartSession() +{ +} + +ClientStateStartSession::~ClientStateStartSession() +{ +} + +void +ClientStateStartSession::Enter(boost::shared_ptr client) +{ +} + +void +ClientStateStartSession::Exit(boost::shared_ptr /*client*/) +{ +} + +void +ClientStateStartSession::InternalHandlePacket(boost::shared_ptr client, boost::shared_ptr tmpPacket) +{ + if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_announceMessage) + { + // Server has send announcement - check data. + AnnounceMessage_t *netAnnounce = &tmpPacket->GetMsg()->choice.announceMessage; + // Check current game version. + if (netAnnounce->latestGameVersion.major != POKERTH_VERSION_MAJOR + || netAnnounce->latestGameVersion.minor != POKERTH_VERSION_MINOR) + { + client->GetCallback().SignalNetClientNotification(NTF_NET_NEW_RELEASE_AVAILABLE); + } + else if (POKERTH_BETA_REVISION && netAnnounce->latestBetaRevision != POKERTH_BETA_REVISION) + { + client->GetCallback().SignalNetClientNotification(NTF_NET_OUTDATED_BETA); + } + else + { + ClientContext &context = client->GetContext(); + + // CASE 1: Authenticated login (username, challenge/response for password). + if (netAnnounce->serverType == serverType_serverTypeInternetAuth) + { + client->GetCallback().SignalNetClientLoginShow(); + client->SetState(ClientStateWaitEnterLogin::Instance()); + } + // CASE 2: Unauthenticated login (dedicated server without auth backend). + else if (netAnnounce->serverType == serverType_serverTypeInternetNoAuth + || netAnnounce->serverType == serverType_serverTypeLAN) + { + boost::shared_ptr init(new NetPacket(NetPacket::Alloc)); + init->GetMsg()->present = PokerTHMessage_PR_initMessage; + InitMessage_t *netInit = &init->GetMsg()->choice.initMessage; + netInit->requestedVersion.major = NET_VERSION_MAJOR; + netInit->requestedVersion.minor = NET_VERSION_MINOR; + 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()); + } + } + } +} + +//----------------------------------------------------------------------------- + +ClientStateWaitEnterLogin & +ClientStateWaitEnterLogin::Instance() +{ + static ClientStateWaitEnterLogin state; + return state; +} + +ClientStateWaitEnterLogin::ClientStateWaitEnterLogin() +{ +} + +ClientStateWaitEnterLogin::~ClientStateWaitEnterLogin() +{ +} + +void +ClientStateWaitEnterLogin::Enter(boost::shared_ptr client) +{ + client->GetStateTimer().expires_from_now( + boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC)); + client->GetStateTimer().async_wait( + boost::bind( + &ClientStateWaitEnterLogin::TimerLoop, this, boost::asio::placeholders::error, client)); +} + +void +ClientStateWaitEnterLogin::Exit(boost::shared_ptr client) +{ + client->GetStateTimer().cancel(); +} + +void +ClientStateWaitEnterLogin::TimerLoop(const boost::system::error_code& ec, boost::shared_ptr client) +{ + if (!ec && &client->GetState() == this) + { + ClientContext &context = client->GetContext(); + if (!context.GetPassword().empty()) + { + boost::shared_ptr init(new NetPacket(NetPacket::Alloc)); + init->GetMsg()->present = PokerTHMessage_PR_initMessage; + 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 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()) + { + 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); + } + } + + client->GetSender().Send(context.GetSessionData(), init); + client->SetState(ClientStateWaitAuthChallenge::Instance()); + } + else + { + client->GetStateTimer().expires_from_now( + boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC)); + client->GetStateTimer().async_wait( + boost::bind( + &ClientStateWaitEnterLogin::TimerLoop, this, boost::asio::placeholders::error, client)); + } + } +} + +//----------------------------------------------------------------------------- + ClientStateWaitAuthChallenge & ClientStateWaitAuthChallenge::Instance() { @@ -1053,22 +1138,7 @@ ClientStateWaitAuthChallenge::Exit(boost::shared_ptr /*client*/) void ClientStateWaitAuthChallenge::InternalHandlePacket(boost::shared_ptr client, boost::shared_ptr tmpPacket) { - if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_announceMessage) - { - // Server has send announcement - check data. - AnnounceMessage_t *netAnnounce = &tmpPacket->GetMsg()->choice.announceMessage; - // Check current game version. - if (netAnnounce->latestGameVersion.major != POKERTH_VERSION_MAJOR - || netAnnounce->latestGameVersion.minor != POKERTH_VERSION_MINOR) - { - client->GetCallback().SignalNetClientNotification(NTF_NET_NEW_RELEASE_AVAILABLE); - } - else if (POKERTH_BETA_REVISION && netAnnounce->latestBetaRevision != POKERTH_BETA_REVISION) - { - client->GetCallback().SignalNetClientNotification(NTF_NET_OUTDATED_BETA); - } - } - else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_authMessage) + if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_authMessage) { // Check subtype. AuthMessage_t *netAuth = &tmpPacket->GetMsg()->choice.authMessage; diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index cf1ef6f7..e65dc283 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -86,8 +86,7 @@ ClientThread::Init( const string &serverAddress, const string &serverListUrl, bool useServerList, unsigned serverPort, bool ipv6, bool sctp, const string &avatarServerAddress, const string &playerName, - const string &playerPwd, const string &avatarFile, - const string &cacheDir) + const string &avatarFile, const string &cacheDir) { if (IsRunning()) { @@ -105,7 +104,6 @@ ClientThread::Init( context.SetServerPort(serverPort); context.SetAvatarServerAddr(avatarServerAddress); context.SetPlayerName(playerName); - context.SetPassword(playerPwd); context.SetAvatarFile(avatarFile); context.SetCacheDir(cacheDir); } diff --git a/src/session.cpp b/src/session.cpp index 8d3f2d22..d031c3b0 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -179,13 +179,12 @@ void Session::startInternetClient() myConfig->readConfigInt("InternetServerUseSctp") == 1, useAvatarServer ? myConfig->readConfigString("AvatarServerAddress") : "", myConfig->readConfigString("MyName"), - "testpw", myConfig->readConfigString("MyAvatar"), myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir"))); myNetClient->Run(); } -void Session::startNetworkClient(const string &serverAddress, unsigned serverPort, bool ipv6, bool sctp, const string &pwd) +void Session::startNetworkClient(const string &serverAddress, unsigned serverPort, bool ipv6, bool sctp) { if (myNetClient || !myGui) { @@ -204,7 +203,6 @@ void Session::startNetworkClient(const string &serverAddress, unsigned serverPor sctp, "", // no avatar server myConfig->readConfigString("MyName"), - pwd, myConfig->readConfigString("MyAvatar"), myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir"))); myNetClient->Run(); @@ -232,7 +230,6 @@ void Session::startNetworkClientForLocalServer(const GameData &gameData) myConfig->readConfigInt("ServerUseSctp") == 1, "", // no avatar server myConfig->readConfigString("MyName"), - myConfig->readConfigString("ServerPassword"), myConfig->readConfigString("MyAvatar"), myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir"))); myNetClient->Run(); diff --git a/src/session.h b/src/session.h index 3de165b6..05a375e8 100755 --- a/src/session.h +++ b/src/session.h @@ -63,7 +63,7 @@ public: boost::shared_ptr getAvatarManager(); void startInternetClient(); - void startNetworkClient(const std::string &serverAddress, unsigned serverPort, bool ipv6, bool sctp, const std::string &pwd); + void startNetworkClient(const std::string &serverAddress, unsigned serverPort, bool ipv6, bool sctp); void startNetworkClientForLocalServer(const GameData &gameData); void terminateNetworkClient(); void clientCreateGame(const GameData &gameData, const std::string &name, const std::string &password);