ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/schmorp-irc.ext
Revision: 1.5
Committed: Mon Aug 14 04:19:28 2006 UTC (17 years, 9 months ago) by elmex
Branch: MAIN
Changes since 1.4: +1 -1 lines
Log Message:
added reseller extension and fixed bug in schmorp-irc

File Contents

# Content
1 #! perl
2
3 use Time::HiRes;
4 use Net::IRC3::Client::Connection;
5
6 my $BOTSERVER = 'irc.plan9.de';
7 my $BOTPORT = '6667';
8 my $BOTNAME = 'cfbot';
9 my $BOTCHAN = '#cf';
10
11 my $CON; # the connection
12
13 sub on_unload {
14 $CON->disconnect if $CON;
15 undef $CON;
16 }
17
18 sub do_notice {
19 my ($msg) = @_;
20 $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN);
21 }
22
23 sub check_connection {
24 return if $CON;
25
26 $CON = Net::IRC3::Client::Connection->new;
27 $CON->connect ($BOTSERVER, $BOTPORT);
28 $CON->send_srv (JOIN => undef, $BOTCHAN);
29 $CON->register ($BOTNAME, $BOTNAME, 'crossfire connection');
30 $CON->reg_cb (
31 #d# 'irc_*' => sub { warn "IRC $_[1]->{trailing}\n"; 1 },
32 irc_privmsg => sub {
33 my ($con, $msg) = @_;
34 my $name = 'irc';
35 my $NOW = Time::HiRes::time;
36 my $tmsg = $msg->{trailing};
37 $tmsg =~ s/\x01[^\x01]*\x01//g;
38 if ($tmsg =~ m/\S/) {
39 $_->ob->message (
40 "$name/".Net::IRC3::Util::prefix_nick ($msg)." chats: $tmsg",
41 cf::NDI_BLUE
42 ) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
43 }
44 1;
45 },
46 # registered => sub {
47 # 1;
48 # },
49 disconnect => sub {
50 undef $CON;
51 0;
52 }
53 );
54 }
55
56 my $timer;
57
58 sub new_timer {
59 $timer = AnyEvent->timer (after => 10, cb => sub {
60 check_connection ();
61 &new_timer; # and restart the time
62 });
63 }
64
65 new_timer; # create first timer
66 check_connection ();