ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/schmorp-irc.ext
Revision: 1.21
Committed: Fri Dec 15 19:11:47 2006 UTC (17 years, 5 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.20: +0 -0 lines
State: FILE REMOVED
Log Message:
move .ext to server

File Contents

# User Rev Content
1 elmex 1.1 #! perl
2 root 1.4
3 elmex 1.1 use Time::HiRes;
4     use Net::IRC3::Client::Connection;
5    
6 root 1.16 # requires: commands.ext
7    
8 root 1.18 return unless exists $cf::CFG{irc_server};
9 root 1.17
10     my $BOTSERVER = $cf::CFG{irc_server};
11     my $BOTPORT = $cf::CFG{irc_port};
12     my $BOTNAME = $cf::CFG{irc_nick};
13     my $BOTCHAN = $cf::CFG{irc_chan};
14 elmex 1.1
15     my $CON; # the connection
16    
17 root 1.8 sub unload {
18 elmex 1.5 $CON->disconnect if $CON;
19 elmex 1.1 undef $CON;
20     }
21    
22     sub do_notice {
23     my ($msg) = @_;
24 elmex 1.7 $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN)
25     if $CON;
26 elmex 1.1 }
27    
28 root 1.19 sub users {
29     $CON
30     ? grep $_ ne $CON->nick, keys %{ $CON->channel_list->{$BOTCHAN} || {} }
31     : ()
32     }
33    
34 pippijn 1.9 sub handle_fcmd {
35 pippijn 1.12 my ($name, $me, $msg) = @_;
36 pippijn 1.9
37     if ($msg eq "!who") {
38 root 1.16 $CON->send_chan ($BOTCHAN, NOTICE => $_, $BOTCHAN)
39     for ext::commands::who_listing ();
40 pippijn 1.9
41 pippijn 1.12 } elsif ($msg =~ /^\!tell/) {
42     my (undef, $target, $tmsg) = split / /, $msg, 3;
43    
44     if (my $other = cf::player::find $target) {
45    
46     if ($tmsg) {
47     if ($me eq $target) {
48     $CON->send_chan ($BOTCHAN, NOTICE => "$me: You are talking to yourself, you freak!", $BOTCHAN);
49     } elsif ($other->ob->{ext_ignore_tell}{$me} >= time) {
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);
60     }
61    
62     }
63 pippijn 1.9 }
64     }
65    
66 elmex 1.1 sub check_connection {
67     return if $CON;
68 root 1.4
69 elmex 1.1 $CON = Net::IRC3::Client::Connection->new;
70     $CON->connect ($BOTSERVER, $BOTPORT);
71     $CON->send_srv (JOIN => undef, $BOTCHAN);
72     $CON->register ($BOTNAME, $BOTNAME, 'crossfire connection');
73     $CON->reg_cb (
74     #d# 'irc_*' => sub { warn "IRC $_[1]->{trailing}\n"; 1 },
75     irc_privmsg => sub {
76     my ($con, $msg) = @_;
77     my $name = 'irc';
78 pippijn 1.12 my $nick = Net::IRC3::Util::prefix_nick ($msg);
79 elmex 1.1 my $NOW = Time::HiRes::time;
80 elmex 1.3 my $tmsg = $msg->{trailing};
81     $tmsg =~ s/\x01[^\x01]*\x01//g;
82 elmex 1.15 $tmsg =~ s/\015?\012/ /g;
83 pippijn 1.9 if ($tmsg =~ /^\!/) {
84 pippijn 1.12 handle_fcmd ($name, $nick, $tmsg);
85 pippijn 1.9 } elsif ($tmsg =~ m/\S/) {
86 elmex 1.3 $_->ob->message (
87 pippijn 1.12 "$name/".$nick." chats: $tmsg", cf::NDI_BLUE
88 elmex 1.3 ) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
89     }
90 elmex 1.1 1;
91     },
92 elmex 1.2 # registered => sub {
93     # 1;
94     # },
95 elmex 1.1 disconnect => sub {
96     undef $CON;
97     0;
98     }
99     );
100     }
101    
102 root 1.20 Event->timer (after => 1, interval => 30, data => cf::WF_AUTOCANCEL, cb => \&check_connection);
103 elmex 1.1