#include "client.h"
#include "ircd.h"
#include "numeric.h"
-#include "common.h"
#include "s_conf.h"
#include "s_serv.h"
#include "msg.h"
#include "tgchange.h"
#include "inline/stringops.h"
-static int m_message(enum message_type, struct MsgBuf *, struct Client *, struct Client *, int, const char **);
-static int m_privmsg(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
-static int m_notice(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static const char message_desc[] =
+ "Provides the PRIVMSG and NOTICE commands to send messages to users and channels";
+
+static void m_message(enum message_type, struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void m_privmsg(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void m_notice(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void m_echo(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+
+static void echo_msg(struct Client *, struct Client *, enum message_type, const char *);
static void expire_tgchange(void *unused);
static struct ev_entry *expire_tgchange_event;
"NOTICE", 0, 0, 0, 0,
{mg_unreg, {m_notice, 0}, {m_notice, 0}, {m_notice, 0}, mg_ignore, {m_notice, 0}}
};
+struct Message echo_msgtab = {
+ "ECHO", 0, 0, 0, 0,
+ {mg_unreg, mg_ignore, {m_echo, 3}, mg_ignore, mg_ignore, mg_ignore}
+};
-mapi_clist_av1 message_clist[] = { &privmsg_msgtab, ¬ice_msgtab, NULL };
+mapi_clist_av1 message_clist[] = { &privmsg_msgtab, ¬ice_msgtab, &echo_msgtab, NULL };
-DECLARE_MODULE_AV2(message, modinit, moddeinit, message_clist, NULL, NULL, NULL, NULL, NULL);
+DECLARE_MODULE_AV2(message, modinit, moddeinit, message_clist, NULL, NULL, NULL, NULL, message_desc);
struct entity
{
struct Client *client_p,
struct Client *source_p, const char *nicks_channels, const char *text);
-static int flood_attack_client(enum message_type msgtype, struct Client *source_p, struct Client *target_p);
+static bool flood_attack_client(enum message_type msgtype, struct Client *source_p, struct Client *target_p);
/* Fifteen seconds should be plenty for a client to reply a ctcp */
#define LARGE_CTCP_TIME 15
static struct entity targets[512];
static int ntargets = 0;
-static int duplicate_ptr(void *);
+static bool duplicate_ptr(void *);
static void msg_channel(enum message_type msgtype,
struct Client *client_p,
[MESSAGE_TYPE_NOTICE] = "NOTICE",
};
-static int
+static void
m_privmsg(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{
- return m_message(MESSAGE_TYPE_PRIVMSG, msgbuf_p, client_p, source_p, parc, parv);
+ m_message(MESSAGE_TYPE_PRIVMSG, msgbuf_p, client_p, source_p, parc, parv);
}
-static int
+static void
m_notice(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{
- return m_message(MESSAGE_TYPE_NOTICE, msgbuf_p, client_p, source_p, parc, parv);
+ m_message(MESSAGE_TYPE_NOTICE, msgbuf_p, client_p, source_p, parc, parv);
}
/*
* - pointer to source_p
* - pointer to channel
*/
-static int
+static void
m_message(enum message_type msgtype, struct MsgBuf *msgbuf_p,
struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{
if(msgtype != MESSAGE_TYPE_NOTICE)
sendto_one(source_p, form_str(ERR_NORECIPIENT), me.name,
source_p->name, cmdname[msgtype]);
- return 0;
+ return;
}
if(parc < 3 || EmptyString(parv[2]))
{
if(msgtype != MESSAGE_TYPE_NOTICE)
sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name);
- return 0;
+ return;
}
/* Finish the flood grace period if theyre not messaging themselves
if(build_target_list(msgtype, client_p, source_p, parv[1], parv[2]) < 0)
{
- return 0;
+ return;
}
for(i = 0; i < ntargets; i++)
break;
}
}
+}
- return 0;
+static void
+m_echo(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
+ int parc, const char *parv[])
+{
+ struct Client *target_p = find_person(parv[2]);
+ enum message_type msgtype;
+
+ if (target_p == NULL)
+ return;
+
+ switch (parv[1][0])
+ {
+ case 'P': msgtype = MESSAGE_TYPE_PRIVMSG; break;
+ case 'N': msgtype = MESSAGE_TYPE_NOTICE; break;
+ default: return;
+ }
+
+ echo_msg(source_p, target_p, msgtype, parv[3]);
}
/*
* inputs - pointer to check
* - pointer to table of entities
* - number of valid entities so far
- * output - YES if duplicate pointer in table, NO if not.
+ * output - true if duplicate pointer in table, false if not.
* note, this does the canonize using pointers
* side effects - NONE
*/
-static int
+static bool
duplicate_ptr(void *ptr)
{
int i;
for(i = 0; i < ntargets; i++)
if(targets[i].ptr == ptr)
- return YES;
- return NO;
+ return true;
+ return false;
}
/*
if((result = can_send(chptr, source_p, NULL)))
{
if(result != CAN_SEND_OPV && MyClient(source_p) &&
- !IsOper(source_p) &&
+ !IsOperGeneral(source_p) &&
!add_channel_target(source_p, chptr))
{
sendto_one(source_p, form_str(ERR_TARGCHANGE),
(!(chptr->mode.mode & MODE_NOPRIVMSGS) ||
IsMember(source_p, chptr)))
{
- if(MyClient(source_p) && !IsOper(source_p) &&
+ if(MyClient(source_p) && !IsOperGeneral(source_p) &&
!add_channel_target(source_p, chptr))
{
sendto_one(source_p, form_str(ERR_TARGCHANGE),
}
}
+static void
+echo_msg(struct Client *source_p, struct Client *target_p,
+ enum message_type msgtype, const char *text)
+{
+ if (MyClient(target_p))
+ {
+ if (!IsCapable(target_p, CLICAP_ECHO_MESSAGE))
+ return;
+
+ sendto_one(target_p, ":%s!%s@%s %s %s :%s",
+ target_p->name, target_p->username, target_p->host,
+ cmdname[msgtype],
+ source_p->name,
+ text);
+ return;
+ }
+
+ sendto_one(target_p, ":%s ECHO %c %s :%s",
+ use_id(source_p),
+ msgtype == MESSAGE_TYPE_PRIVMSG ? 'P' : 'N',
+ use_id(target_p),
+ text);
+}
+
/*
* msg_client
*
if(MyClient(source_p))
{
- /*
- * XXX: Controversial? Allow target users to send replies
- * through a +g. Rationale is that people can presently use +g
- * as a way to taunt users, e.g. harass them and hide behind +g
- * as a way of griefing. --nenolod
- */
- if(msgtype != MESSAGE_TYPE_NOTICE &&
- (IsSetCallerId(source_p) ||
- (IsSetRegOnlyMsg(source_p) && !target_p->user->suser[0])) &&
- !accept_message(target_p, source_p) &&
- !IsOper(target_p))
- {
- if(rb_dlink_list_length(&source_p->localClient->allow_list) <
- (unsigned long)ConfigFileEntry.max_accept)
- {
- rb_dlinkAddAlloc(target_p, &source_p->localClient->allow_list);
- rb_dlinkAddAlloc(source_p, &target_p->on_allow_list);
- }
- else
- {
- sendto_one_numeric(source_p, ERR_OWNMODE,
- form_str(ERR_OWNMODE),
- target_p->name, "+g");
- return;
- }
- }
-
/* reset idle time for message only if its not to self
* and its not a notice */
if(msgtype != MESSAGE_TYPE_NOTICE)
source_p->localClient->last = rb_current_time();
/* auto cprivmsg/cnotice */
- do_floodcount = !IsOper(source_p) &&
+ do_floodcount = !IsOperGeneral(source_p) &&
!find_allowing_channel(source_p, target_p);
/* target change stuff, dont limit ctcp replies as that
sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY),
target_p->name, target_p->user->away);
- if(MyClient(target_p))
- {
- hdata.msgtype = msgtype;
- hdata.source_p = source_p;
- hdata.target_p = target_p;
- hdata.text = text;
- hdata.approved = 0;
+ hdata.msgtype = msgtype;
+ hdata.source_p = source_p;
+ hdata.target_p = target_p;
+ hdata.text = text;
+ hdata.approved = 0;
- call_hook(h_privmsg_user, &hdata);
+ call_hook(h_privmsg_user, &hdata);
- /* buffer location may have changed. */
- text = hdata.text;
+ /* buffer location may have changed. */
+ text = hdata.text;
- if (hdata.approved != 0)
- return;
+ if (hdata.approved != 0)
+ return;
+ if(MyClient(target_p))
+ {
if (EmptyString(text))
{
/* could be empty after colour stripping and
return;
}
- /* XXX Controversial? allow opers always to send through a +g */
- if(!IsServer(source_p) && (IsSetCallerId(target_p) ||
- (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0])))
- {
- /* Here is the anti-flood bot/spambot code -db */
- if(accept_message(source_p, target_p) || IsOper(source_p))
- {
- add_reply_target(target_p, source_p);
- sendto_one(target_p, ":%s!%s@%s %s %s :%s",
- source_p->name,
- source_p->username,
- source_p->host, cmdname[msgtype], target_p->name, text);
- }
- else if (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0])
- {
- if (msgtype != MESSAGE_TYPE_NOTICE)
- sendto_one_numeric(source_p, ERR_NONONREG,
- form_str(ERR_NONONREG),
- target_p->name);
- }
- else
- {
- /* check for accept, flag recipient incoming message */
- if(msgtype != MESSAGE_TYPE_NOTICE)
- {
- sendto_one_numeric(source_p, ERR_TARGUMODEG,
- form_str(ERR_TARGUMODEG),
- target_p->name);
- }
-
- if((target_p->localClient->last_caller_id_time +
- ConfigFileEntry.caller_id_wait) < rb_current_time())
- {
- if(msgtype != MESSAGE_TYPE_NOTICE)
- sendto_one_numeric(source_p, RPL_TARGNOTIFY,
- form_str(RPL_TARGNOTIFY),
- target_p->name);
-
- add_reply_target(target_p, source_p);
- sendto_one(target_p, form_str(RPL_UMODEGMSG),
- me.name, target_p->name, source_p->name,
- source_p->username, source_p->host);
-
- target_p->localClient->last_caller_id_time = rb_current_time();
- }
- }
- }
- else
- {
- add_reply_target(target_p, source_p);
- sendto_anywhere(target_p, source_p, cmdname[msgtype], ":%s", text);
- }
+ add_reply_target(target_p, source_p);
+ sendto_anywhere(target_p, source_p, cmdname[msgtype], ":%s", text);
+ echo_msg(target_p, source_p, msgtype, text);
}
else
sendto_anywhere(target_p, source_p, cmdname[msgtype], ":%s", text);
/*
* flood_attack_client
* inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
- * say NOTICE must not auto reply
+ * says NOTICE must not auto reply
* - pointer to source Client
* - pointer to target Client
- * output - 1 if target is under flood attack
+ * output - true if target is under flood attack
* side effects - check for flood attack on target target_p
*/
-static int
+static bool
flood_attack_client(enum message_type msgtype, struct Client *source_p, struct Client *target_p)
{
int delta;
sendto_one(source_p,
":%s NOTICE %s :*** Message to %s throttled due to flooding",
me.name, source_p->name, target_p->name);
- return 1;
+ return true;
}
else
target_p->received_number_of_privmsgs++;
}
- return 0;
+ return false;
}
/*
{
struct Client *target_p;
char *server;
- char *s;
/* user[%host]@server addressed?
* NOTE: users can send to user@server, but not user%host@server
return;
}
- if((s = strrchr(nick, '.')) == NULL)
- {
- sendto_one_numeric(source_p, ERR_NOTOPLEVEL,
- form_str(ERR_NOTOPLEVEL), nick);
- return;
- }
- while(*++s)
- if(*s == '.' || *s == '*' || *s == '?')
- break;
- if(*s == '*' || *s == '?')
+ if(MyClient(source_p))
{
- sendto_one_numeric(source_p, ERR_WILDTOPLEVEL,
- form_str(ERR_WILDTOPLEVEL), nick);
- return;
+ sendto_realops_snomask(SNO_GENERAL, L_ALL | L_NETWIDE, "%s sent mass-%s to %s: %s",
+ get_oper_name(source_p),
+ msgtype == MESSAGE_TYPE_PRIVMSG ? "privmsg" : "notice",
+ nick, text);
}
sendto_match_butone(IsServer(client_p) ? client_p : NULL, source_p,