Prevent handshake spoofing of Client data.

This commit is contained in:
Paul Chote
2013-06-29 11:05:08 +12:00
parent 6cd69f5c05
commit 79779d69ba

View File

@@ -236,7 +236,25 @@ namespace OpenRA.Server
} }
var handshake = HandshakeResponse.Deserialize(data); var handshake = HandshakeResponse.Deserialize(data);
var client = handshake.Client;
var client = new Session.Client()
{
Name = handshake.Client.Name,
IpAddress = ((IPEndPoint)newConn.socket.RemoteEndPoint).Address.ToString(),
Index = newConn.PlayerIndex,
Slot = lobbyInfo.FirstEmptySlot(),
PreferredColor = handshake.Client.Color,
Color = handshake.Client.Color,
Country = "random",
SpawnPoint = 0,
Team = 0,
State = Session.ClientState.NotReady,
IsAdmin = !lobbyInfo.Clients.Any(c1 => c1.IsAdmin)
};
if (client.Slot != null)
SyncClientToPlayerReference(client, Map.Players[client.Slot]);
var mods = handshake.Mods; var mods = handshake.Mods;
// Check that the client has compatible mods // Check that the client has compatible mods
@@ -267,8 +285,6 @@ namespace OpenRA.Server
return; return;
} }
client.IpAddress = ((IPEndPoint)newConn.socket.RemoteEndPoint).Address.ToString();
// Check if IP is banned // Check if IP is banned
if (lobbyInfo.GlobalSettings.Ban != null) if (lobbyInfo.GlobalSettings.Ban != null)
{ {
@@ -287,21 +303,8 @@ namespace OpenRA.Server
// Promote connection to a valid client // Promote connection to a valid client
preConns.Remove(newConn); preConns.Remove(newConn);
conns.Add(newConn); conns.Add(newConn);
// Enforce correct PlayerIndex and Slot
client.Index = newConn.PlayerIndex;
client.Slot = lobbyInfo.FirstEmptySlot();
if (client.Slot != null)
SyncClientToPlayerReference(client, Map.Players[client.Slot]);
lobbyInfo.Clients.Add(client); lobbyInfo.Clients.Add(client);
// Promote to admin if this is the first client
var clientAdmin = lobbyInfo.Clients.Where(c1 => c1.IsAdmin).FirstOrDefault() ?? client;
if (clientAdmin == client)
client.IsAdmin = true;
Log.Write("server", "Client {0}: Accepted connection from {1}.", Log.Write("server", "Client {0}: Accepted connection from {1}.",
newConn.PlayerIndex, newConn.socket.RemoteEndPoint); newConn.PlayerIndex, newConn.socket.RemoteEndPoint);
@@ -320,12 +323,6 @@ namespace OpenRA.Server
SendOrderTo(newConn, "Message", motd); SendOrderTo(newConn, "Message", motd);
} }
if (lobbyInfo.GlobalSettings.Dedicated)
{
var message = client.IsAdmin ? "You are the server admin." : "{0} is the server admin.".F(clientAdmin.Name);
SendOrderTo(newConn, "Message", message);
}
if (mods.Any(m => m.Contains("{DEV_VERSION}"))) if (mods.Any(m => m.Contains("{DEV_VERSION}")))
SendMessage("{0} is running an unversioned development build, ".F(client.Name) + SendMessage("{0} is running an unversioned development build, ".F(client.Name) +
"and may desynchronize the game state if they have incompatible rules."); "and may desynchronize the game state if they have incompatible rules.");