Fix NRE with ConnectionStateChanged
This commit is contained in:
@@ -62,17 +62,17 @@ namespace OpenRA
|
||||
|
||||
public static OrderManager JoinServer(ConnectionTarget endpoint, string password, bool recordReplay = true)
|
||||
{
|
||||
var connection = new NetworkConnection(endpoint);
|
||||
var newConnection = new NetworkConnection(endpoint);
|
||||
if (recordReplay)
|
||||
connection.StartRecording(() => { return TimestampedFilename(); });
|
||||
newConnection.StartRecording(() => { return TimestampedFilename(); });
|
||||
|
||||
var om = new OrderManager(connection);
|
||||
var om = new OrderManager(newConnection);
|
||||
JoinInner(om);
|
||||
CurrentServerSettings.Password = password;
|
||||
CurrentServerSettings.Target = endpoint;
|
||||
|
||||
lastConnectionState = ConnectionState.PreConnecting;
|
||||
ConnectionStateChanged(OrderManager, password, connection);
|
||||
ConnectionStateChanged(OrderManager, password, newConnection);
|
||||
|
||||
return om;
|
||||
}
|
||||
@@ -653,10 +653,10 @@ namespace OpenRA
|
||||
{
|
||||
PerformDelayedActions();
|
||||
|
||||
if (OrderManager.Connection.ConnectionState != lastConnectionState)
|
||||
if (OrderManager.Connection is NetworkConnection nc && nc.ConnectionState != lastConnectionState)
|
||||
{
|
||||
lastConnectionState = OrderManager.Connection.ConnectionState;
|
||||
ConnectionStateChanged(OrderManager, null, null);
|
||||
lastConnectionState = nc.ConnectionState;
|
||||
ConnectionStateChanged(OrderManager, null, nc);
|
||||
}
|
||||
|
||||
InnerLogicTick(OrderManager);
|
||||
|
||||
@@ -31,7 +31,6 @@ namespace OpenRA.Network
|
||||
public interface IConnection : IDisposable
|
||||
{
|
||||
int LocalClientId { get; }
|
||||
ConnectionState ConnectionState { get; }
|
||||
void Send(int frame, List<byte[]> orders);
|
||||
void SendImmediate(IEnumerable<byte[]> orders);
|
||||
void SendSync(int frame, byte[] syncData);
|
||||
@@ -51,8 +50,6 @@ namespace OpenRA.Network
|
||||
|
||||
public virtual int LocalClientId => 1;
|
||||
|
||||
public virtual ConnectionState ConnectionState => ConnectionState.PreConnecting;
|
||||
|
||||
public virtual void Send(int frame, List<byte[]> orders)
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
@@ -256,7 +253,7 @@ namespace OpenRA.Network
|
||||
}
|
||||
|
||||
public override int LocalClientId => clientId;
|
||||
public override ConnectionState ConnectionState => connectionState;
|
||||
public ConnectionState ConnectionState => connectionState;
|
||||
|
||||
public override void SendSync(int frame, byte[] syncData)
|
||||
{
|
||||
|
||||
@@ -34,7 +34,6 @@ namespace OpenRA.Network
|
||||
Dictionary<int, int> lastClientsFrame = new Dictionary<int, int>();
|
||||
|
||||
public int LocalClientId => -1;
|
||||
public ConnectionState ConnectionState => ConnectionState.Connected;
|
||||
|
||||
public IPEndPoint EndPoint => throw new NotSupportedException("A replay connection doesn't have an endpoint");
|
||||
|
||||
|
||||
@@ -22,12 +22,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
void ConnectionStateChanged(OrderManager om, string password, NetworkConnection connection)
|
||||
{
|
||||
if (om.Connection.ConnectionState == ConnectionState.Connected)
|
||||
if (connection.ConnectionState == ConnectionState.Connected)
|
||||
{
|
||||
CloseWindow();
|
||||
onConnect();
|
||||
}
|
||||
else if (om.Connection.ConnectionState == ConnectionState.NotConnected)
|
||||
else if (connection.ConnectionState == ConnectionState.NotConnected)
|
||||
{
|
||||
CloseWindow();
|
||||
|
||||
|
||||
@@ -22,14 +22,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var disconnected = false;
|
||||
widget.Get<LogicTickerWidget>("DISCONNECT_WATCHER").OnTick = () =>
|
||||
{
|
||||
if (disconnected || orderManager.Connection.ConnectionState != ConnectionState.NotConnected)
|
||||
if (!(orderManager.Connection is NetworkConnection connection))
|
||||
return;
|
||||
|
||||
if (disconnected || connection.ConnectionState != ConnectionState.NotConnected)
|
||||
return;
|
||||
|
||||
Game.RunAfterTick(() => Ui.OpenWindow("CONNECTIONFAILED_PANEL", new WidgetArgs
|
||||
{
|
||||
{ "orderManager", orderManager },
|
||||
{ "password", CurrentServerSettings.Password },
|
||||
{ "connection", orderManager.Connection as NetworkConnection },
|
||||
{ "connection", connection },
|
||||
{ "onAbort", null },
|
||||
{ "onRetry", null }
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user