From 40157a056be44d43decfccf5d446bfe77a71c5ed Mon Sep 17 00:00:00 2001 From: codemastr Date: Tue, 3 Jun 2003 22:38:46 +0000 Subject: [PATCH] Added short motds --- Changes | 8 +++++ doc/unreal32docs.html | 8 +++-- include/config.h | 1 + include/h.h | 2 +- include/struct.h | 6 ++-- src/ircd.c | 8 +++-- src/s_conf.c | 15 +++++++++ src/s_serv.c | 78 ++++++++++++++++++++++++++++++++++++++++++- src/s_user.c | 4 ++- 9 files changed, 118 insertions(+), 12 deletions(-) diff --git a/Changes b/Changes index 2f1430f48..3ca627367 100644 --- a/Changes +++ b/Changes @@ -2209,3 +2209,11 @@ seen. gmtime warning still there - Fixed another serious bug in the win32 resolver. - Removed mutex stuff from rem_request, no longer needed, should make the resolver much faster. +- Implemented short motds (ircd.smotd). If you don't know what short motds are, read on: + short motds are a method of conserving bandwidth. When a user connects ircd.smotd + is displayed (or a tld::shortmotd). This file contains brief text. Alternatively, + ircd.motd (or tld::motd) is displayed when a user types /motd. The idea behind this is + instead of displaying huge ASCII art, and tons of text to every user when they connect + (since most users will ignore it anyway) you only show that stuff to users who specifically + request it. Also, if you choose not to use short motds, everything will function as it used + to the ircd.motd (or tld::motd) will be displayed both when users connect and /motd. diff --git a/doc/unreal32docs.html b/doc/unreal32docs.html index 5dec24bf8..8b8642e59 100644 --- a/doc/unreal32docs.html +++ b/doc/unreal32docs.html @@ -21,7 +21,7 @@ http://www.unrealircd.com
Version: 3.2
Current Version: 3.2 Beta16
- Last doc update: 2003-05-29 + Last doc update: 2003-06-03 Head Coders: Stskeeps / codemastr / Luke / McSkaf / Syzop
Contributors: Zogg / NiQuiL / assyrian / chasm / DrBin / llthangel / Griever / nighthawk
Documentation: CKnight^ / Syzop
@@ -970,6 +970,7 @@ tld { mask <hostmask>; motd <motd-file>; rules <rules-file>; + shortmotd <shortmotd-file>; channel <channel-name>; options { ssl; @@ -978,8 +979,9 @@ tld {

The tld block allows you to specify a motd, rules, and channel for a user based on their host. This is useful if you want different motds for different languages. The tld::mask is a user@host mask that the user's username and hostname must - match. The tld::motd and tld::rules specify the motd and rules file, respectively, - to be displayed to this hostmask. tld::channel is optional, it allows + match. The tld::motd, tld::shortmotd, and tld::rules specify the + motd, shortmotd, and rules file, respectively, to be displayed to this hostmask. + The tld::shortmotd is optional. tld::channel is optional, it allows you to specify a channel that this user will be forced to join on connect. If this exists it will override the default auto join channel. The tld::options block allows you to define additional requirements, diff --git a/include/config.h b/include/config.h index 32e068d2f..ce97f2d02 100644 --- a/include/config.h +++ b/include/config.h @@ -272,6 +272,7 @@ */ #define CPATH "unrealircd.conf" /* server configuration file */ #define MPATH "ircd.motd" /* server MOTD file */ +#define SMPATH "ircd.smotd" /* short MOTD file */ #define RPATH "ircd.rules" /* server rules file */ #define OPATH "oper.motd" /* Operators MOTD file */ #define LPATH "debug.log" /* Where the debug file lives, if DEBUGMODE */ diff --git a/include/h.h b/include/h.h index a960fb82a..a3276ae61 100644 --- a/include/h.h +++ b/include/h.h @@ -135,7 +135,7 @@ int match_ipv4(struct IN_ADDR *addr, struct IN_ADDR *mask, int b); #ifdef INET6 int match_ipv6(struct IN_ADDR *addr, struct IN_ADDR *mask, int b); #endif -extern struct tm motd_tm; +extern struct tm motd_tm, smotd_tm; extern Link *Servers; void add_ListItem(ListStruct *, ListStruct **); ListStruct *del_ListItem(ListStruct *, ListStruct **); diff --git a/include/struct.h b/include/struct.h index 143bad007..c1df9305a 100644 --- a/include/struct.h +++ b/include/struct.h @@ -1000,9 +1000,9 @@ struct _configitem_ulines { struct _configitem_tld { ConfigItem *prev, *next; ConfigFlag_tld flag; - char *mask, *motd_file, *rules_file, *channel; - struct tm motd_tm; - aMotd *rules, *motd; + char *mask, *motd_file, *rules_file, *smotd_file, *channel; + struct tm motd_tm, smotd_tm; + aMotd *rules, *motd, *smotd; u_short options; }; diff --git a/src/ircd.c b/src/ircd.c index 4cf1f0bb3..9d339b3f3 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -91,6 +91,7 @@ extern aMotd *svsmotd; extern aMotd *motd; extern aMotd *rules; extern aMotd *botmotd; +extern aMotd *smotd; MemoryInfo StatsZ; int R_do_dns, R_fin_dns, R_fin_dnsc, R_fail_dns, R_do_id, R_fin_id, R_fail_id; @@ -1133,11 +1134,12 @@ int InitwIRCD(int argc, char *argv[]) me.umodes = conf_listen->options; conf_listen->listener = &me; run_configuration(); - botmotd = (aMotd *) read_file(BPATH, &botmotd); + botmotd = (aMotd *) read_file(BPATH, NULL); rules = (aMotd *) read_file(RPATH, NULL); - opermotd = (aMotd *) read_file(OPATH, &opermotd); + opermotd = (aMotd *) read_file(OPATH, NULL); motd = (aMotd *) read_file_ex(MPATH, NULL, &motd_tm); - svsmotd = (aMotd *) read_file(VPATH, &svsmotd); + smotd = (aMotd *) read_file_ex(SMPATH, NULL, &smotd_tm); + svsmotd = (aMotd *) read_file(VPATH, NULL); strncpy(me.sockhost, conf_listen->ip, sizeof(me.sockhost) - 1); if (me.name[0] == '\0') strncpyzt(me.name, me.sockhost, sizeof(me.name)); diff --git a/src/s_conf.c b/src/s_conf.c index 4188aa35f..e91051021 100644 --- a/src/s_conf.c +++ b/src/s_conf.c @@ -1449,6 +1449,7 @@ void config_rehash() next = (ListStruct *)tld_ptr->next; ircfree(tld_ptr->motd_file); ircfree(tld_ptr->rules_file); + ircfree(tld_ptr->smotd_file); if (!tld_ptr->flag.motdptr) { while (tld_ptr->motd) { motd = tld_ptr->motd->next; @@ -1465,6 +1466,12 @@ void config_rehash() tld_ptr->rules = motd; } } + while (tld_ptr->smotd) { + motd = tld_ptr->smotd->next; + ircfree(tld_ptr->smotd->line); + ircfree(tld_ptr->smotd); + tld_ptr->smotd = motd; + } DelListItem(tld_ptr, conf_tld); MyFree(tld_ptr); } @@ -3139,6 +3146,12 @@ int _conf_tld(ConfigFile *conf, ConfigEntry *ce) cep = config_find_entry(ce->ce_entries, "motd"); ca->motd_file = strdup(cep->ce_vardata); ca->motd = read_file_ex(cep->ce_vardata, NULL, &ca->motd_tm); + if ((cep = config_find_entry(ce->ce_entries, "shortmotd"))) + { + ca->smotd_file = strdup(cep->ce_vardata); + ca->smotd = read_file_ex(cep->ce_vardata, NULL, &ca->smotd_tm); + } + cep = config_find_entry(ce->ce_entries, "rules"); ca->rules_file = strdup(cep->ce_vardata); ca->rules = read_file(cep->ce_vardata, NULL); @@ -3188,6 +3201,8 @@ int _test_tld(ConfigFile *conf, ConfigEntry *ce) } else if (!strcmp(cep->ce_varname, "channel")) { } + else if (!strcmp(cep->ce_varname, "shortmotd")) { + } else if (!strcmp(cep->ce_varname, "options")) { ConfigEntry *cep2; for (cep2 = cep->ce_entries; cep2; cep2 = cep2->ce_next) diff --git a/src/s_serv.c b/src/s_serv.c index e2e184c68..aec6a1ae2 100644 --- a/src/s_serv.c +++ b/src/s_serv.c @@ -57,7 +57,9 @@ aMotd *rules; aMotd *motd; aMotd *svsmotd; aMotd *botmotd; +aMotd *smotd; struct tm motd_tm; +struct tm smotd_tm; aMotd *read_file(char *filename, aMotd **list); aMotd *read_file_ex(char *filename, aMotd **list, struct tm *); extern aMotd *Find_file(char *, short); @@ -3533,10 +3535,13 @@ ConfigItem_tld *tlds; motd = (aMotd *) read_file_ex(MPATH, &motd, &motd_tm); rules = (aMotd *) read_file(RPATH, &rules); + smotd = (aMotd *) read_file_ex(SMPATH, &smotd, &smotd_tm); for (tlds = conf_tld; tlds; tlds = (ConfigItem_tld *) tlds->next) { tlds->motd = read_file_ex(tlds->motd_file, &tlds->motd, &tlds->motd_tm); tlds->rules = read_file(tlds->rules_file, &tlds->rules); + if (tlds->smotd_file) + tlds->smotd = read_file_ex(tlds->smotd_file, &tlds->smotd, &tlds->smotd_tm); } } @@ -3675,7 +3680,7 @@ CMD_FUNC(m_rehash) /* Normal rehash, rehash main motd&rules too, just like the on in the tld block will :p */ motd = (aMotd *) read_file_ex(MPATH, &motd, &motd_tm); rules = (aMotd *) read_file(RPATH, &rules); - + smotd = (aMotd *) read_file_ex(SMPATH, &smotd, &smotd_tm); if (cptr == sptr) sendto_one(sptr, rpl_str(RPL_REHASHING), me.name, parv[0], configfile); return rehash(cptr, sptr, (parc > 1) ? ((*parv[1] == 'q') ? 2 : 0) : 0); @@ -3964,6 +3969,77 @@ CMD_FUNC(m_trace) return 0; } +/* + * Heavily modified from the ircu m_motd by codemastr + * Also svsmotd support added + */ +int short_motd(aClient *sptr) { + ConfigItem_tld *ptr; + aMotd *temp, *temp2; + struct tm *tm = &smotd_tm; + char userhost[HOSTLEN + USERLEN + 6]; + char is_short = 1; + strlcpy(userhost,make_user_host(sptr->user->username, sptr->user->realhost), sizeof userhost); + ptr = Find_tld(sptr, userhost); + + if (ptr) + { + if (ptr->smotd) + { + temp = ptr->smotd; + tm = &ptr->smotd_tm; + } + else if (smotd) + temp = smotd; + else + { + temp = ptr->motd; + tm = &ptr->motd_tm; + is_short = 0; + } + } + else + { + if (smotd) + temp = smotd; + else + { + temp = motd; + tm = &motd_tm; + is_short = 0; + } + } + + if (!temp) + { + sendto_one(sptr, err_str(ERR_NOMOTD), me.name, sptr->name); + return 0; + } + if (tm) + { + sendto_one(sptr, rpl_str(RPL_MOTDSTART), me.name, sptr->name, + me.name); + sendto_one(sptr, ":%s %d %s :- %d/%d/%d %d:%02d", me.name, + RPL_MOTD, sptr->name, tm->tm_mday, tm->tm_mon + 1, + 1900 + tm->tm_year, tm->tm_hour, tm->tm_min); + } + if (is_short) + { + sendto_one(sptr, rpl_str(RPL_MOTD), me.name, sptr->name, + "This is the short MOTD. To view the complete MOTD type /motd"); + sendto_one(sptr, rpl_str(RPL_MOTD), me.name, sptr->name, ""); + } + + while (temp) + { + sendto_one(sptr, rpl_str(RPL_MOTD), me.name, sptr->name, + temp->line); + temp = temp->next; + } + sendto_one(sptr, rpl_str(RPL_ENDOFMOTD), me.name, sptr->name); + return 0; +} + /* * Heavily modified from the ircu m_motd by codemastr diff --git a/src/s_user.c b/src/s_user.c index 5bb562c7a..6e23b0352 100644 --- a/src/s_user.c +++ b/src/s_user.c @@ -57,6 +57,7 @@ void send_umode_out_nickv2(aClient *, aClient *, long); void send_umode(aClient *, aClient *, long, long, char *); void set_snomask(aClient *, char *); int create_snomask(char *, int); +extern int short_motd(aClient *sptr); char *get_snostr(long sno); /* static Link *is_banned(aClient *, aChannel *); */ int dontspread = 0; @@ -1018,7 +1019,8 @@ extern int register_user(aClient *cptr, aClient *sptr, char *nick, char *usernam ssl_get_cipher(sptr->ssl)); #endif (void)m_lusers(sptr, sptr, 1, parv); - (void)m_motd(sptr, sptr, 1, parv); + short_motd(sptr); +// (void)m_motd(sptr, sptr, 1, parv); #ifdef EXPERIMENTAL sendto_one(sptr, ":%s NOTICE %s :*** \2NOTE:\2 This server (%s) is running experimental IRC server software. If you find any bugs or problems, please mail unreal-dev@lists.sourceforge.net about it",