]>
Commit | Line | Data |
---|---|---|
aecfa1fd | 1 | # This file is part of SurrealServices. |
2 | # | |
3 | # SurrealServices is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 2 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # SurrealServices is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with SurrealServices; if not, write to the Free Software | |
15 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
16 | package connectserv; | |
17 | ||
18 | use strict; | |
19 | no strict 'refs'; | |
20 | ||
21 | use SrSv::IRCd::State qw( initial_synced synced ); | |
22 | use SrSv::IRCd::Event 'addhandler'; | |
23 | use SrSv::RunLevel qw( $runlevel :levels ); | |
24 | ||
25 | use SrSv::Conf::Parameters connectserv => [ | |
26 | [ joinpart => 0 ], | |
27 | ]; | |
28 | ||
29 | use SrSv::Conf2Consts qw( main connectserv ); | |
30 | ||
31 | use SrSv::Log; | |
32 | ||
33 | use SrSv::Process::InParent qw( | |
34 | ev_nickconn ev_nickchange ev_quit ev_kill ev_umode ev_connect message | |
35 | ); | |
36 | ||
37 | my %userlist; | |
38 | ||
39 | use SrSv::Agent; | |
40 | ||
41 | my $csnick = 'ConnectServ'; | |
aecfa1fd | 42 | agent_connect($csnick, 'services', undef, '+pqzBHS', 'Connection Monitor'); |
5e682044 | 43 | my $csUser = { NICK => $csnick, ID => ircd::getUuid($csnick); } |
aecfa1fd | 44 | agent_join($csnick, main_conf_diag); |
5e682044 | 45 | ircd::setmode($csUser, main_conf_diag, '+o', $csUser); |
aecfa1fd | 46 | |
47 | addhandler('NICKCONN', undef, undef, 'connectserv::ev_nickconn', 1); | |
48 | sub ev_nickconn { | |
49 | my ($nick, $ident, $host, $server, $gecos) = @_[0,3,4,5,9]; | |
50 | ||
51 | $userlist{lc $nick} = [$ident, $host, $gecos, $server]; | |
52 | ||
53 | return unless initial_synced(); | |
54 | message("\00304\002SIGNED ON\002 user: \002$nick\002 ($ident\@$host - $gecos\017\00304) at $server"); | |
55 | } | |
56 | ||
57 | addhandler('NICKCHANGE', undef, undef, 'connectserv::ev_nickchange', 1); | |
58 | sub ev_nickchange { | |
59 | my ($old, $new) = @_; | |
60 | my ($ident, $host); | |
61 | unless(lc($new) eq lc($old)) { | |
62 | $userlist{lc $new} = $userlist{lc $old}; | |
63 | delete($userlist{lc $old}); | |
64 | } | |
65 | ($ident, $host) = @{$userlist{lc $new}} if (defined($userlist{lc $new})); | |
66 | message("\00307\002NICK CHANGE\002 user: \002$old\002 ($ident\@$host) changed their nick to \002$new\002"); | |
67 | } | |
68 | ||
69 | addhandler('CHGIDENT', undef, undef, 'connectserv::ev_identchange', 1); | |
70 | sub ev_identchange { | |
71 | my (undef, $nick, $ident) = @_; | |
72 | ||
73 | my ($oldident, $host, $gecos, $server); | |
74 | ($oldident, $host, $gecos, $server) = @{$userlist{lc $nick}} if (defined($userlist{lc $nick})); | |
75 | $userlist{lc $nick} = [$ident, $host, $gecos, $server]; | |
76 | ||
77 | message("\00310\002IDENT CHANGE\002 user: \002$nick\002 ($oldident\@$host) changed their virtual ident to \002$ident\002"); | |
78 | } | |
79 | ||
80 | addhandler('QUIT', undef, undef, 'connectserv::ev_quit', 1); | |
81 | sub ev_quit { | |
82 | my ($nick, $reason) = @_; | |
83 | return unless synced() && $runlevel == ST_NORMAL; | |
84 | my ($ident, $host, $gecos, $server); | |
85 | if(defined($userlist{lc $nick})) { | |
86 | ($ident, $host, $gecos, $server) = @{$userlist{lc $nick}}; | |
87 | delete($userlist{lc $nick}); | |
88 | } | |
89 | return unless initial_synced(); | |
90 | message("\00303\002SIGNED OFF\002 user: \002$nick\002 ($ident\@$host - $gecos\017\00303) at $server - $reason"); | |
91 | } | |
92 | ||
93 | addhandler('KILL', undef, undef, 'connectserv::ev_kill', 1); | |
94 | sub ev_kill { | |
95 | my ($src, $target, $reason) = @_[0,1,3]; | |
96 | my ($ident, $host, $gecos, $server); | |
97 | if(defined($userlist{lc $target})) { | |
98 | ($ident, $host, $gecos, $server) = @{$userlist{lc $target}}; | |
99 | delete($userlist{lc $target}); | |
100 | } | |
101 | message("\00302\002GLOBAL KILL\002 user: \002$target\002 ($ident\@$host) killed by \002$src\002 - $reason"); | |
102 | } | |
103 | ||
104 | addhandler('UMODE', undef, undef, 'connectserv::ev_umode', 1); | |
105 | sub ev_umode { | |
106 | my ($nick, $modes) = @_; | |
107 | my @modes = split(//, $modes); | |
108 | my $sign; | |
109 | foreach my $m (@modes) { | |
110 | $sign = 1 if $m eq '+'; | |
111 | $sign = 0 if $m eq '-'; | |
112 | ||
113 | my $label; | |
114 | $label = 'Global Operator' if $m eq 'o'; | |
115 | $label = 'Services Administrator' if $m eq 'a'; | |
116 | $label = 'Server Administrator' if $m eq 'A'; | |
117 | $label = 'Network Administrator' if $m eq 'N'; | |
118 | $label = 'Co Administrator' if $m eq 'C'; | |
119 | $label = 'Bot' if $m eq 'B'; | |
120 | ||
121 | if($label) { | |
122 | message("\00306\002$nick\002 is ".($sign ? 'now' : 'no longer')." a \002$label\002 (".($sign ? '+' : '-')."$m)"); | |
123 | } | |
124 | } | |
125 | } | |
126 | ||
127 | addhandler('SJOIN', undef, undef, 'connectserv::chan_join', 1) if connectserv_conf_joinpart; | |
128 | sub chan_join { | |
129 | my ($server, $cn, $ts, $chmodes, $chmodeparms, $userarray, $banarray, $exceptarray) = @_; | |
130 | return unless synced() && $runlevel == ST_NORMAL; | |
131 | foreach my $user (@$userarray) { | |
132 | my $nick = $user->{NICK}; | |
133 | message ("\00310CHANNEL JOIN: \002$nick\002 joined to \002$cn\002\003"); | |
134 | } | |
135 | } | |
136 | ||
137 | addhandler('PART', undef, undef, 'connectserv::chan_part', 1) if connectserv_conf_joinpart; | |
138 | sub chan_part { | |
139 | my ($nick, $cn) = @_; | |
140 | return unless synced() && $runlevel == ST_NORMAL; | |
141 | message ("\00310CHANNEL PART: \002$nick\002 parted from \002$cn\002\003"); | |
142 | } | |
143 | ||
144 | addhandler('JOIN', undef, undef, 'connectserv::chan_join0', 1) if connectserv_conf_joinpart; | |
145 | sub chan_join0 { | |
146 | my ($nick, $cn) = @_; | |
147 | return unless synced() && $runlevel == ST_NORMAL; | |
148 | if($cn eq '0') { | |
149 | message ("\00310CHANNEL PART: \002$nick\002 parted all channels\003"); | |
150 | } else { | |
151 | message ("\00310CHANNEL JOIN: \002$nick\002 joined to \002$cn\002\003"); | |
152 | } | |
153 | } | |
154 | ||
155 | sub message(@) { | |
156 | ircd::privmsg($csnick, main_conf_diag, @_); | |
157 | write_log('diag', '<'.$csnick.'>', @_); | |
158 | } | |
159 | ||
160 | sub init { } | |
161 | sub begin { } | |
162 | sub end { } | |
163 | sub unload { } | |
164 | ||
165 | 1; |