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.12 by pippijn, Sun Sep 17 23:57:20 2006 UTC vs.
Revision 1.18 by root, Sun Oct 1 23:57:54 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;
23 27
24sub handle_fcmd { 28sub handle_fcmd {
25 my ($name, $me, $msg) = @_; 29 my ($name, $me, $msg) = @_;
26 30
27 if ($msg eq "!who") { 31 if ($msg eq "!who") {
28 my ($numplayers, $numwiz, @plist) = (0, 0); 32 $CON->send_chan ($BOTCHAN, NOTICE => $_, $BOTCHAN)
33 for ext::commands::who_listing ();
29 34
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->flag (cf::FLAG_WIZ) ? " [WIZ] " : "")
43 ." [" . ($pl->ob->map ? $pl->ob->map->path : "NULL") . "]", $BOTCHAN);
44 }
45 }
46 } elsif ($msg =~ /^\!tell/) { 35 } elsif ($msg =~ /^\!tell/) {
47 my (undef, $target, $tmsg) = split / /, $msg, 3; 36 my (undef, $target, $tmsg) = split / /, $msg, 3;
48 37
49 if (my $other = cf::player::find $target) { 38 if (my $other = cf::player::find $target) {
50 39
82 my $name = 'irc'; 71 my $name = 'irc';
83 my $nick = Net::IRC3::Util::prefix_nick ($msg); 72 my $nick = Net::IRC3::Util::prefix_nick ($msg);
84 my $NOW = Time::HiRes::time; 73 my $NOW = Time::HiRes::time;
85 my $tmsg = $msg->{trailing}; 74 my $tmsg = $msg->{trailing};
86 $tmsg =~ s/\x01[^\x01]*\x01//g; 75 $tmsg =~ s/\x01[^\x01]*\x01//g;
76 $tmsg =~ s/\015?\012/ /g;
87 if ($tmsg =~ /^\!/) { 77 if ($tmsg =~ /^\!/) {
88 handle_fcmd ($name, $nick, $tmsg); 78 handle_fcmd ($name, $nick, $tmsg);
89 } elsif ($tmsg =~ m/\S/) { 79 } elsif ($tmsg =~ m/\S/) {
90 $_->ob->message ( 80 $_->ob->message (
91 "$name/".$nick." chats: $tmsg", cf::NDI_BLUE 81 "$name/".$nick." chats: $tmsg", cf::NDI_BLUE
101 0; 91 0;
102 } 92 }
103 ); 93 );
104} 94}
105 95
106my $timer; 96Event->timer (after => 1, interval => 30, cb => \&check_connection);
107 97
108sub new_timer {
109 $timer = AnyEvent->timer (after => 10, cb => sub {
110 check_connection ();
111 &new_timer; # and restart the time
112 });
113}
114
115new_timer; # create first timer
116check_connection ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines