Пример #1
0
        private void Initialize()
        {
            AppendLog("RotMG Tool initializing...");

            try
            {
                Settings = new SimpleSettings();
                string packetFile = Path.Combine(Program.RootDirectory, "packets.dat");
                if (File.Exists(packetFile))
                {
                    PacketTable = PacketTable.Load(File.ReadAllText(packetFile));
                }
                AppendLog("Settings loaded.");
            }
            catch (Exception ex)
            {
                AppendLog("Error when loading settings: " + ex.Message);
                return;
            }

            //new System.Threading.Thread(DoCheckUpdate) { IsBackground = true }.Start();

            AppendLog("Retrieving server list...");
            var doc =
                XDocument.Load("http://realmofthemadgodhrd.appspot.com/char/list?guid=" +
                               Guid.NewGuid().ToString().Replace("-", "").ToUpper());
            byte id = 1;

            Servers = doc.XPathSelectElements("//Server").Select(srv => new RemoteServer
            {
                Name     = srv.Element("Name").Value,
                DNS      = srv.Element("DNS").Value,
                Loopback = new IPAddress(new byte[] { 127, 0, 0, id++ })
            }).ToArray();
            AppendLog("Server list retrieved, total {0} servers.", Servers.Length);


            if (!InitializeComponent("Spam Filter", () =>
            {
                Filter = new SpamFilter(this);
                Filter.LoadWordList();
            }))
            {
                return;
            }

            if (!InitializeComponent("Handlers", () =>
            {
                Commands = new CommandManager();
                Hooks = new HookManager();
                Invoke(new Action(() => Windows = new WindowManager(this, windowDropDown)));
            }))
            {
                return;
            }

            AppendLog("If you see any firewall warning, allow this program to pass!");

            if (!InitializeComponent("Web Proxy", () =>
            {
                WebProxy = new HttpProxy(this);
                WebProxy.Start();
                BeginInvoke(new Action(() => { proxyLink.Text = new Uri(WebProxy.ProxyUrl).AbsoluteUri; }));
            }))
            {
                return;
            }

            if (!InitializeComponent("Socket Proxy", () =>
            {
                SocketProxy = new SocketProxy(this);
                SocketProxy.Start();
            }))
            {
                return;
            }

            if (!InitializeComponent("Policy Server", () =>
            {
                PolicyServer = new PolicyServer();
                if (!PolicyServer.Start())
                {
                    throw new Exception("Cannot start policy server! Try start as adminstrator/sudo!");
                }
            }))
            {
                return;
            }

            new HttpHandler(this).Attach();
            new SocketHandler(this).Attach();
            BeginInvoke(new Action(() => timer.Start()));

            AppendLog("RotMG Tool initialized.");
        }