/************************************************************************
 * IRC - Internet Relay Chat, modules/m_ircops.c
 *
 *   Copyright (C) 2000-2003 TR-IRCD Development
 *
 *   Copyright (C) 1990 Jarkko Oikarinen and
 *                      University of Oulu, Co Center
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "struct.h"
#include "numeric.h"
#include "sys.h"
#include "msg.h"
#include "h.h"
#include "s_conf.h"

static struct Message _msgtab[] = {
    {MSG_IRCOPS, 0, MAXPARA, M_SLOW, 0L,
     m_unregistered, m_ircops, m_ircops, m_ignore, m_ignore}
};

#ifndef STATIC_MODULES

char *_version = "$Revision: 1.3 $";

void _modinit(void)
{
    mod_add_cmd(_msgtab);
}

void _moddeinit(void)
{
    mod_del_cmd(_msgtab);
}
#else
void m_ircops_init(void)
{
    mod_add_cmd(_msgtab);
}
#endif

int m_ircops(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
    aClient *acptr;
    char buf[BUFSIZE];
    int opers = 0, admins = 0, globs = 0, aways = 0;

    for (acptr = GlobalClientList; acptr; acptr = acptr->next) {
	if (!IsULine(acptr) && IsAnOper(acptr)) {
	    if (!acptr->user)
		continue;
	    if (IsServer(acptr) || IsMe(acptr))
		continue;
	    sendto_one(sptr,
		       ":%C %N %s :\2%s\2 is %s %s (%s) %s",
		       &me, RPL_IRCOPS, sptr->name,
		       acptr->name ? acptr->name : "<unknown>",
		       ServerInfo.networkname,
		       IsAdmin(acptr) ? "Server Administrator" :
		       "Operator", acptr->info, acptr->user->away ? "- (Away)" : "");

	    if (!acptr->user->away) {
		if (IsAdmin(acptr))
		    admins++;
		else
		    opers++;
	    } else {
		aways++;
	    }
	}
    }
    globs = opers + admins + aways;
    sprintf(buf,
	    "Total: \2%d\2 IRCOP%s online - \2%d\2 Admin%s, \2%d\2 Oper%s and \2%d\2 Away",
	    globs, (globs) > 1 ? "s" : "", admins, admins > 1 ? "s" : "",
	    opers, opers > 1 ? "s" : "", aways);

    sendto_one(sptr, ":%C %N %s :%s", &me, RPL_IRCOPS, sptr->name, buf);
    send_me_numeric(sptr, RPL_ENDOFIRCOPS);
    return 0;
}


syntax highlighted by Code2HTML, v. 0.9.1