Beispiel #1
0
        public void Launch_IsJustUpdatedValueSet_ClientStartsWithSpecifiedParameters(bool isJustUpdated)
        {
            // arrange
            _isJustUpdated = isJustUpdated;

            // act
            _clientLauncher.Launch(_isJustUpdated);

            // assert
            _clientMock.Verify(x => x.Start(It.Is <StartOptions>(s => s.ForbidUpdates == _forbidUpdates && s.IsJustUpdated == _isJustUpdated)), Times.Once);
            _clientMock.Verify(x => x.Start(It.IsAny <StartOptions>()), Times.Once);
        }
 private void Form1_Load(object sender, EventArgs e)
 {
     eventManager = new UiEventManager(dataGridView1, this);
     indication   = new Indication(this);
     InitializeAppProperties();
     try
     {
         client = new ClientLauncher(eventManager, this);
         client.Launch();
         eventManager.client = client;
         StatusesForOwner.Init(client.GetServerInstance());
         eventManager.GetEventList();
         eventManager.HideClosedEventsAccordingToConfigValue();
     }
     catch (UserIsNullException) //user has not logged in
     {
         ExitApp();
     }
 }
Beispiel #3
0
        public void Play()
        {
            try
            {
                Dictionary <string, string> table = new Dictionary <string, string>();
                string   dataString = string.Empty;
                string[] split      = null;

                dataString = _url;
                dataString = Uri.UnescapeDataString(dataString);

                bool encoded = Regex.IsMatch(dataString, "^[A-Za-z0-9+/=]+$", RegexOptions.IgnoreCase);

                if (encoded)
                {
                    dataString = Encoding.UTF8.GetString(Convert.FromBase64String(dataString));
                }

                _log.Debug("dataString = {0}", dataString);

                split = dataString.Split('&');

                for (int i = 0; i < split.Length; i++)
                {
                    string[] keyValue = split[i].Split('=');

                    if (keyValue.Length == 2)
                    {
                        string key   = keyValue[0];
                        string value = keyValue[1];

                        table.Add(key, value);
                    }
                }

                for (int i = 0; i < _requiredFields.Length; i++)
                {
                    if (!table.ContainsKey(_requiredFields[i]))
                    {
                        MessageBoxEx.Show(Program.MainForm, string.Format("One or more of the following fields was missing from the ConnectUO Url Protocol string: {0}", string.Join(" ", _requiredFields)));
                        return;
                    }
                }

                string idString    = table[Id];
                string name        = table[NameTolken];
                string portString  = table[PortTolken];
                string hostAddress = table[HostTolken];
                string allowRazor;
                string removeEnc;
                string patches;

                bool razor = Program.Database.LaunchRazor;
                bool enc;

                if (!table.TryGetValue(AllowRazorTolken, out allowRazor))
                {
                    allowRazor = "false";
                }

                if (!table.TryGetValue(RemoveEncTolken, out removeEnc))
                {
                    removeEnc = "true";
                }

                if (!table.TryGetValue(PatchesTolken, out patches))
                {
                    patches = "";
                }

                int port;
                int id;

                if (!int.TryParse(idString, out id))
                {
                    MessageBoxEx.Show(Program.MainForm, "Invalid server id.");
                    return;
                }

                if (!int.TryParse(portString, out port) || (port > 65536 || port < 0))
                {
                    MessageBoxEx.Show(Program.MainForm, "Invalid port number, please use a valid port number between 0 and 65535");
                    return;
                }

                bool shardAllowsRazor;
                bool.TryParse(allowRazor, out shardAllowsRazor);
                bool.TryParse(removeEnc, out enc);

                //Make sure the user wants razor, and that shard allows it.
                razor = razor && shardAllowsRazor;

                if (string.IsNullOrEmpty(Program.Database.UltimaOnlineDirectory))
                {
                    MessageBoxEx.Show(Program.MainForm, "ConnectUO was unable to find the directory that Ultima Online is installed to.  This must be set in order to launch the client.");
                    return;
                }

                if (string.IsNullOrEmpty(Program.Database.UltimaOnlineExe))
                {
                    MessageBoxEx.Show(Program.MainForm, "ConnectUO was unable to find the client executable.  This must be set in order to launch the client.");
                    return;
                }

                string folderName = name;
                Utility.EnsureValidFolderName(ref folderName);

                string   serverDirectory = Path.Combine(Program.Database.PatchDirectory, folderName);
                string[] patchFiles      = null;

                Utility.EnsureDirectory(serverDirectory);

                List <ServerPatch> patchList = new List <ServerPatch>();

                split = patches.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                for (int i = 0; i < split.Length; i++)
                {
                    string[] patchVersion = split[i].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

                    if (patchVersion.Length == 2)
                    {
                        string patchUri      = patchVersion[0];
                        string versionString = patchVersion[1];
                        int    version;

                        int.TryParse(versionString, out version);

                        ServerPatch patch = new ServerPatch();

                        patch.ShardId  = id;
                        patch.PatchUrl = patchUri;
                        patch.Version  = version;

                        if (!Program.Database.IsPatchApplied(patch))
                        {
                            patchList.Add(patch);
                        }
                    }
                }

                if (patchList.Count > 0)
                {
                    if (Program.Database.IsServerBeingPatched(id))
                    {
                        MessageBoxEx.Show(Program.MainForm, String.Format("{0} is already being patched, you cannot play until the patching process has been completed", name), "ConnectUO 2.0");
                        return;
                    }
                    else
                    {
                        frmTaskManager taskManager = new frmTaskManager(patchList, serverDirectory);

                        if (taskManager.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                        {
                            return;
                        }
                    }
                }

                patchFiles = Directory.GetFiles(serverDirectory);

                ThreadPool.QueueUserWorkItem(delegate(object o)
                {
                    new ConnectUOWebService().UpdatePlayStatistics(Program.Database.Guid, id);
                });

                ClientLauncher.Launch(id, hostAddress, port,
                                      Path.Combine(Program.Database.UltimaOnlineDirectory, Program.Database.UltimaOnlineExe),
                                      Program.Database.RazorDirectory, razor, enc,
                                      Path.Combine(Program.Database.PatchDirectory, folderName), patchFiles);
            }
            catch (Exception e)
            {
                _log.Error(e);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Launch a new client instance.
 /// </summary>
 /// <param name="options">UOMachine.OptionsData to use for launching client.</param>
 /// <param name="clientIndex">Client index of launched client.</param>
 /// <returns>Client index of launched client.</returns>
 public static bool LaunchClient(OptionsData options, out int clientIndex)
 {
     return(ClientLauncher.Launch(options, out clientIndex));
 }
Beispiel #5
0
 /// <summary>
 /// Launch a new client instance.
 /// </summary>
 /// <param name="clientIndex">Client index of launched client.</param>
 /// <returns>Client index of launched client.</returns>
 public static bool LaunchClient(out int clientIndex)
 {
     return(ClientLauncher.Launch(MainWindow.CurrentOptions, out clientIndex));
 }
Beispiel #6
0
        public void Play(string url)
        {
            try
            {
                string[] split = null;

                if (url.Contains("//"))
                {
                    split = url.Split(new string[] { "//" }, StringSplitOptions.RemoveEmptyEntries);

                    if (split.Length >= 2)
                    {
                        url = split[1];
                    }
                }

                url = url.Replace("/", "");

                Dictionary <string, string> table = new Dictionary <string, string>();
                string dataString = string.Empty;

                dataString = url;
                dataString = Uri.UnescapeDataString(dataString);

                bool encoded = Regex.IsMatch(dataString, "^[A-Za-z0-9+/=]+$", RegexOptions.IgnoreCase);

                if (encoded)
                {
                    dataString = Encoding.UTF8.GetString(Convert.FromBase64String(dataString));
                }

                Tracer.Verbose("dataString = {0}", dataString);

                split = dataString.Split('&');

                for (int i = 0; i < split.Length; i++)
                {
                    string[] keyValue = split[i].Split('=');

                    if (keyValue.Length == 2)
                    {
                        string key   = keyValue[0];
                        string value = keyValue[1];

                        table.Add(key, value);
                    }
                }

                for (int i = 0; i < _requiredFields.Length; i++)
                {
                    if (!table.ContainsKey(_requiredFields[i]))
                    {
                        MessageBoxEx.Show(_applicationService.MainForm, string.Format("One or more of the following fields was missing from the ConnectUO Url Protocol string: {0}", string.Join(" ", _requiredFields)));
                        return;
                    }
                }

                string idString    = table[Id];
                string name        = table[NameTolken];
                string portString  = table[PortTolken];
                string hostAddress = table[HostTolken];
                string allowRazor;
                string removeEnc;
                string patches;

                bool razor = _settingsService.LaunchRazor;
                bool enc;

                if (!table.TryGetValue(AllowRazorTolken, out allowRazor))
                {
                    allowRazor = "false";
                }

                if (!table.TryGetValue(RemoveEncTolken, out removeEnc))
                {
                    removeEnc = "true";
                }

                if (!table.TryGetValue(PatchesTolken, out patches))
                {
                    patches = "";
                }

                int port;
                int id;

                if (!int.TryParse(idString, out id))
                {
                    MessageBoxEx.Show(_applicationService.MainForm, "Invalid server id.");
                    return;
                }

                if (!int.TryParse(portString, out port) || (port > 65536 || port < 0))
                {
                    MessageBoxEx.Show(_applicationService.MainForm, "Invalid port number, please use a valid port number between 0 and 65535");
                    return;
                }

                bool shardAllowsRazor;
                bool.TryParse(allowRazor, out shardAllowsRazor);
                bool.TryParse(removeEnc, out enc);

                //Make sure the user wants razor, and that shard allows it.
                razor = razor && shardAllowsRazor;

                if (string.IsNullOrEmpty(_settingsService.UltimaOnlineDirectory))
                {
                    MessageBoxEx.Show(_applicationService.MainForm, "ConnectUO was unable to find the directory that Ultima Online is installed to.  This must be set in order to launch the client.");
                    return;
                }

                if (string.IsNullOrEmpty(_settingsService.UltimaOnlineExe))
                {
                    MessageBoxEx.Show(_applicationService.MainForm, "ConnectUO was unable to find the client executable.  This must be set in order to launch the client.");
                    return;
                }

                string folderName = name;
                EnsureValidFolderName(ref folderName);

                string   serverDirectory = Path.Combine(_settingsService.PatchDirectory, folderName);
                string[] patchFiles      = null;

                FileSystemHelper.EnsureDirectoryExists(serverDirectory);

                List <ServerPatch> patchList = new List <ServerPatch>();

                split = patches.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                for (int i = 0; i < split.Length; i++)
                {
                    string[] patchVersion = split[i].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

                    if (patchVersion.Length == 2)
                    {
                        string patchUri      = patchVersion[0];
                        string versionString = patchVersion[1];
                        int    version;

                        int.TryParse(versionString, out version);

                        ServerPatch patch = new ServerPatch();

                        patch.ShardId  = id;
                        patch.PatchUrl = patchUri;
                        patch.Version  = version;

                        patchList.Add(patch);

                        //if (!_storageService.IsPatchApplied(patch))
                        //{
                        //    //_storageService.ResetPatches(id);
                        //    patchList.Add(patch);
                        //    //i = 0;
                        //    //continue;
                        //}
                    }
                }

                ServerPatch[] notPatched = (from p in patchList where !_storageService.IsPatchApplied(p) select p).ToArray();

                if (notPatched.Length > 0)
                {
                    if (_storageService.IsServerBeingPatched(id))
                    {
                        MessageBoxEx.Show(_applicationService.MainForm, String.Format("{0} is already being patched, you cannot play until the patching process has been completed", name), "ConnectUO 2.0");
                        return;
                    }
                    else
                    {
                        //_storageService.ResetPatches(id);

                        PatcherForm taskManager = _kernel.Get <PatcherForm>();

                        taskManager.Patches         = notPatched;
                        taskManager.ServerDirectory = serverDirectory;

                        if (taskManager.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                        {
                            return;
                        }
                    }
                }

                patchFiles = Directory.GetFiles(serverDirectory);

                _storageService.UpdatePlayStatistics(_settingsService.Guid, id);

                ClientLauncher.Launch(
                    _kernel,
                    id,
                    hostAddress,
                    port,
                    Path.Combine(_settingsService.UltimaOnlineDirectory, _settingsService.UltimaOnlineExe),
                    _settingsService.RazorDirectory,
                    razor,
                    enc,
                    Path.Combine(_settingsService.PatchDirectory, folderName),
                    patchFiles);
            }
            catch (Exception e)
            {
                Tracer.Error(e);
            }
        }