ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/schmorp-irc.ext
(Generate patch)

Comparing deliantra/maps/perl/schmorp-irc.ext (file contents):
Revision 1.1 by elmex, Wed Aug 2 16:59:47 2006 UTC vs.
Revision 1.13 by pippijn, Mon Sep 18 02:37:29 2006 UTC

1#! perl 1#! perl
2
2use Time::HiRes; 3use Time::HiRes;
3use Net::IRC3::Client::Connection; 4use Net::IRC3::Client::Connection;
4 5
5my $BOTSERVER = 'irc.plan9.de'; 6my $BOTSERVER = 'localhost';
6my $BOTPORT = '6667'; 7my $BOTPORT = '6667';
7my $BOTNAME = 'cfbot'; 8my $BOTNAME = 'cfbot';
8my $BOTCHAN = '#cf'; 9my $BOTCHAN = '#cf';
9 10
10my $CON; # the connection 11my $CON; # the connection
11 12
12sub on_unload { 13sub unload {
13 $CON->disconnect; 14 $CON->disconnect if $CON;
14 undef $CON; 15 undef $CON;
15} 16}
16 17
17sub do_notice { 18sub 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
24sub handle_fcmd {
25 my ($name, $me, $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 . " " . $pl->ob->race . " "
43 .($pl->ob->flag (cf::FLAG_WIZ) ? " [WIZ] " : "")
44 ." [" . ($pl->ob->map ? $pl->ob->map->path : "NULL") . "]", $BOTCHAN);
45 }
46 }
47 } elsif ($msg =~ /^\!tell/) {
48 my (undef, $target, $tmsg) = split / /, $msg, 3;
49
50 if (my $other = cf::player::find $target) {
51
52 if ($tmsg) {
53 if ($me eq $target) {
54 $CON->send_chan ($BOTCHAN, NOTICE => "$me: You are talking to yourself, you freak!", $BOTCHAN);
55 } elsif ($other->ob->{ext_ignore_tell}{$me} >= time) {
56 $CON->send_chan ($BOTCHAN, NOTICE => "$me: $target ignores what you say. Give up on it.", $BOTCHAN);
57 } else {
58 utf8::encode $tmsg; # ->message not yet utf8-ified
59 cf::LOG cf::llevDebug, sprintf "TELL [%s/%s>%s] %s\n", $name, $me, $target, $tmsg;
60
61 $other->ob->message ("$name/$me tells you: $tmsg");
62 $other->ob->{ext_last_tell} = "$name/$me";
63 }
64 } else {
65 $CON->send_chan ($BOTCHAN, NOTICE => "$me: What do you want to tell $target?", cf::NDI_UNIQUE);
66 }
67
68 }
69 }
20} 70}
21 71
22sub check_connection { 72sub check_connection {
23 return if $CON; 73 return if $CON;
74
24 $CON = Net::IRC3::Client::Connection->new; 75 $CON = Net::IRC3::Client::Connection->new;
25 $CON->connect ($BOTSERVER, $BOTPORT); 76 $CON->connect ($BOTSERVER, $BOTPORT);
26 $CON->send_srv (JOIN => undef, $BOTCHAN); 77 $CON->send_srv (JOIN => undef, $BOTCHAN);
27 $CON->register ($BOTNAME, $BOTNAME, 'crossfire connection'); 78 $CON->register ($BOTNAME, $BOTNAME, 'crossfire connection');
28 $CON->reg_cb ( 79 $CON->reg_cb (
29 #d# 'irc_*' => sub { warn "IRC $_[1]->{trailing}\n"; 1 }, 80 #d# 'irc_*' => sub { warn "IRC $_[1]->{trailing}\n"; 1 },
30 irc_privmsg => sub { 81 irc_privmsg => sub {
31 my ($con, $msg) = @_; 82 my ($con, $msg) = @_;
32 my $name = 'irc'; 83 my $name = 'irc';
84 my $nick = Net::IRC3::Util::prefix_nick ($msg);
33 my $NOW = Time::HiRes::time; 85 my $NOW = Time::HiRes::time;
86 my $tmsg = $msg->{trailing};
87 $tmsg =~ s/\x01[^\x01]*\x01//g;
88 if ($tmsg =~ /^\!/) {
89 handle_fcmd ($name, $nick, $tmsg);
90 } elsif ($tmsg =~ m/\S/) {
34 $_->ob->message ( 91 $_->ob->message (
35 "$name/".Net::IRC3::Util::prefix_nick ($msg)." chats: $msg->{trailing}", 92 "$name/".$nick." chats: $tmsg", cf::NDI_BLUE
36 cf::NDI_BLUE
37 ) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; 93 ) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
94 }
38 1; 95 1;
39 }, 96 },
40 registered => sub { 97# registered => sub {
41 warn "BOP\n";
42 1; 98# 1;
43 }, 99# },
44 disconnect => sub { 100 disconnect => sub {
45 undef $CON; 101 undef $CON;
46 0; 102 0;
47 } 103 }
48 ); 104 );

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines