complete password protected servers

closes #2290
This commit is contained in:
Matthias Mailänder
2013-10-05 13:02:47 +02:00
parent a6cdcea414
commit b618fc7cc2
17 changed files with 229 additions and 81 deletions

View File

@@ -49,9 +49,9 @@ namespace OpenRA
public static Renderer Renderer;
public static bool HasInputFocus = false;
public static void JoinServer(string host, int port)
public static void JoinServer(string host, int port, string password)
{
JoinInner(new OrderManager(host, port,
JoinInner(new OrderManager(host, port, password,
new ReplayRecorderConnection(new NetworkConnection(host, port), ChooseReplayFilename)));
}
@@ -70,12 +70,12 @@ namespace OpenRA
public static void JoinReplay(string replayFile)
{
JoinInner(new OrderManager("<no server>", -1, new ReplayConnection(replayFile)));
JoinInner(new OrderManager("<no server>", -1, "", new ReplayConnection(replayFile)));
}
static void JoinLocal()
{
JoinInner(new OrderManager("<no server>", -1, new EchoConnection()));
JoinInner(new OrderManager("<no server>", -1, "", new EchoConnection()));
}
public static int RenderFrame = 0;

View File

@@ -28,6 +28,7 @@ namespace OpenRA.GameRules
public int ListenPort = 1234;
public int ExternalPort = 1234;
public bool AdvertiseOnline = true;
public string Password = "";
public string MasterServer = "http://master.open-ra.org/";
public bool DiscoverNatDevices = false; // Allow users to disable NAT discovery if problems occur
public bool AllowPortForward = true; // let the user disable it even if compatible devices are found
@@ -51,6 +52,7 @@ namespace OpenRA.GameRules
ListenPort = other.ListenPort;
ExternalPort = other.ExternalPort;
AdvertiseOnline = other.AdvertiseOnline;
Password = other.Password;
MasterServer = other.MasterServer;
DiscoverNatDevices = other.DiscoverNatDevices;
AllowPortForward = other.AllowPortForward;

View File

@@ -135,7 +135,7 @@ namespace OpenRA.Network
{
var len = reader.ReadInt32();
var client = reader.ReadInt32();
var buf = reader.ReadBytes( len );
var buf = reader.ReadBytes(len);
if (len == 0)
throw new NotImplementedException();
lock (this)

View File

@@ -27,8 +27,10 @@ namespace OpenRA.Network
public readonly string Host;
public readonly int Port;
public readonly string Password = "";
public string ServerError = "Server is not responding.";
public string ServerError = "Server is not responding";
public bool AuthenticationFailed = false;
public int NetFrameNumber { get; private set; }
public int LocalFrameNumber;
@@ -52,10 +54,11 @@ namespace OpenRA.Network
Connection.Send(i, new List<byte[]>());
}
public OrderManager(string host, int port, IConnection conn)
public OrderManager(string host, int port, string password, IConnection conn)
{
this.Host = host;
this.Port = port;
Host = host;
Port = port;
Password = password;
Connection = conn;
syncReport = new SyncReport(this);
}

14
OpenRA.Game/Network/UnitOrders.cs Executable file → Normal file
View File

@@ -51,9 +51,11 @@ namespace OpenRA.Network
Game.AddChatLine(Color.White, "(player {0})".F(clientId), order.TargetString);
break;
}
case "Message": // Server message
Game.AddChatLine(Color.White, "Server", order.TargetString);
break;
case "Disconnected": /* reports that the target player disconnected */
{
var client = orderManager.LobbyInfo.ClientWithIndex(clientId);
@@ -146,7 +148,7 @@ namespace OpenRA.Network
{
Client = info,
Mods = localMods,
Password = "Foo"
Password = orderManager.Password
};
orderManager.IssueOrder(Order.HandshakeResponse(response.Serialize()));
@@ -156,6 +158,14 @@ namespace OpenRA.Network
case "ServerError":
{
orderManager.ServerError = order.TargetString;
orderManager.AuthenticationFailed = false;
break;
}
case "AuthenticationError":
{
orderManager.ServerError = order.TargetString;
orderManager.AuthenticationFailed = true;
break;
}
@@ -195,11 +205,13 @@ namespace OpenRA.Network
break;
}
case "Ping":
{
orderManager.IssueOrder(Order.Pong(order.TargetString));
break;
}
default:
{
if (!order.IsImmediate)

View File

@@ -239,6 +239,14 @@ namespace OpenRA.Server
var handshake = HandshakeResponse.Deserialize(data);
if (!string.IsNullOrEmpty(Settings.Password) && handshake.Password != Settings.Password)
{
var message = string.IsNullOrEmpty(handshake.Password) ? "Server requires a password" : "Incorrect password";
SendOrderTo(newConn, "AuthenticationError", message);
DropClient(newConn);
return;
}
var client = new Session.Client()
{
Name = handshake.Client.Name,
@@ -270,7 +278,7 @@ namespace OpenRA.Server
Log.Write("server", "Rejected connection from {0}; mods do not match.",
newConn.socket.RemoteEndPoint);
SendOrderTo(newConn, "ServerError", "Your mods don't match the server");
SendOrderTo(newConn, "ServerError", "Server is running an incompatible mod");
DropClient(newConn);
return;
}
@@ -283,7 +291,7 @@ namespace OpenRA.Server
Log.Write("server", "Rejected connection from {0}; Not running the same version.",
newConn.socket.RemoteEndPoint);
SendOrderTo(newConn, "ServerError", "Not running the same version.");
SendOrderTo(newConn, "ServerError", "Server is running an incompatible version");
DropClient(newConn);
return;
}
@@ -293,7 +301,7 @@ namespace OpenRA.Server
if (bans.Contains(client.IpAddress))
{
Log.Write("server", "Rejected connection from {0}; Banned.", newConn.socket.RemoteEndPoint);
SendOrderTo(newConn, "ServerError", "You are {0} from the server.".F(Settings.Ban.Contains(client.IpAddress) ? "banned" : "temporarily banned"));
SendOrderTo(newConn, "ServerError", "You have been {0} from the server".F(Settings.Ban.Contains(client.IpAddress) ? "banned" : "temporarily banned"));
DropClient(newConn);
return;
}