Changeset View
Changeset View
Standalone View
Standalone View
source/network/NetServer.cpp
Show All 25 Lines | |||||
#include "NetStats.h" | #include "NetStats.h" | ||||
#include "lib/external_libraries/enet.h" | #include "lib/external_libraries/enet.h" | ||||
#include "lib/types.h" | #include "lib/types.h" | ||||
#include "network/StunClient.h" | #include "network/StunClient.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/ConfigDB.h" | #include "ps/ConfigDB.h" | ||||
#include "ps/GUID.h" | #include "ps/GUID.h" | ||||
#include "ps/Hashing.h" | |||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "ps/Threading.h" | #include "ps/Threading.h" | ||||
#include "scriptinterface/ScriptContext.h" | #include "scriptinterface/ScriptContext.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include "simulation2/system/TurnManager.h" | #include "simulation2/system/TurnManager.h" | ||||
#if CONFIG2_MINIUPNPC | #if CONFIG2_MINIUPNPC | ||||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | #endif | ||||
delete m_ServerTurnManager; | delete m_ServerTurnManager; | ||||
} | } | ||||
void CNetServerWorker::SetPassword(const CStr& hashedPassword) | void CNetServerWorker::SetPassword(const CStr& hashedPassword) | ||||
{ | { | ||||
m_Password = hashedPassword; | m_Password = hashedPassword; | ||||
} | } | ||||
bool CNetServerWorker::CheckPassword(const CStr& password, const std::string& username) const | |||||
{ | |||||
return HashPassword(m_Password, username) == password; | |||||
} | |||||
bool CNetServerWorker::SetupConnection(const u16 port) | bool CNetServerWorker::SetupConnection(const u16 port) | ||||
{ | { | ||||
ENSURE(m_State == SERVER_STATE_UNCONNECTED); | ENSURE(m_State == SERVER_STATE_UNCONNECTED); | ||||
ENSURE(!m_Host); | ENSURE(!m_Host); | ||||
// Bind to default host | // Bind to default host | ||||
ENetAddress addr; | ENetAddress addr; | ||||
addr.host = ENET_HOST_ANY; | addr.host = ENET_HOST_ANY; | ||||
▲ Show 20 Lines • Show All 783 Lines • ▼ Show 20 Lines | if (server.m_LobbyAuth && usernameWithoutRating.LowerCase() != session->GetUserName().LowerCase()) | ||||
LOGERROR("Net server: lobby auth: %s tried joining as %s", | LOGERROR("Net server: lobby auth: %s tried joining as %s", | ||||
session->GetUserName().ToUTF8(), | session->GetUserName().ToUTF8(), | ||||
usernameWithoutRating.ToUTF8()); | usernameWithoutRating.ToUTF8()); | ||||
session->Disconnect(NDR_LOBBY_AUTH_FAILED); | session->Disconnect(NDR_LOBBY_AUTH_FAILED); | ||||
return true; | return true; | ||||
} | } | ||||
// Check the password before anything else. | // Check the password before anything else. | ||||
if (server.m_Password != message->m_Password) | if (!server.CheckPassword(message->m_Password, username.ToUTF8())) | ||||
{ | { | ||||
// Noisy logerror because players are not supposed to be able to get the IP, | // Noisy logerror because players are not supposed to be able to get the IP, | ||||
// so this might be someone targeting the host for some reason | // so this might be someone targeting the host for some reason | ||||
// (or TODO a dedicated server and we do want to log anyways) | // (or TODO a dedicated server and we do want to log anyways) | ||||
LOGERROR("Net server: user %s tried joining with the wrong password", | LOGERROR("Net server: user %s tried joining with the wrong password", | ||||
session->GetUserName().ToUTF8()); | session->GetUserName().ToUTF8()); | ||||
session->Disconnect(NDR_SERVER_REFUSED); | session->Disconnect(NDR_SERVER_REFUSED); | ||||
return true; | return true; | ||||
▲ Show 20 Lines • Show All 630 Lines • ▼ Show 20 Lines | void CNetServer::SetConnectionData(const CStr& ip, const u16 port, bool useSTUN) | ||||
m_PublicIp = ip; | m_PublicIp = ip; | ||||
m_PublicPort = port; | m_PublicPort = port; | ||||
m_UseSTUN = useSTUN; | m_UseSTUN = useSTUN; | ||||
} | } | ||||
bool CNetServer::CheckPasswordAndIncrement(const CStr& password, const std::string& username) | bool CNetServer::CheckPasswordAndIncrement(const CStr& password, const std::string& username) | ||||
{ | { | ||||
std::unordered_map<std::string, int>::iterator it = m_FailedAttempts.find(username); | std::unordered_map<std::string, int>::iterator it = m_FailedAttempts.find(username); | ||||
if (m_Password == password) | if (m_Worker->CheckPassword(password, username)) | ||||
{ | { | ||||
if (it != m_FailedAttempts.end()) | if (it != m_FailedAttempts.end()) | ||||
it->second = 0; | it->second = 0; | ||||
return true; | return true; | ||||
} | } | ||||
if (it == m_FailedAttempts.end()) | if (it == m_FailedAttempts.end()) | ||||
m_FailedAttempts.emplace(username, 1); | m_FailedAttempts.emplace(username, 1); | ||||
else | else | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator