POE::Component::Server::IRC::Backend - A POE component class that provides network connection abstraction for POE::Component::Server::IRC
package MyIRCD; use strict; use warnings; use base 'POE::Component::Server::IRC::Backend'; sub spawn { my ($package, %args) = @_; my $self = $package->create(prefix => 'ircd_', @_); # process %args ... return $self; }
POE::Component::Server::IRC::Backend - A POE component class that provides network connection abstraction for POE::Component::Server::IRC. It uses a plugin system. See POE::Component::Server::IRC::Plugin for details.
create
Returns an object. Accepts the following parameters, all are optional:
'alias', a POE::Kernel alias to set;
'auth', set to a false value to globally disable IRC authentication, default is auth is enabled;
'antiflood', set to a false value to globally disable flood protection, default is true;
'prefix', this is the prefix that is used to generate event names that the component produces. The default is 'ircd_'.
'states', an array reference of extra objects states for the IRC daemon's POE sessions. The elements can be array references of states as well as hash references of state => handler pairs.
'plugin_debug', set to a true value to print plugin debug info. Default is false.
'options', a hashref of options to POE::Session
'raw_events', whether to send raw events. False by default. Can be enabled later with raw_events;
raw_events
If the component is created from within another session, that session will be automagcially registered with the component to receive events and get an 'ircd_backend_registered' event.
shutdown
Takes no arguments. Terminates the component. Removes all listeners and connectors. Disconnects all current client and server connections. This is a shorthand for $ircd->yield('shutdown').
$ircd->yield('shutdown')
session_id
Inherited from POE::Component::Syndicator
Takes no arguments. Returns the ID of the component's session. Ideal for posting events to the component.
session_alias
Takes no arguments. Returns the session alias that has been set through create's 'alias' argument.
yield
This method provides an alternative object based means of posting events to the component. First argument is the event to post, following arguments are sent as arguments to the resultant post.
call
This method provides an alternative object based means of calling events to the component. First argument is the event to call, following arguments are sent as arguments to the resultant call.
delay
This method provides a way of posting delayed events to the component. The first argument is an arrayref consisting of the delayed command to post and any command arguments. The second argument is the time in seconds that one wishes to delay the command being posted.
Returns an alarm ID that can be used with delay_remove to cancel the delayed event. This will be undefined if something went wrong.
delay_remove
This method removes a previously scheduled delayed event from the component. Takes one argument, the alarm_id that was returned by a delay method call.
alarm_id
Returns an arrayref that was originally requested to be delayed.
send_event
Sends an event through the component's event handling system. These will get processed by plugins then by registered sessions. First argument is the event name, followed by any parameters for that event.
send_event_next
This sends an event right after the one that's currently being processed. Useful if you want to generate some event which is directly related to another event so you want them to appear together. This method can only be called when POE::Component::IRC is processing an event, e.g. from one of your event handlers. Takes the same arguments as send_event.
send_event_now
This will send an event to be processed immediately. This means that if an event is currently being processed and there are plugins or sessions which will receive it after you do, then an event sent with send_event_now will be received by those plugins/sessions before the current event. Takes the same arguments as send_event.
If called with a true value, raw events (ircd_raw_input and ircd_raw_output) will be enabled.
ircd_raw_input
ircd_raw_output
antiflood
Takes two arguments, a connection id and true/false value. If value is specified antiflood protection is enabled or disabled accordingly for the specified connection. If a value is not specified the current status of antiflood protection is returned. Returns undef on error.
compressed_link
Takes two arguments, a connection id and true/false value. If a value is specified, compression will be enabled or disabled accordingly for the specified connection. If a value is not specified the current status of compression is returned. Returns undef on error.
disconnect
Requires on argument, the connection id you wish to disconnect. The component will terminate the connection the next time that the wheel input is flushed, so you may send some sort of error message to the client on that connection. Returns true on success, undef on error.
connection_exists
Requires one argument, a connection id. Returns true value if the connection exists, false otherwise.
connection_info
Takes one argument, a connection_id. Returns a list consisting of: the IP address of the peer; the port on the peer; our socket address; our socket port. Returns undef on error.
my ($peeraddr, $peerport, $sockaddr, $sockport) = $ircd->connection_info($conn_id);
add_denial
Takes one mandatory argument and one optional. The first mandatory argument is a Net::Netmask object that will be used to check connecting IP addresses against. The second optional argument is a reason string for the denial.
del_denial
Takes one mandatory argument, a Net::Netmask object to remove from the current denial list.
denied
Takes one argument, an IP address. Returns true or false depending on whether that IP is denied or not.
add_exemption
Takes one mandatory argument, a Net::Netmask object that will be checked against connecting IP addresses for exemption from denials.
del_exemption
Takes one mandatory argument, a Net::Netmask object to remove from the current exemption list.
exempted
Takes one argument, an IP address. Returns true or false depending on whether that IP is exempt from denial or not.
pipeline
Inherited from Object::Pluggable
Returns the Object::Pluggable::Pipeline object.
plugin_add
Accepts two arguments:
The alias for the plugin The actual plugin object Any number of extra arguments
The alias is there for the user to refer to it, as it is possible to have multiple plugins of the same kind active in one Object::Pluggable object.
This method goes through the pipeline's push() method, which will call $plugin->plugin_register($pluggable, @args).
push()
$plugin->plugin_register($pluggable, @args)
Returns the number of plugins now in the pipeline if plugin was initialized, undef/an empty list if not.
undef
plugin_del
Accepts the following arguments:
The alias for the plugin or the plugin object itself Any number of extra arguments
This method goes through the pipeline's remove() method, which will call $plugin->plugin_unregister($pluggable, @args).
remove()
$plugin->plugin_unregister($pluggable, @args)
Returns the plugin object if the plugin was removed, undef/an empty list if not.
plugin_get
The alias for the plugin
This method goes through the pipeline's get() method.
get()
Returns the plugin object if it was found, undef/an empty list if not.
plugin_list
Takes no arguments.
Returns a hashref of plugin objects, keyed on alias, or an empty list if there are no plugins loaded.
plugin_order
Returns an arrayref of plugin objects, in the order which they are encountered in the pipeline.
plugin_register
The plugin object The type of the hook (the hook types are specified with _pluggable_init()'s 'types') The event name[s] to watch
The event names can be as many as possible, or an arrayref. They correspond to the prefixed events and naturally, arbitrary events too.
You do not need to supply events with the prefix in front of them, just the names.
It is possible to register for all events by specifying 'all' as an event.
Returns 1 if everything checked out fine, undef/an empty list if something is seriously wrong.
plugin_unregister
The plugin object The type of the hook (the hook types are specified with _pluggable_init()'s 'types') The event name[s] to unwatch
Returns 1 if all the event name[s] was unregistered, undef if some was not found.
These are POE events that the component will accept:
register
Takes N arguments: a list of event names that your session wants to listen for, minus the irc_ prefix.
irc_
$ircd->yield('register', qw(connected disconnected));
The special argument 'all' will register your session for all events. Registering will generate an ircd_registered event that your session can trap.
ircd_registered
unregister
Takes N arguments: a list of event names which you don't want to receive. If you've previously done a register for a particular event which you no longer care about, this event will tell the component to stop sending them to you. (If you haven't, it just ignores you. No big deal.)
If you have registered with 'all', attempting to unregister individual events such as 'connected', etc. will not work. This is a 'feature'.
add_listener
Takes a number of arguments. Adds a new listener.
'port', the TCP port to listen on. Default is a random port;
'auth', enable or disable auth sub-system for this listener. Enabled by default;
'bindaddr', specify a local address to bind the listener to;
'listenqueue', change the SocketFactory's ListenQueue;
'usessl', whether the listener should use SSL. Default is false;
'antiflood', whether the listener should use flood protection. Defaults is true;
'idle', the time, in seconds, after which a connection will be considered idle. Defaults is 180.
del_listener
Takes one of the following arguments:
'listener', a previously returned listener ID;
'port', a listening port;
The listener will be deleted. Note: any connected clients on that port will not be disconnected.
add_connector
Takes two mandatory arguments, 'remoteaddress' and 'remoteport'. Opens a TCP connection to specified address and port.
'remoteaddress', hostname or IP address to connect to;
'remoteport', the TCP port on the remote host;
'bindaddress', a local address to bind from (optional);
send_output
Takes a hashref and one or more connection IDs.
$ircd->yield( 'send_output', { prefix => 'blah!~blah@blah.blah.blah', command => 'PRIVMSG', params => ['#moo', 'cows go moo, not fish :D'] }, @list_of_connection_ids, );
Takes no arguments. Terminates the component. Removes all listeners and connectors. Disconnects all current client and server connections.
These following events are sent to interested sessions.
ARG0: the component's object;
ARG0
ircd_connection
ARG0: the conn id;
ARG1: their ip address;
ARG1
ARG2: their tcp port;
ARG2
ARG3: our ip address;
ARG3
ARG4: our socket port;
ARG4
ARG5: a boolean indicating whether the client needs to be authed
ARG5
ircd_auth_done
ARG0, the connection id;
ARG1, a HASHREF with the following keys: 'ident' and 'hostname';
ircd_listener_add
ARG0, the listening port;
ARG1, the listener id;
ARG2, the listening address;
ircd_listener_del
ARG2, the listener address;
ircd_listener_failure
ARG0, the listener id;
ARG1, the name of the operation that failed;
ARG2, numeric value for $!;
ARG3, string value for $!;
ARG4, the port it tried to listen on;
ARG5, the address it tried to listen on;
ircd_socketerr
ARG0, a HASHREF containing the params that add_connector() was called with;
ircd_connected
ARG1, their ip address;
ARG2, their tcp port;
ARG3, our ip address;
ARG4, our socket port;
ARG5, the peer's name;
ircd_connection_flood
ircd_connection_idle
ARG1, the number of seconds period we consider as idle;
ircd_compressed_conn
ircd_cmd_*
ARG1, a HASHREF containing the output record from POE::Filter::IRCD:
{ prefix => 'blah!~blah@blah.blah.blah', command => 'PRIVMSG', params => [ '#moo', 'cows go moo, not fish :D' ], raw_line => ':blah!~blah@blah.blah.blah.blah PRIVMSG #moo :cows go moo, not fish :D' }
ARG1, the raw line of input
ARG1, the raw line of output
ircd_disconnected
ARG1, the error or reason for disconnection;
ircd_shutdown
ARG0: the session ID of the requesting component
ircd_delay_set
ARG0: the alarm id which can be used later with delay_remove
ARG1..$#_: subsequent arguments are those which were passed to delay
ARG1..$#_
ircd_delay_removed
ARG0: the alarm id which was removed
ircd_plugin_add
ARG0: the plugin alias
ARG1: the plugin object
ircd_plugin_del
ircd_plugin_error
ARG0: the error message
ARG1: the plugin alias
ARG2: the plugin object
Chris 'BinGOs' Williams
Copyright © Chris Williams
This module may be used, modified, and distributed under the same terms as Perl itself. Please see the license that came with your Perl distribution for details.
POE
POE::Filter::IRCD
POE::Component::Server::IRC
To install POE::Component::Server::IRC, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POE::Component::Server::IRC
CPAN shell
perl -MCPAN -e shell install POE::Component::Server::IRC
For more information on module installation, please visit the detailed CPAN module installation guide.