/************************************************************************
 *   IRC - Internet Relay Chat, modules/m_servset.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 "common.h"
#include "sys.h"
#include "numeric.h"
#include "msg.h"
#include "channel.h"
#include "h.h"

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

#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_servset_init(void)
{
    mod_add_cmd(_msgtab);
}
#endif

/*
 * sets the modes for the service, respecting the defines
 * about what the service is going to be able to see.
 * -TimeMr14C
 *      parv[0] = sender prefix
 *      parv[1] = service name
 *      parv[2] = +/-modes
 */

int m_servset(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
    int flag;
    int *s;
    char *m;
    aClient *acptr;
    int what = 0;

    if (parc < 3) {
	send_me_numeric(sptr, ERR_NEEDMOREPARAMS, MSG_SERVSET);
	return 0;
    }

    if ((acptr = find_client(parv[1])) == NULL) {
	sendto_lev(SERVICE_LEV, "Received SERVSET for non existant service %s", parv[1]);
	return 0;
    }

    for (m = parv[2]; *m; m++) {
	switch (*m) {
	    case '+':
		what = CMODE_ADD;
		break;
	    case '-':
		what = CMODE_DEL;
		break;
	    case ' ':
	    case '\r':
	    case '\n':
	    case '\t':
		break;
	    default:
		for (s = service_modes; (flag = *s); s += 2) {
		    if (*m == (char) (*(s + 1))) {
			if (what == CMODE_ADD)
			    acptr->service->enable |= flag;
			else
			    acptr->service->enable &= ~flag;
		    }
		}
		break;
	}
    }

    sendto_one(acptr, ":%C %d %s +%s", &me, RPL_UMODEIS, parv[0],
		   service_modes_to_char(acptr->service));

    return 0;
}


syntax highlighted by Code2HTML, v. 0.9.1