Add banlist (Server.Ban settings item) support to game servers

This commit is contained in:
Igor Popov
2012-05-26 16:31:14 +04:00
committed by Chris Forbes
parent 1bb1e00a0d
commit 3f0fafb380
3 changed files with 22 additions and 0 deletions

View File

@@ -31,6 +31,7 @@ namespace OpenRA.GameRules
public string MasterServer = "http://master.open-ra.org/"; public string MasterServer = "http://master.open-ra.org/";
public bool AllowCheats = false; public bool AllowCheats = false;
public string Map = null; public string Map = null;
public string[] Ban = null;
public ServerSettings() { } public ServerSettings() { }
@@ -43,6 +44,7 @@ namespace OpenRA.GameRules
MasterServer = other.MasterServer; MasterServer = other.MasterServer;
AllowCheats = other.AllowCheats; AllowCheats = other.AllowCheats;
Map = other.Map; Map = other.Map;
Ban = other.Ban;
} }
} }

View File

@@ -70,6 +70,7 @@ namespace OpenRA.Network
{ {
public string ServerName; public string ServerName;
public string Map; public string Map;
public string[] Ban;
public string[] Mods = { "ra" }; // mod names public string[] Mods = { "ra" }; // mod names
public int OrderLatency = 3; public int OrderLatency = 3;
public int RandomSeed = 0; public int RandomSeed = 0;

View File

@@ -71,6 +71,7 @@ namespace OpenRA.Server
lobbyInfo.GlobalSettings.RandomSeed = randomSeed; lobbyInfo.GlobalSettings.RandomSeed = randomSeed;
lobbyInfo.GlobalSettings.Map = settings.Map; lobbyInfo.GlobalSettings.Map = settings.Map;
lobbyInfo.GlobalSettings.ServerName = settings.Name; lobbyInfo.GlobalSettings.ServerName = settings.Name;
lobbyInfo.GlobalSettings.Ban = settings.Ban;
foreach (var t in ServerTraits.WithInterface<INotifyServerStart>()) foreach (var t in ServerTraits.WithInterface<INotifyServerStart>())
t.ServerStarted(this); t.ServerStarted(this);
@@ -205,6 +206,21 @@ namespace OpenRA.Server
return; return;
} }
// Check if IP is banned
if (lobbyInfo.GlobalSettings.Ban != null)
{
var remote_addr = ((IPEndPoint)newConn.socket.RemoteEndPoint).Address.ToString();
if (lobbyInfo.GlobalSettings.Ban.Contains(remote_addr))
{
Console.WriteLine("Rejected connection from "+client.Name+"("+newConn.socket.RemoteEndPoint+"); Banned.");
Log.Write("server", "Rejected connection from {0}; Banned.",
newConn.socket.RemoteEndPoint);
SendOrderTo(newConn, "ServerError", "You are banned from the server!");
DropClient(newConn);
return;
}
}
// Promote connection to a valid client // Promote connection to a valid client
preConns.Remove(newConn); preConns.Remove(newConn);
conns.Add(newConn); conns.Add(newConn);
@@ -406,6 +422,9 @@ namespace OpenRA.Server
public void StartGame() public void StartGame()
{ {
GameStarted = true; GameStarted = true;
listener.Stop();
Console.WriteLine("Game started");
foreach( var c in conns ) foreach( var c in conns )
foreach( var d in conns ) foreach( var d in conns )
DispatchOrdersToClient( c, d.PlayerIndex, 0x7FFFFFFF, new byte[] { 0xBF } ); DispatchOrdersToClient( c, d.PlayerIndex, 0x7FFFFFFF, new byte[] { 0xBF } );