What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal
RebornBuddy Forums

Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Re-compile check & callback for HB plugins

cowdude

Active Member
Joined
Feb 17, 2010
Messages
337
Hi,

I am currently working on a small http server plugin (=> using threads) for HB and had some trouble detecting when the user forced a re-compilation of its plugins. I tried to use a class deconstructor which did not work at all, hence I coded a small and dirty class as a workaround.

Why would it be great to be able to hook it or implement class destruction ?

Code:
class Foo : HBPlugin {
public Foo () {
Styx.FiniteStateMachine.Engine.OnEngineStart += onBotStart;
Styx.FiniteStateMachine.Engine.OnEngineStop += onBotStop;
}
~Foo {
Styx.FiniteStateMachine.Engine.OnEngineStart -= onBotStart;
Styx.FiniteStateMachine.Engine.OnEngineStop -= onBotStop;
}
}

That won't work at all, and there is no OnRecompile delegate as far as I know... Because of this, you'll have many onBotStart/onBotStop callbacks registered that will be ALL called when the bot is starting or stopping if you recompiled your plugins....

Anyway, here is my (awful) workaround:

Code:
    class RecompileHelper
    {
        public delegate void Callback();
        Callback callback;
        string hook = null;

        public RecompileHelper(string h, Callback cb)
        {
            hook = h;
            callback = cb;
            Logging.Write(hook);
            Logging.OnWrite += ReadLog;
        }

        void ReadLog(string line, System.Drawing.Color c)
        {
            if (line == hook)
            {
                Logging.OnWrite -= ReadLog;
                Logging.Write("Recompile detected.");
                callback();
            }
        }
    }

public class Foo : HBPlugin {
...
public Foo () {
Styx.FiniteStateMachine.Engine.OnEngineStart += onBotStart;
Styx.FiniteStateMachine.Engine.OnEngineStop += onBotStop;
recompileHelper = new RecompileHelper("My Foo plugin is launching.", Cleaner);
}
void Cleaner () {
Styx.FiniteStateMachine.Engine.OnEngineStart -= onBotStart;
Styx.FiniteStateMachine.Engine.OnEngineStop -= onBotStop;
}
}
 
Hi,

I am currently working on a small http server plugin (=> using threads) for HB and had some trouble detecting when the user forced a re-compilation of its plugins. I tried to use a class deconstructor which did not work at all, hence I coded a small and dirty class as a workaround.

Why would it be great to be able to hook it or implement class destruction ?

Code:
class Foo : HBPlugin {
public Foo () {
Styx.FiniteStateMachine.Engine.OnEngineStart += onBotStart;
Styx.FiniteStateMachine.Engine.OnEngineStop += onBotStop;
}
~Foo {
Styx.FiniteStateMachine.Engine.OnEngineStart -= onBotStart;
Styx.FiniteStateMachine.Engine.OnEngineStop -= onBotStop;
}
}

That won't work at all, and there is no OnRecompile delegate as far as I know... Because of this, you'll have many onBotStart/onBotStop callbacks registered that will be ALL called when the bot is starting or stopping if you recompiled your plugins....

Anyway, here is my (awful) workaround:

Code:
    class RecompileHelper
    {
        public delegate void Callback();
        Callback callback;
        string hook = null;

        public RecompileHelper(string h, Callback cb)
        {
            hook = h;
            callback = cb;
            Logging.Write(hook);
            Logging.OnWrite += ReadLog;
        }

        void ReadLog(string line, System.Drawing.Color c)
        {
            if (line == hook)
            {
                Logging.OnWrite -= ReadLog;
                Logging.Write("Recompile detected.");
                callback();
            }
        }
    }

public class Foo : HBPlugin {
...
public Foo () {
Styx.FiniteStateMachine.Engine.OnEngineStart += onBotStart;
Styx.FiniteStateMachine.Engine.OnEngineStop += onBotStop;
recompileHelper = new RecompileHelper("My Foo plugin is launching.", Cleaner);
}
void Cleaner () {
Styx.FiniteStateMachine.Engine.OnEngineStart -= onBotStart;
Styx.FiniteStateMachine.Engine.OnEngineStop -= onBotStop;
}
}

I found the same issues on my CC, i made a descontructor but it just ended up crashing hb on the start. As i placed a text in the Constructor to print when loading up the bot. it Just print it 2 to 8 times when i press start.
 
Back
Top