On Tue, Aug 05, 2003 at 08:57:46PM +0000, [EMAIL PROTECTED] wrote:
> I'm sure I'm missing something simple here, so bare with me.  I realize that 
> POE is a multitasking environment, and I realize that this is part of the 
> beauty of it, but I can't seem to figure out the best way to utilize this.
> 
> Basically, I have a wrapper(sort of) for POE::Component::IRC.  The program has 
> a configuration file, using Config::General.  The constructor for my wrapper 
> module handles all the needed options, like the server name, port, nick, etc.  
> Now, what I need to do is make a connection for each server listed in the 
> config file.  Sounds simple enough, right?  I worked out a way to do it using a 
> loop and fork, but I'm already daemonizing the process, so that makes things 
> seem a bit wonky to me.  I was hoping to do it in a more POE'ish way.  The 
> problem is figuring out how to do it.  My code is a bit jacked up right now, 
> since I've been trying to make this work, but I'll give you a basic idea:
> 
> ~code~
> 
>     my $conf = Config::General->new("servers.conf");
>     my %config = $conf->getall();

my %bots;

> 
>     foreach (keys %{$config{server}}) {
> 
>     # Where I was using fork(), didn't seem right.
>     # my $pid;               
>     # if (!($pid = fork)) {
> 
>       my $bot = Bot->new(

$bot{$_} = Bot->new(

>                              Debug    => 0,
>                              Nick     => $config{'server'}{$_}{'nick'},
>                              Server   => $_,
>                              Pass     => $config{'server'}{$_}{'pass'},
>                              Port     => $config{'server'}{$_}{'port'},
>                              Username => $config{'server'}{$_}{'username'},
>                              Ircname  => $config{'server'}{$_}{'ircname'},
>                              Admin    => 'admin',
>                              Apass    => 'changeme',
>                              Channels => $config{'server'}{$_}{'channel'},
>                              LogPath  => $config{'server'}{$_}{'logpath'},
>                           );
>         $bot->run();     # Actuall calls POE::Session->create()
>         $bot->daemon();  # Daemonize
> 
>     #}

Now you have a hash of bots, each keyed on the server name.  I don't
really recommend keying things on server name, especially in IRC where
the logical unit of existence is a network rather than an individual
host.

In my own bots, I usually describe bots by network instead of server,
which lets me create a server list and cycle through them if something
bad happens.

>From a configuration file I use for pastebot:

irc
        name            rhizo
        server          irc.perl.org
        server          irc.rhizomatic.net
        server          rhizo.mati.ca
        nick            eatpaste
        uname           eatnopaste
        iname           http://poe.dyndns.org:32088/
        away            Saving humanity from evil paste.
        quit            *byoop*
        flags           +i
        cuinfo          default user information
        cver            pastebot 1.0 <http://pastebot.sf.net/>
        ccinfo          ACTION VERSION CLIENTINFO USERINFO
        channel         poe
        channel         perl
        localaddr       poe.dyndns.org

irc
        name            efnet
        server          irc.vrfx.com
        server          irc.desync.com
        server          irc.aol.com
        nick            eatpaste
        uname           eatnopaste
        iname           http://poe.dyndns.org:32087/
        away            Saving humanity from evil paste.
        quit            *byoop*
        flags           +i
        cuinfo          default user information
        cver            pastebot 1.0 <http://pastebot.sf.net/>
        ccinfo          ACTION VERSION CLIENTINFO USERINFO
        channel         perl
        channel         perlhelp
        channel         poe
        localaddr       poe.dyndns.org

If you use networks rather than servers as your key, you can refer to
$bot{efnet} or $bot{rhizo} without needing to know which server it's on
at any given time.

-- 
Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/

Reply via email to