unrealircd

- supernets unrealircd source & configuration
git clone git://git.acid.vegas/unrealircd.git
Log | Files | Refs | Archive | README | LICENSE

ircops.c (3889B)

      1 /*
      2  *   cmd_ircops - /IRCOPS command that lists IRC Operators
      3  *   (C) Copyright 2004-2016 Syzop <syzop@vulnscan.org>
      4  *   (C) Copyright 2003-2004 AngryWolf <angrywolf@flashmail.com>
      5  *
      6  *   This program is free software; you can redistribute it and/or modify
      7  *   it under the terms of the GNU General Public License as published by
      8  *   the Free Software Foundation; either version 1, or (at your option)
      9  *   any later version.
     10  *
     11  *   This program is distributed in the hope that it will be useful,
     12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14  *   GNU General Public License for more details.
     15  *
     16  *   You should have received a copy of the GNU General Public License
     17  *   along with this program; if not, write to the Free Software
     18  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     19  */
     20 
     21 #include "unrealircd.h"
     22 
     23 #define MSG_IRCOPS        "IRCOPS"
     24 #define IsAway(x)         (x)->user->away
     25 
     26 CMD_FUNC(cmd_ircops);
     27 
     28 ModuleHeader MOD_HEADER
     29   = {
     30 	"ircops",
     31 	"3.71",
     32 	"/IRCOPS command that lists IRC Operators",
     33 	"UnrealIRCd Team",
     34 	"unrealircd-6",
     35     };
     36 
     37 MOD_INIT()
     38 {
     39 	MARK_AS_OFFICIAL_MODULE(modinfo);
     40 	if (CommandExists(MSG_IRCOPS))
     41 	{
     42 		config_error("Command " MSG_IRCOPS " already exists");
     43 		return MOD_FAILED;
     44 	}
     45 	CommandAdd(modinfo->handle, MSG_IRCOPS, cmd_ircops, MAXPARA, CMD_USER);
     46 
     47 	if (ModuleGetError(modinfo->handle) != MODERR_NOERROR)
     48 	{
     49 		config_error("Error adding command " MSG_IRCOPS ": %s",
     50 			ModuleGetErrorStr(modinfo->handle));
     51 		return MOD_FAILED;
     52 	}
     53 
     54 	return MOD_SUCCESS;
     55 }
     56 
     57 MOD_LOAD()
     58 {
     59 	return MOD_SUCCESS;
     60 }
     61 
     62 MOD_UNLOAD()
     63 {
     64 	return MOD_SUCCESS;
     65 }
     66 
     67 
     68 /*
     69  * cmd_ircops
     70  *
     71  *     parv[0]: sender prefix
     72  *
     73  *     Originally comes from TR-IRCD, but I changed it in several places.
     74  *     In addition, I didn't like to display network name. In addition,
     75  *     instead of realname, servername is shown. See the original
     76  *     header below.
     77  */
     78 
     79 /************************************************************************
     80  * IRC - Internet Relay Chat, modules/ircops.c
     81  *
     82  *   Copyright (C) 2000-2002 TR-IRCD Development
     83  *
     84  *   Copyright (C) 1990 Jarkko Oikarinen and
     85  *                      University of Oulu, Co Center
     86  *
     87  * This program is free software; you can redistribute it and/or modify
     88  * it under the terms of the GNU General Public License as published by
     89  * the Free Software Foundation; either version 2, or (at your option)
     90  * any later version.
     91  *
     92  * This program is distributed in the hope that it will be useful,
     93  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     94  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     95  * GNU General Public License for more details.
     96  *
     97  * You should have received a copy of the GNU General Public License
     98  * along with this program; if not, write to the Free Software
     99  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    100  */
    101 
    102 CMD_FUNC(cmd_ircops)
    103 {
    104 	Client *acptr;
    105 	char buf[512];
    106 	int opers = 0, total = 0, aways = 0;
    107 
    108 	list_for_each_entry(acptr, &client_list, client_node)
    109 	{
    110 		/* List only real IRC Operators */
    111 		if (IsULine(acptr) || !IsUser(acptr) || !IsOper(acptr))
    112 			continue;
    113 		/* Don't list +H users */
    114 		if (!IsOper(client) && IsHideOper(acptr))
    115 			continue;
    116 
    117 		sendto_one(client, NULL, ":%s %d %s :\2%s\2 is %s on %s" "%s",
    118 			me.name, RPL_TEXT, client->name,
    119 			acptr->name,
    120 			"an IRC Operator", /* find_otype(acptr->umodes), */
    121 			acptr->user->server,
    122 			(IsAway(acptr) ? " [Away]" : ""));
    123 
    124 		if (IsAway(acptr))
    125 			aways++;
    126 		else
    127 			opers++;
    128 
    129 	}
    130 
    131 	total = opers + aways;
    132 
    133 	snprintf(buf, sizeof(buf),
    134 		"Total: \2%d\2 IRCOP%s online - \2%d\2 Oper%s available and \2%d\2 Away",
    135 		total, (total) != 1 ? "s" : "",
    136 		opers, opers != 1 ? "s" : "",
    137 		aways);
    138 
    139 	sendnumericfmt(client, RPL_TEXT, ":%s", buf);
    140 	sendnumericfmt(client, RPL_TEXT, ":End of /IRCOPS list");
    141 }