public static void MakePostRequestAsync(string url, byte[] bytes, Action <string> on_response, Action <Exception, string> on_error, Action on_completion = null)
        {
            ThreadPool.QueueUserWorkItem(_ => {
                bool success;
                string output = null;

                try {
                    //lock( NetHelpers.RequestMutex ) {
                    output = NetHelpers.MakePostRequest(url, bytes, out success);
                    //}

                    if (success)
                    {
                        on_response(output);
                    }
                    else
                    {
                        output = null;
                        throw new Exception("POST request unsuccessful (url: " + url + ")");
                    }
                } catch (Exception e) {
                    if (on_error != null)
                    {
                        on_error(e, output);
                    }
                }

                if (on_completion != null)
                {
                    on_completion();
                }
            });
        }
        private void LoadIPAsync()
        {
            Action <string> on_success = delegate(string output) {
                if (this.PublicIP != null)
                {
                    return;
                }

                string[] a  = output.Split(':');
                string   a2 = a[1].Substring(1);
                string[] a3 = a2.Split('<');
                string   a4 = a3[0];

                this.PublicIP = a4;
            };
            Action <Exception, string> on_fail = delegate(Exception e, string output) {
                if (e is WebException)
                {
                    LogHelpers.Log("Could not acquire IP: " + e.Message);
                }
                else
                {
                    LogHelpers.Log("Could not acquire IP: " + e.ToString());
                }
            };

            NetHelpers.MakeGetRequestAsync("http://checkip.dyndns.org/", on_success, on_fail);
            //NetHelpers.MakeGetRequestAsync( "https://api.ipify.org/", on_success, on_fail );
            //using( WebClient web_client = new WebClient() ) {
            //	this.PublicIP = web_client.DownloadString( "http://ifconfig.me/ip" );
            //}
        }
        public static void MakePostRequestAsync(string url, byte[] bytes, Action <string> on_response, Action <Exception> on_error = null, Action on_completion = null)
        {
            Action <Exception, string> on_wrapped_error = (e, _) => {
                if (on_error != null)
                {
                    on_error(e);
                }
            };

            NetHelpers.MakePostRequestAsync(url, bytes, on_response, on_wrapped_error, on_completion);
        }
Beispiel #4
0
        public override void Load()
        {
            HamstarHelpersMod.Instance = this;

            this.LoadConfigs();

            if (!this.HasUnhandledExceptionLogger && this.Config.DebugModeUnhandledExceptionLogging)
            {
                this.HasUnhandledExceptionLogger            = true;
                AppDomain.CurrentDomain.UnhandledException += HamstarHelpersMod.UnhandledLogger;
            }

            this.LoadHelpers = new TmlHelpers.LoadHelpers();
            this.Promises    = new Promises();

            this.Timers                    = new Timers();
            this.LogHelpers                = new DebugHelpers.LogHelpers();
            this.ModMetaDataManager        = new TmlHelpers.ModMetaDataManager();
            this.BuffHelpers               = new BuffHelpers.BuffHelpers();
            this.NetHelpers                = new NetHelpers.NetHelpers();
            this.ItemIdentityHelpers       = new ItemHelpers.ItemIdentityHelpers();
            this.NPCIdentityHelpers        = new NPCHelpers.NPCIdentityHelpers();
            this.ProjectileIdentityHelpers = new ProjectileHelpers.ProjectileIdentityHelpers();
            this.BuffIdentityHelpers       = new BuffHelpers.BuffIdentityHelpers();
            this.NPCBannerHelpers          = new NPCHelpers.NPCBannerHelpers();
            this.RecipeHelpers             = new RecipeHelpers.RecipeHelpers();
            this.TmlPlayerHelpers          = new TmlHelpers.TmlPlayerHelpers();
            this.WorldHelpers              = new WorldHelpers.WorldHelpers();
            this.ControlPanel              = new UIControlPanel();
            this.ModLockHelpers            = new TmlHelpers.ModHelpers.ModLockHelpers();
            this.EntityGroups              = new EntityGroups();
            this.PlayerMessages            = new PlayerMessages();
            this.Inbox           = new InboxControl();
            this.ModVersionGet   = new ModVersionGet();
            this.ServerBrowser   = new ServerBrowserReporter();
            this.MenuItemMngr    = new MenuItemManager();
            this.MenuUIMngr      = new MenuUIManager();
            this.OldMenuItemMngr = new Utilities.Menu.OldMenuItemManager();
            this.MusicHelpers    = new MusicHelpers();

#pragma warning disable 612, 618
            TmlHelpers.AltNPCInfo.DataInitialize();
            TmlHelpers.AltProjectileInfo.DataInitialize();
#pragma warning restore 612, 618

            if (!this.Config.DisableControlPanelHotkey)
            {
                this.ControlPanelHotkey = this.RegisterHotKey("Mod Helpers Control Panel", "O");
            }

            this.LoadModData();
        }
Beispiel #5
0
        public override void Unload()
        {
            this.UnloadModData();

            this.Promises.FulfillModUnloadPromises();

            try {
                if (this.HasUnhandledExceptionLogger)
                {
                    this.HasUnhandledExceptionLogger            = false;
                    AppDomain.CurrentDomain.UnhandledException -= HamstarHelpersMod.UnhandledLogger;
                }
            } catch { }

            this.ExceptionMngr             = null;
            this.Timers                    = null;
            this.ConfigJson                = null;
            this.PacketProtocols           = null;
            this.LogHelpers                = null;
            this.ModMetaDataManager        = null;
            this.BuffHelpers               = null;
            this.NetHelpers                = null;
            this.ItemIdentityHelpers       = null;
            this.NPCIdentityHelpers        = null;
            this.ProjectileIdentityHelpers = null;
            this.BuffIdentityHelpers       = null;
            this.NPCBannerHelpers          = null;
            this.RecipeHelpers             = null;
            this.TmlPlayerHelpers          = null;
            this.LoadHelpers               = null;
            this.ModVersionGet             = null;
            this.WorldHelpers              = null;
            this.ModLockHelpers            = null;
            this.EntityGroups              = null;
            this.AnimatedColors            = null;
            this.PlayerMessages            = null;
            this.Inbox = null;
            this.ControlPanelHotkey = null;
            this.ControlPanel       = null;
            this.ServerBrowser      = null;
            this.MenuItemMngr       = null;
            this.MenuUIMngr         = null;
            this.OldMenuItemMngr    = null;
            this.MusicHelpers       = null;
            this.Promises           = null;

            HamstarHelpersMod.Instance = null;
        }
        public static string MakePostRequest(string url, byte[] bytes)
        {
            bool _;

            return(NetHelpers.MakePostRequest(url, bytes, out _));
        }
        public static string MakeGetRequest(string url)
        {
            bool _;

            return(NetHelpers.MakeGetRequest(url, out _));
        }