diff --git a/src/config/configfile.cpp b/src/config/configfile.cpp index 5f0ac8e7..0bdb5741 100644 --- a/src/config/configfile.cpp +++ b/src/config/configfile.cpp @@ -48,7 +48,7 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly) myConfigState = OK; // !!!! Revisionsnummer der Configdefaults !!!!! - configRev = 92; + configRev = 93; //standard defaults logOnOffDefault = "1"; @@ -206,7 +206,6 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly) configList.push_back(ConfigInfo("InternetServerListAddress", CONFIG_TYPE_STRING, "pokerth.net/serverlist.xml.z")); configList.push_back(ConfigInfo("InternetServerAddress", CONFIG_TYPE_STRING, "pokerth.6dns.org")); configList.push_back(ConfigInfo("InternetServerPort", CONFIG_TYPE_INT, "7234")); - configList.push_back(ConfigInfo("InternetServerPassword", CONFIG_TYPE_STRING, "")); configList.push_back(ConfigInfo("InternetServerUseIpv6", CONFIG_TYPE_INT, "0")); configList.push_back(ConfigInfo("InternetServerUseSctp", CONFIG_TYPE_INT, "0")); configList.push_back(ConfigInfo("UseAvatarServer", CONFIG_TYPE_INT, "0")); diff --git a/src/net/clientcontext.h b/src/net/clientcontext.h index 282d2616..84e10aa1 100644 --- a/src/net/clientcontext.h +++ b/src/net/clientcontext.h @@ -55,6 +55,12 @@ public: void SetServerAddr(const std::string &serverAddr) { m_serverAddr = serverAddr; } + const std::string &GetServerPassword() const { + return m_serverPassword; + } + void SetServerPassword(const std::string &serverPassword) { + m_serverPassword = serverPassword; + } const std::string &GetServerListUrl() const { return m_serverListUrl; } @@ -134,6 +140,7 @@ private: bool m_sctp; int m_addrFamily; std::string m_serverAddr; + std::string m_serverPassword; std::string m_serverListUrl; bool m_useServerList; unsigned m_serverPort; diff --git a/src/net/clientthread.h b/src/net/clientthread.h index 468da139..bf5e7b73 100644 --- a/src/net/clientthread.h +++ b/src/net/clientthread.h @@ -56,6 +56,7 @@ public: void Init( const std::string &serverAddress, const std::string &serverListUrl, + const std::string &serverPassword, bool useServerList, unsigned serverPort, bool ipv6, diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 3e011772..53fdd66c 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -944,6 +944,14 @@ ClientStateStartSession::InternalHandlePacket(boost::shared_ptr cl InitMessage_t *netInit = &init->GetMsg()->choice.initMessage; netInit->requestedVersion.major = NET_VERSION_MAJOR; netInit->requestedVersion.minor = NET_VERSION_MINOR; + if (!context.GetServerPassword().empty()) + { + netInit->authServerPassword = + OCTET_STRING_new_fromBuf( + &asn_DEF_OCTET_STRING, + context.GetServerPassword().c_str(), + context.GetServerPassword().length()); + } netInit->login.present = login_PR_unauthenticatedLogin; UnauthenticatedLogin_t *noauthLogin = &netInit->login.choice.unauthenticatedLogin; OCTET_STRING_fromBuf(&noauthLogin->nickName, @@ -953,7 +961,7 @@ ClientStateStartSession::InternalHandlePacket(boost::shared_ptr cl if (!avatarFile.empty()) { MD5Buf tmpMD5; if (client->GetAvatarManager().GetHashForAvatar(avatarFile, tmpMD5)) { - // TODO: use sha1. + // Send MD5 hash of avatar. noauthLogin->avatar = OCTET_STRING_new_fromBuf( &asn_DEF_OCTET_STRING, @@ -1019,6 +1027,14 @@ ClientStateWaitEnterLogin::TimerLoop(const boost::system::error_code& ec, boost: context.GetSessionGuid().c_str(), (int)context.GetSessionGuid().length()); } + if (!context.GetServerPassword().empty()) + { + netInit->authServerPassword = + OCTET_STRING_new_fromBuf( + &asn_DEF_OCTET_STRING, + context.GetServerPassword().c_str(), + context.GetServerPassword().length()); + } context.SetPlayerName(loginData.userName); diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index 400f98f8..5f298a5b 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -68,6 +68,7 @@ ClientThread::~ClientThread() void ClientThread::Init( const string &serverAddress, const string &serverListUrl, + const string &serverPassword, bool useServerList, unsigned serverPort, bool ipv6, bool sctp, const string &avatarServerAddress, const string &playerName, const string &avatarFile, const string &cacheDir) @@ -83,6 +84,7 @@ ClientThread::Init( context.SetAddrFamily(ipv6 ? AF_INET6 : AF_INET); context.SetServerAddr(serverAddress); context.SetServerListUrl(serverListUrl); + context.SetServerPassword(serverPassword); context.SetUseServerList(useServerList); context.SetServerPort(serverPort); context.SetAvatarServerAddr(avatarServerAddress); diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 8f656991..bcabeca1 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -959,6 +959,15 @@ ServerLobbyThread::HandleNetPacketInit(boost::shared_ptr session, c SessionError(session, ERR_NET_VERSION_NOT_SUPPORTED); return; } + // Check (clear text) server password. + string serverPassword; + if (initMessage.authServerPassword) { + serverPassword = STL_STRING_FROM_OCTET_STRING(*initMessage.authServerPassword); + } + if (serverPassword != m_serverConfig.readConfigString("ServerPassword")) { + SessionError(session, ERR_NET_INVALID_PASSWORD); + return; + } string playerName; MD5Buf avatarMD5; diff --git a/src/session.cpp b/src/session.cpp index 29117e92..dbcf5c25 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -175,6 +175,7 @@ void Session::startInternetClient() myNetClient->Init( myConfig->readConfigString("InternetServerAddress"), myConfig->readConfigString("InternetServerListAddress"), + myConfig->readConfigString("ServerPassword"), myConfig->readConfigInt("InternetServerConfigMode") == 0, myConfig->readConfigInt("InternetServerPort"), myConfig->readConfigInt("InternetServerUseIpv6") == 1, @@ -198,6 +199,7 @@ void Session::startNetworkClient(const string &serverAddress, unsigned serverPor myNetClient->Init( serverAddress, "", + myConfig->readConfigString("ServerPassword"), false, serverPort, ipv6, @@ -227,6 +229,7 @@ void Session::startNetworkClientForLocalServer(const GameData &gameData) myNetClient->Init( loopbackAddr, "", + myConfig->readConfigString("ServerPassword"), false, myConfig->readConfigInt("ServerPort"), useIpv6,