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 -2
View File
@@ -28,7 +28,7 @@
#define PS_PROTOCOL_MAGIC 0x5073013f // 'P', 's', 0x01, '?'
#define PS_PROTOCOL_MAGIC_RESPONSE 0x50630121 // 'P', 'c', 0x01, '!'
#define PS_PROTOCOL_VERSION 0x01010016 // Arbitrary protocol
#define PS_PROTOCOL_VERSION 0x01010017 // Arbitrary protocol
#define PS_DEFAULT_PORT 0x5073 // 'P', 's'
// Set when lobby authentication is required. Used in the SrvHandshakeResponseMessage.
@@ -122,12 +122,13 @@ END_NMT_CLASS()
START_NMT_CLASS_(Authenticate, NMT_AUTHENTICATE)
NMT_FIELD(CStrW, m_Name)
NMT_FIELD_SECRET(CStr, m_Password)
NMT_FIELD_INT(m_IsLocalClient, u8, 1)
NMT_FIELD_SECRET(CStr, m_ControllerSecret)
END_NMT_CLASS()
START_NMT_CLASS_(AuthenticateResult, NMT_AUTHENTICATE_RESULT)
NMT_FIELD_INT(m_Code, u32, 4)
NMT_FIELD_INT(m_HostID, u32, 2)
NMT_FIELD_INT(m_IsController, u8, 1)
NMT_FIELD(CStrW, m_Message)
END_NMT_CLASS()