1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_testmask.c: Counts the birdies err local and remote clients. |
4 |
* |
5 |
* Copyright (C) 2005 by Diane Bruce |
6 |
* Coypright (C) 2005 ircd-hybrid team |
7 |
* |
8 |
* Redistribution and use in source and binary forms, with or without |
9 |
* modification, are permitted provided that the following conditions are |
10 |
* met: |
11 |
* |
12 |
* 1.Redistributions of source code must retain the above copyright notice, |
13 |
* this list of conditions and the following disclaimer. |
14 |
* 2.Redistributions in binary form must reproduce the above copyright |
15 |
* notice, this list of conditions and the following disclaimer in the |
16 |
* documentation and/or other materials provided with the distribution. |
17 |
* 3.The name of the author may not be used to endorse or promote products |
18 |
* derived from this software without specific prior written permission. |
19 |
* |
20 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
21 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
22 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
23 |
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
24 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
25 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
26 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
27 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
28 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
29 |
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
30 |
* POSSIBILITY OF SUCH DAMAGE. |
31 |
* |
32 |
* $Id$ |
33 |
*/ |
34 |
|
35 |
#include "stdinc.h" |
36 |
#include "handlers.h" |
37 |
#include "client.h" |
38 |
#include "common.h" |
39 |
#include "irc_string.h" |
40 |
#include "ircd_defs.h" |
41 |
#include "ircd.h" |
42 |
#include "restart.h" |
43 |
#include "s_conf.h" |
44 |
#include "send.h" |
45 |
#include "msg.h" |
46 |
#include "hostmask.h" |
47 |
#include "numeric.h" |
48 |
#include "parse.h" |
49 |
#include "modules.h" |
50 |
|
51 |
static void mo_testmask(struct Client *, struct Client *, int, char *[]); |
52 |
|
53 |
struct Message testmask_msgtab = { |
54 |
"TESTMASK", 0, 0, 0, 0, MFLG_SLOW, 0, |
55 |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_testmask, m_ignore} |
56 |
}; |
57 |
|
58 |
#ifndef STATIC_MODULES |
59 |
void |
60 |
_modinit(void) |
61 |
{ |
62 |
mod_add_cmd(&testmask_msgtab); |
63 |
} |
64 |
|
65 |
void |
66 |
_moddeinit(void) |
67 |
{ |
68 |
mod_del_cmd(&testmask_msgtab); |
69 |
} |
70 |
|
71 |
const char *_version = "$Revision$"; |
72 |
#endif |
73 |
|
74 |
/* mo_testmask() |
75 |
* |
76 |
* inputs - pointer to physical connection request is coming from |
77 |
* - pointer to source connection request is coming from |
78 |
* - parc arg count |
79 |
* - parv actual arguments |
80 |
* output - NONE |
81 |
* side effects - count up clients matching mask |
82 |
* i.e. /quote testmask user@host |
83 |
*/ |
84 |
static void |
85 |
mo_testmask(struct Client *client_p, struct Client *source_p, |
86 |
int parc, char *parv[]) |
87 |
{ |
88 |
struct split_nuh_item nuh; |
89 |
char given_nick[IRCD_BUFSIZE]; |
90 |
char given_user[IRCD_BUFSIZE]; |
91 |
char given_host[IRCD_BUFSIZE]; |
92 |
unsigned int count[2] = { 0, 0 }; |
93 |
const dlink_node *ptr = NULL; |
94 |
|
95 |
if (EmptyString(parv[1])) |
96 |
{ |
97 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
98 |
me.name, source_p->name, "TESTMASK"); |
99 |
return; |
100 |
} |
101 |
|
102 |
nuh.nuhmask = parv[1]; |
103 |
nuh.nickptr = given_nick; |
104 |
nuh.userptr = given_user; |
105 |
nuh.hostptr = given_host; |
106 |
|
107 |
nuh.nicksize = sizeof(given_nick); |
108 |
nuh.usersize = sizeof(given_user); |
109 |
nuh.hostsize = sizeof(given_host); |
110 |
|
111 |
split_nuh(&nuh); |
112 |
|
113 |
DLINK_FOREACH(ptr, global_client_list.head) |
114 |
{ |
115 |
const struct Client *target_p = ptr->data; |
116 |
|
117 |
if (!IsClient(target_p) || !match(given_nick, target_p->name)) |
118 |
continue; |
119 |
|
120 |
if (match(given_user, target_p->username)) |
121 |
if (match(given_host, target_p->host) || match(given_host, target_p->sockhost)) |
122 |
++count[!MyConnect(target_p)]; |
123 |
} |
124 |
|
125 |
sendto_one(source_p, form_str(RPL_TESTMASK), me.name, |
126 |
source_p->name, |
127 |
given_nick, given_user, |
128 |
given_host, count[0], count[1]); |
129 |
} |