Adding enhancement #76 (server password). The server password is checked during init, in addition to possible player auth. It can be set as option "ServerPassword" in config.xml, on client and server.

This commit is contained in:
lotodore
2011-10-20 21:19:58 +00:00
parent 2f588ffed7
commit ddf2ca784b
7 changed files with 40 additions and 3 deletions
+1 -2
View File
@@ -48,7 +48,7 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly)
myConfigState = OK; myConfigState = OK;
// !!!! Revisionsnummer der Configdefaults !!!!! // !!!! Revisionsnummer der Configdefaults !!!!!
configRev = 92; configRev = 93;
//standard defaults //standard defaults
logOnOffDefault = "1"; 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("InternetServerListAddress", CONFIG_TYPE_STRING, "pokerth.net/serverlist.xml.z"));
configList.push_back(ConfigInfo("InternetServerAddress", CONFIG_TYPE_STRING, "pokerth.6dns.org")); configList.push_back(ConfigInfo("InternetServerAddress", CONFIG_TYPE_STRING, "pokerth.6dns.org"));
configList.push_back(ConfigInfo("InternetServerPort", CONFIG_TYPE_INT, "7234")); 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("InternetServerUseIpv6", CONFIG_TYPE_INT, "0"));
configList.push_back(ConfigInfo("InternetServerUseSctp", CONFIG_TYPE_INT, "0")); configList.push_back(ConfigInfo("InternetServerUseSctp", CONFIG_TYPE_INT, "0"));
configList.push_back(ConfigInfo("UseAvatarServer", CONFIG_TYPE_INT, "0")); configList.push_back(ConfigInfo("UseAvatarServer", CONFIG_TYPE_INT, "0"));
+7
View File
@@ -55,6 +55,12 @@ public:
void SetServerAddr(const std::string &serverAddr) { void SetServerAddr(const std::string &serverAddr) {
m_serverAddr = 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 { const std::string &GetServerListUrl() const {
return m_serverListUrl; return m_serverListUrl;
} }
@@ -134,6 +140,7 @@ private:
bool m_sctp; bool m_sctp;
int m_addrFamily; int m_addrFamily;
std::string m_serverAddr; std::string m_serverAddr;
std::string m_serverPassword;
std::string m_serverListUrl; std::string m_serverListUrl;
bool m_useServerList; bool m_useServerList;
unsigned m_serverPort; unsigned m_serverPort;
+1
View File
@@ -56,6 +56,7 @@ public:
void Init( void Init(
const std::string &serverAddress, const std::string &serverAddress,
const std::string &serverListUrl, const std::string &serverListUrl,
const std::string &serverPassword,
bool useServerList, bool useServerList,
unsigned serverPort, unsigned serverPort,
bool ipv6, bool ipv6,
+17 -1
View File
@@ -944,6 +944,14 @@ ClientStateStartSession::InternalHandlePacket(boost::shared_ptr<ClientThread> cl
InitMessage_t *netInit = &init->GetMsg()->choice.initMessage; InitMessage_t *netInit = &init->GetMsg()->choice.initMessage;
netInit->requestedVersion.major = NET_VERSION_MAJOR; netInit->requestedVersion.major = NET_VERSION_MAJOR;
netInit->requestedVersion.minor = NET_VERSION_MINOR; 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; netInit->login.present = login_PR_unauthenticatedLogin;
UnauthenticatedLogin_t *noauthLogin = &netInit->login.choice.unauthenticatedLogin; UnauthenticatedLogin_t *noauthLogin = &netInit->login.choice.unauthenticatedLogin;
OCTET_STRING_fromBuf(&noauthLogin->nickName, OCTET_STRING_fromBuf(&noauthLogin->nickName,
@@ -953,7 +961,7 @@ ClientStateStartSession::InternalHandlePacket(boost::shared_ptr<ClientThread> cl
if (!avatarFile.empty()) { if (!avatarFile.empty()) {
MD5Buf tmpMD5; MD5Buf tmpMD5;
if (client->GetAvatarManager().GetHashForAvatar(avatarFile, tmpMD5)) { if (client->GetAvatarManager().GetHashForAvatar(avatarFile, tmpMD5)) {
// TODO: use sha1. // Send MD5 hash of avatar.
noauthLogin->avatar = noauthLogin->avatar =
OCTET_STRING_new_fromBuf( OCTET_STRING_new_fromBuf(
&asn_DEF_OCTET_STRING, &asn_DEF_OCTET_STRING,
@@ -1019,6 +1027,14 @@ ClientStateWaitEnterLogin::TimerLoop(const boost::system::error_code& ec, boost:
context.GetSessionGuid().c_str(), context.GetSessionGuid().c_str(),
(int)context.GetSessionGuid().length()); (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); context.SetPlayerName(loginData.userName);
+2
View File
@@ -68,6 +68,7 @@ ClientThread::~ClientThread()
void void
ClientThread::Init( ClientThread::Init(
const string &serverAddress, const string &serverListUrl, const string &serverAddress, const string &serverListUrl,
const string &serverPassword,
bool useServerList, unsigned serverPort, bool ipv6, bool sctp, bool useServerList, unsigned serverPort, bool ipv6, bool sctp,
const string &avatarServerAddress, const string &playerName, const string &avatarServerAddress, const string &playerName,
const string &avatarFile, const string &cacheDir) const string &avatarFile, const string &cacheDir)
@@ -83,6 +84,7 @@ ClientThread::Init(
context.SetAddrFamily(ipv6 ? AF_INET6 : AF_INET); context.SetAddrFamily(ipv6 ? AF_INET6 : AF_INET);
context.SetServerAddr(serverAddress); context.SetServerAddr(serverAddress);
context.SetServerListUrl(serverListUrl); context.SetServerListUrl(serverListUrl);
context.SetServerPassword(serverPassword);
context.SetUseServerList(useServerList); context.SetUseServerList(useServerList);
context.SetServerPort(serverPort); context.SetServerPort(serverPort);
context.SetAvatarServerAddr(avatarServerAddress); context.SetAvatarServerAddr(avatarServerAddress);
+9
View File
@@ -959,6 +959,15 @@ ServerLobbyThread::HandleNetPacketInit(boost::shared_ptr<SessionData> session, c
SessionError(session, ERR_NET_VERSION_NOT_SUPPORTED); SessionError(session, ERR_NET_VERSION_NOT_SUPPORTED);
return; 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; string playerName;
MD5Buf avatarMD5; MD5Buf avatarMD5;
+3
View File
@@ -175,6 +175,7 @@ void Session::startInternetClient()
myNetClient->Init( myNetClient->Init(
myConfig->readConfigString("InternetServerAddress"), myConfig->readConfigString("InternetServerAddress"),
myConfig->readConfigString("InternetServerListAddress"), myConfig->readConfigString("InternetServerListAddress"),
myConfig->readConfigString("ServerPassword"),
myConfig->readConfigInt("InternetServerConfigMode") == 0, myConfig->readConfigInt("InternetServerConfigMode") == 0,
myConfig->readConfigInt("InternetServerPort"), myConfig->readConfigInt("InternetServerPort"),
myConfig->readConfigInt("InternetServerUseIpv6") == 1, myConfig->readConfigInt("InternetServerUseIpv6") == 1,
@@ -198,6 +199,7 @@ void Session::startNetworkClient(const string &serverAddress, unsigned serverPor
myNetClient->Init( myNetClient->Init(
serverAddress, serverAddress,
"", "",
myConfig->readConfigString("ServerPassword"),
false, false,
serverPort, serverPort,
ipv6, ipv6,
@@ -227,6 +229,7 @@ void Session::startNetworkClientForLocalServer(const GameData &gameData)
myNetClient->Init( myNetClient->Init(
loopbackAddr, loopbackAddr,
"", "",
myConfig->readConfigString("ServerPassword"),
false, false,
myConfig->readConfigInt("ServerPort"), myConfig->readConfigInt("ServerPort"),
useIpv6, useIpv6,