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.10 by pippijn, Sun Sep 17 22:53:35 2006 UTC vs.
Revision 1.19 by root, Sun Nov 26 02:37:53 2006 UTC

1#! perl 1#! perl
2 2
3use Time::HiRes; 3use Time::HiRes;
4use Net::IRC3::Client::Connection; 4use Net::IRC3::Client::Connection;
5 5
6my $BOTSERVER = 'localhost'; 6# requires: commands.ext
7my $BOTPORT = '6667'; 7
8my $BOTNAME = 'cfbot'; 8return unless exists $cf::CFG{irc_server};
9my $BOTCHAN = '#cf'; 9
10my $BOTSERVER = $cf::CFG{irc_server};
11my $BOTPORT = $cf::CFG{irc_port};
12my $BOTNAME = $cf::CFG{irc_nick};
13my $BOTCHAN = $cf::CFG{irc_chan};
10 14
11my $CON; # the connection 15my $CON; # the connection
12 16
13sub unload { 17sub unload {
14 $CON->disconnect if $CON; 18 $CON->disconnect if $CON;
19 my ($msg) = @_; 23 my ($msg) = @_;
20 $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN) 24 $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN)
21 if $CON; 25 if $CON;
22} 26}
23 27
28sub users {
29 $CON
30 ? grep $_ ne $CON->nick, keys %{ $CON->channel_list->{$BOTCHAN} || {} }
31 : ()
32}
33
24sub handle_fcmd { 34sub handle_fcmd {
25 my ($msg) = @_; 35 my ($name, $me, $msg) = @_;
26 36
27 if ($msg eq "!who") { 37 if ($msg eq "!who") {
28 my ($numplayers, $numwiz, @plist) = (0, 0); 38 $CON->send_chan ($BOTCHAN, NOTICE => $_, $BOTCHAN)
39 for ext::commands::who_listing ();
29 40
30 foreach my $pl (cf::player::list) { 41 } elsif ($msg =~ /^\!tell/) {
31 $numplayers++; 42 my (undef, $target, $tmsg) = split / /, $msg, 3;
32 $numwiz++
33 if ($pl->ob->flag (cf::FLAG_WIZ));
34 push (@plist, $pl);
35 }
36 43
37 $CON->send_chan ($BOTCHAN, NOTICE => "Total Players in The World. ($numplayers) -- WIZ($numwiz)", $BOTCHAN); 44 if (my $other = cf::player::find $target) {
38 45
39 if ($numplayers > 0) { 46 if ($tmsg) {
40 foreach my $pl (@plist) { 47 if ($me eq $target) {
41 $CON->send_chan ($BOTCHAN, NOTICE => 48 $CON->send_chan ($BOTCHAN, NOTICE => "$me: You are talking to yourself, you freak!", $BOTCHAN);
42 "* " . $pl->ob->name . "/" . $pl->ob->level 49 } elsif ($other->ob->{ext_ignore_tell}{$me} >= time) {
43 ." [" . ($pl->ob->map ? $pl->ob->map->path : "NULL") . "]", $BOTCHAN); 50 $CON->send_chan ($BOTCHAN, NOTICE => "$me: $target ignores what you say. Give up on it.", $BOTCHAN);
51 } else {
52 utf8::encode $tmsg; # ->message not yet utf8-ified
53 cf::LOG cf::llevDebug, sprintf "TELL [%s/%s>%s] %s\n", $name, $me, $target, $tmsg;
54
55 $other->ob->message ("$name/$me tells you: $tmsg");
56 $other->ob->{ext_last_tell} = "$name/$me";
57 }
58 } else {
59 $CON->send_chan ($BOTCHAN, NOTICE => "$me: What do you want to tell $target?", cf::NDI_UNIQUE);
44 } 60 }
61
45 } 62 }
46 } 63 }
47} 64}
48 65
49sub check_connection { 66sub check_connection {
56 $CON->reg_cb ( 73 $CON->reg_cb (
57 #d# 'irc_*' => sub { warn "IRC $_[1]->{trailing}\n"; 1 }, 74 #d# 'irc_*' => sub { warn "IRC $_[1]->{trailing}\n"; 1 },
58 irc_privmsg => sub { 75 irc_privmsg => sub {
59 my ($con, $msg) = @_; 76 my ($con, $msg) = @_;
60 my $name = 'irc'; 77 my $name = 'irc';
78 my $nick = Net::IRC3::Util::prefix_nick ($msg);
61 my $NOW = Time::HiRes::time; 79 my $NOW = Time::HiRes::time;
62 my $tmsg = $msg->{trailing}; 80 my $tmsg = $msg->{trailing};
63 $tmsg =~ s/\x01[^\x01]*\x01//g; 81 $tmsg =~ s/\x01[^\x01]*\x01//g;
82 $tmsg =~ s/\015?\012/ /g;
64 if ($tmsg =~ /^\!/) { 83 if ($tmsg =~ /^\!/) {
65 handle_fcmd ($tmsg); 84 handle_fcmd ($name, $nick, $tmsg);
66 } elsif ($tmsg =~ m/\S/) { 85 } elsif ($tmsg =~ m/\S/) {
67 $_->ob->message ( 86 $_->ob->message (
68 "$name/".Net::IRC3::Util::prefix_nick ($msg)." chats: $tmsg", cf::NDI_BLUE 87 "$name/".$nick." chats: $tmsg", cf::NDI_BLUE
69 ) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; 88 ) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
70 } 89 }
71 1; 90 1;
72 }, 91 },
73# registered => sub { 92# registered => sub {
78 0; 97 0;
79 } 98 }
80 ); 99 );
81} 100}
82 101
83my $timer; 102Event->timer (after => 1, interval => 30, cb => \&check_connection);
84 103
85sub new_timer {
86 $timer = AnyEvent->timer (after => 10, cb => sub {
87 check_connection ();
88 &new_timer; # and restart the time
89 });
90}
91
92new_timer; # create first timer
93check_connection ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines