Netcode: Identify controller client via a secret key

The 'controller' of an MP game (the host in general, though dedicated
servers would change that) is currently whoever first tells the server
that it is. This can be abused since it relies on trusting the clients.

This changes that logic: the server defines a 'controller secret', and
the first client to sent the correct controller secret is the
controller. This is safe assuming the secret is unknowable enough (the
current solution wouldn't pass strict cryptography tests, but it's
likely good enough).

Reverts 1a3fb29ff3, which introduced the 'trust the clients' mechanic,
as a change over 'the first local IP is controller'.

Necessary step towards dedicated server, if we want to use the regular
gamesetup (Refs #3556)

Differential Revision: https://code.wildfiregames.com/D3075
This was SVN commit r24952.
This commit is contained in:
wraitii
2021-02-27 17:44:59 +00:00
parent 32c3f4fb90
commit 113fefeeb7
14 changed files with 110 additions and 73 deletions
+3 -17
View File
@@ -33,7 +33,7 @@ constexpr int CHANNEL_COUNT = 1;
CNetClientSession::CNetClientSession(CNetClient& client) :
m_Client(client), m_FileTransferer(this), m_Host(nullptr), m_Server(nullptr),
m_Stats(nullptr), m_IsLocalClient(false), m_IncomingMessages(16), m_OutgoingMessages(16),
m_Stats(nullptr), m_IncomingMessages(16), m_OutgoingMessages(16),
m_LoopRunning(false), m_ShouldShutdown(false), m_MeanRTT(0), m_LastReceivedTime(0)
{
}
@@ -55,7 +55,7 @@ CNetClientSession::~CNetClientSession()
}
}
bool CNetClientSession::Connect(const CStr& server, const u16 port, const bool isLocalClient, ENetHost* enetClient)
bool CNetClientSession::Connect(const CStr& server, const u16 port, ENetHost* enetClient)
{
ENSURE(!m_LoopRunning);
ENSURE(!m_Host);
@@ -84,7 +84,6 @@ bool CNetClientSession::Connect(const CStr& server, const u16 port, const bool i
m_Host = host;
m_Server = peer;
m_IsLocalClient = isLocalClient;
m_Stats = new CNetStatsTable(m_Server);
if (CProfileViewer::IsInitialised())
@@ -236,7 +235,7 @@ u32 CNetClientSession::GetMeanRTT() const
}
CNetServerSession::CNetServerSession(CNetServerWorker& server, ENetPeer* peer) :
m_Server(server), m_FileTransferer(this), m_Peer(peer), m_IsLocalClient(false), m_HostID(0), m_GUID(), m_UserName()
m_Server(server), m_FileTransferer(this), m_Peer(peer), m_HostID(0), m_GUID(), m_UserName()
{
}
@@ -283,16 +282,3 @@ bool CNetServerSession::SendMessage(const CNetMessage* message)
{
return m_Server.SendMessage(m_Peer, message);
}
bool CNetServerSession::IsLocalClient() const
{
return m_IsLocalClient;
}
void CNetServerSession::SetLocalClient(bool isLocalClient)
{
m_IsLocalClient = isLocalClient;
if (!isLocalClient)
return;
}