From 48c4c69277858cd60e5ec3c190865c3d1fe89aaa Mon Sep 17 00:00:00 2001 From: lotodore Date: Sat, 26 Sep 2009 16:05:35 +0000 Subject: [PATCH] Integrating authentication - now all authentication attempts fail (still work in progress). --- src/core/openssl_wrapper.h | 2 +- src/net/common/clientstate.cpp | 11 +++++++---- src/net/common/serveraccepthelper.cpp | 4 ++-- src/net/common/serverlobbythread.cpp | 5 +++-- src/net/common/servermanager.cpp | 4 ++-- src/net/common/sessionmanager.cpp | 4 ++-- src/net/serveraccepthelper.h | 2 +- src/net/sessionmanager.h | 2 +- 8 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/core/openssl_wrapper.h b/src/core/openssl_wrapper.h index 7a58124e..b1aefac5 100644 --- a/src/core/openssl_wrapper.h +++ b/src/core/openssl_wrapper.h @@ -46,7 +46,7 @@ // "2. Can I use OpenSSL with GPL software?" // http://www.openssl.org/support/faq.html#LEGAL2 // -#if defined(__APPLE__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) +#if defined (_WIN32) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) #define HAVE_OPENSSL #endif diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 818dff1c..c5b7b7f6 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -674,11 +674,14 @@ ClientStateStartSession::Enter(boost::shared_ptr 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_anonymousLogin; - AnonymousLogin_t *anonLogin = &netInit->login.choice.anonymousLogin; - OCTET_STRING_fromBuf(&anonLogin->playerName, + netInit->login.present = login_PR_authenticatedLogin; + AuthenticatedLogin_t *authLogin = &netInit->login.choice.authenticatedLogin; + OCTET_STRING_fromBuf(&authLogin->playerName, context.GetPlayerName().c_str(), context.GetPlayerName().length()); + OCTET_STRING_fromBuf(&authLogin->password, + context.GetPassword().c_str(), + context.GetPassword().length()); //context.GetPassword(); string avatarFile = client->GetQtToolsInterface().stringFromUtf8(context.GetAvatarFile()); if (!avatarFile.empty()) @@ -687,7 +690,7 @@ ClientStateStartSession::Enter(boost::shared_ptr client) if (client->GetAvatarManager().GetHashForAvatar(avatarFile, tmpMD5)) { // TODO: use sha1. - anonLogin->avatar = + authLogin->avatar = OCTET_STRING_new_fromBuf( &asn_DEF_OCTET_STRING, (const char *)tmpMD5.data, diff --git a/src/net/common/serveraccepthelper.cpp b/src/net/common/serveraccepthelper.cpp index 52e6f681..410b079e 100644 --- a/src/net/common/serveraccepthelper.cpp +++ b/src/net/common/serveraccepthelper.cpp @@ -38,7 +38,7 @@ ServerAcceptHelper::~ServerAcceptHelper() } void -ServerAcceptHelper::Listen(unsigned serverPort, bool ipv6, bool sctp, const string &pwd, const string &logDir, boost::shared_ptr lobbyThread) +ServerAcceptHelper::Listen(unsigned serverPort, bool ipv6, bool sctp, const string &/*logDir*/, boost::shared_ptr lobbyThread) { m_lobbyThread = lobbyThread; @@ -61,7 +61,7 @@ ServerAcceptHelper::Listen(unsigned serverPort, bool ipv6, bool sctp, const stri } void -ServerAcceptHelper::InternalListen(unsigned serverPort, bool ipv6, bool sctp) +ServerAcceptHelper::InternalListen(unsigned serverPort, bool ipv6, bool /*sctp*/) { if (serverPort < 1024) throw ServerException(__FILE__, __LINE__, ERR_SOCK_INVALID_PORT, 0); diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index a36831c1..2c8a2775 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -883,7 +883,7 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const InitMessage memcpy(avatarMD5.data, authLogin->avatar->buf, MD5_DATA_SIZE); } else - SessionError(session, ERR_NET_INVALID_PASSWORD); // TODO not yet supported + SessionError(session, ERR_NET_INVALID_PASSWORD); // Check the server password. /* if (!CheckPassword(initData.password)) @@ -1268,6 +1268,7 @@ ServerLobbyThread::AuthenticationSuccess(unsigned playerId, db_id dbPlayerId) void ServerLobbyThread::AuthenticationFailure(unsigned playerId) { + SessionError(m_sessionManager.GetSessionByUniquePlayerId(playerId, true), ERR_NET_INVALID_PASSWORD); } void @@ -1578,7 +1579,7 @@ ServerLobbyThread::InternalCheckSessionTimeouts(SessionWrapper session) void ServerLobbyThread::SessionError(SessionWrapper session, int errorCode) { - if (session.sessionData.get()) + if (session.sessionData) { SendError(session.sessionData, errorCode); CloseSession(session); diff --git a/src/net/common/servermanager.cpp b/src/net/common/servermanager.cpp index 244bebdc..bd193b79 100644 --- a/src/net/common/servermanager.cpp +++ b/src/net/common/servermanager.cpp @@ -55,13 +55,13 @@ ServerManager::Init(unsigned serverPort, bool ipv6, ServerNetworkMode mode, cons if (mode & NETWORK_MODE_TCP) { boost::shared_ptr tcpAcceptHelper(new ServerAcceptHelper(GetGui(), m_ioService)); - tcpAcceptHelper->Listen(serverPort, ipv6, false, pwd, logDir, m_lobbyThread); + tcpAcceptHelper->Listen(serverPort, ipv6, false, logDir, m_lobbyThread); m_acceptHelperPool.push_back(tcpAcceptHelper); } /* if (mode & NETWORK_MODE_SCTP) { boost::shared_ptr sctpAcceptHelper(new ServerAcceptHelper(GetGui(), m_ioService)); - sctpAcceptHelper->Listen(serverPort, ipv6, true, pwd, logDir, m_lobbyThread); + sctpAcceptHelper->Listen(serverPort, ipv6, true, logDir, m_lobbyThread); m_acceptHelperPool.push_back(sctpAcceptHelper); }*/ } diff --git a/src/net/common/sessionmanager.cpp b/src/net/common/sessionmanager.cpp index 28e8c4d4..5ae22a0d 100644 --- a/src/net/common/sessionmanager.cpp +++ b/src/net/common/sessionmanager.cpp @@ -121,7 +121,7 @@ SessionManager::GetSessionByPlayerName(const string playerName) const } SessionWrapper -SessionManager::GetSessionByUniquePlayerId(unsigned uniqueId) const +SessionManager::GetSessionByUniquePlayerId(unsigned uniqueId, bool preInitSessions) const { SessionWrapper tmpSession; boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex); @@ -132,7 +132,7 @@ SessionManager::GetSessionByUniquePlayerId(unsigned uniqueId) const while (session_i != session_end) { // Check all players which are fully connected. - if (session_i->second.sessionData->GetState() != SessionData::Init) + if (preInitSessions || session_i->second.sessionData->GetState() != SessionData::Init) { boost::shared_ptr tmpPlayer(session_i->second.playerData); if (!tmpPlayer.get()) diff --git a/src/net/serveraccepthelper.h b/src/net/serveraccepthelper.h index c4bd57bc..ef2a47b0 100644 --- a/src/net/serveraccepthelper.h +++ b/src/net/serveraccepthelper.h @@ -36,7 +36,7 @@ public: virtual ~ServerAcceptHelper(); // Set the parameters. - void Listen(unsigned serverPort, bool ipv6, bool sctp, const std::string &pwd, const std::string &logDir, + void Listen(unsigned serverPort, bool ipv6, bool sctp, const std::string &logDir, boost::shared_ptr lobbyThread); protected: diff --git a/src/net/sessionmanager.h b/src/net/sessionmanager.h index 0ffaab51..509356f7 100644 --- a/src/net/sessionmanager.h +++ b/src/net/sessionmanager.h @@ -55,7 +55,7 @@ public: SessionWrapper GetSessionById(SessionId id) const; SessionWrapper GetSessionByPlayerName(const std::string playerName) const; - SessionWrapper GetSessionByUniquePlayerId(unsigned uniqueId) const; + SessionWrapper GetSessionByUniquePlayerId(unsigned uniqueId, bool preInitSessions = false) const; PlayerDataList GetPlayerDataList() const; PlayerIdList GetPlayerIdList(SessionData::State state) const;