+2000-11-22 Kevin L. Mitchell <klmitch@mit.edu>
+
+ * ircd/s_user.c (register_user): use motd_signon() instead of
+ calling m_motd; much cleaner this way
+
+ * ircd/motd.c: write the new motd_* stuff to make MOTD handling
+ less of a crock
+
+ * ircd/m_motd.c: rewrite m{,s}_motd to call out to new motd_*
+ functions
+
+ * include/motd.h: define new MOTD API stuff
+
2000-11-20 Kevin L. Mitchell <klmitch@mit.edu>
* ircd/ircd_reply.c (protocol_violation): rewrite
--- /dev/null
+#ifndef INCLUDED_motd_h
+#define INCLUDED_motd_h
+/*
+ * IRC - Internet Relay Chat, include/motd.h
+ * Copyright (C) 1990 Jarkko Oikarinen and
+ * University of Oulu, Computing Center
+ * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
+ *
+ * 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.
+ *
+ * $Id$
+ */
+#ifndef INCLUDED_config_h
+#include "config.h"
+#endif
+#ifndef INCLUDED_sys_types_h
+#include <sys/types.h>
+#define INCLUDED_sys_types_h
+#endif
+
+
+struct Client;
+struct TRecord;
+
+/* motd_find is used to find a matching T-line if any */
+struct TRecord *motd_find(struct Client* cptr);
+
+/* motd_send sends a MOTD off to a user */
+int motd_send(struct Client* cptr, struct TRecord* trec);
+
+/* motd_signon sends a MOTD off to a newly-registered user */
+void motd_signon(struct Client* cptr);
+
+#endif /* INCLUDED_motd_h */
../include/ircd.h ../include/struct.h ../include/ircd_reply.h \
../include/ircd_string.h ../include/ircd_chattr.h ../include/msg.h \
../include/numeric.h ../include/numnicks.h ../include/s_debug.h \
- ../include/send.h
+ ../include/s_user.h ../include/send.h
m_defaults.o: m_defaults.c ../include/client.h ../include/ircd_defs.h \
../include/dbuf.h ../include/ircd_handler.h ../include/ircd.h \
../config/config.h ../config/setup.h ../include/struct.h \
m_map.o: m_map.c ../include/client.h ../include/ircd_defs.h \
../include/dbuf.h ../include/ircd_handler.h ../include/ircd.h \
../config/config.h ../config/setup.h ../include/struct.h \
- ../include/ircd_reply.h ../include/ircd_string.h \
- ../include/ircd_chattr.h ../include/numeric.h ../include/send.h
+ ../include/ircd_reply.h ../include/ircd_snprintf.h \
+ ../include/ircd_string.h ../include/ircd_chattr.h ../include/list.h \
+ ../include/match.h ../include/numeric.h ../include/s_user.h \
+ ../include/s_serv.h ../include/send.h ../include/querycmds.h
m_mode.o: m_mode.c ../include/handlers.h ../include/channel.h \
../config/config.h ../config/setup.h ../include/ircd_defs.h \
../include/client.h ../include/dbuf.h ../include/ircd_handler.h \
../include/dbuf.h ../include/ircd_handler.h ../include/ircd.h \
../config/config.h ../config/setup.h ../include/struct.h \
../include/ircd_reply.h ../include/ircd_string.h \
- ../include/ircd_chattr.h ../include/match.h ../include/msg.h \
- ../include/numeric.h ../include/numnicks.h ../include/s_conf.h \
- ../include/s_user.h ../include/send.h
+ ../include/ircd_chattr.h ../include/match.h ../include/motd.h \
+ ../include/msg.h ../include/numeric.h ../include/numnicks.h \
+ ../include/s_conf.h ../include/class.h ../include/s_user.h \
+ ../include/send.h
m_names.o: m_names.c ../include/channel.h ../config/config.h \
../config/setup.h ../include/ircd_defs.h ../include/client.h \
../include/dbuf.h ../include/ircd_handler.h ../include/hash.h \
m_quit.o: m_quit.c ../include/channel.h ../config/config.h \
../config/setup.h ../include/ircd_defs.h ../include/client.h \
../include/dbuf.h ../include/ircd_handler.h ../include/ircd_string.h \
- ../include/ircd_chattr.h ../include/struct.h ../include/s_misc.h
+ ../include/ircd_chattr.h ../include/struct.h ../include/s_misc.h \
+ ../include/ircd_reply.h
m_rehash.o: m_rehash.c ../include/client.h ../include/ircd_defs.h \
../include/dbuf.h ../include/ircd_handler.h ../include/ircd.h \
../config/config.h ../config/setup.h ../include/struct.h \
../include/numnicks.h ../include/s_user.h ../include/s_misc.h \
../include/send.h ../include/whowas.h
match.o: match.c ../include/match.h ../include/ircd_chattr.h
+motd.o: motd.c ../include/motd.h ../config/config.h ../config/setup.h \
+ ../include/client.h ../include/ircd_defs.h ../include/dbuf.h \
+ ../include/ircd_handler.h ../include/ircd.h ../include/struct.h \
+ ../include/ircd_reply.h ../include/ircd_string.h \
+ ../include/ircd_chattr.h ../include/match.h ../include/msg.h \
+ ../include/numeric.h ../include/numnicks.h ../include/s_conf.h \
+ ../include/class.h ../include/s_user.h ../include/send.h
numnicks.o: numnicks.c ../include/numnicks.h ../include/client.h \
../include/ircd_defs.h ../include/dbuf.h ../include/ircd_handler.h \
../include/ircd.h ../config/config.h ../config/setup.h \
../include/ircd.h ../config/config.h ../config/setup.h \
../include/struct.h ../include/ircd_chattr.h ../include/parse.h \
../include/s_bsd.h ../include/s_misc.h ../include/send.h
+parse.o: parse.c ../include/parse.h ../include/client.h \
+ ../include/ircd_defs.h ../include/dbuf.h ../include/ircd_handler.h \
+ ../include/channel.h ../config/config.h ../config/setup.h \
+ ../include/handlers.h ../include/hash.h ../include/ircd.h \
+ ../include/struct.h ../include/ircd_alloc.h ../include/fda.h \
+ ../include/ircd_chattr.h ../include/ircd_reply.h \
+ ../include/ircd_string.h ../include/msg.h ../include/numeric.h \
+ ../include/numnicks.h ../include/opercmds.h ../include/querycmds.h \
+ ../include/res.h ../include/s_bsd.h ../include/s_conf.h \
+ ../include/s_debug.h ../include/s_misc.h ../include/s_numeric.h \
+ ../include/s_user.h ../include/send.h ../include/sys.h \
+ ../include/whocmds.h ../include/whowas.h
querycmds.o: querycmds.c ../include/querycmds.h
random.o: random.c ../include/random.h ../config/config.h \
../config/setup.h
../include/ircd_alloc.h ../include/fda.h ../include/ircd_chattr.h \
../include/ircd_log.h ../include/ircd_reply.h \
../include/ircd_string.h ../include/list.h ../include/match.h \
- ../include/msg.h ../include/numeric.h ../include/numnicks.h \
- ../include/parse.h ../include/querycmds.h ../include/random.h \
- ../include/s_bsd.h ../include/s_conf.h ../include/s_debug.h \
- ../include/s_misc.h ../include/s_serv.h ../include/send.h \
- ../include/sprintf_irc.h ../include/support.h ../include/supported.h \
- ../include/sys.h ../include/userload.h ../include/version.h \
- ../include/whowas.h ../include/handlers.h
+ ../include/motd.h ../include/msg.h ../include/numeric.h \
+ ../include/numnicks.h ../include/parse.h ../include/querycmds.h \
+ ../include/random.h ../include/s_bsd.h ../include/s_conf.h \
+ ../include/s_debug.h ../include/s_misc.h ../include/s_serv.h \
+ ../include/send.h ../include/sprintf_irc.h ../include/support.h \
+ ../include/supported.h ../include/sys.h ../include/userload.h \
+ ../include/version.h ../include/whowas.h ../include/handlers.h
send.o: send.c ../include/send.h ../include/channel.h \
../config/config.h ../config/setup.h ../include/ircd_defs.h \
../include/class.h ../include/client.h ../include/dbuf.h \
#include "ircd_reply.h"
#include "ircd_string.h"
#include "match.h"
+#include "motd.h"
#include "msg.h"
#include "numeric.h"
#include "numnicks.h"
* stolen from comstud & Xorath. All motd files are read into
* memory in read_motd() in s_conf.c
*
- * When NODEFAULTMOTD is defined, then it is possible that
- * sptr == NULL, which means that this function is called from
- * register_user.
+ * Now using the motd_* family of functions defined in motd.c
*/
int m_motd(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
{
- struct tm *tm = &motd_tm; /* Default: Most general case */
- struct TRecord *ptr;
- int count;
- struct MotdItem *temp;
- int class = get_client_class(cptr);
-
-#ifdef NODEFAULTMOTD
- int no_motd;
-
- if (sptr)
- {
- no_motd = 0;
-#endif
- if (hunt_server_cmd(sptr, CMD_MOTD, cptr, 0, "%C", 1, parc, parv) !=
- HUNTED_ISME)
- return 0;
-#ifdef NODEFAULTMOTD
- }
- else
- {
- sptr = cptr;
- no_motd = 1;
- }
-#endif
- /* 2.10.11: Allow per Class T:'s
- * -- Isomer 2000-11-19
- */
- for (ptr = tdata; ptr; ptr = ptr->next)
- {
- if (IsDigit(*ptr->hostmask)) {
- if (atoi(ptr->hostmask)==class)
- break;
- }
- else if (!match(ptr->hostmask, cptr->sockhost))
- break;
- }
- if (ptr)
- {
- temp = ptr->tmotd;
- tm = &ptr->tmotd_tm;
- }
- else
- temp = motd;
- if (temp == 0)
- {
- send_reply(sptr, ERR_NOMOTD);
+ if (hunt_server_cmd(sptr, CMD_MOTD, cptr, 0, "%C", 1, parc, parv) !=
+ HUNTED_ISME)
return 0;
- }
-#ifdef NODEFAULTMOTD
- if (!no_motd)
- {
-#endif
- if (tm) /* Not remote? */
- {
- send_reply(sptr, RPL_MOTDSTART, me.name);
- send_reply(sptr, SND_EXPLICIT | RPL_MOTD, ":- %d/%d/%d %d:%02d",
- tm->tm_mday, tm->tm_mon + 1, 1900 + tm->tm_year, tm->tm_hour,
- tm->tm_min);
- count = 100;
- }
- else
- count = 3;
- for (; temp; temp = temp->next)
- {
- send_reply(sptr, RPL_MOTD, temp->line);
- if (--count == 0)
- break;
- }
-#ifdef NODEFAULTMOTD
- }
- else
- {
- send_reply(sptr, RPL_MOTDSTART, me.name);
- send_reply(sptr, SND_EXPLICIT | RPL_MOTD, ":\ 2Type /MOTD to read the "
- "AUP before continuing using this service.\ 2");
- send_reply(sptr, SND_EXPLICIT | RPL_MOTD, ":The message of the day was "
- "last changed: %d/%d/%d", tm->tm_mday, tm->tm_mon + 1,
- 1900 + tm->tm_year);
- }
-#endif
- send_reply(sptr, RPL_ENDOFMOTD);
- return 0;
+
+ return motd_send(sptr, motd_find(sptr));
}
/*
* stolen from comstud & Xorath. All motd files are read into
* memory in read_motd() in s_conf.c
*
- * When NODEFAULTMOTD is defined, then it is possible that
- * sptr == NULL, which means that this function is called from
- * register_user.
+ * Now using the motd_* family of functions defined in motd.c
*/
int ms_motd(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
{
- struct tm *tm = &motd_tm; /* Default: Most general case */
- struct TRecord *ptr;
- int count;
- struct MotdItem *temp;
-
-#ifdef NODEFAULTMOTD
- int no_motd;
-
- if (sptr)
- {
- no_motd = 0;
-#endif
- if (hunt_server_cmd(sptr, CMD_MOTD, cptr, 0, "%C", 1, parc, parv) !=
- HUNTED_ISME)
- return 0;
-#ifdef NODEFAULTMOTD
- }
- else
- {
- sptr = cptr;
- no_motd = 1;
- }
-#endif
-
- /*
- * Find out if this is a remote query or if we have a T line for our hostname
- */
- if (IsServer(cptr))
- {
- tm = 0; /* Remote MOTD */
- temp = rmotd;
- }
- else
- {
- for (ptr = tdata; ptr; ptr = ptr->next)
- {
- if (!match(ptr->hostmask, cptr->sockhost))
- break;
- }
- if (ptr)
- {
- temp = ptr->tmotd;
- tm = &ptr->tmotd_tm;
- }
- else
- temp = motd;
- }
- if (temp == 0)
- {
- send_reply(sptr, ERR_NOMOTD);
+ if (hunt_server_cmd(sptr, CMD_MOTD, cptr, 0, "%C", 1, parc, parv) !=
+ HUNTED_ISME)
return 0;
- }
-#ifdef NODEFAULTMOTD
- if (!no_motd)
- {
-#endif
- if (tm) /* Not remote? */
- {
- send_reply(sptr, RPL_MOTDSTART, me.name);
- send_reply(sptr, SND_EXPLICIT | RPL_MOTD, ":- %d/%d/%d %d:%02d",
- tm->tm_mday, tm->tm_mon + 1, 1900 + tm->tm_year, tm->tm_hour,
- tm->tm_min);
- count = 100;
- }
- else
- count = 3;
- for (; temp; temp = temp->next)
- {
- send_reply(sptr, RPL_MOTD, temp->line);
- if (--count == 0)
- break;
- }
-#ifdef NODEFAULTMOTD
- }
- else
- {
- send_reply(sptr, RPL_MOTDSTART, me.name);
- send_reply(sptr, SND_EXPLICIT | RPL_MOTD, ":\ 2Type /MOTD to read the "
- "AUP before continuing using this service.\ 2");
- send_reply(sptr, SND_EXPLICIT | RPL_MOTD, ":The message of the day was "
- "last changed: %d/%d/%d", tm->tm_mday, tm->tm_mon + 1,
- 1900 + tm->tm_year);
- }
-#endif
- send_reply(sptr, RPL_ENDOFMOTD);
- return 0;
-}
-#if 0
-/*
- * m_motd
- *
- * parv[0] - sender prefix
- * parv[1] - servername
- *
- * modified 30 mar 1995 by flux (cmlambertus@ucdavis.edu)
- * T line patch - display motd based on hostmask
- * modified again 7 sep 97 by Ghostwolf with code and ideas
- * stolen from comstud & Xorath. All motd files are read into
- * memory in read_motd() in s_conf.c
- *
- * When NODEFAULTMOTD is defined, then it is possible that
- * sptr == NULL, which means that this function is called from
- * register_user.
- */
-int m_motd(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
-{
- struct tm *tm = &motd_tm; /* Default: Most general case */
- struct TRecord *ptr;
- int count;
- struct MotdItem *temp;
-
-#ifdef NODEFAULTMOTD
- int no_motd;
-
- if (sptr)
- {
- no_motd = 0;
-#endif
- if (hunt_server(0, cptr, sptr, "%s%s " TOK_MOTD " %s", 1, parc, /* XXX DEAD */
- parv) != HUNTED_ISME)
- return 0;
-#ifdef NODEFAULTMOTD
- }
- else
- {
- sptr = cptr;
- no_motd = 1;
- }
-#endif
-
- /*
- * Find out if this is a remote query or if we have a T line for our hostname
- */
- if (IsServer(cptr))
- {
- tm = 0; /* Remote MOTD */
- temp = rmotd;
- }
- else
- {
- for (ptr = tdata; ptr; ptr = ptr->next)
- {
- if (!match(ptr->hostmask, cptr->sockhost))
- break;
- }
- if (ptr)
- {
- temp = ptr->tmotd;
- tm = &ptr->tmotd_tm;
- }
- else
- temp = motd;
- }
- if (temp == 0)
- {
- sendto_one(sptr, err_str(ERR_NOMOTD), me.name, parv[0]); /* XXX DEAD */
- return 0;
- }
-#ifdef NODEFAULTMOTD
- if (!no_motd)
- {
-#endif
- if (tm) /* Not remote? */
- {
- sendto_one(sptr, rpl_str(RPL_MOTDSTART), me.name, parv[0], me.name); /* XXX DEAD */
- sendto_one(sptr, ":%s %d %s :- %d/%d/%d %d:%02d", me.name, RPL_MOTD, /* XXX DEAD */
- parv[0], tm->tm_mday, tm->tm_mon + 1, 1900 + tm->tm_year,
- tm->tm_hour, tm->tm_min);
- count = 100;
- }
- else
- count = 3;
- for (; temp; temp = temp->next)
- {
- sendto_one(sptr, rpl_str(RPL_MOTD), me.name, parv[0], temp->line); /* XXX DEAD */
- if (--count == 0)
- break;
- }
-#ifdef NODEFAULTMOTD
- }
- else
- {
- sendto_one(sptr, rpl_str(RPL_MOTDSTART), me.name, parv[0], me.name); /* XXX DEAD */
- sendto_one(sptr, ":%s %d %s :%s", me.name, RPL_MOTD, parv[0], /* XXX DEAD */
- "\ 2Type /MOTD to read the AUP before continuing using this service.\ 2");
- sendto_one(sptr, /* XXX DEAD */
- ":%s %d %s :The message of the day was last changed: %d/%d/%d", me.name,
- RPL_MOTD, parv[0], tm->tm_mday, tm->tm_mon + 1, 1900 + tm->tm_year);
- }
-#endif
- sendto_one(sptr, rpl_str(RPL_ENDOFMOTD), me.name, parv[0]); /* XXX DEAD */
- return 0;
+ return motd_send(sptr, motd_find(sptr));
}
-#endif /* 0 */
-
--- /dev/null
+/*
+ * IRC - Internet Relay Chat, ircd/motd.c
+ * Copyright (C) 1990 Jarkko Oikarinen and
+ * University of Oulu, Computing Center
+ * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
+ *
+ * See file AUTHORS in IRC package for additional names of
+ * the programmers.
+ *
+ * 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 1, 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.
+ *
+ * $Id$
+ */
+#include "motd.h"
+#include "client.h"
+#include "ircd.h"
+#include "ircd_reply.h"
+#include "ircd_string.h"
+#include "match.h"
+#include "msg.h"
+#include "numeric.h"
+#include "numnicks.h"
+#include "s_conf.h"
+#include "class.h"
+#include "s_user.h"
+#include "send.h"
+
+#include <stdlib.h>
+#include <assert.h>
+
+/* This routine returns the TRecord structure for a user, or 0 if there
+ * is no matching T-line--in which case, we should use the standard
+ * MOTD.
+ */
+struct TRecord *
+motd_find(struct Client* cptr)
+{
+ struct TRecord *ptr;
+ int class = -1;
+
+ assert(0 != cptr);
+
+ if (MyUser(cptr))
+ class = get_client_class(cptr);
+
+ for (ptr = tdata; ptr; ptr = ptr->next) {
+ if (class >= 0 && IsDigit(*ptr->hostmask)) {
+ if (atoi(ptr->hostmask) == class)
+ return ptr;
+ } else if (!match(ptr->hostmask, cptr->sockhost))
+ return ptr;
+ }
+
+ return 0;
+}
+
+/* This routine is used to send the MOTD off to a user. */
+int
+motd_send(struct Client* cptr, struct TRecord* trec)
+{
+ struct MotdItem *t_motd;
+ struct tm *t_tm;
+ int count;
+
+ assert(0 != cptr);
+
+ if (!MyUser(cptr)) { /* not our user, send the remote MOTD */
+ t_motd = rmotd;
+ t_tm = 0;
+ } else if (trec) { /* We were given a TRecord */
+ t_motd = trec->tmotd;
+ t_tm = &trec->tmotd_tm;
+ } else { /* use the basic MOTD */
+ t_motd = motd;
+ t_tm = &motd_tm;
+ }
+
+ if (!t_motd) /* No motd to send */
+ return send_reply(cptr, ERR_NOMOTD);
+
+ /* this is a change; we now always send the start numeric */
+ send_reply(cptr, RPL_MOTDSTART, me.name);
+
+ if (t_tm) { /* We should probably go for ISO dates here: yyyy-mm-dd. */
+ send_reply(cptr, SND_EXPLICIT | RPL_MOTD, ":- %d/%d/%d %d:%02d",
+ t_tm->tm_mday, t_tm->tm_mon + 1, 1900 + t_tm->tm_year,
+ t_tm->tm_hour, t_tm->tm_min);
+ count = 100;
+ } else
+ count = 3;
+
+ for (; t_motd; t_motd = t_motd->next) { /* send along the MOTD */
+ send_reply(cptr, RPL_MOTD, t_motd->line);
+ if (!--count)
+ break;
+ }
+
+ send_reply(cptr, RPL_ENDOFMOTD); /* end */
+
+ return 0; /* Convenience return */
+}
+
+/* This routine sends the MOTD or something to newly-registered users. */
+void
+motd_signon(struct Client* cptr)
+{
+ struct TRecord *trec;
+ struct tm *t_tm = &motd_tm;
+
+ if ((trec = motd_find(cptr)))
+ t_tm = &trec->tmotd_tm;
+
+#ifdef NODEFAULTMOTD
+ send_reply(cptr, RPL_MOTDSTART, me.name);
+ send_reply(cptr, SND_EXPLICIT | RPL_MOTD, ":\002Type /MOTD to read the AUP "
+ "before continuing using this service.\002");
+ /* Perhaps we should switch to an ISO date here? */
+ send_reply(cptr, SND_EXPLICIT | RPL_MOTD, ":The message of the day was last "
+ "changed: %d/%d/%d", t_tm->tm_mday, t_tm->tm_mon + 1,
+ 1900 + t_tm->tm_year);
+ send_reply(cptr, RPL_ENDOFMOTD);
+#else
+ motd_send(cptr, trec);
+#endif
+}
#include "ircd_string.h"
#include "list.h"
#include "match.h"
+#include "motd.h"
#include "msg.h"
#include "numeric.h"
#include "numnicks.h"
send_reply(sptr, RPL_ISUPPORT, featurebuf);
m_lusers(sptr, sptr, 1, parv);
update_load();
-#ifdef NODEFAULTMOTD
- m_motd(sptr, NULL, 1, parv);
-#else
- m_motd(sptr, sptr, 1, parv);
-#endif
+ motd_signon(sptr);
nextping = CurrentTime;
if (sptr->snomask & SNO_NOISY)
set_snomask(sptr, sptr->snomask & SNO_NOISY, SNO_ADD);