unrealircd

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

wallops.c (2993B)

      1 /*
      2  *   IRC - Internet Relay Chat, src/modules/usermodes/wallops.c
      3  *   (C) 2004-2021 The UnrealIRCd Team
      4  *
      5  *   See file AUTHORS in IRC package for additional names of
      6  *   the programmers.
      7  *
      8  *   This program is free software; you can redistribute it and/or modify
      9  *   it under the terms of the GNU General Public License as published by
     10  *   the Free Software Foundation; either version 1, or (at your option)
     11  *   any later version.
     12  *
     13  *   This program is distributed in the hope that it will be useful,
     14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16  *   GNU General Public License for more details.
     17  *
     18  *   You should have received a copy of the GNU General Public License
     19  *   along with this program; if not, write to the Free Software
     20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     21  */
     22 
     23 #include "unrealircd.h"
     24 
     25 CMD_FUNC(cmd_wallops);
     26 
     27 #define MSG_WALLOPS 	"WALLOPS"	
     28 
     29 ModuleHeader MOD_HEADER
     30   = {
     31 	"usermodes/wallops",
     32 	"5.0",
     33 	"command /wallops", 
     34 	"UnrealIRCd Team",
     35 	"unrealircd-6",
     36     };
     37 
     38 long UMODE_WALLOP = 0L;        /* send wallops to them */
     39 
     40 MOD_INIT()
     41 {
     42 	MARK_AS_OFFICIAL_MODULE(modinfo);
     43 	CommandAdd(modinfo->handle, MSG_WALLOPS, cmd_wallops, 1, CMD_USER|CMD_SERVER);
     44 	UmodeAdd(modinfo->handle, 'w', UMODE_GLOBAL, 0, umode_allow_all, &UMODE_WALLOP);
     45 	return MOD_SUCCESS;
     46 }
     47 
     48 MOD_LOAD()
     49 {
     50 	return MOD_SUCCESS;
     51 }
     52 
     53 MOD_UNLOAD()
     54 {
     55 	return MOD_SUCCESS;
     56 }
     57 
     58 #define SendWallops(x)          (!IsMe(x) && IsUser(x) && ((x)->umodes & UMODE_WALLOP))
     59 
     60 /** Send a message to all wallops, except one.
     61  * @param one		Skip sending the message to this client/direction
     62  * @param from		The sender (can not be NULL)
     63  * @param pattern	The format string / pattern to use.
     64  * @param ...		Format string parameters.
     65  */
     66 void sendto_wallops(Client *one, Client *from, FORMAT_STRING(const char *pattern), ...)
     67 {
     68 	va_list vl;
     69 	Client *acptr;
     70 
     71 	++current_serial;
     72 	list_for_each_entry(acptr, &client_list, client_node)
     73 	{
     74 		if (!SendWallops(acptr))
     75 			continue;
     76 		if (acptr->direction->local->serial == current_serial)	/* sent message along it already ? */
     77 			continue;
     78 		if (acptr->direction == one)
     79 			continue;	/* ...was the one I should skip */
     80 		acptr->direction->local->serial = current_serial;
     81 
     82 		va_start(vl, pattern);
     83 		vsendto_prefix_one(acptr->direction, from, NULL, pattern, vl);
     84 		va_end(vl);
     85 	}
     86 }
     87 
     88 /*
     89 ** cmd_wallops (write to *all* opers currently online)
     90 **	parv[1] = message text
     91 */
     92 CMD_FUNC(cmd_wallops)
     93 {
     94 	const char *message = parc > 1 ? parv[1] : NULL;
     95 
     96 	if (BadPtr(message))
     97 	{
     98 		sendnumeric(client, ERR_NEEDMOREPARAMS, "WALLOPS");
     99 		return;
    100 	}
    101 
    102 	if (!ValidatePermissionsForPath("chat:wallops",client,NULL,NULL,NULL))
    103 	{
    104 		sendnumeric(client, ERR_NOPRIVILEGES);
    105 		return;
    106 	}
    107 
    108 	sendto_wallops(client->direction, client, ":%s WALLOPS :%s", client->name, message);
    109 	if (MyUser(client))
    110 		sendto_prefix_one(client, client, NULL, ":%s WALLOPS :%s", client->name, message);
    111 }