L* R*
HOME FORUM DOWNLOADS
Content
  Links
     Browse SVN
     SVN Commit log
     Documentation (Wiki)
  Developers
     Taskmanager
User
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 01, 2008, 12:21:31 PM

Login with username, password and session length
Search



Advanced search
Support GoPHP5.org
BeBot - An Anarchy Online/Age Of Conan chat automaton > Forum > Development > Feedback and Suggestions > Topic: Core/API Registration
Pages: [1]   Go Down
« previous next »
Print
Author Topic: Core/API Registration  (Read 331 times)
0 Members and 1 Guest are viewing this topic.
Glarawyn
BeBot Developer
Champion
********
Offline Offline

Posts: 414



Core/API Registration
« on: November 01, 2006, 11:51:57 PM »

Before this disappears from my IRC scroll back...

Quote
<Glara> Instead of each core module having it's own variable, couldn't they be packed into a single array?
<Glara> So we'd do $bot -> core['whois'] instead of $bot -> whois = &$whoiscache;
<Glara> $this -> bot -> core['whois'] -> lookup($name);
<Glara> anyone could create a "core" module to share functions without editing Bot.php...
<Glara> Just thinking out loud. Wink
01:28PM <Khalem> A valid suggestion
01:29PM <Naturalistic> Aye
01:29PM <Khalem> Slightly more typing, a slight inconvenience for a gain
<Glara> Bigger inconvenience to edit Bot.php for any custom core modules
<Glara> Upgrading to a new bugfix release replaces anything custom in Bot.php.
01:32PM <Naturalistic> yes, like Vhab's bot... you can't edit the core :p
<Glara> useful stuff has come out of core customizations though
<Glara> but there seem to be workarounds to do the same thing without changing the actual core files.
01:39PM <Khalem> Actually, it could be made more robust by using a function to  do the actual registering
01:39PM <Khalem> But again, if a developer screws up the bot core with his core hooks, it's fairly obvious
<Glara> Khalem: that would probably be a good idea to keep people from clobbering another module.
<Glara> and keeping registered module names unique.

So I went ahead and fiddled a bit and came up with a simple api registration function. By default it won't reset an existing function, but you can pass TRUE as the third function parameter if you're really really sure you want to clobber any existing class reference, though there is no protection from someone else doing the same to you in their module. I added log functions so that if something funky goes on, logs can be reviewed to see registrations.

Add to Bot.php around line 71:
Code:
    var $api;

Add to Bot.php around line 805:
Code:
    /*
    Registers APIs
    */
    function register_api($apiname, &$apiref, $replace=FALSE)
    { // Start function register_api()
        if (isset($this -> api[$apiname]))
        {
            if ($override) // Register the api, replace existing registration.
            {
                $this -> api[$apiname] = $apiref;
                $this -> log("API", "REG", "Reregistered API ".$apiname);
                return TRUE;
            }
            else // Don't register the api over the existing registered api.
            {
                $this -> log("API", "REG", "Did not register API ".$apiname." because it is already registered.");
                return FALSE;
            }
        }
        else // API is not set, so register it.
        {
            $this -> api[$apiname] = $apiref;
            $this -> log("API", "REG", "Register new API ".$apiname);
            return TRUE;
        }
    } // End function register_api()

Test modules attached. APITest1.php registers itself, APITest2.php uses APITest1 functions.
Logged
Nesi
Rookie
**
Offline Offline

Posts: 55


Re: Core/API Registration
« Reply #1 on: November 02, 2006, 04:56:53 AM »

It is already possible to add a reference to $this -> bot -> whateverclass from the module file itself -  If that was all you wanted to do?
« Last Edit: November 02, 2006, 05:16:15 AM by Nesi » Logged
Alreadythere
BeBot Maintainer
Administrator
Grandmaster
********
Offline Offline

Posts: 1085


Re: Core/API Registration
« Reply #2 on: November 02, 2006, 05:47:38 AM »

Like Nesi said, it's not needed to edit the Bot.php just to add another Core class. All you need to do is $bot -> myclass = &$myclass; in the myclass.php. Then you can call $this -> bot -> myclass everywhere.

Still a default way to add new core modules can never harm, especially with your collision check. You just got to rename the variable $overwrite to $replace in your api function (or the other way around). Right now that check can never be true Wink
Logged
Khalem
BeBot Founder
Administrator
Grandmaster
********
Offline Offline

Gender: Male
Posts: 670



WWW
Re: Core/API Registration
« Reply #3 on: November 02, 2006, 10:46:47 AM »

Yes you can do it without modifying Bot.php, but there are no error checking or handling, nor do you have any way to easilly detect conflicts and this could save you from pointless hours of debugging too Smiley
Logged

BeBot Founder and Fixer Kingpin
Madman coder and destroyer of good code
Pages: [1]   Go Up
Print
BeBot - An Anarchy Online/Age Of Conan chat automaton > Forum > Development > Feedback and Suggestions > Topic: Core/API Registration
« previous next »
 
Jump to:  

Recent
[request] Raid timers
by Alreadythere
[Today at 11:42:32 AM]

Shared DB online list
by Temar
[Today at 01:55:47 AM]

relay colors
by Temar
[Today at 01:54:56 AM]

BeBot v0.6.0 released
by Alreadythere
[November 30, 2008, 05:32:00 PM]

Change to Bid.php
by Temar
[November 30, 2008, 11:41:44 AM]

OnlineOrg
by Jiheld
[November 29, 2008, 12:44:27 PM]

Silly Newbie Question.
by Temar
[November 29, 2008, 12:00:02 PM]

massive_pvp_time_table 1
by gerborg
[November 29, 2008, 06:55:35 AM]

Bot not see Guild Chat
by Delvar
[November 28, 2008, 08:30:34 AM]

Starting Bot
by Allisande
[November 28, 2008, 07:08:21 AM]
Stats
Members
Total Members: 1243
Latest: Whackoeng
Stats
Total Posts: 11143
Total Topics: 1505
Online Today: 21
Online Ever: 168
(July 01, 2007, 09:30:02 PM)
Users Online
Users: 4
Guests: 18
Total: 22
Temar
gerborg
Ifris

Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC
TinyPortal v0.9.8 © Bloc | NewDef design by Bloc
Page created in 0.409 seconds with 28 queries. (Pretty URLs adds 0.027s, 4q)
Loading...