Remove public mutable state from Connection.

This commit is contained in:
Paul Chote
2021-05-05 22:47:36 +01:00
committed by reaperrr
parent dacacdf130
commit 7e79e69eae
2 changed files with 40 additions and 33 deletions

View File

@@ -374,20 +374,17 @@ namespace OpenRA.Server
return;
}
var newConn = new Connection { Socket = newSocket };
// Validate player identity by asking them to sign a random blob of data
// which we can then verify against the player public key database
var token = Convert.ToBase64String(OpenRA.Exts.MakeArray(256, _ => (byte)Random.Next()));
var newConn = new Connection(newSocket, ChooseFreePlayerIndex(), token);
try
{
newConn.Socket.Blocking = false;
newConn.Socket.NoDelay = true;
// Validate player identity by asking them to sign a random blob of data
// which we can then verify against the player public key database
var token = Convert.ToBase64String(OpenRA.Exts.MakeArray(256, _ => (byte)Random.Next()));
// Assign the player number.
newConn.PlayerIndex = ChooseFreePlayerIndex();
newConn.AuthToken = token;
// Send handshake and client index.
var ms = new MemoryStream(8);
ms.WriteArray(BitConverter.GetBytes(ProtocolVersion.Handshake));