2007-01-25 07:40:21 +01:00
|
|
|
/*
|
2007-12-02 16:34:45 +01:00
|
|
|
* charybdis: an advanced ircd.
|
2007-01-25 07:40:21 +01:00
|
|
|
* parse.c: The message parser.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
|
|
|
* Copyright (C) 2002-2005 ircd-ratbox development team
|
2016-02-10 07:22:37 +01:00
|
|
|
* Copyright (C) 2007-2016 William Pitcock
|
2007-01-25 07:40:21 +01:00
|
|
|
*
|
|
|
|
* 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 of the License, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
namespace ircd {
|
|
|
|
|
2016-07-31 08:57:04 +02:00
|
|
|
std::map<std::string, std::shared_ptr<alias_entry>, case_insensitive_less> alias_dict;
|
2016-07-31 08:36:14 +02:00
|
|
|
std::map<std::string, Message *, case_insensitive_less> cmd_dict;
|
2007-12-02 16:34:45 +01:00
|
|
|
|
2016-08-22 03:57:43 +02:00
|
|
|
static void cancel_clients(client::client *, client::client *);
|
|
|
|
static void remove_unknown(client::client *, const char *, char *);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-22 03:57:43 +02:00
|
|
|
static void do_numeric(int, client::client *, client::client *, int, const char **);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-22 03:57:43 +02:00
|
|
|
static int handle_command(struct Message *, struct MsgBuf *, client::client *, client::client *);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
static char buffer[1024];
|
|
|
|
|
|
|
|
/* turn a string into a parc/parv pair */
|
|
|
|
|
2016-01-12 05:28:55 +01:00
|
|
|
char *reconstruct_parv(int parc, const char *parv[])
|
|
|
|
{
|
|
|
|
static char tmpbuf[BUFSIZE]; int i;
|
|
|
|
|
|
|
|
rb_strlcpy(tmpbuf, parv[0], BUFSIZE);
|
|
|
|
for (i = 1; i < parc; i++)
|
|
|
|
{
|
|
|
|
rb_strlcat(tmpbuf, " ", BUFSIZE);
|
|
|
|
rb_strlcat(tmpbuf, parv[i], BUFSIZE);
|
|
|
|
}
|
|
|
|
return tmpbuf;
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* parse()
|
|
|
|
*
|
2010-10-25 04:02:32 +02:00
|
|
|
* given a raw buffer, parses it and generates parv and parc
|
2007-01-25 07:40:21 +01:00
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
parse(client::client *client_p, char *pbuffer, char *bufend)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *from = client_p;
|
2007-01-25 07:40:21 +01:00
|
|
|
char *end;
|
2016-03-22 02:52:40 +01:00
|
|
|
int res;
|
2016-02-10 07:22:37 +01:00
|
|
|
int numeric = 0;
|
2007-01-25 07:40:21 +01:00
|
|
|
struct Message *mptr;
|
2016-02-10 07:22:37 +01:00
|
|
|
struct MsgBuf msgbuf;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
s_assert(my_connect(*client_p));
|
2009-04-08 21:30:58 +02:00
|
|
|
s_assert(client_p->localClient->F != NULL);
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_any_dead(*client_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
2016-02-10 07:22:37 +01:00
|
|
|
end = bufend - 1;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-02-10 07:22:37 +01:00
|
|
|
/* XXX this should be done before parse() is called */
|
|
|
|
if(*end == '\n')
|
|
|
|
*end-- = '\0';
|
|
|
|
if(*end == '\r')
|
|
|
|
*end = '\0';
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-02-10 07:22:37 +01:00
|
|
|
res = msgbuf_parse(&msgbuf, pbuffer);
|
|
|
|
if (res)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-02-10 07:22:37 +01:00
|
|
|
ServerStats.is_empt++;
|
|
|
|
return;
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if (msgbuf.origin != NULL && is_server(*client_p))
|
2016-02-10 07:22:37 +01:00
|
|
|
{
|
|
|
|
from = find_client(msgbuf.origin);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-02-10 07:22:37 +01:00
|
|
|
/* didnt find any matching client, issue a kill */
|
|
|
|
if(from == NULL)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-02-10 07:22:37 +01:00
|
|
|
ServerStats.is_unpf++;
|
2016-02-10 17:25:16 +01:00
|
|
|
remove_unknown(client_p, msgbuf.origin, pbuffer);
|
2016-02-10 07:22:37 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-02-10 07:22:37 +01:00
|
|
|
/* fake direction, hmm. */
|
|
|
|
if(from->from != client_p)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-02-10 07:22:37 +01:00
|
|
|
ServerStats.is_wrdi++;
|
|
|
|
cancel_clients(client_p, from);
|
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-16 11:12:01 +02:00
|
|
|
if(rfc1459::is_digit(*msgbuf.cmd) && rfc1459::is_digit(*(msgbuf.cmd + 1)) && rfc1459::is_digit(*(msgbuf.cmd + 2)))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
mptr = NULL;
|
2016-02-10 07:22:37 +01:00
|
|
|
numeric = atoi(msgbuf.cmd);
|
2008-04-04 17:54:37 +02:00
|
|
|
ServerStats.is_num++;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-31 08:36:14 +02:00
|
|
|
mptr = cmd_dict[msgbuf.cmd];
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* no command or its encap only, error */
|
|
|
|
if(!mptr || !mptr->cmd)
|
|
|
|
{
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_person(*from))
|
2016-02-10 07:22:37 +01:00
|
|
|
{
|
|
|
|
sendto_one(from, form_str(ERR_UNKNOWNCOMMAND),
|
2016-02-10 17:25:16 +01:00
|
|
|
me.name, from->name, msgbuf.cmd);
|
2016-02-10 07:22:37 +01:00
|
|
|
}
|
2008-04-04 17:54:37 +02:00
|
|
|
ServerStats.is_unco++;
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-10 07:22:37 +01:00
|
|
|
mptr->bytes += msgbuf.parselen;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(mptr == NULL)
|
|
|
|
{
|
2016-02-10 07:22:37 +01:00
|
|
|
do_numeric(numeric, client_p, from, msgbuf.n_para, msgbuf.para);
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-11 03:13:44 +01:00
|
|
|
if(handle_command(mptr, &msgbuf, client_p, from) < -1)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
for (p = pbuffer; p <= end; p += 8)
|
|
|
|
{
|
|
|
|
/* HACK HACK */
|
|
|
|
/* Its expected this nasty code can be removed
|
|
|
|
* or rewritten later if still needed.
|
|
|
|
*/
|
2016-03-20 10:21:25 +01:00
|
|
|
if((p + 8) > end)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
for (; p <= end; p++)
|
|
|
|
{
|
|
|
|
ilog(L_MAIN, "%02x |%c", p[0], p[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ilog(L_MAIN,
|
|
|
|
"%02x %02x %02x %02x %02x %02x %02x %02x |%c%c%c%c%c%c%c%c",
|
|
|
|
p[0], p[1], p[2], p[3], p[4], p[5],
|
|
|
|
p[6], p[7], p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* handle_command
|
|
|
|
*
|
|
|
|
* inputs - pointer to message block
|
2016-02-11 03:13:44 +01:00
|
|
|
* - pointer to message buffer
|
2007-01-25 07:40:21 +01:00
|
|
|
* - pointer to client
|
|
|
|
* - pointer to client message is from
|
|
|
|
* output - -1 if error from server
|
|
|
|
* side effects -
|
|
|
|
*/
|
|
|
|
static int
|
2016-08-22 03:57:43 +02:00
|
|
|
handle_command(struct Message *mptr, struct MsgBuf *msgbuf_p, client::client *client_p, client::client *from)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
struct MessageEntry ehandler;
|
|
|
|
MessageHandler handler = 0;
|
|
|
|
char squitreason[80];
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_any_dead(*client_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
return -1;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_server(*client_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
mptr->rcount++;
|
|
|
|
|
|
|
|
mptr->count++;
|
|
|
|
|
|
|
|
ehandler = mptr->handlers[from->handler];
|
|
|
|
handler = ehandler.handler;
|
|
|
|
|
|
|
|
/* check right amount of params is passed... --is */
|
2016-02-11 03:13:44 +01:00
|
|
|
if(msgbuf_p->n_para < ehandler.min_para ||
|
|
|
|
(ehandler.min_para && EmptyString(msgbuf_p->para[ehandler.min_para - 1])))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 04:33:36 +02:00
|
|
|
if(!is_server(*client_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
sendto_one(client_p, form_str(ERR_NEEDMOREPARAMS),
|
2014-03-03 05:25:47 +01:00
|
|
|
me.name,
|
|
|
|
EmptyString(client_p->name) ? "*" : client_p->name,
|
2007-01-25 07:40:21 +01:00
|
|
|
mptr->cmd);
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*client_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
return (1);
|
|
|
|
else
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
|
|
|
"Dropping server %s due to (invalid) command '%s'"
|
2016-03-23 03:53:56 +01:00
|
|
|
" with only %zu arguments (expecting %zu).",
|
2016-02-11 03:13:44 +01:00
|
|
|
client_p->name, mptr->cmd, msgbuf_p->n_para, ehandler.min_para);
|
2007-01-25 07:40:21 +01:00
|
|
|
ilog(L_SERVER,
|
2016-03-23 03:53:56 +01:00
|
|
|
"Insufficient parameters (%zu < %zu) for command '%s' from %s.",
|
2016-02-11 03:13:44 +01:00
|
|
|
msgbuf_p->n_para, ehandler.min_para, mptr->cmd, client_p->name);
|
2016-02-10 02:25:32 +01:00
|
|
|
snprintf(squitreason, sizeof squitreason,
|
2016-03-23 03:53:56 +01:00
|
|
|
"Insufficient parameters (%zu < %zu) for command '%s'",
|
2016-02-11 03:13:44 +01:00
|
|
|
msgbuf_p->n_para, ehandler.min_para, mptr->cmd);
|
2007-01-25 07:40:21 +01:00
|
|
|
exit_client(client_p, client_p, client_p, squitreason);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
handler(msgbuf_p, *client_p, *from, msgbuf_p->n_para, msgbuf_p->para);
|
2007-01-25 07:40:21 +01:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
handle_encap(struct MsgBuf *msgbuf_p, client::client *client_p, client::client *source_p,
|
2007-01-25 07:40:21 +01:00
|
|
|
const char *command, int parc, const char *parv[])
|
|
|
|
{
|
|
|
|
struct Message *mptr;
|
|
|
|
struct MessageEntry ehandler;
|
|
|
|
MessageHandler handler = 0;
|
|
|
|
|
2016-07-31 08:36:14 +02:00
|
|
|
mptr = cmd_dict[command];
|
2007-01-25 07:40:21 +01:00
|
|
|
if(mptr == NULL || mptr->cmd == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ehandler = mptr->handlers[ENCAP_HANDLER];
|
|
|
|
handler = ehandler.handler;
|
|
|
|
|
2016-03-23 03:53:56 +01:00
|
|
|
if((size_t)parc < ehandler.min_para ||
|
2007-01-25 07:40:21 +01:00
|
|
|
(ehandler.min_para && EmptyString(parv[ehandler.min_para - 1])))
|
|
|
|
return;
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
handler(msgbuf_p, *client_p, *source_p, parc, parv);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* mod_add_cmd
|
|
|
|
*
|
|
|
|
* inputs - command name
|
|
|
|
* - pointer to struct Message
|
|
|
|
* output - none
|
|
|
|
* side effects - load this one command name
|
|
|
|
* msg->count msg->bytes is modified in place, in
|
|
|
|
* modules address space. Might not want to do that...
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
mod_add_cmd(struct Message *msg)
|
|
|
|
{
|
|
|
|
s_assert(msg != NULL);
|
|
|
|
if(msg == NULL)
|
|
|
|
return;
|
|
|
|
|
2016-07-31 08:36:14 +02:00
|
|
|
if (cmd_dict[msg->cmd] != NULL)
|
|
|
|
{
|
2016-04-24 00:56:41 +02:00
|
|
|
s_assert(0);
|
2007-12-02 16:34:45 +01:00
|
|
|
return;
|
2016-04-24 00:56:41 +02:00
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
msg->count = 0;
|
|
|
|
msg->rcount = 0;
|
|
|
|
msg->bytes = 0;
|
|
|
|
|
2016-07-31 08:36:14 +02:00
|
|
|
cmd_dict[msg->cmd] = msg;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* mod_del_cmd
|
|
|
|
*
|
|
|
|
* inputs - command name
|
|
|
|
* output - none
|
|
|
|
* side effects - unload this one command name
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
mod_del_cmd(struct Message *msg)
|
|
|
|
{
|
|
|
|
s_assert(msg != NULL);
|
|
|
|
if(msg == NULL)
|
|
|
|
return;
|
|
|
|
|
2016-07-31 08:36:14 +02:00
|
|
|
cmd_dict.erase(msg->cmd);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* cancel_clients()
|
|
|
|
*
|
|
|
|
* inputs - client who sent us the message, client with fake
|
2015-04-20 07:55:20 +02:00
|
|
|
* direction
|
2007-01-25 07:40:21 +01:00
|
|
|
* outputs - a given warning about the fake direction
|
|
|
|
* side effects -
|
|
|
|
*/
|
|
|
|
static void
|
2016-08-22 03:57:43 +02:00
|
|
|
cancel_clients(client::client *client_p, client::client *source_p)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
/* ok, fake prefix happens naturally during a burst on a nick
|
|
|
|
* collision with TS5, we cant kill them because one client has to
|
|
|
|
* survive, so we just send an error.
|
|
|
|
*/
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_server(*source_p) || is_me(*source_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
sendto_realops_snomask(SNO_DEBUG, L_ALL,
|
|
|
|
"Message for %s[%s] from %s",
|
|
|
|
source_p->name, source_p->from->name,
|
2008-06-28 12:13:50 +02:00
|
|
|
client_p->name);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sendto_realops_snomask(SNO_DEBUG, L_ALL,
|
|
|
|
"Message for %s[%s@%s!%s] from %s (TS, ignored)",
|
|
|
|
source_p->name,
|
|
|
|
source_p->username,
|
|
|
|
source_p->host,
|
|
|
|
source_p->from->name,
|
2008-06-28 12:13:50 +02:00
|
|
|
client_p->name);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove_unknown()
|
|
|
|
*
|
|
|
|
* inputs - client who gave us message, supposed sender, buffer
|
2014-03-03 05:25:47 +01:00
|
|
|
* output -
|
2007-01-25 07:40:21 +01:00
|
|
|
* side effects - kills issued for clients, squits for servers
|
|
|
|
*/
|
|
|
|
static void
|
2016-08-22 03:57:43 +02:00
|
|
|
remove_unknown(client::client *client_p, const char *lsender, char *lbuffer)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
int slen = strlen(lsender);
|
2009-01-22 00:27:27 +01:00
|
|
|
char sid[4];
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *server;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2008-07-02 00:58:56 +02:00
|
|
|
/* meepfoo is a nickname (ignore)
|
2007-01-25 07:40:21 +01:00
|
|
|
* #XXXXXXXX is a UID (KILL)
|
|
|
|
* #XX is a SID (SQUIT)
|
|
|
|
* meep.foo is a server (SQUIT)
|
|
|
|
*/
|
2016-08-16 11:12:01 +02:00
|
|
|
if((rfc1459::is_digit(lsender[0]) && slen == 3) ||
|
2007-01-25 07:40:21 +01:00
|
|
|
(strchr(lsender, '.') != NULL))
|
|
|
|
{
|
|
|
|
sendto_realops_snomask(SNO_DEBUG, L_ALL,
|
|
|
|
"Unknown prefix (%s) from %s, Squitting %s",
|
2008-06-28 12:13:50 +02:00
|
|
|
lbuffer, client_p->name, lsender);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
sendto_one(client_p,
|
|
|
|
":%s SQUIT %s :(Unknown prefix (%s) from %s)",
|
2014-03-03 05:25:47 +01:00
|
|
|
get_id(&me, client_p), lsender,
|
2007-01-25 07:40:21 +01:00
|
|
|
lbuffer, client_p->name);
|
|
|
|
}
|
2016-08-16 11:12:01 +02:00
|
|
|
else if(!rfc1459::is_digit(lsender[0]))
|
2009-01-22 00:27:27 +01:00
|
|
|
;
|
|
|
|
else if(slen != 9)
|
|
|
|
sendto_realops_snomask(SNO_DEBUG, L_ALL,
|
|
|
|
"Invalid prefix (%s) from %s",
|
|
|
|
lbuffer, client_p->name);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy(sid, lsender, 3);
|
|
|
|
sid[3] = '\0';
|
|
|
|
server = find_server(NULL, sid);
|
|
|
|
if (server != NULL && server->from == client_p)
|
2014-03-03 05:25:47 +01:00
|
|
|
sendto_one(client_p, ":%s KILL %s :%s (Unknown Client)",
|
2009-01-22 00:27:27 +01:00
|
|
|
get_id(&me, client_p), lsender, me.name);
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* parc number of arguments ('sender' counted as one!)
|
|
|
|
* parv[1]..parv[parc-1]
|
|
|
|
* pointers to additional parameters, this is a NULL
|
|
|
|
* terminated list (parv[parc] == NULL).
|
|
|
|
*
|
|
|
|
* *WARNING*
|
|
|
|
* Numerics are mostly error reports. If there is something
|
|
|
|
* wrong with the message, just *DROP* it! Don't even think of
|
|
|
|
* sending back a neat error message -- big danger of creating
|
|
|
|
* a ping pong error message...
|
|
|
|
*/
|
|
|
|
static void
|
2016-08-22 03:57:43 +02:00
|
|
|
do_numeric(int numeric, client::client *client_p, client::client *source_p, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *target_p;
|
2016-08-18 07:33:38 +02:00
|
|
|
chan::chan *chptr;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(parc < 2 || !is_server(*source_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Remap low number numerics. */
|
2016-02-10 07:22:37 +01:00
|
|
|
if(numeric < 100)
|
|
|
|
numeric += 100;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare the parameter portion of the message into 'buffer'.
|
|
|
|
* (Because the buffer is twice as large as the message buffer
|
|
|
|
* for the socket, no overflow can occur here... ...on current
|
|
|
|
* assumptions--bets are off, if these are changed --msa)
|
|
|
|
* Note: if buffer is non-empty, it will begin with SPACE.
|
|
|
|
*/
|
|
|
|
if(parc > 1)
|
|
|
|
{
|
|
|
|
char *t = buffer; /* Current position within the buffer */
|
|
|
|
int i;
|
|
|
|
int tl; /* current length of presently being built string in t */
|
|
|
|
for (i = 2; i < (parc - 1); i++)
|
|
|
|
{
|
2016-02-10 02:25:32 +01:00
|
|
|
tl = sprintf(t, " %s", parv[i]);
|
2007-01-25 07:40:21 +01:00
|
|
|
t += tl;
|
|
|
|
}
|
2016-02-10 02:25:32 +01:00
|
|
|
sprintf(t, " :%s", parv[parc - 1]);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if((target_p = find_client(parv[1])) != NULL)
|
|
|
|
{
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_me(*target_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We shouldn't get numerics sent to us,
|
|
|
|
* any numerics we do get indicate a bug somewhere..
|
|
|
|
*/
|
|
|
|
/* ugh. this is here because of nick collisions. when two servers
|
|
|
|
* relink, they burst each other their nicks, then perform collides.
|
|
|
|
* if there is a nick collision, BOTH servers will kill their own
|
|
|
|
* nicks, and BOTH will kill the other servers nick, which wont exist,
|
|
|
|
* because it will have been already killed by the local server.
|
|
|
|
*
|
|
|
|
* unfortunately, as we cant guarantee other servers will do the
|
2014-03-03 05:25:47 +01:00
|
|
|
* "right thing" on a nick collision, we have to keep both kills.
|
2007-01-25 07:40:21 +01:00
|
|
|
* ergo we need to ignore ERR_NOSUCHNICK. --fl_
|
|
|
|
*/
|
|
|
|
/* quick comment. This _was_ tried. i.e. assume the other servers
|
|
|
|
* will do the "right thing" and kill a nick that is colliding.
|
|
|
|
* unfortunately, it did not work. --Dianora
|
|
|
|
*/
|
|
|
|
/* note, now we send PING on server connect, we can
|
|
|
|
* also get ERR_NOSUCHSERVER..
|
|
|
|
*/
|
2016-02-10 07:22:37 +01:00
|
|
|
if(numeric != ERR_NOSUCHNICK &&
|
|
|
|
numeric != ERR_NOSUCHSERVER)
|
2007-01-25 07:40:21 +01:00
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ADMIN,
|
2016-02-10 07:22:37 +01:00
|
|
|
"*** %s(via %s) sent a %03d numeric to me: %s",
|
2007-01-25 07:40:21 +01:00
|
|
|
source_p->name,
|
|
|
|
client_p->name, numeric, buffer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(target_p->from == client_p)
|
|
|
|
{
|
|
|
|
/* This message changed direction (nick collision?)
|
|
|
|
* ignore it.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* csircd will send out unknown umode flag for +a (admin), drop it here. */
|
2016-08-23 04:33:36 +02:00
|
|
|
if(numeric == ERR_UMODEUNKNOWNFLAG && my(*target_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Fake it for server hiding, if its our client */
|
2016-02-10 07:22:37 +01:00
|
|
|
sendto_one(target_p, ":%s %03d %s%s",
|
2014-03-03 05:25:47 +01:00
|
|
|
get_id(source_p, target_p), numeric,
|
2007-01-25 07:40:21 +01:00
|
|
|
get_id(target_p, target_p), buffer);
|
|
|
|
return;
|
|
|
|
}
|
2016-08-20 04:51:37 +02:00
|
|
|
else if((chptr = chan::get(parv[1], std::nothrow)) != NULL)
|
2016-08-18 07:33:38 +02:00
|
|
|
sendto_channel_flags(client_p, chan::ALL_MEMBERS, source_p, chptr,
|
2016-02-10 07:22:37 +01:00
|
|
|
"%03d %s%s",
|
2016-08-18 07:33:38 +02:00
|
|
|
numeric, chptr->name.c_str(), buffer);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
void
|
2016-08-23 02:37:07 +02:00
|
|
|
m_not_oper(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
void
|
2016-08-23 02:37:07 +02:00
|
|
|
m_unregistered(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_any_server(client))
|
2016-04-24 18:41:44 +02:00
|
|
|
return;
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/* bit of a hack.
|
|
|
|
* I don't =really= want to waste a bit in a flag
|
|
|
|
* number_of_nick_changes is only really valid after the client
|
|
|
|
* is fully registered..
|
|
|
|
*/
|
2016-08-23 02:37:07 +02:00
|
|
|
if(client.localClient->number_of_nick_changes == 0)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&client, form_str(ERR_NOTREGISTERED), me.name);
|
|
|
|
client.localClient->number_of_nick_changes++;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
void
|
2016-08-23 02:37:07 +02:00
|
|
|
m_registered(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&client, form_str(ERR_ALREADYREGISTRED), me.name, source.name);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
void
|
2016-08-23 02:37:07 +02:00
|
|
|
m_ignore(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-03-09 08:37:03 +01:00
|
|
|
/* Does nothing */
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
2016-08-13 05:05:54 +02:00
|
|
|
|
|
|
|
} // namespace ircd
|