Changeset 11546
- Timestamp:
- 05/14/08 03:25:19 (5 years ago)
- Location:
- lang/perl/XIRCD/trunk
- Files:
-
- 2 added
- 1 removed
- 3 modified
-
. (modified) (1 prop)
-
lib/XIRCD.pm (modified) (2 diffs)
-
lib/XIRCD/Component (added)
-
lib/XIRCD/Component/Time.pm (added)
-
lib/XIRCD/Plugin (deleted)
-
lib/XIRCD/Server.pm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/XIRCD/trunk
-
Property
svn:ignore set
to
META.yml
Makefile
blib
inc
pm_to_blib
-
Property
svn:ignore set
to
-
lang/perl/XIRCD/trunk/lib/XIRCD.pm
r7015 r11546 4 4 use warnings; 5 5 our $VERSION = '0.01'; 6 use base qw/Class::Accessor::Fast/;7 8 __PACKAGE__->mk_accessors('config');9 6 10 7 use POE; … … 19 16 my $config = $class->_load_conf; 20 17 21 XIRCD::Server-> spawn($config->{ircd} );18 XIRCD::Server->new( config => $config->{ircd} ); 22 19 23 for my $ plugin ( @{$config->{plugins}} ) {24 my $module = $ plugin->{module};20 for my $component ( @{$config->{components}} ) { 21 my $module = $component->{module}; 25 22 $module->require; 26 $module-> spawn( $plugin);23 $module->new( config => $component ); 27 24 } 28 25 -
lang/perl/XIRCD/trunk/lib/XIRCD/Server.pm
r7015 r11546 1 1 package XIRCD::Server; 2 use strict; 3 use warnings; 2 use MooseX::POE; 3 4 with qw(MooseX::POE::Aliased); 4 5 5 6 use Clone qw/clone/; … … 8 9 use POE qw/Component::Server::IRC/; 9 10 10 sub spawn { 11 my $class = shift; 12 my $config = @_ > 1 ? {@_} : $_[0]; 11 has 'ircd' => ( 12 isa => 'POE::Component::Server::IRC', 13 is => 'rw', 14 ); 13 15 14 $config->{servername} ||= 'xircd.ircd'; 15 $config->{client_encoding} ||= 'utf-8'; 16 17 my $ircd = POE::Component::Server::IRC->spawn( config => clone($config) ); 18 POE::Session->create( 19 package_states => [ 20 __PACKAGE__, [qw/_start ircd_daemon_public publish_message join_channel/], 21 ], 22 heap => { ircd => $ircd, config => $config }, 23 ); 24 } 16 has 'config' => ( 17 isa => 'HashRef', 18 is => 'rw', 19 ); 25 20 26 21 sub debug(@) { ## no critic. … … 28 23 } 29 24 30 sub _start { 31 my ($kernel, $heap) = @_[KERNEL, HEAP]; 25 sub get_args(@) { ## no critic. 26 return @_[9..19]; 27 } 32 28 33 $kernel->alias_set('ircd'); 29 sub START { 30 my $self = shift; 34 31 35 my ($ircd, $config) = @$heap{qw/ircd config/};32 $self->alias('ircd'); 36 33 37 $ircd->yield('register'); 38 $ircd->add_auth( mask => '*@*' ); 39 $ircd->add_listener( port => $config->{port} || 6667 ); 34 $self->config->{servername} ||= 'xircd.ircd'; 35 $self->config->{client_encoding} ||= 'utf-8'; 36 37 $self->ircd(POE::Component::Server::IRC->spawn( config => clone($self->config) )); 38 $self->ircd->yield('register'); 39 $self->ircd->add_auth( mask => '*@*' ); 40 $self->ircd->add_listener( port => $self->config->{port} || 6667 ); 40 41 41 42 debug "start irc \n\n"; 42 43 43 $ircd->yield( add_spoofed_nick => { nick => $config->{server_nick} } ); 44 45 $heap->{nicknames} = {}; 44 $self->ircd->yield( add_spoofed_nick => { nick => $self->config->{server_nick} } ); 46 45 } 47 46 48 sub ircd_daemon_public{49 my ($ kernel, $heap, $user, $channel, $text) = @_[KERNEL, HEAP, ARG0, ARG1, ARG2];50 my $encoding = $ heap->{config}{client_encoding};47 event ircd_daemon_public => sub { 48 my ($self, $user, $channel, $text) = @_; 49 my $encoding = $self->config->{client_encoding}; 51 50 52 $kernel->post( im => send_message => decode( $encoding, $text ) );53 $kernel->post( ustream => say => decode( $encoding, $text ) );54 } 51 POE::Kernel->post( im => send_message => decode( $encoding, $text ) ); 52 POE::Kernel->post( ustream => say => decode( $encoding, $text ) ); 53 }; 55 54 56 sub publish_message { 57 my ($kernel, $heap, $channel, $message) = @_[KERNEL, HEAP, ARG0, ARG1]; 55 event publish_message => sub { 56 my $self = shift; 57 my ($channel, $message) = get_args(@_); 58 58 59 59 debug "publish to irc: [$channel] $message \n\n"; 60 60 61 my ($ircd, $config) = @$heap{qw/ircd config/}; 62 $message = encode( $config->{client_encoding}, $message ); 61 $message = encode( $self->config->{client_encoding}, $message ); 63 62 64 63 my $say = sub { 65 64 my ($nick, $text) = @_; 66 $ ircd->yield( daemon_cmd_privmsg => $nick => $channel, $_ )65 $self->ircd->yield( daemon_cmd_privmsg => $nick => $channel, $_ ) 67 66 for split /\r?\n/, $text; 68 67 }; 69 68 70 $say->($ config->{server_nick}, $message);71 } 69 $say->($self->config->{server_nick}, $message); 70 }; 72 71 73 sub join_channel{74 my ($kernel, $heap, $channel) = @_[KERNEL, HEAP, ARG0];75 my ($ ircd, $config) = @$heap{qw/ircd config/};72 event join_channel => sub { 73 my $self = shift; 74 my ($channel,) = get_args(@_); 76 75 77 76 debug "join channel: $channel"; 78 77 79 $ ircd->yield( daemon_cmd_join => $config->{server_nick}, $channel );80 } 78 $self->ircd->yield( daemon_cmd_join => $self->config->{server_nick}, $channel ); 79 }; 81 80 82 81 1;
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)