Kod: Kodu kopyalamak için üzerine çift tıklayın!
#include "config.h"
#include "struct.h"
#include "common.h"
#include "sys.h"
#include "numeric.h"
#include "msg.h"
#include "proto.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"
#ifdef STRIPBADWORDS
#include "badwords.h"
#endif
#ifdef _WIN32
#include "version.h"
#endif
#define J(x) auser[(x) ? (x)->slot : 0]
typedef struct _JEvent {
Event *event;
} JEvent;
static JEvent *auser[4096];
static Hook *JH = NULL, *PJH = NULL, *PCH = NULL, *PCX = NULL, *QH = NULL;
ModuleInfo joindelay;
DLLFUNC int joindelay_ct(ConfigFile *, ConfigEntry *, int, int *);
DLLFUNC int joindelay_cr(ConfigFile *, ConfigEntry *, int);
DLLFUNC int joindelay_cpt(int *);
DLLFUNC int nickreover();
DLLFUNC int nickover(Cmdoverride *ovr, aClient *cptr, aClient *sptr, int parc, char *parv[]);
static int ptime = 0;
static int pre_connect_h(aClient *);
static int connect_h(aClient *);
static int quit_h(aClient *, char *);
static int join_h(aClient *, aChannel *, char *[]);
static void join_stuff(aClient *);
ModuleHeader MOD_HEADER(joindelay) = {
"joindelay",
"JOIN delay module (fixed RAW JOIN bypass)",
"Adds a delay before allowing users to JOIN channels",
"3.2-b8-1",
NULL
};
ModuleInfo joindelay;
DLLFUNC int MOD_TEST(joindelay)(ModuleInfo *module)
{
bcopy(module, &joindelay, module->size);
HookAddEx(joindelay.handle, HOOKTYPE_CONFIGTEST, joindelay_ct);
HookAddEx(joindelay.handle, HOOKTYPE_CONFIGPOSTTEST, joindelay_cpt);
return MOD_SUCCESS;
}
DLLFUNC int MOD_INIT(joindelay)(ModuleInfo *module)
{
ModuleSetOptions(joindelay.handle, MOD_OPT_PERM);
JH = HookAddEx(joindelay.handle, HOOKTYPE_PRE_LOCAL_JOIN, join_h);
PJH = HookAddEx(joindelay.handle, HOOKTYPE_PRE_JOIN, join_h);
PCH = HookAddEx(joindelay.handle, HOOKTYPE_PRE_LOCAL_CONNECT, pre_connect_h);
PCX = HookAddEx(joindelay.handle, HOOKTYPE_LOCAL_CONNECT, connect_h);
QH = HookAddEx(joindelay.handle, HOOKTYPE_LOCAL_QUIT, quit_h);
HookAddEx(joindelay.handle, HOOKTYPE_CONFIGRUN, joindelay_cr);
HookAddEx(joindelay.handle, HOOKTYPE_REHASH_COMPLETE, nickreover);
if (!JH || !PCH || !PCX || !QH || !PJH)
return MOD_FAILED;
return MOD_SUCCESS;
}
DLLFUNC int MOD_LOAD(joindelay)(int module_load)
{
CmdoverrideAdd(joindelay.handle, "NICK", nickover);
return MOD_SUCCESS;
}
DLLFUNC int MOD_UNLOAD(joindelay)(int module_unload)
{
if (JH) HookDel(JH);
if (PJH) HookDel(PJH);
if (PCH) HookDel(PCH);
if (PCX) HookDel(PCX);
if (QH) HookDel(QH);
return MOD_SUCCESS;
}
DLLFUNC int nickreover()
{
CmdoverrideAdd(joindelay.handle, "NICK", nickover);
return 1;
}
DLLFUNC int joindelay_ct(ConfigFile *cf, ConfigEntry *ce, int type, int *errs)
{
int errors = 0;
if (type != CONFIG_SET)
return 0;
if (!strcmp(ce->ce_varname, "join-delay"))
{
if (!ce->ce_vardata)
{
config_error("Make sure you have the join-delay set!");
errors++;
}
ptime = 1;
*errs = errors;
return errors ? -1 : 1;
}
return 0;
}
DLLFUNC int joindelay_cr(ConfigFile *cf, ConfigEntry *ce, int type)
{
if (type != CONFIG_SET)
return 0;
if (!strcmp(ce->ce_varname, "join-delay"))
{
ptime = config_checkval(ce->ce_vardata, CFG_TIME);
return 1;
}
return 0;
}
DLLFUNC int joindelay_cpt(int *errs)
{
int errors = 0;
if (!ptime)
{
config_error("Make sure you have the join-delay set!");
errors++;
}
*errs = errors;
return errors ? -1 : 1;
}
static int join_h(aClient *cptr, aChannel *chptr, char *parv[])
{
if (!cptr)
return HOOK_CONTINUE;
if (!MyConnect(cptr))
return HOOK_CONTINUE;
if (!J(cptr))
return HOOK_CONTINUE;
if (!IsAnOper(cptr))
{
time_t elapsed = TStime() - cptr->firsttime;
if (elapsed < ptime)
{
int remain = ptime - elapsed;
sendto_one(cptr, ":%s NOTICE %s :You must wait %d more seconds before joining channels.",
me.name, cptr->name, remain);
return HOOK_DENY;
}
}
return HOOK_CONTINUE;
}
static void join_stuff(aClient *cptr)
{
if (!cptr) return;
if (IsAnOper(cptr)) return;
if (!BadPtr(AUTO_JOIN_CHANS) && strcmp(AUTO_JOIN_CHANS, "0") &&
cptr->listener->port != 7013 && cptr->listener->port != 7014)
{
char *chans[3] = { cptr->name, AUTO_JOIN_CHANS, NULL };
do_cmd(cptr, cptr, "JOIN", 3, chans);
}
}
static int pre_connect_h(aClient *cptr)
{
if (!cptr) return HOOK_CONTINUE;
if (MyConnect(cptr))
{
if (!J(cptr))
{
J(cptr) = MyMallocEx(sizeof(JEvent));
memset(J(cptr), 0, sizeof(JEvent));
J(cptr)->event = EventAddEx(joindelay.handle, "join-stuff", ptime, 1, join_stuff, cptr);
}
}
return HOOK_CONTINUE;
}
static int connect_h(aClient *cptr)
{
if (!cptr) return HOOK_CONTINUE;
if (MyConnect(cptr)) {
sendto_one(cptr, ":%s NOTICE %s :Your connection is being scanned for proxies.", me.name, cptr->name);
sendto_one(cptr, ":%s NOTICE %s :You will be automatically joined to channels in %d seconds.",
me.name, cptr->name, ptime - (TStime() - cptr->firsttime));
}
return HOOK_CONTINUE;
}
static int quit_h(aClient *cptr, char *comment)
{
if (!cptr) return 0;
if (MyConnect(cptr))
{
if (J(cptr))
{
if (J(cptr)->event)
EventDel(J(cptr)->event);
memset(J(cptr), 0, sizeof(JEvent));
MyFree(J(cptr));
J(cptr) = NULL;
}
}
return 0;
}
DLLFUNC int nickover(Cmdoverride *ovr, aClient *cptr, aClient *sptr, int parc, char *parv[])
{
if (sptr && MyConnect(sptr))
{
if (cptr && J(cptr) && !IsAnOper(cptr) && (TStime() - cptr->firsttime) < ptime)
return 0;
}
if (ovr->prev)
return ovr->prev->func(ovr->prev, cptr, sptr, parc, parv);
return ovr->command->func(cptr, sptr, parc, parv);
}