ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cf.schmorp.de/maps/perl/schmorp-irc.ext
Revision: 1.21
Committed: Fri Dec 15 19:11:47 2006 UTC (17 years, 7 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

# Content
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 $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN)
25 if $CON;
26 }
27
28 sub users {
29 $CON
30 ? grep $_ ne $CON->nick, keys %{ $CON->channel_list->{$BOTCHAN} || {} }
31 : ()
32 }
33
34 sub handle_fcmd {
35 my ($name, $me, $msg) = @_;
36
37 if ($msg eq "!who") {
38 $CON->send_chan ($BOTCHAN, NOTICE => $_, $BOTCHAN)
39 for ext::commands::who_listing ();
40
41 } 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 }
64 }
65
66 sub check_connection {
67 return if $CON;
68
69 $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 my $nick = Net::IRC3::Util::prefix_nick ($msg);
79 my $NOW = Time::HiRes::time;
80 my $tmsg = $msg->{trailing};
81 $tmsg =~ s/\x01[^\x01]*\x01//g;
82 $tmsg =~ s/\015?\012/ /g;
83 if ($tmsg =~ /^\!/) {
84 handle_fcmd ($name, $nick, $tmsg);
85 } elsif ($tmsg =~ m/\S/) {
86 $_->ob->message (
87 "$name/".$nick." chats: $tmsg", cf::NDI_BLUE
88 ) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
89 }
90 1;
91 },
92 # registered => sub {
93 # 1;
94 # },
95 disconnect => sub {
96 undef $CON;
97 0;
98 }
99 );
100 }
101
102 Event->timer (after => 1, interval => 30, data => cf::WF_AUTOCANCEL, cb => \&check_connection);
103