Changeset 11630
- Timestamp:
- 05/15/08 14:24:25 (5 years ago)
- Location:
- lang/perl/XIRCD/trunk/lib/XIRCD
- Files:
-
- 2 modified
-
Component/Wassr.pm (modified) (5 diffs)
-
Server.pm (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/XIRCD/trunk/lib/XIRCD/Component/Wassr.pm
r11554 r11630 24 24 ); 25 25 26 has 'jid' => ( 27 isa => 'Str', 28 is => 'rw', 29 ); 30 26 31 sub debug(@) { ## no critic. 27 32 print @_ if $ENV{XIRCD_DEBUG}; … … 35 40 my $self = shift; 36 41 37 $self->alias(' jabber');42 $self->alias('wassr'); 38 43 39 44 debug "start wassr\n"; … … 58 63 ); 59 64 60 POE::Kernel->post( ircd => 'join_channel', $self->config->{channel} );65 POE::Kernel->post( ircd => 'join_channel', $self->config->{channel}, $self->alias ); 61 66 POE::Kernel->post( jabber => 'connect' ); 62 67 } … … 69 74 debug "init finished\n"; 70 75 $self->jid($self->jabber->jid); 71 #$heap->{sid} = $sender->ID;72 76 73 77 POE::Kernel->post(jabber => 'output_handler', POE::Filter::XML::Node->new('presence')); … … 82 86 debug "recv:", $node->to_str, "\n\n"; 83 87 84 my ($body) = $node->get_tag('body'); 88 my ($body,) = $node->get_tag('body'); 89 85 90 if ($body && $node->attr('from') =~ /^wassr-bot\@wassr\.jp/) { 86 my ($nick, $text) = $body =~ /^(\w+): (.*)/s; 87 POE::Kernel->post( ircd => 'publish_message', $nick, $self->config->{channel}, $text ) if $nick; 91 my ($nick, $text) = $body->data =~ /^([A-Za-z0-9_.-]+): (.*)/s; 92 if ($nick && $text) { 93 POE::Kernel->post( ircd => 'publish_message', $nick, $self->config->{channel}, $text ); 94 } else { 95 POE::Kernel->post( ircd => 'publish_notice', $self->config->{channel}, $body->data ); 96 } 97 } 98 }; 99 100 event send_message => sub { 101 my $self = shift; 102 my ($message,) = get_args(@_); 103 104 my $node = POE::Filter::XML::Node->new('message'); 105 106 $node->attr('to', 'wassr-bot@wassr.jp'); 107 $node->attr('from', $self->{jid} ); 108 $node->attr('type', 'chat'); 109 $node->insert_tag('body')->data( $message ); 110 111 debug "send:", $node->to_str, "\n\n"; 112 113 POE::Kernel->post( jabber => output_handler => $node ); 114 }; 115 116 event error_handler => sub { 117 my $self = shift; 118 my ($error,) = get_args(@_); 119 120 if ( $error == +PCJ_SOCKETFAIL or $error == +PCJ_SOCKETDISCONNECT or $error == +PCJ_CONNECTFAIL ) { 121 print "Reconnecting!\n"; 122 POE::Kernel->post( jabber => 'reconnect' ); 123 } 124 elsif ( $error == +PCJ_SSLFAIL ) { 125 print "TLS/SSL negotiation failed\n"; 126 } 127 elsif ( $error == +PCJ_AUTHFAIL ) { 128 print "Failed to authenticate\n"; 129 } 130 elsif ( $error == +PCJ_BINDFAIL ) { 131 print "Failed to bind a resource\n"; 132 } 133 elsif ( $error == +PCJ_SESSIONFAIL ) { 134 print "Failed to establish a session\n"; 88 135 } 89 136 }; -
lang/perl/XIRCD/trunk/lib/XIRCD/Server.pm
r11554 r11630 20 20 21 21 has 'nicknames' => ( 22 isa => 'HashRef', 23 is => 'rw', 24 default => sub { {} }, 25 ); 26 27 has 'components' => ( 22 28 isa => 'HashRef', 23 29 is => 'rw', … … 52 58 53 59 event ircd_daemon_public => sub { 54 my ($self, $user, $channel, $text) = @_; 60 my $self = shift; 61 my($nick, $channel, $text) = get_args(@_); 55 62 my $encoding = $self->config->{client_encoding}; 56 63 57 POE::Kernel->post( im => send_message => decode( $encoding, $text ) ); 58 POE::Kernel->post( ustream => say => decode( $encoding, $text ) ); 64 debug "public [$channel] $nick : $text"; 65 66 my $component = $self->components->{$channel}; 67 return unless $component; 68 69 POE::Kernel->post( $component => send_message => decode( $encoding, $text ) ); 59 70 }; 60 71 … … 72 83 } 73 84 74 $message = encode( $self->config->{client_encoding}, $message );85 #$message = encode( $self->config->{client_encoding}, $message ); 75 86 76 87 $self->ircd->yield( daemon_cmd_privmsg => $nick => $channel, $_ ) … … 78 89 }; 79 90 91 event publish_notice => sub { 92 my $self = shift; 93 my ($channel, $message) = get_args(@_); 94 95 debug "notice to irc: [$channel] $message \n\n"; 96 97 #$message = encode( $self->config->{client_encoding}, $message ); 98 99 $self->ircd->yield( daemon_cmd_notice => $self->config->{server_nick} => $channel, $_ ) 100 for split /\r?\n/, $message; 101 }; 102 80 103 event join_channel => sub { 81 104 my $self = shift; 82 my ($channel, ) = get_args(@_);105 my ($channel, $component) = get_args(@_); 83 106 84 107 debug "join channel: $channel"; 108 debug "register: $channel => $component"; 85 109 110 $self->components->{$channel} = $component; 86 111 $self->ircd->yield( daemon_cmd_join => $self->config->{server_nick}, $channel ); 87 112 };
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)