Remove Password and Endpoint from OrderManager
This commit is contained in:
@@ -66,8 +66,14 @@ namespace OpenRA
|
||||
if (recordReplay)
|
||||
connection.StartRecording(() => { return TimestampedFilename(); });
|
||||
|
||||
var om = new OrderManager(endpoint, password, connection);
|
||||
var om = new OrderManager(connection);
|
||||
JoinInner(om);
|
||||
CurrentServerSettings.Password = password;
|
||||
CurrentServerSettings.Target = endpoint;
|
||||
|
||||
lastConnectionState = ConnectionState.PreConnecting;
|
||||
ConnectionStateChanged(OrderManager, password, connection);
|
||||
|
||||
return om;
|
||||
}
|
||||
|
||||
@@ -81,18 +87,16 @@ namespace OpenRA
|
||||
{
|
||||
OrderManager?.Dispose();
|
||||
OrderManager = om;
|
||||
lastConnectionState = ConnectionState.PreConnecting;
|
||||
ConnectionStateChanged(OrderManager);
|
||||
}
|
||||
|
||||
public static void JoinReplay(string replayFile)
|
||||
{
|
||||
JoinInner(new OrderManager(new ConnectionTarget(), "", new ReplayConnection(replayFile)));
|
||||
JoinInner(new OrderManager(new ReplayConnection(replayFile)));
|
||||
}
|
||||
|
||||
static void JoinLocal()
|
||||
{
|
||||
JoinInner(new OrderManager(new ConnectionTarget(), "", new EchoConnection()));
|
||||
JoinInner(new OrderManager(new EchoConnection()));
|
||||
}
|
||||
|
||||
// More accurate replacement for Environment.TickCount
|
||||
@@ -104,7 +108,7 @@ namespace OpenRA
|
||||
public static int LocalTick => OrderManager.LocalFrameNumber;
|
||||
|
||||
public static event Action<ConnectionTarget> OnRemoteDirectConnect = _ => { };
|
||||
public static event Action<OrderManager> ConnectionStateChanged = _ => { };
|
||||
public static event Action<OrderManager, string, NetworkConnection> ConnectionStateChanged = (om, pass, conn) => { };
|
||||
static ConnectionState lastConnectionState = ConnectionState.PreConnecting;
|
||||
public static int LocalClientId => OrderManager.Connection.LocalClientId;
|
||||
|
||||
@@ -415,7 +419,7 @@ namespace OpenRA
|
||||
{
|
||||
// Clear static state if we have switched mods
|
||||
LobbyInfoChanged = () => { };
|
||||
ConnectionStateChanged = om => { };
|
||||
ConnectionStateChanged = (om, p, conn) => { };
|
||||
BeforeGameStart = () => { };
|
||||
OnRemoteDirectConnect = endpoint => { };
|
||||
delayedActions = new ActionQueue();
|
||||
@@ -652,7 +656,7 @@ namespace OpenRA
|
||||
if (OrderManager.Connection.ConnectionState != lastConnectionState)
|
||||
{
|
||||
lastConnectionState = OrderManager.Connection.ConnectionState;
|
||||
ConnectionStateChanged(OrderManager);
|
||||
ConnectionStateChanged(OrderManager, null, null);
|
||||
}
|
||||
|
||||
InnerLogicTick(OrderManager);
|
||||
@@ -997,4 +1001,10 @@ namespace OpenRA
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class CurrentServerSettings
|
||||
{
|
||||
public static string Password;
|
||||
public static ConnectionTarget Target;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace OpenRA.Network
|
||||
void Receive(Action<int, byte[]> packetFn);
|
||||
}
|
||||
|
||||
class EchoConnection : IConnection
|
||||
public class EchoConnection : IConnection
|
||||
{
|
||||
protected struct ReceivedPacket
|
||||
{
|
||||
@@ -136,9 +136,9 @@ namespace OpenRA.Network
|
||||
}
|
||||
}
|
||||
|
||||
sealed class NetworkConnection : EchoConnection
|
||||
public sealed class NetworkConnection : EchoConnection
|
||||
{
|
||||
readonly ConnectionTarget target;
|
||||
public readonly ConnectionTarget Target;
|
||||
TcpClient tcp;
|
||||
IPEndPoint endpoint;
|
||||
readonly List<byte[]> queuedSyncPackets = new List<byte[]>();
|
||||
@@ -153,7 +153,7 @@ namespace OpenRA.Network
|
||||
|
||||
public NetworkConnection(ConnectionTarget target)
|
||||
{
|
||||
this.target = target;
|
||||
Target = target;
|
||||
new Thread(NetworkConnectionConnect)
|
||||
{
|
||||
Name = $"{GetType().Name} (connect to {target})",
|
||||
@@ -166,7 +166,7 @@ namespace OpenRA.Network
|
||||
var queue = new BlockingCollection<TcpClient>();
|
||||
|
||||
var atLeastOneEndpoint = false;
|
||||
foreach (var endpoint in target.GetConnectEndPoints())
|
||||
foreach (var endpoint in Target.GetConnectEndPoints())
|
||||
{
|
||||
atLeastOneEndpoint = true;
|
||||
new Thread(() =>
|
||||
|
||||
@@ -28,9 +28,6 @@ namespace OpenRA.Network
|
||||
public Session.Client LocalClient => LobbyInfo.ClientWithIndex(Connection.LocalClientId);
|
||||
public World World;
|
||||
|
||||
public readonly ConnectionTarget Endpoint;
|
||||
public readonly string Password = "";
|
||||
|
||||
public string ServerError = null;
|
||||
public bool AuthenticationFailed = false;
|
||||
public ExternalMod ServerExternalMod = null;
|
||||
@@ -94,10 +91,8 @@ namespace OpenRA.Network
|
||||
Connection.Send(i, new List<byte[]>());
|
||||
}
|
||||
|
||||
public OrderManager(ConnectionTarget endpoint, string password, IConnection conn)
|
||||
public OrderManager(IConnection conn)
|
||||
{
|
||||
Endpoint = endpoint;
|
||||
Password = password;
|
||||
Connection = conn;
|
||||
syncReport = new SyncReport(this);
|
||||
AddChatLine += CacheChatLine;
|
||||
|
||||
@@ -17,7 +17,7 @@ using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Network
|
||||
{
|
||||
sealed class ReplayRecorder
|
||||
public sealed class ReplayRecorder
|
||||
{
|
||||
// Arbitrary value.
|
||||
const int CreateReplayFileMaxRetryCount = 128;
|
||||
|
||||
@@ -218,7 +218,7 @@ namespace OpenRA.Network
|
||||
Client = info,
|
||||
Mod = mod.Id,
|
||||
Version = mod.Metadata.Version,
|
||||
Password = orderManager.Password,
|
||||
Password = CurrentServerSettings.Password,
|
||||
Fingerprint = localProfile.Fingerprint,
|
||||
OrdersProtocol = ProtocolVersion.Orders
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
Action onConnect, onAbort;
|
||||
Action<string> onRetry;
|
||||
|
||||
void ConnectionStateChanged(OrderManager om)
|
||||
void ConnectionStateChanged(OrderManager om, string password, NetworkConnection connection)
|
||||
{
|
||||
if (om.Connection.ConnectionState == ConnectionState.Connected)
|
||||
{
|
||||
@@ -35,6 +35,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
Ui.OpenWindow(switchPanel, new WidgetArgs()
|
||||
{
|
||||
{ "orderManager", om },
|
||||
{ "connection", connection },
|
||||
{ "password", password },
|
||||
{ "onAbort", onAbort },
|
||||
{ "onRetry", onRetry }
|
||||
});
|
||||
@@ -83,7 +85,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
bool passwordOffsetAdjusted;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public ConnectionFailedLogic(Widget widget, OrderManager orderManager, Action onAbort, Action<string> onRetry)
|
||||
public ConnectionFailedLogic(Widget widget, OrderManager orderManager, NetworkConnection connection, string password, Action onAbort, Action<string> onRetry)
|
||||
{
|
||||
var panel = widget;
|
||||
var abortButton = panel.Get<ButtonWidget>("ABORT_BUTTON");
|
||||
@@ -95,13 +97,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
retryButton.Visible = onRetry != null;
|
||||
retryButton.OnClick = () =>
|
||||
{
|
||||
var password = passwordField != null && passwordField.IsVisible() ? passwordField.Text : orderManager.Password;
|
||||
var pass = passwordField != null && passwordField.IsVisible() ? passwordField.Text : password;
|
||||
|
||||
Ui.CloseWindow();
|
||||
onRetry(password);
|
||||
onRetry(pass);
|
||||
};
|
||||
|
||||
widget.Get<LabelWidget>("CONNECTING_DESC").GetText = () => $"Could not connect to {orderManager.Endpoint}";
|
||||
widget.Get<LabelWidget>("CONNECTING_DESC").GetText = () => $"Could not connect to {connection.Target}";
|
||||
|
||||
var connectionError = widget.Get<LabelWidget>("CONNECTION_ERROR");
|
||||
connectionError.GetText = () => orderManager.ServerError ?? orderManager.Connection.ErrorMessage ?? "Unknown error";
|
||||
@@ -149,7 +151,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
public class ConnectionSwitchModLogic : ChromeLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public ConnectionSwitchModLogic(Widget widget, OrderManager orderManager, Action onAbort, Action<string> onRetry)
|
||||
public ConnectionSwitchModLogic(Widget widget, OrderManager orderManager, string password, NetworkConnection connection, Action onAbort, Action<string> onRetry)
|
||||
{
|
||||
var panel = widget;
|
||||
var abortButton = panel.Get<ButtonWidget>("ABORT_BUTTON");
|
||||
@@ -161,7 +163,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
switchButton.OnClick = () =>
|
||||
{
|
||||
var launchCommand = $"Launch.URI={new UriBuilder("tcp", orderManager.Connection.EndPoint.Address.ToString(), orderManager.Connection.EndPoint.Port)}";
|
||||
var launchCommand = $"Launch.URI={new UriBuilder("tcp", connection.EndPoint.Address.ToString(), connection.EndPoint.Port)}";
|
||||
Game.SwitchToExternalMod(orderManager.ServerExternalMod, new[] { launchCommand }, () =>
|
||||
{
|
||||
orderManager.ServerError = "Failed to switch mod.";
|
||||
|
||||
@@ -28,6 +28,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
Game.RunAfterTick(() => Ui.OpenWindow("CONNECTIONFAILED_PANEL", new WidgetArgs
|
||||
{
|
||||
{ "orderManager", orderManager },
|
||||
{ "password", CurrentServerSettings.Password },
|
||||
{ "connection", orderManager.Connection as NetworkConnection },
|
||||
{ "onAbort", null },
|
||||
{ "onRetry", null }
|
||||
}));
|
||||
|
||||
@@ -72,9 +72,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
bool MapIsPlayable => (mapStatus & Session.MapStatus.Playable) == Session.MapStatus.Playable;
|
||||
|
||||
// Listen for connection failures
|
||||
void ConnectionStateChanged(OrderManager om)
|
||||
void ConnectionStateChanged(OrderManager om, string password, NetworkConnection connection)
|
||||
{
|
||||
if (om.Connection.ConnectionState == ConnectionState.NotConnected)
|
||||
if (connection.ConnectionState == ConnectionState.NotConnected)
|
||||
{
|
||||
// Show connection failed dialog
|
||||
Ui.CloseWindow();
|
||||
@@ -89,12 +89,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
});
|
||||
};
|
||||
|
||||
Action<string> onRetry = password => ConnectionLogic.Connect(om.Endpoint, password, onConnect, onExit);
|
||||
Action<string> onRetry = pass => ConnectionLogic.Connect(connection.Target, pass, onConnect, onExit);
|
||||
|
||||
var switchPanel = om.ServerExternalMod != null ? "CONNECTION_SWITCHMOD_PANEL" : "CONNECTIONFAILED_PANEL";
|
||||
Ui.OpenWindow(switchPanel, new WidgetArgs()
|
||||
{
|
||||
{ "orderManager", om },
|
||||
{ "connection", connection },
|
||||
{ "password", password },
|
||||
{ "onAbort", onExit },
|
||||
{ "onRetry", onRetry }
|
||||
});
|
||||
@@ -762,7 +764,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
string secret = null;
|
||||
if (orderManager.LobbyInfo.GlobalSettings.Dedicated)
|
||||
{
|
||||
var endpoint = orderManager.Endpoint.GetConnectEndPoints().First();
|
||||
var endpoint = CurrentServerSettings.Target.GetConnectEndPoints().First();
|
||||
secret = string.Concat(endpoint.Address, "|", endpoint.Port);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user