HabboxWiki needs you!
Are you a Habbo buff? Or maybe a rare trader with a bunch of LTDs? Get involved with HabboxWiki to share your knowledge!
Join our team!
Whether you're raving for rares, excited for events or happy helping, there's something for you! Click here to apply
Need a helping hand?
Check out our guides for all things to help you make friends, make rooms, and make money!


Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 39

Thread: Sessions and c

  1. #11
    Join Date
    May 2007
    Posts
    10,481
    Tokens
    3,140

    Latest Awards:

    Default

    I was thinking about writing a modular script (For fun/practise) and was thinking about how it is best to allow modules to affect the core-code. I have some ideas on how to do it but I'm unsure how secure it is / whether it's the best/most efficient way to do it.

    Hooks:
    If I have a variable (or property) with an array where the key is a describing name and is set to a function name:

    $hook_<hookname>['<function description>'] = '<function name>';

    And then whenever is appropriate for the hook to be called I foreach through the array and execute each function in turn, passing through appropriate variables for the hook.

    Class Overriding:
    I figure that at some point or another I'll need to override a class from a module, naturally I can extend the class, however that doesn't change the class objects are created from. So I could try two strategies..
    Use a hook right after an object has been created, rename the object and create a new object from the new class with the same properties or whatever. I'm not sure if there's an easy way of moving across the properties to an object with a different class. The problem with this method is that if two modules use the same hook to override the class then only one module will be working.

    The other method involves having classes register themselves on a global array on initialisation (likely via a function), then modules can override classes using a function which will handle errors and replace the value in the array for the class it's overriding if there isn't a problem, this has the benefit of allowing modules to not just fail and allows for error handling to make them "shutdown" so to speak. The array would probably then be stored as a protected property so that it's difficult for malicious code (Either user-injected or otherwise) to override it after initialisation then whenever the main class is needed you can use something like:

    $object = new $classregister->getClass('superclass')(); //Perhaps a second variable for the function could always return the original function?

    This still has the problem of two modules wanting to override the same class but at least this way there won't just be errors because only one of the modules classes didn't run, there's also the potential that the overriding class can have built in error-handling, recognise that the class that previously overrode the main class does not conflict and then extend and override that instead.

    For the class thing I'm fairly certain there's a better way of doing it but I can't think of anything.
    Chippiewill.


  2. #12
    Join Date
    Jan 2010
    Location
    United Kingdom
    Posts
    846
    Tokens
    1,766
    Habbo
    triston220

    Latest Awards:

    Default

    Does Java not use much more memory than other languages for the same tasks?


    Quote Originally Posted by Jaaaack! View Post
    See, however much I want this, my girlfriend uses my PC too much, and I would be killed.





  3. #13
    Join Date
    May 2007
    Posts
    10,481
    Tokens
    3,140

    Latest Awards:

    Default

    Quote Originally Posted by triston220 View Post
    Does Java not use much more memory than other languages for the same tasks?
    It probably wouldn't be on par if you coded it perfectly, because at that point you may as well do everything in assembler, but for most applications it's going to ease problems enough that the increased efficiency is going to counter-act the (Slightly) larger footprint.
    Chippiewill.


  4. #14
    Join Date
    Apr 2012
    Posts
    35
    Tokens
    0

    Default

    Quote Originally Posted by Chippiewill View Post
    I was thinking about writing a modular script (For fun/practise) and was thinking about how it is best to allow modules to affect the core-code. I have some ideas on how to do it but I'm unsure how secure it is / whether it's the best/most efficient way to do it.

    Hooks:
    If I have a variable (or property) with an array where the key is a describing name and is set to a function name:

    $hook_<hookname>['<function description>'] = '<function name>';

    And then whenever is appropriate for the hook to be called I foreach through the array and execute each function in turn, passing through appropriate variables for the hook.

    Class Overriding:
    I figure that at some point or another I'll need to override a class from a module, naturally I can extend the class, however that doesn't change the class objects are created from. So I could try two strategies..
    Use a hook right after an object has been created, rename the object and create a new object from the new class with the same properties or whatever. I'm not sure if there's an easy way of moving across the properties to an object with a different class. The problem with this method is that if two modules use the same hook to override the class then only one module will be working.

    The other method involves having classes register themselves on a global array on initialisation (likely via a function), then modules can override classes using a function which will handle errors and replace the value in the array for the class it's overriding if there isn't a problem, this has the benefit of allowing modules to not just fail and allows for error handling to make them "shutdown" so to speak. The array would probably then be stored as a protected property so that it's difficult for malicious code (Either user-injected or otherwise) to override it after initialisation then whenever the main class is needed you can use something like:

    $object = new $classregister->getClass('superclass')(); //Perhaps a second variable for the function could always return the original function?

    This still has the problem of two modules wanting to override the same class but at least this way there won't just be errors because only one of the modules classes didn't run, there's also the potential that the overriding class can have built in error-handling, recognise that the class that previously overrode the main class does not conflict and then extend and override that instead.

    For the class thing I'm fairly certain there's a better way of doing it but I can't think of anything.
    Really couldn't be bothered to read that massive essay, but it looks like you're seriously over complicating things.

    I may have interpreted this wrong, but if you're looking to allow user customization by hooks, what's wrong with just doing Hook::get('name'); and then fetching said hook from a cache/the database?
    blob

  5. #15
    Join Date
    May 2007
    Posts
    10,481
    Tokens
    3,140

    Latest Awards:

    Default

    User customisation? No, modular extension of the code.
    Chippiewill.


  6. #16
    Join Date
    Apr 2012
    Posts
    35
    Tokens
    0

    Default

    For what though? If you're setting the custom hooks, why don't you just put the code in instead of calling for a hook? :S
    blob

  7. #17
    Join Date
    May 2007
    Posts
    10,481
    Tokens
    3,140

    Latest Awards:

    Default

    Because I'm creating a modular system, if I just put the code in the core then it defeats the point.
    Chippiewill.


  8. #18
    Join Date
    Apr 2012
    Posts
    35
    Tokens
    0

    Default

    What's the point though if it's only you setting the code..
    blob

  9. #19
    Join Date
    May 2007
    Posts
    10,481
    Tokens
    3,140

    Latest Awards:

    Default

    Quote Originally Posted by froobe View Post
    What's the point though if it's only you setting the code..
    Quote Originally Posted by Chippiewill View Post
    I was thinking about writing a modular script (For fun/practise)
    Srsly?

    Read posts properly in future, I'd already explained every query you've made.
    Chippiewill.


  10. #20
    Join Date
    Apr 2012
    Posts
    35
    Tokens
    0

    Default

    Quote Originally Posted by Chippiewill View Post
    Srsly?

    Read posts properly in future, I'd already explained every query you've made.
    Practice generally means in an attempt to get better, else you wouldn't be practicing, correct? Sorry for attempting to help you out with better methods to do things. Honestly, I'm sorry - I didn't realize it was illegal to offer advice, how dare I.
    blob

Page 2 of 4 FirstFirst 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •