1 | #! perl |
1 | #! perl |
|
|
2 | |
2 | use Time::HiRes; |
3 | use Time::HiRes; |
3 | use Net::IRC3::Client::Connection; |
4 | use Net::IRC3::Client::Connection; |
4 | |
5 | |
5 | my $BOTSERVER = 'irc.plan9.de'; |
6 | my $BOTSERVER = 'localhost'; |
6 | my $BOTPORT = '6667'; |
7 | my $BOTPORT = '6667'; |
7 | my $BOTNAME = 'cfbot'; |
8 | my $BOTNAME = 'cfbot'; |
8 | my $BOTCHAN = '#cf'; |
9 | my $BOTCHAN = '#cf'; |
9 | |
10 | |
10 | my $CON; # the connection |
11 | my $CON; # the connection |
11 | |
12 | |
12 | sub on_unload { |
13 | sub unload { |
13 | $CON->disconnect; |
14 | $CON->disconnect if $CON; |
14 | undef $CON; |
15 | undef $CON; |
15 | } |
16 | } |
16 | |
17 | |
17 | sub do_notice { |
18 | sub do_notice { |
18 | my ($msg) = @_; |
19 | my ($msg) = @_; |
19 | $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN); |
20 | $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN) |
|
|
21 | if $CON; |
|
|
22 | } |
|
|
23 | |
|
|
24 | sub handle_fcmd { |
|
|
25 | my ($msg) = @_; |
|
|
26 | |
|
|
27 | if ($msg eq "!who") { |
|
|
28 | my ($numplayers, $numwiz, @plist) = (0, 0); |
|
|
29 | |
|
|
30 | foreach my $pl (cf::player::list) { |
|
|
31 | $numplayers++; |
|
|
32 | $numwiz++ |
|
|
33 | if ($pl->ob->flag (cf::FLAG_WIZ)); |
|
|
34 | push (@plist, $pl); |
|
|
35 | } |
|
|
36 | |
|
|
37 | $CON->send_chan ($BOTCHAN, NOTICE => "Total Players in The World. ($numplayers) -- WIZ($numwiz)", $BOTCHAN); |
|
|
38 | |
|
|
39 | if ($numplayers > 0) { |
|
|
40 | foreach my $pl (@plist) { |
|
|
41 | $CON->send_chan ($BOTCHAN, NOTICE => |
|
|
42 | "* " . $pl->ob->name . "/" . $pl->ob->level |
|
|
43 | ." [" . ($pl->ob->map ? $pl->ob->map->path : "NULL") . "]", $BOTCHAN); |
|
|
44 | } |
|
|
45 | } |
|
|
46 | } |
20 | } |
47 | } |
21 | |
48 | |
22 | sub check_connection { |
49 | sub check_connection { |
23 | return if $CON; |
50 | return if $CON; |
|
|
51 | |
24 | $CON = Net::IRC3::Client::Connection->new; |
52 | $CON = Net::IRC3::Client::Connection->new; |
25 | $CON->connect ($BOTSERVER, $BOTPORT); |
53 | $CON->connect ($BOTSERVER, $BOTPORT); |
26 | $CON->send_srv (JOIN => undef, $BOTCHAN); |
54 | $CON->send_srv (JOIN => undef, $BOTCHAN); |
27 | $CON->register ($BOTNAME, $BOTNAME, 'crossfire connection'); |
55 | $CON->register ($BOTNAME, $BOTNAME, 'crossfire connection'); |
28 | $CON->reg_cb ( |
56 | $CON->reg_cb ( |
… | |
… | |
31 | my ($con, $msg) = @_; |
59 | my ($con, $msg) = @_; |
32 | my $name = 'irc'; |
60 | my $name = 'irc'; |
33 | my $NOW = Time::HiRes::time; |
61 | my $NOW = Time::HiRes::time; |
34 | my $tmsg = $msg->{trailing}; |
62 | my $tmsg = $msg->{trailing}; |
35 | $tmsg =~ s/\x01[^\x01]*\x01//g; |
63 | $tmsg =~ s/\x01[^\x01]*\x01//g; |
36 | if ($tmsg =~ m/\S/) { |
64 | if ($tmsg =~ /^\!/) { |
|
|
65 | handle_fcmd ($tmsg); |
|
|
66 | } elsif ($tmsg =~ m/\S/) { |
37 | $_->ob->message ( |
67 | $_->ob->message ( |
38 | "$name/".Net::IRC3::Util::prefix_nick ($msg)." chats: $tmsg", |
68 | "$name/".Net::IRC3::Util::prefix_nick ($msg)." chats: $tmsg", cf::NDI_BLUE |
39 | cf::NDI_BLUE |
|
|
40 | ) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
69 | ) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
41 | } |
70 | } |
42 | 1; |
71 | 1; |
43 | }, |
72 | }, |
44 | # registered => sub { |
73 | # registered => sub { |