public static void PresentConnectionError(ConnectionFailedReason reason)
        {
            _mpLobbyConnectionController.LeaveLobby();
            _joiningLobbyViewController.HideLoading();

            if (reason != ConnectionFailedReason.ConnectionCanceled)
            {
                var canRetry = (LastConnectToHostedGame != null &&
                                reason != ConnectionFailedReason.InvalidPassword &&
                                reason != ConnectionFailedReason.VersionMismatch);

                _simpleDialogPromptViewController.Init("Connection failed", ConnectionErrorText.Generate(reason), "Back to browser", canRetry ? "Retry connection" : null, delegate(int btnId)
                {
                    switch (btnId)
                    {
                    default:
                    case 0:     // Back to browser
                        ReplaceTopViewController(PluginUi.ServerBrowserViewController, null, ViewController.AnimationType.In, ViewController.AnimationDirection.Vertical);
                        break;

                    case 1:     // Retry connection
                        ConnectToHostedGame(LastConnectToHostedGame);
                        break;
                    }
                });
                ReplaceTopViewController(_simpleDialogPromptViewController, null, ViewController.AnimationType.In, ViewController.AnimationDirection.Vertical);
            }
            else
            {
                ReplaceTopViewController(PluginUi.ServerBrowserViewController, null, ViewController.AnimationType.In, ViewController.AnimationDirection.Vertical);
            }
        }
Esempio n. 2
0
        public static string Generate(ConnectionFailedReason reason)
        {
            var reasonInt = (int)reason;
            var reasonStr = Regex.Replace(reason.ToString(), "(\\B[A-Z])", " $1"); // insert spaces in error token for readability

            var msg = new StringBuilder();

            msg.AppendLine($"Error CFR-{reasonInt} ({reasonStr})");

            switch (reason)
            {
            case ConnectionFailedReason.ServerUnreachable:
                msg.AppendLine("Could not connect to the host.");
                break;

            case ConnectionFailedReason.ServerDoesNotExist:
                msg.AppendLine("It looks like this game has already ended.");
                break;

            case ConnectionFailedReason.ServerAtCapacity:
                msg.AppendLine("This game is full.");
                break;

            case ConnectionFailedReason.NetworkNotConnected:
            case ConnectionFailedReason.MasterServerUnreachable:
                msg.AppendLine("Could not connect to master server, check your connection and try again.");
                break;

            case ConnectionFailedReason.VersionMismatch:
                msg.AppendLine("Make sure you and the host are using the same game version.");
                break;

            case ConnectionFailedReason.MasterServerNotAuthenticated:
                msg.AppendLine("Could not authenticate master server, you may need to restart the game.");
                break;
            }

            return(msg.ToString());
        }
Esempio n. 3
0
        public static bool Prefix(MultiplayerModeSelectionFlowCoordinator __instance, ConnectionFailedReason reason)
        {
            Plugin.Log.Warn($"Multiplayer connection failed, reason: {reason}");

            if (MpModeSelection.WeInitiatedConnection)
            {
                // We only take over error handling UI if we initiated the connection
                MpModeSelection.PresentConnectionError(reason);
                return(false);
            }

            return(true);
        }
Esempio n. 4
0
    private void DisconnectInternal(DisconnectedReason disconnectedReason = DisconnectedReason.UserInitiated, ConnectionFailedReason connectionFailedReason = ConnectionFailedReason.Unknown)
    {
        if (this._connectionState == LiteNetLibConnectionManager.ConnectionState.Unconnected)
        {
            return;
        }
        bool flag = this._connectionState == LiteNetLibConnectionManager.ConnectionState.Connecting;

        this._connectionState = LiteNetLibConnectionManager.ConnectionState.Unconnected;
        CancellationTokenSource backgroundSentryDisconnectCts = this._backgroundSentryDisconnectCts;

        if (backgroundSentryDisconnectCts != null)
        {
            backgroundSentryDisconnectCts.Cancel();
        }
        this._netManager.DisconnectAll();
        this._netManager.PollEvents();
        if (flag)
        {
            Action <ConnectionFailedReason> action = this.onConnectionFailedEvent;
            if (action == null)
            {
                return;
            }
            action(connectionFailedReason);
            return;
        }
        else
        {
            Action <DisconnectedReason> action2 = this.onDisconnectedEvent;
            if (action2 == null)
            {
                return;
            }
            action2(disconnectedReason);
            return;
        }
    }
Esempio n. 5
0
 /// <summary>
 /// Creates new connection failed attempt event arguments.
 /// </summary>
 /// <param name="failedReason">The reason of failure.</param>
 public PeerConnectionFailedEventArgs(ConnectionFailedReason failedReason)
 {
     this.failedReason = failedReason;
 }
Esempio n. 6
0
        public static bool Prefix(MultiplayerModeSelectionFlowCoordinator __instance, ConnectionFailedReason reason)
        {
            Plugin.Log.Warn($"Multiplayer connection failed, reason: {reason}");

            if (MpModeSelection.WeInitiatedConnection)
            {
                // We only take over error handling UI if we initiated the connection
                if (reason == ConnectionFailedReason.ConnectionCanceled)
                {
                    // ...and if it's just a self-cancel, return to the browser immediately.
                    MpModeSelection.CancelLobbyJoin();
                    MpModeSelection.MakeServerBrowserTopView();
                }
                else
                {
                    MpModeSelection.PresentConnectionFailedError
                    (
                        errorMessage: ConnectionErrorText.Generate(reason),
                        canRetry: reason != ConnectionFailedReason.InvalidPassword && reason != ConnectionFailedReason.VersionMismatch
                    );
                }
                return(false);
            }
            return(true);
        }
Esempio n. 7
0
        /// <summary>
        /// The connection attempt to this peer has failed.
        /// </summary>
        /// <param name="failedReason">The reason of failure.</param>
        protected virtual void OnConnectionFailed(ConnectionFailedReason failedReason)
        {
            var eventArgs = new PeerConnectionFailedEventArgs(failedReason);

            ConnectionFailed.SafeInvoke(this, eventArgs);
        }