Example #1
0
        public void Init()
        {
            // Initialize a socket.io connection.
            socket = new SocketIO();

            // Handle tokens from protocol links.
            IPCadapter.getInstance().OnToken += async(s, e) => await OnTokenHandler(s, e);

            // Register handlers for game-state change events.
            GameMemReader.getInstance().GameStateChanged += GameStateChangedHandler;
            GameMemReader.getInstance().PlayerChanged    += PlayerChangedHandler;
            GameMemReader.getInstance().JoinedLobby      += JoinedLobbyHandler;

            // Handle socket connection events.
            socket.OnConnected += (sender, e) =>
            {
                // Report the connection
                //Settings.form.setConnectionStatus(true);
                Settings.conInterface.WriteModuleTextColored("ClientSocket", Color.Cyan, "Connected successfully!");


                // Alert any listeners that the connection has occurred.
                OnConnected?.Invoke(this, new ConnectedEventArgs()
                {
                    Uri = socket.ServerUri.ToString()
                });

                // On each (re)connection, send the connect code and then force-update everything.
                socket.EmitAsync("connectCode", ConnectCode).ContinueWith((_) =>
                {
                    Settings.conInterface.WriteModuleTextColored("ClientSocket", Color.Cyan,
                                                                 $"Connection code ({Color.Red.ToTextColorPango(ConnectCode)}) sent to server.");
                    GameMemReader.getInstance().ForceUpdatePlayers();
                    GameMemReader.getInstance().ForceTransmitState();
                    GameMemReader.getInstance().ForceTransmitLobby();
                });
            };

            // Handle socket disconnection events.
            socket.OnDisconnected += (sender, e) =>
            {
                //Settings.form.setConnectionStatus(false);
                //Settings.conInterface.WriteTextFormatted($"[§bClientSocket§f] Lost connection!");
                Settings.conInterface.WriteModuleTextColored("ClientSocket", Color.Cyan,
                                                             $"{Color.Red.ToTextColorPango("Connection lost!")}");

                // Alert any listeners that the disconnection has occured.
                OnDisconnected?.Invoke(this, EventArgs.Empty);
            };
        }
Example #2
0
        public void Init()
        {
            // Initialize a socket.io connection.
            socket = new SocketIO();

            // Handle tokens from protocol links.
            IPCadapter.getInstance().OnToken += OnTokenHandler;

            // Register handlers for game-state change events.
            GameMemReader.getInstance().GameStateChanged += GameStateChangedHandler;
            GameMemReader.getInstance().PlayerChanged    += PlayerChangedHandler;
            GameMemReader.getInstance().JoinedLobby      += JoinedLobbyHandler;

            // Handle socket connection events.
            socket.OnConnected += (sender, e) =>
            {
                // Report the connection
                Settings.form.setColor(MetroColorStyle.Green);
                Settings.conInterface.WriteModuleTextColored("ClientSocket", Color.Cyan, "Connected successfully!");


                // Alert any listeners that the connection has occurred.
                OnConnected?.Invoke(this, EventArgs.Empty);

                // On each (re)connection, send the connect code and then force-update everything.
                socket.EmitAsync("connectCode", ConnectCode).ContinueWith((_) =>
                {
                    Settings.conInterface.WriteModuleTextColored("ClientSocket", Color.Cyan, $"Connection code ({Color.Red.ToTextColor()}{ConnectCode}{UserForm.NormalTextColor.ToTextColor()}) sent to server.");
                    GameMemReader.getInstance().ForceUpdatePlayers();
                    GameMemReader.getInstance().ForceTransmitState();
                    GameMemReader.getInstance().ForceTransmitLobby();
                });
            };

            // Handle socket disconnection events.
            socket.OnDisconnected += (sender, e) =>
            {
                // Report the disconnection.
                Settings.form.setColor(MetroColorStyle.Red);
                Settings.conInterface.WriteModuleTextColored("ClientSocket", Color.Cyan, $"{Color.Red.ToTextColor()}Connection lost!");

                // Alert any listeners that the disconnection has occured.
                OnDisconnected?.Invoke(this, EventArgs.Empty);
            };
        }
Example #3
0
        private void _primaryWindowInstallLinkWindow_Dialog(object o, EventArgs e)
        {
            Gtk.Application.Invoke((sender, args) =>
            {
                var xdg_path = System.IO.Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                                   "applications");
                var xdg_file = System.IO.Path.Join(xdg_path, "aucapture-opener.desktop");
                string info  = String.Empty;

                var InstallLinkDialogBox = new MessageDialog(this,
                                                             DialogFlags.Modal,
                                                             MessageType.Question,
                                                             ButtonsType.None,
                                                             false,
                                                             String.Empty);

                if (!File.Exists(xdg_file) && !Settings.PersistentSettings.skipHandlerInstall)
                {
                    info +=
                        "Would you like to enable support for AutoMuteUs one-click connection?" +
                        "This will allow you to use the links provided by AutoMuteUs to connect the capture to the bot automatically.\n\n" +
                        "The following operations will be performed:\n\n" +
                        $"- The following .desktop file will be installed: {xdg_file}\n\n" +
                        "- The following command will be run to link the 'aucapture:' URI to the program:\n\n \'xdg-mime default aucapture-opener.desktop x-scheme-handler/aucapture\'" +
                        "\n\nIf you decline, Discord connection links will not be functional." +
                        "\n\nYou can install or manage One-Click support by using the \"One-Click Connection Management\" link in the File menu.";

                    InstallLinkDialogBox.Text  = info;
                    InstallLinkDialogBox.Title = "Enable One-Click Connection?";
                    InstallLinkDialogBox.AddButton("Cancel", ResponseType.Reject);
                    InstallLinkDialogBox.AddButton("Install", ResponseType.Accept);

                    InstallLinkDialogBox.Response += delegate(object o1, ResponseArgs responseArgs)
                    {
                        if (responseArgs.ResponseId == ResponseType.Reject)
                        {
                            // Make sure we have the setting to ignore the dialog box set.
                            Settings.PersistentSettings.skipHandlerInstall = true;
                        }

                        if (responseArgs.ResponseId == ResponseType.Accept)
                        {
                            IPCadapter.getInstance().InstallHandler();
                        }
                    };
                }
                else
                {
                    info += "This menu manages the One-Click Connection link system.\n\n";

                    info += "One-Click Connection Status: ";
                    if (File.Exists(xdg_file))
                    {
                        info += "Enabled\n\n";
                    }
                    else
                    {
                        info += "Disabled\n\n";
                    }

                    info += $"Runner (.desktop) Installation Path: ";
                    if (File.Exists(xdg_file))
                    {
                        info += xdg_file;
                    }
                    else
                    {
                        info += "Not Found";
                    }

                    InstallLinkDialogBox.Text += info;
                    InstallLinkDialogBox.Title = "Manage One-Click Connection";
                    InstallLinkDialogBox.AddButton("Cancel", ResponseType.Close);
                    InstallLinkDialogBox.AddButton("Uninstall", ResponseType.Reject);
                    InstallLinkDialogBox.AddButton("Reinstall", ResponseType.Accept);

                    InstallLinkDialogBox.Response += delegate(object o1, ResponseArgs responseArgs)
                    {
                        if (responseArgs.ResponseId == ResponseType.Reject)
                        {
                            // Make sure we have the setting to ignore the dialog box set.
                            IPCadapter.getInstance().RemoveHandler();
                        }

                        if (responseArgs.ResponseId == ResponseType.Accept)
                        {
                            IPCadapter.getInstance().InstallHandler();
                        }
                    };
                }

                InstallLinkDialogBox.ShowAll();
                InstallLinkDialogBox.Run();
                InstallLinkDialogBox.Dispose();
            });
        }
Example #4
0
        private static void Main(string[] args)
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Settings.PersistentSettings.debugConsole)
            {
                AllocConsole(); // needs to be the first call in the program to prevent weird bugs
            }
            if (!Directory.Exists(Settings.StorageLocation))
            {
                // Create Settings directory if it doesn't exist, as we need to stick our pidfile there.
                Directory.CreateDirectory(Settings.StorageLocation);
            }

            URIStartResult uriRes = URIStartResult.CLOSE;

            uriRes = IPCadapter.getInstance().HandleURIStart(args);
            switch (uriRes)
            {
            case URIStartResult.CLOSE:
                Environment.Exit(0);
                break;

            case URIStartResult.PARSE:
                Console.WriteLine($"Starting with args : {args[0]}");
                break;

            case URIStartResult.CONTINUE:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            socket = new ClientSocket();

            //Create the Form Console interface.
            var thread = new Thread(OpenGUI);

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                thread.SetApartmentState(ApartmentState.STA);
            }
            thread.Start();
            while (Settings.conInterface is null)
            {
                Thread.Sleep(250);
            }
            Task.Factory.StartNew(() => socket.Init())
            .Wait();     // run socket in background. Important to wait for init to have actually finished before continuing
            Task.Factory.StartNew(() => IPCadapter.getInstance().RegisterMinion()).Wait();

            // Add a GLib Idle handler to fix the issue here.
            Idle.Add(delegate
            {
                Task.Factory.StartNew(() => GameMemReader.getInstance().RunLoop()); // run loop in background
                if (uriRes == URIStartResult.PARSE)
                {
                    IPCadapter.getInstance().SendToken(args[0]);
                }
                return(false);
            });

            thread.Join();
        }