]>
Commit | Line | Data |
---|---|---|
5975999e | 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 'initial_synced'; | |
22 | use SrSv::IRCd::Event 'addhandler'; | |
23 | ||
24 | use SrSv::Conf2Consts qw(main); | |
25 | ||
26 | use SrSv::Log; | |
27 | ||
28 | use SrSv::Process::InParent qw( | |
29 | ev_nickconn ev_nickchange ev_quit ev_kill ev_umode ev_connect message | |
30 | ); | |
31 | ||
32 | my %userlist; | |
33 | ||
34 | use SrSv::Agent; | |
35 | ||
36 | my $csnick = 'ConnectServ'; | |
5975999e | 37 | agent_connect($csnick, 'services', undef, '+pqzBHS', 'Connection Monitor'); |
2eef9154 | 38 | my $csUser = { NICK => $csnick, ID => ircd::getUuid($csnick); } |
5975999e | 39 | agent_join($csnick, main_conf_diag); |
2eef9154 | 40 | ircd::setmode($csUser, main_conf_diag, '+o', $csUser); |
5975999e | 41 | |
42 | addhandler('NICKCONN', undef, undef, 'connectserv::ev_nickconn', 1); | |
43 | sub ev_nickconn { | |
44 | my ($nick, $ident, $host, $server, $gecos) = @_[0,3,4,5,9]; | |
45 | ||
46 | $userlist{lc $nick} = [$ident, $host, $gecos, $server]; | |
47 | ||
48 | return unless initial_synced(); | |
49 | message("\00304\002SIGNED ON\002 user: \002$nick\002 ($ident\@$host - $gecos\017\00304) at $server"); | |
50 | } | |
51 | ||
52 | addhandler('NICKCHANGE', undef, undef, 'connectserv::ev_nickchange', 1); | |
53 | sub ev_nickchange { | |
54 | my ($old, $new) = @_; | |
55 | my ($ident, $host); | |
56 | unless(lc($new) eq lc($old)) { | |
57 | $userlist{lc $new} = $userlist{lc $old}; | |
58 | delete($userlist{lc $old}); | |
59 | } | |
60 | ($ident, $host) = @{$userlist{lc $new}} if (defined($userlist{lc $new})); | |
61 | message("\00307\002NICK CHANGE\002 user: \002$old\002 ($ident\@$host) changed their nick to \002$new\002"); | |
62 | } | |
63 | ||
64 | addhandler('CHGIDENT', undef, undef, 'connectserv::ev_identchange', 1); | |
65 | sub ev_identchange { | |
66 | my (undef, $nick, $ident) = @_; | |
67 | ||
68 | my ($oldident, $host, $gecos, $server) = @{$userlist{lc $nick}} if (defined($userlist{lc $nick})); | |
69 | $userlist{lc $nick} = [$ident, $host, $gecos, $server]; | |
70 | ||
71 | message("\00310\002IDENT CHANGE\002 user: \002$nick\002 ($oldident\@$host) changed their virtual ident to \002$ident\002"); | |
72 | } | |
73 | ||
74 | addhandler('QUIT', undef, undef, 'connectserv::ev_quit', 1); | |
75 | sub ev_quit { | |
76 | my ($nick, $reason) = @_; | |
77 | my ($ident, $host, $gecos, $server); | |
78 | if(defined($userlist{lc $nick})) { | |
79 | ($ident, $host, $gecos, $server) = @{$userlist{lc $nick}}; | |
80 | delete($userlist{lc $nick}); | |
81 | } | |
82 | return unless initial_synced(); | |
83 | message("\00303\002SIGNED OFF\002 user: \002$nick\002 ($ident\@$host - $gecos\017\00303) at $server - $reason"); | |
84 | } | |
85 | ||
86 | addhandler('KILL', undef, undef, 'connectserv::ev_kill', 1); | |
87 | sub ev_kill { | |
88 | my ($src, $target, $reason) = @_[0,1,3]; | |
89 | my ($ident, $host, $gecos, $server); | |
90 | if(defined($userlist{lc $target})) { | |
91 | ($ident, $host, $gecos, $server) = @{$userlist{lc $target}}; | |
92 | delete($userlist{lc $target}); | |
93 | } | |
94 | message("\00302\002GLOBAL KILL\002 user: \002$target\002 ($ident\@$host) killed by \002$src\002 - $reason"); | |
95 | } | |
96 | ||
97 | addhandler('UMODE', undef, undef, 'connectserv::ev_umode', 1); | |
98 | sub ev_umode { | |
99 | my ($nick, $modes) = @_; | |
100 | my @modes = split(//, $modes); | |
101 | my $sign; | |
102 | foreach my $m (@modes) { | |
103 | $sign = 1 if $m eq '+'; | |
104 | $sign = 0 if $m eq '-'; | |
105 | ||
106 | my $label; | |
107 | $label = 'Global Operator' if $m eq 'o'; | |
108 | $label = 'Services Administrator' if $m eq 'a'; | |
109 | $label = 'Server Administrator' if $m eq 'A'; | |
110 | $label = 'Network Administrator' if $m eq 'N'; | |
111 | $label = 'Co Administrator' if $m eq 'C'; | |
112 | $label = 'Bot' if $m eq 'B'; | |
113 | ||
114 | if($label) { | |
115 | message("\00306\002$nick\002 is ".($sign ? 'now' : 'no longer')." a \002$label\002 (".($sign ? '+' : '-')."$m)"); | |
116 | } | |
117 | } | |
118 | } | |
119 | ||
120 | sub message(@) { | |
121 | ircd::privmsg($csnick, main_conf_diag, @_); | |
122 | write_log('diag', '<'.$csnick.'>', @_); | |
123 | } | |
124 | ||
125 | sub init { } | |
126 | sub begin { } | |
127 | sub end { } | |
128 | sub unload { } | |
129 | ||
130 | 1; |