Beispiel #1
0
        public static void Main(string[] args)
        {
            // Configure the monitor with command-line arguments.
            var MonitorIndex = Array.IndexOf(args, "--MonitorType");
            var PIDIndex     = Array.IndexOf(args, "--ProcessID");
            var IPIndex      = Array.IndexOf(args, "--LocalIP");
            var RegionIndex  = Array.IndexOf(args, "--Region");
            var PortIndex    = Array.IndexOf(args, "--Port");
            var TestIndex    = Array.IndexOf(args, "--Test");

            if (TestIndex != -1)
            {
                ValidateOpcodes();
                return;
            }

            var port = 13346U;

            if (PortIndex != -1)
            {
                port = uint.Parse(args[PortIndex + 1]);
            }

            var MonitorType = TCPNetworkMonitor.NetworkMonitorType.RawSocket;

            if (MonitorIndex != -1 && args[MonitorIndex + 1] == "WinPCap")
            {
                MonitorType = TCPNetworkMonitor.NetworkMonitorType.WinPCap;
            }

            var localRegion = Region.Global;

            if (RegionIndex != -1)
            {
                localRegion = args[RegionIndex + 1] switch
                {
                    "KR" => Region.KR,
                    "CN" => Region.CN,
                    _ => localRegion,
                };
            }
            else if (!Util.SystemHasGlobalClient())
            {
                if (Util.SystemHasKRClient())
                {
                    localRegion = Region.KR;
                }
                else if (Util.SystemHasCNClient())
                {
                    localRegion = Region.CN;
                }
            }

            var monitor = new FFXIVNetworkMonitor
            {
                MonitorType     = MonitorType,
                Region          = localRegion,
                ProcessID       = PIDIndex != -1 ? uint.Parse(args[PIDIndex + 1]) : 0,
                LocalIP         = IPIndex != -1 ? args[IPIndex + 1] : "",
                UseSocketFilter = Array.IndexOf(args, "--UseSocketFilter") != -1,
                MessageReceived = MessageReceived,
                MessageSent     = MessageSent,
            };

            var commander = new Commander("kill");

            commander.AddCommand("start", monitor.Start);
            commander.AddCommand("stop", () =>
            {
                try
                {
                    monitor.Stop();
                }
                catch (NullReferenceException nre) // _monitor is null, and it's a private member of monitor so I can't check if it exists beforehand.
                {
                    Console.Error.WriteLine(nre);
                }
            });
            commander.OnKill(() =>
            {
                try
                {
                    monitor.Stop();
                }
                catch (NullReferenceException) { }
            });
            commander.Start();

            /*var server = new WebSocketServer(int.Parse(args[PortIndex + 1]));
             * server.AddWebSocketService("/", () => ParseServer.Create(commander));
             * server.Start();*/

            // Create the parser.
            var ParseAlgorithmIndex = Array.IndexOf(args, "--ParseAlgorithm");

            if (ParseAlgorithmIndex != -1)
            {
                _parser = args[ParseAlgorithmIndex + 1] switch
                {
                    "RAMHeavy" => new Parser(localRegion, ParserMode.RAMHeavy, port),
                    "CPUHeavy" => new Parser(localRegion, ParserMode.CPUHeavy, port),
                    "PacketSpecific" => new Parser(localRegion, ParserMode.PacketSpecific, port),
                    _ => new Parser(localRegion, ParserMode.RAMHeavy, port),
                };
            }
            else
            {
                _parser = new Parser(localRegion, ParserMode.RAMHeavy, port);
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            // Configure the monitor with command-line arguments.
            var MonitorIndex = Array.IndexOf(args, "--MonitorType");
            var PIDIndex     = Array.IndexOf(args, "--ProcessID");
            var IPIndex      = Array.IndexOf(args, "--LocalIP");
            var RegionIndex  = Array.IndexOf(args, "--Region");
            var PortIndex    = Array.IndexOf(args, "--Port");

            if (PortIndex == -1)
            {
                Console.WriteLine("Port must be provided via command line");
                Environment.Exit(1);
            }

            var MonitorType = TCPNetworkMonitor.NetworkMonitorType.RawSocket;

            if (MonitorIndex != -1 && args[MonitorIndex + 1] == "WinPCap")
            {
                MonitorType = TCPNetworkMonitor.NetworkMonitorType.WinPCap;
            }

            var localRegion = Region.Global;

            if (RegionIndex != -1)
            {
                switch (args[RegionIndex + 1])
                {
                case "KR":
                    localRegion = Region.KR;
                    break;

                case "CN":
                    localRegion = Region.CN;
                    break;
                }
            }
            else if (!Util.SystemHasGlobalClient())
            {
                if (Util.SystemHasKRClient())
                {
                    localRegion = Region.KR;
                }
                else if (Util.SystemHasCNClient())
                {
                    localRegion = Region.CN;
                }
            }

            // Create the monitor.
            var monitor = new FFXIVNetworkMonitor
            {
                MonitorType     = MonitorType,
                Region          = localRegion,
                ProcessID       = PIDIndex != -1 ? uint.Parse(args[PIDIndex + 1]) : 0,
                LocalIP         = IPIndex != -1 ? args[IPIndex + 1] : "",
                UseSocketFilter = Array.IndexOf(args, "--UseSocketFilter") != -1 ? true : false,
                MessageReceived = MessageReceived,
                MessageSent     = MessageSent
            };

            // Create the parser.
            var ParseAlgorithmIndex = Array.IndexOf(args, "--ParseAlgorithm");

            if (ParseAlgorithmIndex != -1)
            {
                switch (args[ParseAlgorithmIndex + 1])
                {
                case "RAMHeavy":
                    Parser = new Parser(localRegion, ParserMode.RAMHeavy, uint.Parse(args[PortIndex + 1]));
                    break;

                case "CPUHeavy":
                    Parser = new Parser(localRegion, ParserMode.CPUHeavy, uint.Parse(args[PortIndex + 1]));
                    break;

                case "PacketSpecific":
                    Parser = new Parser(localRegion, ParserMode.PacketSpecific, uint.Parse(args[PortIndex + 1]));
                    break;

                default:
                    Parser = new Parser(localRegion, ParserMode.RAMHeavy, uint.Parse(args[PortIndex + 1]));
                    break;
                }
            }
            else
            {
                Parser = new Parser(localRegion, ParserMode.RAMHeavy, uint.Parse(args[PortIndex + 1]));
            }

            // Check for input.
            var input = "";

            // Get the input without blocking the output.
            var InputLoop = new Thread(() =>
            {
                while (true)
                {
                    input = Console.In.ReadLine(); // This blocks the InputLoop thread, so there's no need to sleep or anything like that.
                }
            });

            InputLoop.Start();

            // Process the input.
            var InputProcessingLoop = new Thread(() => {
                while (input != "kill")
                {
                    if (input == "start")
                    {
                        monitor.Start();
                    }
                    else if (input == "stop")
                    {
                        try
                        {
                            monitor.Stop();
                        }
                        catch (NullReferenceException nre) // _monitor is null, and it's a private member of monitor so I can't check if it exists beforehand.
                        {
                            Console.Error.WriteLine(nre);
                        }
                    }

                    input = "";
                    Thread.Sleep(200); // One-fifth of a second is probably fine for user input, and it's way less intensive than 1.
                }

                try
                {
                    monitor.Stop();
                }
                catch (NullReferenceException) {}
                InputLoop.Abort();
            });

            InputProcessingLoop.Start();
        }
        static void Main(string[] args)
        {
            // Use arguments to configure the monitor.
            int MonitorIndex = Array.IndexOf(args, "--MonitorType");
            int PIDIndex     = Array.IndexOf(args, "--ProcessID");
            int IPIndex      = Array.IndexOf(args, "--LocalIP");
            int RegionIndex  = Array.IndexOf(args, "--Region");

            TCPNetworkMonitor.NetworkMonitorType MonitorType = TCPNetworkMonitor.NetworkMonitorType.RawSocket;
            if (MonitorIndex != -1 && args[MonitorIndex + 1] == "WinPCap")
            {
                MonitorType = TCPNetworkMonitor.NetworkMonitorType.WinPCap;
            }

            Region localRegion = Region.Global;

            if (RegionIndex != -1)
            {
                if (args[RegionIndex + 1] == "KR")
                {
                    localRegion = Region.KR;
                }
            }
            else if (!Util.SystemHasGlobalClient())
            {
                if (Util.SystemHasKRClient())
                {
                    localRegion = Region.KR;
                }
            }

            // Create the monitor.
            FFXIVNetworkMonitor monitor = new FFXIVNetworkMonitor
            {
                MonitorType     = MonitorType,
                ProcessID       = PIDIndex != -1 ? uint.Parse(args[PIDIndex + 1]) : 0,
                LocalIP         = IPIndex != -1 ? args[IPIndex + 1] : "",
                UseSocketFilter = Array.IndexOf(args, "--UseSocketFilter") != -1 ? true : false,
                MessageReceived = (string connection, long epoch, byte[] message) => MessageReceived(connection, epoch, message),
                MessageSent     = (string connection, long epoch, byte[] message) => MessageSent(connection, epoch, message)
            };

            // Create the parser.
            int ParseAlgorithmIndex = Array.IndexOf(args, "--ParseAlgorithm");

            if (ParseAlgorithmIndex != -1)
            {
                if (args[ParseAlgorithmIndex + 1] == "RAMHeavy")
                {
                    Parser = new Parser(localRegion, ParserMode.RAMHeavy);
                }
                else if (args[ParseAlgorithmIndex + 1] == "CPUHeavy")
                {
                    Parser = new Parser(localRegion, ParserMode.CPUHeavy);
                }
                else if (args[ParseAlgorithmIndex + 1] == "PacketSpecific")
                {
                    Parser = new Parser(localRegion, ParserMode.PacketSpecific);
                }
                else
                {
                    Parser = new Parser(localRegion, ParserMode.RAMHeavy);
                }
            }
            else
            {
                Parser = new Parser(localRegion, ParserMode.RAMHeavy);
            }

            // Check for input.
            string input = "";

            // Get the input without blocking the output.
            Thread InputLoop = new Thread(() =>
            {
                while (true)
                {
                    input = Console.In.ReadLine(); // This blocks the InputLoop thread, so there's no need to sleep or anything like that.
                }
            });

            InputLoop.Start();

            // Process the input.
            Thread InputProcessingLoop = new Thread(() => {
                while (input != "kill")
                {
                    if (input == "start")
                    {
                        monitor.Start();
                    }
                    else if (input == "stop")
                    {
                        try
                        {
                            monitor.Stop();
                        }
                        catch (NullReferenceException nre) // _monitor is null, and it's a private member of monitor so I can't check if it exists beforehand.
                        {
                            Console.Error.WriteLine(nre);
                        }
                    }

                    input = "";
                    Thread.Sleep(200); // One-fifth of a second is probably fine for user input, and it's way less intensive than 1.
                }

                try
                {
                    monitor.Stop();
                }
                catch (NullReferenceException) {}
                InputLoop.Abort();
            });

            InputProcessingLoop.Start();
        }
Beispiel #4
0
        public static void Main(string[] args)
        {
            // Configure the monitor with command-line arguments.
            var MonitorIndex = Array.IndexOf(args, "--MonitorType");
            var PIDIndex     = Array.IndexOf(args, "--ProcessID");
            var IPIndex      = Array.IndexOf(args, "--LocalIP");
            var RegionIndex  = Array.IndexOf(args, "--Region");
            var PortIndex    = Array.IndexOf(args, "--Port");

            if (PortIndex != -1)
            {
                Port = uint.Parse(args[PortIndex + 1]);
            }

            var MonitorType = TCPNetworkMonitor.NetworkMonitorType.RawSocket;

            if (MonitorIndex != -1 && args[MonitorIndex + 1] == "WinPCap")
            {
                MonitorType = TCPNetworkMonitor.NetworkMonitorType.WinPCap;
            }

            var localRegion = Region.Global;

            if (RegionIndex != -1)
            {
                localRegion = args[RegionIndex + 1] switch
                {
                    "KR" => Region.KR,
                    "CN" => Region.CN,
                    _ => localRegion,
                };
            }
            else if (!Util.SystemHasGlobalClient())
            {
                if (Util.SystemHasKRClient())
                {
                    localRegion = Region.KR;
                }
                else if (Util.SystemHasCNClient())
                {
                    localRegion = Region.CN;
                }
            }

            var monitor = new FFXIVNetworkMonitor
            {
                MonitorType     = MonitorType,
                Region          = localRegion,
                ProcessID       = PIDIndex != -1 ? uint.Parse(args[PIDIndex + 1]) : 0,
                LocalIP         = IPIndex != -1 ? args[IPIndex + 1] : "",
                UseSocketFilter = Array.IndexOf(args, "--UseSocketFilter") != -1,
                MessageReceived = MessageReceived,
                MessageSent     = MessageSent,
            };

            PacketDispatcher = new PacketDispatcher("http://localhost:" + Port);

            var commander = new Commander("kill");

            commander.AddCommand("start", () =>
            {
                PacketDispatcher.Start();
                monitor.Start();
            });
            commander.AddCommand("stop", () =>
            {
                try
                {
                    monitor.Stop();
                    PacketDispatcher.Cancel();
                }
                catch (NullReferenceException nre) // _monitor is null, and it's a private member of monitor so I can't check if it exists beforehand.
                {
                    Console.Error.WriteLine(nre);
                }
            });
            commander.OnKill(() =>
            {
                try
                {
                    monitor.Stop();
                    PacketDispatcher.Cancel();
                }
                catch (NullReferenceException) { }
            });
            commander.Start();
        }