From 4b9e52eb4d5b1bd417ab10f7bdbd14b856921706 Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Thu, 2 Aug 2007 10:14:26 +0000 Subject: [PATCH] implement /WALLOPS as described in RFC 2812, section 4.7. --- src/ngircd/defines.h | 4 ++-- src/ngircd/irc-mode.c | 3 ++- src/ngircd/irc-oper.c | 52 ++++++++++++++++++++++++++++++++++++++++++- src/ngircd/irc-oper.h | 3 ++- src/ngircd/parse.c | 3 ++- 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/ngircd/defines.h b/src/ngircd/defines.h index b686f883..251a6997 100644 --- a/src/ngircd/defines.h +++ b/src/ngircd/defines.h @@ -8,7 +8,7 @@ * (at your option) any later version. * Please read the file COPYING, README and AUTHORS for more information. * - * $Id: defines.h,v 1.60 2007/05/17 23:34:25 alex Exp $ + * $Id: defines.h,v 1.61 2007/08/02 10:14:26 fw Exp $ */ @@ -54,7 +54,7 @@ see RFC 2812, section 1.2.1 */ #define CLIENT_NAME_LEN 32 /* Max. length of "real names" */ #define CLIENT_HOST_LEN 64 /* Max. host name length */ -#define CLIENT_MODE_LEN 8 /* Max. lenth of all client modes */ +#define CLIENT_MODE_LEN 9 /* Max. lenth of all client modes */ #define CLIENT_INFO_LEN 64 /* Max. length of server info texts */ #define CLIENT_AWAY_LEN 128 /* Max. length of away messages */ #define CLIENT_FLAGS_LEN 100 /* Max. length of client flags */ diff --git a/src/ngircd/irc-mode.c b/src/ngircd/irc-mode.c index 75f99d9e..4a6127ad 100644 --- a/src/ngircd/irc-mode.c +++ b/src/ngircd/irc-mode.c @@ -14,7 +14,7 @@ #include "portab.h" -static char UNUSED id[] = "$Id: irc-mode.c,v 1.48 2006/12/07 17:57:20 fw Exp $"; +static char UNUSED id[] = "$Id: irc-mode.c,v 1.49 2007/08/02 10:14:26 fw Exp $"; #include "imp.h" #include @@ -164,6 +164,7 @@ Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target ) { case 'i': /* Invisible */ case 's': /* Server messages */ + case 'w': /* Wallops messages */ x[0] = *mode_ptr; break; diff --git a/src/ngircd/irc-oper.c b/src/ngircd/irc-oper.c index c80b8b05..c9286d70 100644 --- a/src/ngircd/irc-oper.c +++ b/src/ngircd/irc-oper.c @@ -14,7 +14,7 @@ #include "portab.h" -static char UNUSED id[] = "$Id: irc-oper.c,v 1.28 2007/06/28 05:15:18 fw Exp $"; +static char UNUSED id[] = "$Id: irc-oper.c,v 1.29 2007/08/02 10:14:26 fw Exp $"; #include "imp.h" #include @@ -263,4 +263,54 @@ IRC_DISCONNECT(CLIENT *Client, REQUEST *Req ) } /* IRC_CONNECT */ +GLOBAL bool +IRC_WALLOPS( CLIENT *Client, REQUEST *Req ) +{ + CLIENT *to, *from; + int client_type; + + assert( Client != NULL ); + assert( Req != NULL ); + + if (Req->argc != 1) + return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, Client_ID(Client), Req->command); + + client_type = Client_Type(Client); + switch (client_type) { + case CLIENT_USER: + if (!Client_OperByMe(Client)) + return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG, Client_ID(Client)); + from = Client; + break; + case CLIENT_SERVER: + from = Client_Search(Req->prefix); + break; + default: + return CONNECTED; + } + + if (!from) + return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, Client_ID(Client), Req->prefix); + + for (to=Client_First(); to != NULL; to=Client_Next(to)) { + if (Client_Conn(to) < 0) /* no local connection or WALLOPS origin */ + continue; + + client_type = Client_Type(to); + switch (client_type) { + case CLIENT_USER: + if (Client_HasMode(to, 'w')) + IRC_WriteStrClientPrefix(to, from, "WALLOPS :%s", Req->argv[0]); + break; + case CLIENT_SERVER: + if (to != Client) + IRC_WriteStrClientPrefix(to, from, "WALLOPS :%s", Req->argv[0]); + break; + } + } + return CONNECTED; +} + + + /* -eof- */ diff --git a/src/ngircd/irc-oper.h b/src/ngircd/irc-oper.h index dd2faa24..8b867c45 100644 --- a/src/ngircd/irc-oper.h +++ b/src/ngircd/irc-oper.h @@ -8,7 +8,7 @@ * (at your option) any later version. * Please read the file COPYING, README and AUTHORS for more information. * - * $Id: irc-oper.h,v 1.11 2005/03/19 18:43:48 fw Exp $ + * $Id: irc-oper.h,v 1.12 2007/08/02 10:14:26 fw Exp $ * * IRC operator commands (header) */ @@ -24,6 +24,7 @@ GLOBAL bool IRC_REHASH PARAMS((CLIENT *Client, REQUEST *Req )); GLOBAL bool IRC_RESTART PARAMS((CLIENT *Client, REQUEST *Req )); GLOBAL bool IRC_CONNECT PARAMS((CLIENT *Client, REQUEST *Req )); GLOBAL bool IRC_DISCONNECT PARAMS((CLIENT *Client, REQUEST *Req )); +GLOBAL bool IRC_WALLOPS PARAMS(( CLIENT *Client, REQUEST *Req )); #endif diff --git a/src/ngircd/parse.c b/src/ngircd/parse.c index 548c3729..b5e64a33 100644 --- a/src/ngircd/parse.c +++ b/src/ngircd/parse.c @@ -12,7 +12,7 @@ #include "portab.h" -static char UNUSED id[] = "$Id: parse.c,v 1.67 2006/04/23 10:37:27 fw Exp $"; +static char UNUSED id[] = "$Id: parse.c,v 1.68 2007/08/02 10:14:26 fw Exp $"; /** * @file @@ -93,6 +93,7 @@ COMMAND My_Commands[] = { "USER", IRC_USER, 0xFFFF, 0, 0, 0 }, { "USERHOST", IRC_USERHOST, CLIENT_USER, 0, 0, 0 }, { "VERSION", IRC_VERSION, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 }, + { "WALLOPS", IRC_WALLOPS, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 }, { "WHO", IRC_WHO, CLIENT_USER, 0, 0, 0 }, { "WHOIS", IRC_WHOIS, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 }, { "WHOWAS", IRC_WHOWAS, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 }, -- 2.39.2