| 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: m_testmask.c,v 1.4 2005/07/16 12:19:44 michael Exp $ |
| 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: 1.4 $"; |
| 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 |
char *given_host; |
| 89 |
char *given_user = parv[1]; |
| 90 |
int local_count = 0, remote_count = 0; |
| 91 |
dlink_node *ptr, *next_ptr; |
| 92 |
struct Client *target_p; |
| 93 |
|
| 94 |
if (parc < 2 || ((given_host = strchr(given_user, '@')) == NULL)) |
| 95 |
{ |
| 96 |
sendto_one(source_p, ":%s NOTICE %s :usage: user@host", |
| 97 |
me.name, source_p->name); |
| 98 |
return; |
| 99 |
} |
| 100 |
|
| 101 |
*given_host++ = '\0'; |
| 102 |
|
| 103 |
DLINK_FOREACH_SAFE(ptr, next_ptr, global_client_list.head) |
| 104 |
{ |
| 105 |
target_p = ptr->data; |
| 106 |
|
| 107 |
if (IsDead(target_p) || !IsClient(target_p)) |
| 108 |
continue; |
| 109 |
|
| 110 |
if (match(given_user, target_p->username) && |
| 111 |
match(given_host, target_p->host)) |
| 112 |
{ |
| 113 |
if (MyConnect(target_p)) |
| 114 |
local_count++; |
| 115 |
else |
| 116 |
remote_count++; |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
sendto_one(source_p, form_str(RPL_TESTMASK), me.name, source_p->name, |
| 121 |
given_user, given_host, local_count, remote_count); |
| 122 |
} |