ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/irc.ext
Revision: 1.10
Committed: Fri Dec 28 19:49:29 2007 UTC (16 years, 4 months ago) by root
Branch: MAIN
CVS Tags: rel-2_4, rel-2_5, rel-2_52, rel-2_43, rel-2_42, rel-2_41
Changes since 1.9: +1 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #! perl
2    
3     use Time::HiRes;
4     use Net::IRC3::Client::Connection;
5    
6     # requires: commands.ext
7    
8     return unless exists $cf::CFG{irc_server};
9    
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    
15     my $CON; # the connection
16    
17     sub unload {
18     $CON->disconnect if $CON;
19     undef $CON;
20     }
21    
22     sub do_notice {
23     my ($msg) = @_;
24    
25     utf8::encode $msg;
26     $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN)
27     if $CON;
28     }
29    
30     sub users {
31     $CON
32     ? grep $_ ne $CON->nick, keys %{ $CON->channel_list->{$BOTCHAN} || {} }
33     : ()
34     }
35    
36     sub handle_fcmd {
37     my ($name, $me, $msg) = @_;
38    
39     if ($msg eq "!who") {
40 root 1.6 # clobbers irc, http is available
41 elmex 1.8 do_notice "see http://www.deliantra.net/userlist.crossfire.schmorp.de.html";
42 root 1.6 # do_notice $_
43     # for ext::commands::who_listing (0, ".");
44 root 1.1
45     } elsif ($msg =~ /^\!tell/) {
46     my (undef, $target, $tmsg) = split / /, $msg, 3;
47    
48     if (my $other = cf::player::find_active $target) {
49    
50     if ($tmsg) {
51     if ($me eq $target) {
52     $CON->send_chan ($BOTCHAN, NOTICE => "$me: You are talking to yourself, you freak!", $BOTCHAN);
53     } elsif ($other->ob->{ext_ignore_tell}{$me} >= time) {
54     $CON->send_chan ($BOTCHAN, NOTICE => "$me: $target ignores what you say. Give up on it.", $BOTCHAN);
55     } else {
56     cf::LOG cf::llevDebug, sprintf "TELL [%s/%s>%s] %s\n", $name, $me, $target, $tmsg;
57    
58 elmex 1.7 $other->ns->send_msg (ext::chat::tell_channel ("$name/$me"), "$name/$me tells you: $tmsg", cf::NDI_DK_ORANGE | cf::NDI_DEF);
59 root 1.1 }
60     } else {
61     do_notice "$me: What do you want to tell $target?";
62     }
63    
64     }
65     }
66     }
67    
68     sub check_connection {
69     return if $CON;
70    
71     $CON = Net::IRC3::Client::Connection->new;
72     $CON->connect ($BOTSERVER, $BOTPORT);
73     $CON->send_srv (JOIN => undef, $BOTCHAN);
74     $CON->register ($BOTNAME, $BOTNAME, 'crossfire connection');
75     $CON->reg_cb (
76     #d# 'irc_*' => sub { warn "IRC $_[1]->{trailing}\n"; 1 },
77     irc_privmsg => sub {
78     my ($con, $msg) = @_;
79     my $name = 'irc';
80     my $nick = Net::IRC3::Util::prefix_nick ($msg);
81     my $NOW = Time::HiRes::time;
82 root 1.2
83 root 1.1 my $tmsg = $msg->{trailing};
84     $tmsg =~ s/\x01[^\x01]*\x01//g;
85     $tmsg =~ s/\015?\012/ /g;
86 root 1.2
87     utf8::decode $tmsg;
88    
89 root 1.1 if ($tmsg =~ /^\!/) {
90     handle_fcmd ($name, $nick, $tmsg);
91     } elsif ($tmsg =~ m/\S/) {
92 root 1.4 $_->ns->send_msg ($ext::chat::CHAT_CHANNEL,
93 root 1.3 "$name/".$nick." chats: $tmsg", cf::NDI_BLUE | cf::NDI_DEF
94 root 1.1 ) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
95 root 1.10 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", "$name/$nick", $tmsg;
96 root 1.1 }
97     1;
98     },
99     # registered => sub {
100     # 1;
101     # },
102     disconnect => sub {
103     my ($con, $reason) = @_;
104     warn "CFBOT: disconnect: $reason\n";
105     undef $CON;
106     0;
107     }
108     );
109     }
110    
111 root 1.9 our $RECONNECT = cf::periodic 30, Coro::unblock_sub {
112     check_connection;
113     };
114 root 1.1