Example #1
0
        static bool IncompatibleReplayDialog(string type, string name, Action onCancel)
        {
            var error = "It was recorded with an " + type;

            error += string.IsNullOrEmpty(name) ? "." : ":\n{0}".F(name);

            ConfirmationDialogs.CancelPrompt("Incompatible Replay", error, onCancel);

            return(false);
        }
Example #2
0
        void CreateAndJoin()
        {
            var name = Settings.SanitizedServerName(panel.Get <TextFieldWidget>("SERVER_NAME").Text);
            int listenPort, externalPort;

            if (!Exts.TryParseIntegerInvariant(panel.Get <TextFieldWidget>("LISTEN_PORT").Text, out listenPort))
            {
                listenPort = 1234;
            }

            if (!Exts.TryParseIntegerInvariant(panel.Get <TextFieldWidget>("EXTERNAL_PORT").Text, out externalPort))
            {
                externalPort = 1234;
            }

            var passwordField = panel.GetOrNull <PasswordFieldWidget>("PASSWORD");
            var password      = passwordField != null ? passwordField.Text : "";

            // Save new settings
            Game.Settings.Server.Name             = name;
            Game.Settings.Server.ListenPort       = listenPort;
            Game.Settings.Server.ExternalPort     = externalPort;
            Game.Settings.Server.AdvertiseOnline  = advertiseOnline;
            Game.Settings.Server.AllowPortForward = allowPortForward;
            Game.Settings.Server.Map      = preview.Uid;
            Game.Settings.Server.Password = password;
            Game.Settings.Save();

            // Take a copy so that subsequent changes don't affect the server
            var settings = new ServerSettings(Game.Settings.Server);

            // Create and join the server
            try
            {
                Game.CreateServer(settings);
            }
            catch (System.Net.Sockets.SocketException e)
            {
                var err_msg = "Could not listen on port {0}.".F(Game.Settings.Server.ListenPort);
                if (e.ErrorCode == 10048)                   // AddressAlreadyInUse (WSAEADDRINUSE)
                {
                    err_msg += "\n\nCheck if the port is already being used.";
                }
                else
                {
                    err_msg += "\n\nError is: \"{0}\" ({1})".F(e.Message, e.ErrorCode);
                }

                ConfirmationDialogs.CancelPrompt("Server Creation Failed", err_msg, cancelText: "OK");
                return;
            }

            ConnectionLogic.Connect(IPAddress.Loopback.ToString(), Game.Settings.Server.ListenPort, password, onCreate, onExit);
        }