Remove public mutable state from Connection.
This commit is contained in:
@@ -19,21 +19,29 @@ namespace OpenRA.Server
|
||||
public class Connection
|
||||
{
|
||||
public const int MaxOrderLength = 131072;
|
||||
public Socket Socket;
|
||||
public List<byte> Data = new List<byte>();
|
||||
public ReceiveState State = ReceiveState.Header;
|
||||
public int ExpectLength = 8;
|
||||
public int Frame = 0;
|
||||
public int MostRecentFrame = 0;
|
||||
public bool Validated;
|
||||
|
||||
public readonly Socket Socket;
|
||||
public readonly List<byte> Data = new List<byte>();
|
||||
public readonly int PlayerIndex;
|
||||
public readonly string AuthToken;
|
||||
|
||||
public long TimeSinceLastResponse => Game.RunTime - lastReceivedTime;
|
||||
public bool TimeoutMessageShown = false;
|
||||
public int MostRecentFrame { get; private set; }
|
||||
|
||||
public bool TimeoutMessageShown;
|
||||
public bool Validated;
|
||||
|
||||
ReceiveState state = ReceiveState.Header;
|
||||
int expectLength = 8;
|
||||
int frame = 0;
|
||||
long lastReceivedTime = 0;
|
||||
|
||||
/* client data */
|
||||
public int PlayerIndex;
|
||||
public string AuthToken;
|
||||
public Connection(Socket socket, int playerIndex, string authToken)
|
||||
{
|
||||
Socket = socket;
|
||||
PlayerIndex = playerIndex;
|
||||
AuthToken = authToken;
|
||||
}
|
||||
|
||||
public byte[] PopBytes(int n)
|
||||
{
|
||||
@@ -85,21 +93,22 @@ namespace OpenRA.Server
|
||||
public void ReadData(Server server)
|
||||
{
|
||||
if (ReadDataInner(server))
|
||||
while (Data.Count >= ExpectLength)
|
||||
{
|
||||
while (Data.Count >= expectLength)
|
||||
{
|
||||
var bytes = PopBytes(ExpectLength);
|
||||
switch (State)
|
||||
var bytes = PopBytes(expectLength);
|
||||
switch (state)
|
||||
{
|
||||
case ReceiveState.Header:
|
||||
{
|
||||
ExpectLength = BitConverter.ToInt32(bytes, 0) - 4;
|
||||
Frame = BitConverter.ToInt32(bytes, 4);
|
||||
State = ReceiveState.Data;
|
||||
expectLength = BitConverter.ToInt32(bytes, 0) - 4;
|
||||
frame = BitConverter.ToInt32(bytes, 4);
|
||||
state = ReceiveState.Data;
|
||||
|
||||
if (ExpectLength < 0 || ExpectLength > MaxOrderLength)
|
||||
if (expectLength < 0 || expectLength > MaxOrderLength)
|
||||
{
|
||||
server.DropClient(this);
|
||||
Log.Write("server", "Dropping client {0} for excessive order length = {1}", PlayerIndex, ExpectLength);
|
||||
Log.Write("server", "Dropping client {0} for excessive order length = {1}", PlayerIndex, expectLength);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -108,17 +117,18 @@ namespace OpenRA.Server
|
||||
|
||||
case ReceiveState.Data:
|
||||
{
|
||||
if (MostRecentFrame < Frame)
|
||||
MostRecentFrame = Frame;
|
||||
if (MostRecentFrame < frame)
|
||||
MostRecentFrame = frame;
|
||||
|
||||
server.DispatchOrders(this, Frame, bytes);
|
||||
ExpectLength = 8;
|
||||
State = ReceiveState.Header;
|
||||
server.DispatchOrders(this, frame, bytes);
|
||||
expectLength = 8;
|
||||
state = ReceiveState.Header;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user