unreal32 /Modules/m_delayjoin.c

Language C Lines 272
MD5 Hash 74203f39f2c90ae8c005cd84ab800902 Estimated Cost $4,022 (why?)
Repository https://bitbucket.org/stealth/unreal32 View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*
 * ==================================================================
 * Module:      m_delayjoin.c
 * Author:      Stealth <stealth@x-tab.org>
 * Version:     2.0.2
 * License:     GNU Afferro General Public Licnese
 * Description: Requires clients to be connected for a certain amount
 *              of time before allowing them to join any channels.
 * ==================================================================
 * Copyright (C) 2012  "Stealth" <stealth@x-tab.org>
 *
 * This license grants permission to freely use, modify, and
 * distribute this module with the following conditions:
 * - You must keep this module licensed with the GNU Affero General
 *   Public Licnese, either version 3 or newer.
 * - This copyright notice must stay intact.
 * - You must provide the module source (incluing any modifications)
 *   upon request to anyone who wishes to see it.
 * Please see the GNU AGPL text for full details (link below).
 *
 * 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 Affero General Public License for more details.
 *
 * The full version of the GNU AGPL license may be found at
 * http://www.gnu.org/licenses/agpl.html
 */

/*
 * Configuration:
 *
 * There are 2 directives that need to be set in your unrealircd.conf file:
 *
 * set::delayjoin::time
 *   This should be set to the time users will be unable to join channels after
 * connecting to your server. The default is in seconds, unless you specify
 * otherwise. The time value should be formatted the same as a G:Line.
 *
 * set::delayjoin::reason
 *   This is what will be displayed to users when they attempt to join a
 * channel. The reason will be prefixed with "Cannot join #Channel:". It would
 * probably be helpful to your users if you put the time you set in this
 * reason.
 *
 *
 * ChangeLog:
 *  1/8/2012 - 2.0.2
 *    - Changed license to GNU AGPL
 *
 *  12/31/2011 - 2.0.1
 *    - Don't remember when/why I made the module 2.0.1, but I did...
 *    - Fix whitespaces in docs/changelog. Everything is now consistent.
 *
 *  12/19/2007 - 2.0.0
 *    - Changed module from using Command Override to hooking pre_local_join
 *    - Added configuration
 *    - Thanks to fez for helping with set::auto-join issues
 *
 *  12/18/2007 - 0.0.1
 *    -Initial version (built off of delaylist by w00t <surreal.w00t@gmail.com>)
 *
 *
 *
 * Credits:
 *   - w00t <surreal.w00t@gmail.com>
 *     Initial version was built off of DelayList.
 *
 *   - Syzop <syzop@vulnscan.org>
 *     Configuration stuff was borrowed from the antirandom module
 *
 *   - DukePyrolator <DukePyrolator@FantasyIRC.net>
 *     Guide for hooking pre_local_join in m_onlyopersjoin
 *
 *   - fez <wrongway.org>
 *     Hours of debugging and putting up with my n00bness :P
 */

#include "config.h"
#include "struct.h"
#include "common.h"
#include "sys.h"
#include "numeric.h"
#include "msg.h"
#include "channel.h"
#include <time.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <io.h>
#endif
#include <fcntl.h>
#include "h.h"
#include "proto.h"
#ifdef STRIPBADWORDS
#include "badwords.h"
#endif
#ifdef _WIN32
#include "version.h"
#endif

struct {
	int reason;
	int time;
} req;

struct {
	char *reason;
	long time;
} cfg;

static Cmdoverride *delayjoin_override = NULL;
static ModuleInfo *delayjoin_modinfo = NULL;
static void free_config(void);
#define DelHook(x)    if (x) HookDel(x); x = NULL
Hook   *HookJoin = NULL;

DLLFUNC int delayjoin_config_test(ConfigFile *, ConfigEntry *, int, int *);
DLLFUNC int delayjoin_config_run(ConfigFile *, ConfigEntry *, int);
DLLFUNC int delayjoin_config_posttest(int *);
DLLFUNC int m_delayjoin(aClient *sptr, aChannel *chptr, char *parv[]);

ModuleHeader MOD_HEADER(delayjoin)
  = {
	"delayjoin",	/* Name */
	"2.0.2", /* Ver */
	"Deny /join for newly connected users by Stealth <stealth@x-tab.org>", /* Desc. */
	"3.2-b8-1",
	NULL
    };

DLLFUNC int MOD_TEST(delayjoin)(ModuleInfo *modinfo)
{
	memset(&req, 0, sizeof(req));
	memset(&cfg, 0, sizeof(cfg));
	HookAddEx(modinfo->handle, HOOKTYPE_CONFIGTEST, delayjoin_config_test);
	HookAddEx(modinfo->handle, HOOKTYPE_CONFIGPOSTTEST, delayjoin_config_posttest);
	return MOD_SUCCESS;
}

DLLFUNC int MOD_INIT(delayjoin)(ModuleInfo *modinfo)
{
	delayjoin_modinfo = modinfo;
	HookAddEx(modinfo->handle, HOOKTYPE_CONFIGRUN, delayjoin_config_run);
	HookJoin = HookAddEx(modinfo->handle, HOOKTYPE_PRE_LOCAL_JOIN, m_delayjoin);
	return MOD_SUCCESS;
}

DLLFUNC int MOD_LOAD(delayjoin)(int module_load)
{
	return MOD_SUCCESS;
}

DLLFUNC int MOD_UNLOAD(delayjoin)(int module_unload)
{
	DelHook(HookJoin);
	free_config();
	return MOD_SUCCESS;
}

static void free_config(void)
{
	if (cfg.reason)
		MyFree(cfg.reason);

	memset(&cfg, 0, sizeof(cfg)); /* needed! */
}

DLLFUNC int delayjoin_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs)
{
int errors = 0;
ConfigEntry *cep;

	if (type != CONFIG_SET)
		return 0;

	/* We are only interrested in set::delayjoin... */
	if (!ce || !ce->ce_varname || strcmp(ce->ce_varname, "delayjoin"))
		return 0;

	for (cep = ce->ce_entries; cep; cep = cep->ce_next)
	{
		if (!cep->ce_varname)
		{
			config_error("%s:%i: blank set::delayjoin item",
				cep->ce_fileptr->cf_filename, cep->ce_varlinenum);
			errors++;
		} else
		if (!cep->ce_vardata)
		{
			config_error("%s:%i: set::delayjoin::%s with no value",
				cep->ce_fileptr->cf_filename, cep->ce_varlinenum, cep->ce_varname);
			errors++;
		} else
		if (!strcmp(cep->ce_varname, "reason"))
		{
			req.reason = 1;
		} else
		if (!strcmp(cep->ce_varname, "time"))
		{
			req.time = 1;
		} else
		{
			config_error("%s:%i: unknown directive set::delayjoin::%s",
				cep->ce_fileptr->cf_filename, cep->ce_varlinenum, cep->ce_varname);
			errors++;
		}
	}
	*errs = errors;
	return errors ? -1 : 1;
}

DLLFUNC int delayjoin_config_run(ConfigFile *cf, ConfigEntry *ce, int type)
{
ConfigEntry *cep, *cep2;

	if (type != CONFIG_SET)
		return 0;

	/* We are only interrested in set::delayjoin... */
	if (!ce || !ce->ce_varname || strcmp(ce->ce_varname, "delayjoin"))
		return 0;

	for (cep = ce->ce_entries; cep; cep = cep->ce_next)
	{
		if (!strcmp(cep->ce_varname, "reason"))
		{
			if (cfg.reason)
				MyFree(cfg.reason);
			cfg.reason = strdup(cep->ce_vardata);
		} else
		if (!strcmp(cep->ce_varname, "time"))
		{
			cfg.time = config_checkval(cep->ce_vardata, CFG_TIME);
		}
	}
	return 1;
}

DLLFUNC int delayjoin_config_posttest(int *errs)
{
int errors = 0;

	if (!req.time) { config_error("set::delayjoin::time missing"); errors++; }
	if (!req.reason) { config_error("set::delayjoin::reason missing"); errors++; }

	*errs = errors;
	return errors ? -1 : 1;
}

DLLFUNC int m_delayjoin(aClient *sptr, aChannel *chptr, char *parv[])
{
	if (is_autojoin_chan(chptr->chname))
	  return HOOK_CONTINUE;

	if (!IsAnOper(sptr))
	{
		if ((TStime() - sptr->firsttime) < cfg.time)
		{
			/* DENIED! */
			sendto_one(sptr, ":%s %s %s :*** Cannot join %s: %s", me.name, IsWebTV(sptr) ? "PRIVMSG" : "NOTICE", sptr->name, chptr->chname, cfg.reason);

			return HOOK_DENY;
		}
	}

	/* aww, no fun. they've been connected a while :( - let it through */
	return HOOK_CONTINUE;
}
Back to Top