Example #1
0
        /// <summary>
        /// プラグインが無効化されたときに呼び出されます。
        /// </summary>
        public void DeInitPlugin()
        {
            SaveConfig();

            if (controlPanel != null)
            {
                controlPanel.Dispose();
            }

            if (Overlays != null)
            {
                foreach (var overlay in this.Overlays)
                {
                    overlay.Dispose();
                }

                this.Overlays.Clear();
            }

            try { WSServer.Stop(); }
            catch { }

            if (this.wsTabPage != null && this.wsTabPage.Parent != null)
            {
                ((TabControl)this.wsTabPage.Parent).TabPages.Remove(this.wsTabPage);
            }

            Logger.Log(LogLevel.Info, "DeInitPlugin: Finalized.");
            if (this.label != null)
            {
                this.label.Text = "Finalized.";
            }
        }
Example #2
0
        public WSConfigPanel(TinyIoCContainer container)
        {
            InitializeComponent();

            _config   = container.Resolve <IPluginConfig>();
            _server   = container.Resolve <WSServer>();
            _plugin   = container.Resolve <PluginMain>();
            _registry = container.Resolve <Registry>();


            ipTxt.Text     = _config.WSServerIP;
            portTxt.Text   = "" + _config.WSServerPort;
            sslBox.Checked = _config.WSServerSSL;
            sslBox.Enabled = _server.IsSSLPossible();

            for (var i = 0; i < regionCb.Items.Count; i++)
            {
                if ((string)regionCb.Items[i] == _config.TunnelRegion)
                {
                    regionCb.SelectedIndex = i;
                    break;
                }
            }

            UpdateStatus(null, new WSServer.StateChangedArgs(_server.IsRunning(), _server.IsFailed()));
            _server.OnStateChanged += UpdateStatus;

            UpdateTunnelStatus(TunnelStatus.Inactive);

            lblUrlConfidentWarning.Visible = false;
        }
Example #3
0
        private void GenSsl()
        {
            try
            {
                var mkcertPath = Path.Combine(PluginMain.PluginDirectory, "mkcert.exe");

                if (!File.Exists(mkcertPath))
                {
                    logDisplay.AppendText("Downloading mkcert...\r\n");

                    if ((ServicePointManager.SecurityProtocol & SecurityProtocolType.Tls12) != SecurityProtocolType.Tls12)
                    {
                        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
                    }
                    var client = new WebClient();

                    try
                    {
                        client.DownloadFile(MKCERT_DOWNLOAD, mkcertPath);
                    }
                    catch (Exception e)
                    {
                        logDisplay.AppendText(string.Format("\nFailed: {0}", e));
                        genSslBtn.Enabled = true;
                        return;
                    }
                }

                logDisplay.AppendText("Installing CA...\r\n");
                if (!RunLogCmd(mkcertPath, "-install"))
                {
                    logDisplay.AppendText("\r\nFailed!\r\n");
                    genSslBtn.Enabled = true;
                    return;
                }

                logDisplay.AppendText("Generating certificate...\r\n");
                if (!RunLogCmd(mkcertPath, string.Format("-pkcs12 -p12-file \"{0}\" localhost 127.0.0.1 ::1", WSServer.GetCertPath())))
                {
                    logDisplay.AppendText("\r\nFailed!\r\n");
                    genSslBtn.Enabled = true;
                    return;
                }

                logDisplay.AppendText("\r\nDone.\r\n");

                sslBox.Enabled     = WSServer.IsSSLPossible();
                sslBox.Checked     = sslBox.Enabled;
                Config.WSServerSSL = sslBox.Enabled;
                genSslBtn.Enabled  = true;
            }
            catch (Exception e)
            {
                logDisplay.AppendText(string.Format("\r\nException: {0}", e));
                genSslBtn.Enabled = true;
            }
        }
Example #4
0
        public WSConfigPanel(PluginConfig cfg)
        {
            InitializeComponent();

            Config         = cfg;
            ipTxt.Text     = Config.WSServerIP;
            portTxt.Text   = "" + Config.WSServerPort;
            sslBox.Checked = Config.WSServerSSL;
            sslBox.Enabled = WSServer.IsSSLPossible();

            UpdateStatus(null, new WSServer.StateChangedArgs(WSServer.IsRunning(), WSServer.IsFailed()));
            WSServer.OnStateChanged += UpdateStatus;
        }
Example #5
0
        private void GenSsl()
        {
            try
            {
                var mkcertPath = Path.Combine(PluginMain.PluginDirectory, "mkcert.exe");

                if (!File.Exists(mkcertPath))
                {
                    logDisplay.AppendText("Downloading mkcert...\r\n");

                    try
                    {
                        CurlWrapper.Get(MKCERT_DOWNLOAD, new Dictionary <string, string>(), mkcertPath, null, false);
                    }
                    catch (Exception e)
                    {
                        logDisplay.AppendText(string.Format("\nFailed: {0}", e));
                        genSslBtn.Enabled = true;
                        return;
                    }
                }

                logDisplay.AppendText("Installing CA...\r\n");
                if (!RunLogCmd(mkcertPath, "-install"))
                {
                    logDisplay.AppendText("\r\nFailed!\r\n");
                    genSslBtn.Enabled = true;
                    return;
                }

                logDisplay.AppendText("Generating certificate...\r\n");
                if (!RunLogCmd(mkcertPath, string.Format("-pkcs12 -p12-file \"{0}\" localhost 127.0.0.1 ::1", WSServer.GetCertPath())))
                {
                    logDisplay.AppendText("\r\nFailed!\r\n");
                    genSslBtn.Enabled = true;
                    return;
                }

                logDisplay.AppendText("\r\nDone.\r\n");

                sslBox.Enabled     = WSServer.IsSSLPossible();
                sslBox.Checked     = sslBox.Enabled;
                Config.WSServerSSL = sslBox.Enabled;
                genSslBtn.Enabled  = true;
            }
            catch (Exception e)
            {
                logDisplay.AppendText(string.Format("\r\nException: {0}", e));
                genSslBtn.Enabled = true;
            }
        }
Example #6
0
        private void cbOverlay_SelectedIndexChanged(object sender, EventArgs e)
        {
            var item    = cbOverlay.Items[cbOverlay.SelectedIndex];
            var overlay = (Overlays.MiniParseOverlay)item.GetType().GetProperty("overlay").GetValue(item);

            if (overlay == null)
            {
                return;
            }

            var(confident, url) = WSServer.GetUrl(overlay);

            lblUrlConfidentWarning.Visible = !confident;
            txtOverlayUrl.Text             = url;
        }
Example #7
0
        public static void Stop()
        {
            if (_inst != null)
            {
                try
                {
                    _inst._server.Stop();
                }
                catch (Exception e)
                {
                    Log(LogLevel.Error, Resources.WSShutdownError, e);
                }
                _inst   = null;
                _failed = false;

                OnStateChanged(null, new StateChangedArgs(false, false));
            }
        }
Example #8
0
        public WSConfigPanel(PluginConfig cfg)
        {
            InitializeComponent();

            Config         = cfg;
            ipTxt.Text     = Config.WSServerIP;
            portTxt.Text   = "" + Config.WSServerPort;
            sslBox.Checked = Config.WSServerSSL;
            sslBox.Enabled = WSServer.IsSSLPossible();

            UpdateStatus(null, new WSServer.StateChangedArgs(WSServer.IsRunning(), WSServer.IsFailed()));
            WSServer.OnStateChanged += UpdateStatus;

            lblUrlConfidentWarning.Visible = false;
            Registry.Resolve <PluginMain>().OverlaysChanged += (o, e) =>
            {
                RebuildOverlayOptions();
            };
        }
Example #9
0
        /// <summary>
        /// プラグインが無効化されたときに呼び出されます。
        /// </summary>
        public void DeInitPlugin()
        {
            xivWindowTimer.Stop();
            xivWindowTimer.Dispose();

            SaveConfig();

            controlPanel.Dispose();

            foreach (var overlay in this.Overlays)
            {
                overlay.Dispose();
            }

            this.Overlays.Clear();

            try { WSServer.Stop(); }
            catch { }

            ((TabControl)this.wsTabPage.Parent).TabPages.Remove(this.wsTabPage);

            Logger.Log(LogLevel.Info, "DeInitPlugin: Finalized.");
            this.label.Text = "Finalized.";
        }
Example #10
0
 private void stopBtn_Click(object sender, EventArgs e)
 {
     Config.WSServerRunning = false;
     WSServer.Stop();
 }
Example #11
0
 private void startBtn_Click(object sender, EventArgs e)
 {
     Config.WSServerRunning = true;
     WSServer.Initialize();
 }
Example #12
0
        /// <summary>
        /// プラグインが有効化されたときに呼び出されます。
        /// </summary>
        /// <param name="pluginScreenSpace"></param>
        /// <param name="pluginStatusText"></param>
        public void InitPlugin(TabPage pluginScreenSpace, Label pluginStatusText)
        {
            try
            {
                this.tabPage = pluginScreenSpace;
                this.label   = pluginStatusText;

#if DEBUG
                Logger.Log(LogLevel.Warning, "##################################");
                Logger.Log(LogLevel.Warning, "    THIS IS THE DEBUG BUILD");
                Logger.Log(LogLevel.Warning, "##################################");
#endif

                Logger.Log(LogLevel.Info, "InitPlugin: PluginDirectory = {0}", PluginDirectory);

#if DEBUG
                Stopwatch watch = new Stopwatch();
                watch.Start();
#endif

                try
                {
                    Renderer.Initialize(PluginDirectory);
                }
                catch (Exception e)
                {
                    Logger.Log(LogLevel.Error, "InitPlugin: {0}", e);
                }

#if DEBUG
                Logger.Log(LogLevel.Debug, "CEF init took {0}s.", watch.Elapsed.TotalSeconds);
                watch.Reset();
#endif

                FFXIVExportVariables.Init();

                // プラグイン読み込み
                LoadAddons();

                // コンフィグ系読み込み
                LoadConfig();

#if DEBUG
                Logger.Log(LogLevel.Debug, "Addon and config load took {0}s.", watch.Elapsed.TotalSeconds);
                watch.Reset();
#endif

                if (Config.WSServerRunning)
                {
                    try
                    {
                        WSServer.Initialize();
                    }
                    catch (Exception e)
                    {
                        Logger.Log(LogLevel.Error, "InitPlugin: {0}", e);
                    }
                }

                // プラグイン間のメッセージ関連
                OverlayApi.BroadcastMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        foreach (var overlay in this.Overlays)
                        {
                            overlay.SendMessage(e.Message);
                        }
                    });
                };
                OverlayApi.SendMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        var targetOverlay = this.Overlays.FirstOrDefault(x => x.Name == e.Target);
                        if (targetOverlay != null)
                        {
                            targetOverlay.SendMessage(e.Message);
                        }
                    });
                };
                OverlayApi.OverlayMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        var targetOverlay = this.Overlays.FirstOrDefault(x => x.Name == e.Target);
                        if (targetOverlay != null)
                        {
                            targetOverlay.OverlayMessage(e.Message);
                        }
                    });
                };

#if DEBUG
                watch.Reset();
#endif
                InitializeOverlays();

#if DEBUG
                Logger.Log(LogLevel.Debug, "ES and overlay init took {0}s.", watch.Elapsed.TotalSeconds);
                watch.Stop();
#endif

                // コンフィグUI系初期化
                this.controlPanel      = new ControlPanel(this, this.Config);
                this.controlPanel.Dock = DockStyle.Fill;
                this.tabPage.Controls.Add(this.controlPanel);
                this.tabPage.Name = "OverlayPlugin";

                this.wsConfigPanel      = new WSConfigPanel(this.Config);
                this.wsConfigPanel.Dock = DockStyle.Fill;

                this.wsTabPage = new TabPage("OverlayPlugin WSServer");
                this.wsTabPage.Controls.Add(wsConfigPanel);
                ((TabControl)this.tabPage.Parent).TabPages.Add(this.wsTabPage);

                Logger.Log(LogLevel.Info, "InitPlugin: Initialized.");
                this.label.Text = "Initialized.";
            }
            catch (Exception e)
            {
                Logger.Log(LogLevel.Error, "InitPlugin: {0}", e.ToString());
                MessageBox.Show(e.ToString());

                throw;
            }
        }
Example #13
0
            public LegacyHandler(TinyIoCContainer container, IWebSocketConnection conn, WSServer server) : base()
            {
                _logger     = container.Resolve <ILogger>();
                _dispatcher = container.Resolve <EventDispatcher>();
                _repository = container.Resolve <FFXIVRepository>();
                _conn       = conn;

                conn.OnOpen    = OnOpen;
                conn.OnMessage = OnMessage;
                conn.OnClose   = () =>
                {
                    try
                    {
                        _dispatcher.UnsubscribeAll(this);
                        server._connections.Remove(this);
                    }
                    catch (Exception ex)
                    {
                        _logger.Log(LogLevel.Error, $"Failed to unsubscribe WebSocket connection: {ex}");
                    }
                };
            }
Example #14
0
        /// <summary>
        /// プラグインが有効化されたときに呼び出されます。
        /// </summary>
        /// <param name="pluginScreenSpace"></param>
        /// <param name="pluginStatusText"></param>
        public void InitPlugin(TabPage pluginScreenSpace, Label pluginStatusText)
        {
            try
            {
                this.tabPage = pluginScreenSpace;
                this.label   = pluginStatusText;

#if DEBUG
                Logger.Log(LogLevel.Warning, "##################################");
                Logger.Log(LogLevel.Warning, "    THIS IS THE DEBUG BUILD");
                Logger.Log(LogLevel.Warning, "##################################");
#endif

                Logger.Log(LogLevel.Info, "InitPlugin: PluginDirectory = {0}", PluginDirectory);

#if DEBUG
                Stopwatch watch = new Stopwatch();
                watch.Start();
#endif

                FFXIVExportVariables.Init();
                NetworkParser.Init();
                EventDispatcher.Init();

                // LoadAddons();
                LoadConfig();

#if DEBUG
                Logger.Log(LogLevel.Debug, "Component init and config load took {0}s.", watch.Elapsed.TotalSeconds);
                watch.Reset();
#endif

                try
                {
                    Renderer.Initialize(PluginDirectory, ActGlobals.oFormActMain.AppDataFolder.FullName, Config.ErrorReports);
                }
                catch (Exception e)
                {
                    Logger.Log(LogLevel.Error, "InitPlugin: {0}", e);
                }

#if DEBUG
                Logger.Log(LogLevel.Debug, "CEF init took {0}s.", watch.Elapsed.TotalSeconds);
                watch.Reset();
#endif

                // プラグイン間のメッセージ関連
                OverlayApi.BroadcastMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        foreach (var overlay in this.Overlays)
                        {
                            overlay.SendMessage(e.Message);
                        }
                    });
                };
                OverlayApi.SendMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        var targetOverlay = this.Overlays.FirstOrDefault(x => x.Name == e.Target);
                        if (targetOverlay != null)
                        {
                            targetOverlay.SendMessage(e.Message);
                        }
                    });
                };
                OverlayApi.OverlayMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        var targetOverlay = this.Overlays.FirstOrDefault(x => x.Name == e.Target);
                        if (targetOverlay != null)
                        {
                            targetOverlay.OverlayMessage(e.Message);
                        }
                    });
                };

#if DEBUG
                watch.Reset();
#endif

                // コンフィグUI系初期化
                this.controlPanel      = new ControlPanel(this, this.Config);
                this.controlPanel.Dock = DockStyle.Fill;
                this.tabPage.Controls.Add(this.controlPanel);
                this.tabPage.Name = "OverlayPlugin";

                this.wsConfigPanel      = new WSConfigPanel(this.Config);
                this.wsConfigPanel.Dock = DockStyle.Fill;

                this.wsTabPage = new TabPage("OverlayPlugin WSServer");
                this.wsTabPage.Controls.Add(wsConfigPanel);
                ((TabControl)this.tabPage.Parent).TabPages.Add(this.wsTabPage);

                Logger.Log(LogLevel.Info, "InitPlugin: Initialized.");
                this.label.Text = "Initialized.";

                if (Config.UpdateCheck)
                {
                    Updater.Updater.PerformUpdateIfNecessary(controlPanel, PluginDirectory);
                }

                initTimer          = new Timer();
                initTimer.Interval = 300;
                initTimer.Tick    += (o, e) =>
                {
                    if (ActGlobals.oFormActMain.InitActDone && ActGlobals.oFormActMain.Handle != IntPtr.Zero)
                    {
                        initTimer.Stop();

                        Registry.Register(new KeyboardHook());

                        LoadAddons();
                        InitializeOverlays();
                        controlPanel.InitializeOverlayConfigTabs();

                        OverlayHider.Initialize();

                        if (Config.WSServerRunning)
                        {
                            try
                            {
                                WSServer.Initialize();
                            }
                            catch (Exception ex)
                            {
                                Logger.Log(LogLevel.Error, "InitPlugin: {0}", ex);
                            }
                        }
                    }
                };
                initTimer.Start();
            }
            catch (Exception e)
            {
                Logger.Log(LogLevel.Error, "InitPlugin: {0}", e.ToString());
                MessageBox.Show(e.ToString());

                throw;
            }
        }
Example #15
0
 public static void Initialize()
 {
     _inst = new WSServer();
 }
Example #16
0
        /// <summary>
        /// プラグインが有効化されたときに呼び出されます。
        /// </summary>
        /// <param name="pluginScreenSpace"></param>
        /// <param name="pluginStatusText"></param>
        public void InitPlugin(TabPage pluginScreenSpace, Label pluginStatusText)
        {
            try
            {
                this.tabPage = pluginScreenSpace;
                this.label   = pluginStatusText;

#if DEBUG
                Logger.Log(LogLevel.Warning, "##################################");
                Logger.Log(LogLevel.Warning, "    THIS IS THE DEBUG BUILD");
                Logger.Log(LogLevel.Warning, "##################################");
#endif

                Logger.Log(LogLevel.Info, "InitPlugin: PluginDirectory = {0}", PluginDirectory);

#if DEBUG
                Stopwatch watch = new Stopwatch();
                watch.Start();
#endif

                // ** Init phase 1
                // Only init stuff here that works without the FFXIV plugin or addons (event sources, overlays).
                // Everything else should be initialized in the second phase.
                NativeMethods.Init();
                FFXIVExportVariables.Init();
                EventDispatcher.Init();
                Registry.Register(new KeyboardHook());
                LoadConfig();

#if DEBUG
                Logger.Log(LogLevel.Debug, "Component init and config load took {0}s.", watch.Elapsed.TotalSeconds);
                watch.Reset();
#endif

                try
                {
                    Renderer.Initialize(PluginDirectory, ActGlobals.oFormActMain.AppDataFolder.FullName, Config.ErrorReports);
                }
                catch (Exception e)
                {
                    Logger.Log(LogLevel.Error, "InitPlugin: {0}", e);
                }

#if DEBUG
                Logger.Log(LogLevel.Debug, "CEF init took {0}s.", watch.Elapsed.TotalSeconds);
                watch.Reset();
#endif

                // プラグイン間のメッセージ関連
                OverlayApi.BroadcastMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        foreach (var overlay in this.Overlays)
                        {
                            overlay.SendMessage(e.Message);
                        }
                    });
                };
                OverlayApi.SendMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        var targetOverlay = this.Overlays.FirstOrDefault(x => x.Name == e.Target);
                        if (targetOverlay != null)
                        {
                            targetOverlay.SendMessage(e.Message);
                        }
                    });
                };
                OverlayApi.OverlayMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        var targetOverlay = this.Overlays.FirstOrDefault(x => x.Name == e.Target);
                        if (targetOverlay != null)
                        {
                            targetOverlay.OverlayMessage(e.Message);
                        }
                    });
                };

#if DEBUG
                watch.Reset();
#endif

                // コンフィグUI系初期化
                this.controlPanel      = new ControlPanel(this, this.Config);
                this.controlPanel.Dock = DockStyle.Fill;
                this.tabPage.Controls.Add(this.controlPanel);
                this.tabPage.Name = "OverlayPlugin";

                this.wsConfigPanel      = new WSConfigPanel(this.Config);
                this.wsConfigPanel.Dock = DockStyle.Fill;

                this.wsTabPage = new TabPage("OverlayPlugin WSServer");
                this.wsTabPage.Controls.Add(wsConfigPanel);
                ((TabControl)this.tabPage.Parent).TabPages.Add(this.wsTabPage);

                Logger.Log(LogLevel.Info, "InitPlugin: Initialized.");
                this.label.Text = "Initialized.";

                if (Config.UpdateCheck)
                {
                    Updater.Updater.PerformUpdateIfNecessary(PluginDirectory);
                }

                initTimer          = new Timer();
                initTimer.Interval = 300;
                initTimer.Tick    += async(o, e) =>
                {
                    if (ActGlobals.oFormActMain == null)
                    {
                        // Something went really wrong.
                        initTimer.Stop();
                    }
                    else if (ActGlobals.oFormActMain.InitActDone && ActGlobals.oFormActMain.Handle != IntPtr.Zero)
                    {
                        try
                        {
                            initTimer.Stop();

                            // ** Init phase 2

                            // Initialize the parser in the second phase since it needs the FFXIV plugin.
                            // If OverlayPlugin is placed above the FFXIV plugin, it won't be available in the first
                            // phase but it'll be loaded by the time we enter the second phase.
                            NetworkParser.Init();

                            TriggIntegration.Init();

                            // This timer runs on the UI thread (it has to since we create UI controls) but LoadAddons()
                            // can block for some time. We run it on the background thread to avoid blocking the UI.
                            // We can't run LoadAddons() in the first init phase since it checks other ACT plugins for
                            // addons. Plugins below OverlayPlugin wouldn't have been loaded in the first init phase.
                            // However, in the second phase all plugins have been loaded which means we can look for addons
                            // in that list.
                            await Task.Run(LoadAddons);

                            ActGlobals.oFormActMain.Invoke((Action)(() =>
                            {
                                // Now that addons have been loaded, we can finish the overlay setup.
                                InitializeOverlays();
                                controlPanel.InitializeOverlayConfigTabs();
                                OverlayHider.Init();
                                OverlayZCorrector.Init();

                                // WSServer has to start after the LoadAddons() call because clients can connect immediately
                                // after it's initialized and that requires the event sources to be initialized.
                                if (Config.WSServerRunning)
                                {
                                    WSServer.Init();
                                }
                            }));
                        }
                        catch (Exception ex)
                        {
                            Logger.Log(LogLevel.Error, "InitPlugin: {0}", ex);
                        }
                    }
                };
                initTimer.Start();
            }
            catch (Exception e)
            {
                Logger.Log(LogLevel.Error, "InitPlugin: {0}", e.ToString());
                MessageBox.Show(e.ToString());

                throw;
            }
        }
Example #17
0
            public LegacyHandler(TinyIoCContainer container, IWebSocketConnection conn, WSServer server) : base()
            {
                _logger     = container.Resolve <ILogger>();
                _dispatcher = container.Resolve <EventDispatcher>();
                _repository = container.Resolve <FFXIVRepository>();
                _conn       = conn;

                var open = true;

                conn.OnOpen    = OnOpen;
                conn.OnMessage = OnMessage;
                conn.OnClose   = () =>
                {
                    if (!open)
                    {
                        return;
                    }
                    open = false;

                    try
                    {
                        _dispatcher.UnsubscribeAll(this);
                        server._connections.Remove(this);
                    }
                    catch (Exception ex)
                    {
                        _logger.Log(LogLevel.Error, $"Failed to unsubscribe WebSocket connection: {ex}");
                    }
                };
                conn.OnError = (ex) =>
                {
                    // Fleck will close the connection; make sure we always clean up even if Fleck doesn't call OnClose().
                    conn.OnClose();

                    _logger.Log(LogLevel.Info, $"WebSocket connection was closed with error: {ex}");
                };
            }