1 /*
2  *   IRC - Internet Relay Chat, src/modules/out.c
3  *   (C) 2004 The UnrealIRCd Team
4  *
5  *   See file AUTHORS in IRC package for additional names of
6  *   the programmers.
7  *
8  *   This program is free software; you can redistribute it and/or modify
9  *   it under the terms of the GNU General Public License as published by
10  *   the Free Software Foundation; either version 1, or (at your option)
11  *   any later version.
12  *
13  *   This program is distributed in the hope that it will be useful,
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *   GNU General Public License for more details.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with this program; if not, write to the Free Software
20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22 #include "config.h"
23 #include "struct.h"
24 #include "common.h"
25 #include "sys.h"
26 #include "numeric.h"
27 #include "msg.h"
28 #include "proto.h"
29 #include "channel.h"
30 #include <time.h>
31 #include <sys/stat.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #ifdef _WIN32
36 #include <io.h>
37 #endif
38 #include <fcntl.h>
39 #include "h.h"
40 #ifdef STRIPBADWORDS
41 #include "badwords.h"
42 #endif
43 #ifdef _WIN32
44 #include "version.h"
45 #endif
46 
47 DLLFUNC int m_rules(aClient *cptr, aClient *sptr, int parc, char *parv[]);
48 
49 #define MSG_RULES 	"RULES"
50 #define TOK_RULES 	"t"
51 
52 ModuleHeader MOD_HEADER(m_rules)
53   = {
54 	"m_rules",
55 	"$Id$",
56 	"command /rules",
57 	"3.2-b8-1",
58 	NULL
59     };
60 
MOD_INIT(m_rules)61 DLLFUNC int MOD_INIT(m_rules)(ModuleInfo *modinfo)
62 {
63 	add_Command(MSG_RULES, TOK_RULES, m_rules, MAXPARA);
64 	MARK_AS_OFFICIAL_MODULE(modinfo);
65 	return MOD_SUCCESS;
66 }
67 
MOD_LOAD(m_rules)68 DLLFUNC int MOD_LOAD(m_rules)(int module_load)
69 {
70 	return MOD_SUCCESS;
71 }
72 
MOD_UNLOAD(m_rules)73 DLLFUNC int MOD_UNLOAD(m_rules)(int module_unload)
74 {
75 	if (del_Command(MSG_RULES, TOK_RULES, m_rules) < 0)
76 	{
77 		sendto_realops("Failed to delete commands when unloading %s",
78 			MOD_HEADER(m_rules).name);
79 	}
80 	return MOD_SUCCESS;
81 }
82 
83 /*
84  * Heavily modified from the ircu m_motd by codemastr
85  * Also svsmotd support added
86  */
CMD_FUNC(m_rules)87 DLLFUNC CMD_FUNC(m_rules)
88 {
89 	ConfigItem_tld *ptr;
90 	aMotdLine *temp;
91 	char userhost[USERLEN + HOSTLEN + 6];
92 
93 	temp = NULL;
94 
95 	if (IsServer(sptr))
96 		return 0;
97 
98 	if (hunt_server_token(cptr, sptr, MSG_RULES, TOK_RULES, ":%s", 1, parc,
99 	    parv) != HUNTED_ISME)
100 		return 0;
101 #ifndef TLINE_Remote
102 	if (!MyConnect(sptr))
103 	{
104 		temp = rules.lines;
105 		goto playrules;
106 	}
107 #endif
108 	strlcpy(userhost,make_user_host(cptr->user->username, cptr->user->realhost), sizeof userhost);
109 	ptr = Find_tld(sptr, userhost);
110 
111 	if (ptr)
112 		temp = ptr->rules.lines;
113 	if(!temp)
114 		temp = rules.lines;
115 
116       playrules:
117 	if (temp == NULL)
118 	{
119 		sendto_one(sptr, err_str(ERR_NORULES), me.name, parv[0]);
120 		return 0;
121 
122 	}
123 
124 	sendto_one(sptr, rpl_str(RPL_RULESSTART), me.name, parv[0], me.name);
125 
126 	while (temp)
127 	{
128 		sendto_one(sptr, rpl_str(RPL_RULES), me.name, parv[0],
129 		    temp->line);
130 		temp = temp->next;
131 	}
132 	sendto_one(sptr, rpl_str(RPL_ENDOFRULES), me.name, parv[0]);
133 	return 0;
134 }
135