static void Main()
        {
            if (!debugGui)
            {
                AllocConsole(); // needs to be the first call in the program to prevent weird bugs
            }
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ClientSocket socket = new ClientSocket();

            string guildID = "754465589958803548";

            if (File.Exists("guildid.txt"))
            {
                guildID = File.ReadAllText("guildid.txt");
            }

            Task.Factory.StartNew(() => socket.Connect("http://localhost:8123", guildID)); //synchronously force the socket to connect, and also broadcast the guildID

            Task.Factory.StartNew(() => GameMemReader.getInstance().RunLoop());            // run loop in background

            if (debugGui)
            {
                Application.Run(new MainForm());
            }
            else
            {
                (new DebugConsole()).Run();
            }
        }
Exemple #2
0
        static void Main()
        {
            if (doConsole)
            {
                AllocConsole(); // needs to be the first call in the program to prevent weird bugs
            }
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ClientSocket socket = new ClientSocket();

            string hostPath = "host.txt";

            //TODO make proper properties file
            string host = File.Exists(hostPath) ? File.ReadAllText(hostPath) : "http://localhost:8123";
            var    form = new UserForm(socket);

            conInterface = new FormConsole(form);                               //Create the Form Console interface.
            Task.Factory.StartNew(() => socket.Connect(host));                  //synchronously force the socket to connect
            Task.Factory.StartNew(() => GameMemReader.getInstance().RunLoop()); // run loop in background
            //(new DebugConsole(debugGui)).Run();

            Application.Run(form);
            //test
        }
Exemple #3
0
        public void Connect(string url)
        {
            //Settings.conInterface.WriteTextFormatted($"[§bClientSocket§f] Connecting to §1{url}§f...");
            Settings.conInterface.WriteModuleTextColored("ClientSocket", Color.Cyan, $"Connecting to {url}...");
            socket = new SocketIO(url);

            /*socket.On("hi", response =>
             * {
             *  string text = response.GetValue<string>();
             * });*/
            socket.OnConnected += (sender, e) =>
            {
                //Settings.conInterface.WriteTextFormatted($"[§bClientSocket§f] Connected successfully!");
                Settings.conInterface.WriteModuleTextColored("ClientSocket", Color.Cyan, "Connected successfully!");
                GameMemReader.getInstance().GameStateChanged += GameStateChangedHandler;
                GameMemReader.getInstance().PlayerChanged    += PlayerChangedHandler;
                GameMemReader.getInstance().JoinedLobby      += JoinedLobbyHandler;
                this.OnConnected(this, new EventArgs());
            };

            socket.OnDisconnected += (sender, e) =>
            {
                //Settings.conInterface.WriteTextFormatted($"[§bClientSocket§f] Lost connection!");
                Settings.conInterface.WriteModuleTextColored("ClientSocket", Color.Cyan, $"{Color.Red.ToTextColor()}Connection lost!");
                GameMemReader.getInstance().GameStateChanged -= GameStateChangedHandler;
                GameMemReader.getInstance().PlayerChanged    -= PlayerChangedHandler;
                GameMemReader.getInstance().JoinedLobby      -= JoinedLobbyHandler;
            };

            socket.ConnectAsync();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            if (Settings.PersistentSettings.debugConsole)
            {
                AllocConsole(); // needs to be the first call in the program to prevent weird bugs
            }

            URIStartResult uriRes = HandleURIStart(args);

            if (uriRes == URIStartResult.CLOSE)
            {
                return;
            }

            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ClientSocket socket = new ClientSocket();

            form                  = new UserForm(socket);
            Settings.form         = form;
            Settings.conInterface = new FormConsole(form);                                                                  //Create the Form Console interface.
            Task.Factory.StartNew(() => socket.Init()).Wait();                                                              // run socket in background. Important to wait for init to have actually finished before continuing
            Task.Factory.StartNew(() => GameMemReader.getInstance().RunLoop());                                             // run loop in background
            Task.Factory.StartNew(() => IPCadapter.getInstance().RunLoop(uriRes == URIStartResult.PARSE ? args[0] : null)); // Run listener for tokens

            //AllocConsole();
            Application.Run(form);

            //test
        }
Exemple #5
0
        public void Connect(string url, string paramGuildID)
        {
            GuildID = paramGuildID;
            socket  = new SocketIO(url);

            /*socket.On("hi", response =>
             * {
             *  string text = response.GetValue<string>();
             * });*/
            socket.OnConnected += (sender, e) =>
            {
                GameMemReader.getInstance().GameStateChanged += GameStateChangedHandler;
                GameMemReader.getInstance().PlayerChanged    += PlayerChangedHandler;
                UpdateGuildID(paramGuildID, false);
            };

            socket.ConnectAsync();

            while (true)
            {
                string[] command = Console.ReadLine().Split();
                if (command.Length > 1 && command[0] == "setid")
                {
                    UpdateGuildID(command[1]);
                }
            }
        }
Exemple #6
0
        public UserForm(ClientSocket clientSocket)
        {
            this.clientSocket = clientSocket;
            InitializeComponent();
            GameMemReader.getInstance().GameStateChanged += GameStateChangedHandler;
            GameMemReader.getInstance().PlayerChanged    += UserForm_PlayerChanged;
            GameMemReader.getInstance().ChatMessageAdded += OnChatMessageAdded;
            GameMemReader.getInstance().JoinedLobby      += OnJoinedLobby;

            clientSocket.OnConnected += (sender, e) =>
            {
                Settings.PersistentSettings.host = e.Uri;
            };

            // Load URL
            URLTextBox.Text = Settings.PersistentSettings.host;

            // Connect on Enter
            AcceptButton = ConnectButton;

            if (DarkTheme())
            {
                EnableDarkTheme();
            }
            else
            {
                metroStyleExtender1.SetApplyMetroTheme(ConsoleTextBox, false);
                ConsoleTextBox.ResetBackColor();
                ConsoleTextBox.ResetForeColor();
            }

            NormalTextColor = DarkTheme() ? Color.White : Color.Black;
        }
 protected override void OnOpen()
 {
     GameMemReader.getInstance().GameStateChanged += GameStateChangedHandler;
     GameMemReader.getInstance().PlayerChanged    += PlayerChangedHandler;
     GameMemReader.getInstance().JoinedLobby      += JoinedLobbyHandler;
     GameMemReader.getInstance().GameOver         += GameOverHandler;
     Logger.Debug("New connection to API server");
 }
Exemple #8
0
 protected override void OnClose(CloseEventArgs e)
 {
     GameMemReader.getInstance().GameStateChanged -= GameStateChangedHandler;
     GameMemReader.getInstance().PlayerChanged    -= PlayerChangedHandler;
     GameMemReader.getInstance().JoinedLobby      -= JoinedLobbyHandler;
     GameMemReader.getInstance().GameOver         -= GameOverHandler;
     Settings.conInterface.WriteModuleTextColored("APIServer", Color.Brown, "Connection terminated");
 }
Exemple #9
0
 protected override void OnOpen()
 {
     GameMemReader.getInstance().GameStateChanged += GameStateChangedHandler;
     GameMemReader.getInstance().PlayerChanged    += PlayerChangedHandler;
     GameMemReader.getInstance().JoinedLobby      += JoinedLobbyHandler;
     GameMemReader.getInstance().GameOver         += GameOverHandler;
     Settings.conInterface.WriteModuleTextColored("APIServer", Color.Brown, "New connection");
 }
Exemple #10
0
        public void Connect(string url)
        {
            httpClient.BaseAddress = new Uri("http://localhost:8080");

            GameMemReader.getInstance().GameStateChanged += GameStateChangedHandler;
            GameMemReader.getInstance().PlayerChanged    += PlayerChangedHandler;
            GameMemReader.getInstance().JoinedLobby      += JoinedLobbyHandler;
        }
Exemple #11
0
 protected override void OnClose(CloseEventArgs e)
 {
     GameMemReader.getInstance().GameStateChanged -= GameStateChangedHandler;
     GameMemReader.getInstance().PlayerChanged    -= PlayerChangedHandler;
     GameMemReader.getInstance().JoinedLobby      -= JoinedLobbyHandler;
     GameMemReader.getInstance().GameOver         -= GameOverHandler;
     Logger.Info("Connection terminated on API server");
 }
Exemple #12
0
        public void SendConnectCode(string connectCode)
        {
            ConnectCode = connectCode;
            httpClient.DefaultRequestHeaders.Remove("Capture-Code");
            httpClient.DefaultRequestHeaders.Add("Capture-Code", connectCode);

            GameMemReader.getInstance().ForceUpdatePlayers();// FORCE UPDATE EVERYTHING
            GameMemReader.getInstance().ForceTransmitState();
        }
Exemple #13
0
        /// <summary>
        ///     The main entry point for the application.
        /// </summary>
        public static void Main()
        {
            //Create the Form Console interface.
            var socketTask = Task.Factory.StartNew(() => socket.Init());        // run socket in background. Important to wait for init to have actually finished before continuing

            Task.Factory.StartNew(() => GameMemReader.getInstance().RunLoop()); // run loop in background
            socketTask.Wait();
            IPCadapter.getInstance().RegisterMinion();
        }
Exemple #14
0
 public void SendConnectCode(string connectCode)
 {
     ConnectCode = connectCode;
     socket.EmitAsync("connect", ConnectCode).ContinueWith((t) => {
         GameMemReader.getInstance().ForceUpdate();
         GameMemReader.getInstance().ForceTransmitState();
     });
     Program.conInterface.WriteLine($"Connection code ({connectCode}) sent to server.");
 }
Exemple #15
0
        public void Init()
        {
            // Initialize a socket.io connection.
            socket = new SocketIO();

            // Handle tokens from protocol links.


            // Register handlers for game-state change events.
            GameMemReader.getInstance().GameStateChanged += GameStateChangedHandler;
            GameMemReader.getInstance().PlayerChanged    += PlayerChangedHandler;
            GameMemReader.getInstance().DisplayImposter  += DisplayImposterHandler;
            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.ToTextColor()}{ConnectCode}{Settings.conInterface.getNormalColor().ToTextColor()}) sent to server.");
                    GameMemReader.getInstance().ForceUpdatePlayers();
                    GameMemReader.getInstance().ForceTransmitState();
                    GameMemReader.getInstance().ForceTransmitLobby();
                });
            };

            socket.On("killself", response =>
            {
                Environment.Exit(0);
            });

            // 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.ToTextColor()}Connection lost!");

                // Alert any listeners that the disconnection has occured.
                OnDisconnected?.Invoke(this, EventArgs.Empty);
            };
        }
Exemple #16
0
 public void SendConnectCode(string connectCode)
 {
     ConnectCode = connectCode;
     socket.EmitAsync("connect", ConnectCode).ContinueWith((t) => {
         GameMemReader.getInstance().ForceUpdatePlayers();
         GameMemReader.getInstance().ForceTransmitState();
     });
     Settings.conInterface.WriteModuleTextColored("ClientSocket", Color.Cyan, $"Connection code ({Color.Red.ToTextColor()}{connectCode}{UserForm.NormalTextColor.ToTextColor()}) sent to server.");
     //Program.conInterface.WriteModuleTextColored("GameMemReader", System.Drawing.Color.Aqua, $"Connection code ({connectCode}) sent to server.");
 }
 public void SendConnectCode(string connectCode)
 {
     ConnectCode = connectCode;
     socket.EmitAsync("connect", ConnectCode).ContinueWith((t) => {
         GameMemReader.getInstance().ForceUpdatePlayers();
         GameMemReader.getInstance().ForceTransmitState();
     });
     Program.conInterface.WriteTextFormatted($"[§bClientSocket§f] Connection code (§c{connectCode}§f) sent to server.");
     //Program.conInterface.WriteModuleTextColored("GameMemReader", System.Drawing.Color.Aqua, $"Connection code ({connectCode}) sent to server.");
 }
Exemple #18
0
        private void _eventGameIsUnverified(object o, ValidatorEventArgs e)
        {
            Gtk.Application.Invoke((obj, ev) =>
            {
                var badversionBox = new MessageDialog(this,
                                                      DialogFlags.Modal,
                                                      MessageType.Warning,
                                                      ButtonsType.None,
                                                      false,
                                                      "We have detected an unverified version of Among Us. The capture may not work properly.",
                                                      new object[] { });

                if (e.Validity.HasFlag(AmongUsValidity.GAME_VERIFICATION_FAIL))
                {
                    badversionBox.Text += "\n\nThis version of Among Us appears to be an out-of-date or Beta version of the game.";
                }

                var marea = badversionBox.MessageArea as Box;

                if (e.Validity.HasFlag(AmongUsValidity.STEAM_VERIFICAITON_FAIL))
                {
                    badversionBox.Text +=
                        "\n\nThis version appears to be a cracked or pirated version of the game. Please consider buying a copy of the game at the link below.";
                    marea.Add(new LinkButton("https://store.steampowered.com/app/945360/Among_Us/", "Open Steam Store"));
                }

                badversionBox.Text += "\n\nWe cannot provide support for this configuration should you choose to continue.";

                badversionBox.AddButton("Quit", ResponseType.Reject);
                badversionBox.AddButton("I Understand", ResponseType.Accept);

                badversionBox.Response += delegate(object o1, ResponseArgs args)
                {
                    if (args.ResponseId == ResponseType.Reject)
                    {
                        Close();
                    }

                    if (args.ResponseId == ResponseType.Accept)
                    {
                        GameMemReader.getInstance().cracked        = false;
                        GameMemReader.getInstance().invalidversion = false;
                        GameMemReader.getInstance().paused         = false;
                    }
                };

                badversionBox.ShowAll();
                badversionBox.Run();
                badversionBox.Dispose();
            });


            Settings.conInterface.WriteModuleTextColored("Notification", Color.Red,
                                                         $"We have detected an unverified version of Among Us. Things may not work properly.");
        }
Exemple #19
0
        private static void Main(string[] args)
        {
            if (Settings.PersistentSettings.debugConsole)
            {
                AllocConsole(); // needs to be the first call in the program to prevent weird bugs
            }
            var 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();
            }



            var socket = new ClientSocket();

            //Create the Form Console interface.
            Task.Factory.StartNew(() => socket.Init()).Wait(); // run socket in background. Important to wait for init to have actually finished before continuing
            var thread = new Thread(OpenGUI);

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            while (Settings.conInterface is null)
            {
                Thread.Sleep(250);
            }
            //Create the Form Console interface.
            Task.Factory.StartNew(() => socket.Init())
            .Wait();     // run socket in background. Important to wait for init to have actually finished before continuing
            IPCadapter.getInstance().RegisterMinion();
            window.Loaded += (sender, eventArgs) =>
            {
                Task.Factory.StartNew(() => GameMemReader.getInstance().RunLoop()); // run loop in background
                if (uriRes == URIStartResult.PARSE)
                {
                    IPCadapter.getInstance().SendToken(args[0]);
                }
            };
            thread.Join();
        }
Exemple #20
0
 private void UpdateGuildID(string newGuildId, bool toFile = true)
 {
     GuildID = newGuildId;
     if (toFile)
     {
         File.WriteAllText("guildid.txt", GuildID);
     }
     socket.EmitAsync("guildID", GuildID).ContinueWith((t) => {
         GameMemReader.getInstance().ForceUpdate();
         GameMemReader.getInstance().ForceTransmitState();
     });;
 }
Exemple #21
0
 public UserForm(ClientSocket sock)
 {
     clientSocket = sock;
     InitializeComponent();
     GameMemReader.getInstance().GameStateChanged += GameStateChangedHandler;
     GameMemReader.getInstance().PlayerChanged    += UserForm_PlayerChanged;
     GameMemReader.getInstance().ChatMessageAdded += OnChatMessageAdded;
     if (DarkTheme())
     {
         EnableDarkTheme();
     }
 }
Exemple #22
0
        public UserForm(ClientSocket sock)
        {
            clientSocket = sock;
            InitializeComponent();
            GameMemReader.getInstance().GameStateChanged += GameStateChangedHandler;
            GameMemReader.getInstance().PlayerChanged    += UserForm_PlayerChanged;
            GameMemReader.getInstance().ChatMessageAdded += OnChatMessageAdded;
            GameMemReader.getInstance().JoinedLobby      += OnJoinedLobby;

            if (DarkTheme())
            {
                EnableDarkTheme();
            }
            NormalTextColor = DarkTheme() ? Color.White : Color.Black;
        }
Exemple #23
0
        public void Connect(string url)
        {
            socket = new SocketIO(url);

            /*socket.On("hi", response =>
             * {
             *  string text = response.GetValue<string>();
             * });*/
            socket.OnConnected += (sender, e) =>
            {
                GameMemReader.getInstance().GameStateChanged += GameStateChangedHandler;
                GameMemReader.getInstance().PlayerChanged    += PlayerChangedHandler;
            };


            socket.ConnectAsync();
        }
Exemple #24
0
        private void OnRequestData(SocketIOResponse resp)
        {
            int requestedData = resp.GetValue <int>();

            if ((requestedData & (int)GameDataType.GameState) > 0)
            {
                GameMemReader.getInstance().ForceTransmitState();
            }
            if ((requestedData & (int)GameDataType.LobbyCode) > 0)
            {
                GameMemReader.getInstance().ForceTransmitLobby();
            }
            if ((requestedData & (int)GameDataType.Players) > 0)
            {
                GameMemReader.getInstance().ForceUpdatePlayers();
            }
        }
Exemple #25
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);
            };
        }
Exemple #26
0
        public UserForm(ClientSocket sock) : base("Among Us Capture - GTK")
        {
            //builder.Autoconnect(this);
            Icon         = new Pixbuf(Assembly.GetExecutingAssembly().GetManifestResourceStream("amonguscapture_gtk.icon.ico"));
            clientSocket = sock;
            InitializeWindow();
            GameMemReader.getInstance().GameStateChanged      += GameStateChangedHandler;
            GameMemReader.getInstance().PlayerChanged         += UserForm_PlayerChanged;
            GameMemReader.getInstance().ChatMessageAdded      += OnChatMessageAdded;
            GameMemReader.getInstance().JoinedLobby           += OnJoinedLobby;
            GameMemReader.getInstance().GameVersionUnverified += _eventGameIsUnverified;



            // Load URL
            _urlHostEntryField.Text = Settings.PersistentSettings.host;

            // Connect on Enter
            //this.AcceptButton = ConnectButton;
            this.Default = _connectCodeSubmitButton;

            // Get the user's default GTK TextView foreground color.
            NormalTextColor = GetRgbColorFromFloat(_consoleTextView.StyleContext.GetColor(Gtk.StateFlags.Normal));

            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");

            var skippingHandler = Settings.PersistentSettings.skipHandlerInstall;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                // Windows doesn't support this. Skip the handler automatically and deactivate the button.
                skippingHandler = true;
                _primaryWindowInstallLinkHandler.Sensitive = false;
            }

            if (!File.Exists(xdg_file) && !skippingHandler)
            {
                // Activate the button if we aren't skipping the handler install.
                _primaryWindowInstallLinkHandler.Activate();
            }
        }
Exemple #27
0
        static void Main()
        {
            if (doConsole)
            {
                AllocConsole(); // needs to be the first call in the program to prevent weird bugs
            }
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ClientSocket socket = new ClientSocket();
            var          form   = new UserForm(socket);

            Settings.conInterface = new FormConsole(form);                                 //Create the Form Console interface.
            Task.Factory.StartNew(() => socket.Connect(Settings.PersistentSettings.host)); //synchronously force the socket to connect
            Task.Factory.StartNew(() => GameMemReader.getInstance().RunLoop());            // run loop in background

            //AllocConsole();
            Application.Run(form);

            //test
        }
        public UserForm(ClientSocket clientSocket)
        {
            this.clientSocket = clientSocket;
            InitializeComponent();
            GameMemReader.getInstance().GameStateChanged += GameStateChangedHandler;
            GameMemReader.getInstance().PlayerChanged    += UserForm_PlayerChanged;
            GameMemReader.getInstance().ChatMessageAdded += OnChatMessageAdded;
            GameMemReader.getInstance().JoinedLobby      += OnJoinedLobby;

            // Load URL
            URLTextBox.Text = Settings.PersistentSettings.host;

            // Connect on Enter
            this.AcceptButton = ConnectButton;

            if (DarkTheme())
            {
                EnableDarkTheme();
            }
            NormalTextColor = DarkTheme() ? Color.White : Color.Black;
        }
Exemple #29
0
        public void Run()
        {
            GameMemReader.getInstance().GameStateChanged += GameStateChangedHandler;
            GameMemReader.getInstance().PlayerChanged    += PlayerChangedHandler;

            //while (true)
            //{
            //    string command = Console.ReadLine();
            //    Console.WriteLine($"Received command: {command}");
            //    if (command == "list")
            //    {
            //        Console.WriteLine("Player List:");
            //        foreach (KeyValuePair<string, PlayerInfo> kvp in GameMemReader.getInstance().oldPlayerInfos) // thread safety ??
            //        {
            //            string playerName = kvp.Key;
            //            PlayerInfo pi = kvp.Value;
            //            Console.WriteLine(kvp.Key);
            //        }
            //    }
            //}

            Thread.Sleep(Timeout.Infinite);
        }
Exemple #30
0
        public void Init()
        {
            // Initialize a socket.io connection.
            socket = new SocketIO();
            // Handle tokens from protocol links.

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



            // 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.ToTextColor()}{ConnectCode}{Settings.conInterface.getNormalColor().ToTextColor()}) sent to server.");
                    GameMemReader.getInstance().ForceUpdatePlayers();
                    GameMemReader.getInstance().ForceTransmitState();
                    GameMemReader.getInstance().ForceTransmitLobby();
                });
                if (!(this.handler is null))
                {
                    socket.EmitAsync("botID", handler.DClient.CurrentUser.Id);
                    Settings.conInterface.WriteModuleTextColored("ClientSocket", Color.Cyan,
                                                                 $"{Color.Red.ToTextColor()}Sending BotID: {Color.LightGreen.ToTextColor()}{handler.DClient.CurrentUser.Id}");
                }
            };
            socket.On("modify", response =>
            {
                string jsonRequest   = response.GetValue(0).ToString();
                UpdateRequest update = JsonConvert.DeserializeObject <UpdateRequest>(jsonRequest);
                Console.Write(JsonConvert.SerializeObject(update, Formatting.Indented));
                if (handler is null)
                {
                    socket.EmitAsync("taskFailed", update.TaskId);
                    return;
                }
                ;
                Settings.conInterface.WriteModuleTextColored("Discord", Color.Red,
                                                             $"{Color.LawnGreen.ToTextColor()}Got task: {Color.LightGreen.ToTextColor()}{update.ToJson()}");
                handler.UpdateUser(update.GuildId, update.UserId, update.Parameters.Mute, update.Parameters.Deaf).ContinueWith(x =>
                {
                    Settings.conInterface.WriteModuleTextColored("Discord", Color.Red, $"TaskComplete: {Color.Aqua.ToTextColor()}{x.Result}");
                    socket.EmitAsync(x.Result ? "taskComplete" : "taskFailed", update.TaskId);
                });
            });
            socket.On("killself", response =>
            {
                Environment.Exit(0);
            });

            // 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.ToTextColor()}Connection lost!");

                // Alert any listeners that the disconnection has occured.
                OnDisconnected?.Invoke(this, EventArgs.Empty);
            };

            socket.On("requestdata", OnRequestData);
        }