[How to] Adding command before pre-connect

These are old archives. They are kept for historic purposes only.
Post Reply
xwerswoodx
Posts: 3
Joined: Sun Jun 26, 2016 6:59 pm

[How to] Adding command before pre-connect

Post by xwerswoodx »

I have a problem with adding command before HOOKTYPE_PRE_LOCAL_CONNECT.

UNREAL 3.2.10.6

I want to add a /GCODE command and when it start to connect to unreal it has to use /GCODE to login;

Code: Select all

DLLFUNC int MOD_INIT(m_logincode)(ModuleInfo *module) {
    if (!CommandExists(MSG_GCODE))
		CommandAdd(module->handle, MSG_GCODE, TOK_GCODE, m_giris, 1, M_USER);
		
    if (!CommandExists(MSG_GCODEON))
		CommandAdd(module->handle, MSG_GCODE, TOK_GCODEON, m_girisac, 1, M_USER);

    if (!CommandExists(MSG_GCODEOFF))
		CommandAdd(module->handle, MSG_GCODEOFF, TOK_GCODEOFF, m_giriskapat, 1, M_USER);	
	return MOD_SUCCESS;
}

DLLFUNC int MOD_LOAD(m_logincode)(int module_load, ModuleInfo *module) {
	PLC = HookAddEx(m_logincode.handle, HOOKTYPE_PRE_LOCAL_CONNECT, prelogincode);
	if (!PLC)
		return MOD_FAILED;

	return MOD_SUCCESS;
}
This is my init and load sections, when I use this and connect to server, I can use commands but at the start of server It doesn't working.

Code: Select all

static int prelogincode(aClient *cptr, ModuleInfo *module) {
	if (MyConnect(cptr)) {
	    if (!CommandExists(MSG_GCODE))
			CommandAdd(module->handle, MSG_GCODE, TOK_GCODE, m_giris, 1, M_USER);
	    sendto_one(cptr, ":%s NOTICE %s :*** Mod Aktif.", me.name, cptr->name); 
	}
	return HOOK_DENY;
}
When I use this, it block the user at pre-connect (like what I want) and after that point user should use /GCODE to login but,

Code: Select all

DLLFUNC CMD_FUNC(m_giris) {
//	register_user(cptr, sptr, sptr->name, sptr->user->username, NULL, NULL, NULL);
//	HookDel(PLC);
    sendto_one(sptr, ":%s NOTICE %s :*** Verification Ok.", me.name, sptr->name); 
//	PLC = HookAddEx(m_logincode.handle, HOOKTYPE_PRE_LOCAL_CONNECT, prelogincodeok);
	return 0;
}
When I already connected server, and use /GCODE it said Verification Ok. But when I use it on pre-connect function (I added it to parse.c so I can use command) it doesn't send any notice to me.

I don't know if I explain well, what I want but here is all code;

Code: Select all

#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 

typedef struct _JEvent {
	Event *event;
} JEvent;

#define MSG_GCODE        "GCODE" 
#define TOK_GCODE        "GCD1"
#define MSG_GCODEON      "GON"
#define TOK_GCODEON      "GCD2"
#define MSG_GCODEOFF     "GOFF"
#define TOK_GCODEOFF     "GCD3"

ModuleInfo m_logincode;
static int prelogincode(aClient *, ModuleInfo *);
static int prelogincodeok(aClient *);
static Hook *PLC = NULL;
DLLFUNC int m_giris(aClient *cptr, aClient *sptr, int parc, char *parv[]);
DLLFUNC int m_girisac(aClient *cptr, aClient *sptr, int parc, char *parv[]);
DLLFUNC int m_giriskapat(aClient *cptr, aClient *sptr, int parc, char *parv[]);
int GirisAc = 0;

ModuleHeader MOD_HEADER(m_logincode) = {
	"m_logincode",
	"$Id: m_logincode.c,v 1.1 2011/03/17 00:42:25 xwerswoodx Exp $",
	"Login code system. (xwerswoodx)",
	"3.2-b8-1",
	NULL 
};

ModuleInfo m_logincode;

DLLFUNC int MOD_TEST(m_logincode)(ModuleInfo *module) {
	return MOD_SUCCESS;
}

DLLFUNC int MOD_INIT(m_logincode)(ModuleInfo *module) {
    if (!CommandExists(MSG_GCODE))
		CommandAdd(module->handle, MSG_GCODE, TOK_GCODE, m_giris, 1, M_USER);
		
    if (!CommandExists(MSG_GCODEON))
		CommandAdd(module->handle, MSG_GCODE, TOK_GCODEON, m_girisac, 1, M_USER);

    if (!CommandExists(MSG_GCODEOFF))
		CommandAdd(module->handle, MSG_GCODEOFF, TOK_GCODEOFF, m_giriskapat, 1, M_USER);	
	return MOD_SUCCESS;
}

DLLFUNC int MOD_LOAD(m_logincode)(int module_load, ModuleInfo *module) {
	PLC = HookAddEx(m_logincode.handle, HOOKTYPE_PRE_LOCAL_CONNECT, prelogincode);
	if (!PLC)
		return MOD_FAILED;

	return MOD_SUCCESS;
}

DLLFUNC int MOD_UNLOAD(m_logincode)(int module_unload) {
	return MOD_SUCCESS;
}

static int prelogincode(aClient *cptr, ModuleInfo *module) {
	if (MyConnect(cptr)) {
	    if (!CommandExists(MSG_GCODE))
			CommandAdd(module->handle, MSG_GCODE, TOK_GCODE, m_giris, 1, M_USER);
	    sendto_one(cptr, ":%s NOTICE %s :*** Mod Aktif.", me.name, cptr->name); 
	}
//	return HOOK_CONTINUE;
	return HOOK_ALLOW;
}

static int prelogincodeok(aClient *cptr) {
	if (MyConnect(cptr)) {
	    sendto_one(cptr, ":%s NOTICE %s :*** Giriş başarılı.", me.name, cptr->name); 
	}
	return HOOK_CONTINUE;
}


DLLFUNC CMD_FUNC(m_giris) {
//	register_user(cptr, sptr, sptr->name, sptr->user->username, NULL, NULL, NULL);
//	HookDel(PLC);
    sendto_one(sptr, ":%s NOTICE %s :*** Ok.", me.name, sptr->name); 
//	PLC = HookAddEx(m_logincode.handle, HOOKTYPE_PRE_LOCAL_CONNECT, prelogincodeok);
	return 0;
}

DLLFUNC CMD_FUNC(m_girisac) {
	if (!sptr)
	return 0;
	if (!sptr->name)
	return 0;
	if (!IsOper(sptr))
	return 0;
	GirisAc = 1;
	sendto_snomask(SNO_EYES, "%s activated the secure code.", sptr->name);
	sendto_one(sptr, ":%s NOTICE %s :Güvenlik kodu açıldı.", me.name, sptr->name);
	return 0;
}

DLLFUNC CMD_FUNC(m_giriskapat) {
	if (!sptr)
	return 0;
	if (!sptr->name)
	return 0;
	if (!IsOper(sptr))
	return 0;
	GirisAc = 0;
	sendto_snomask(SNO_EYES, "%s deactivated the secure code.", sptr->name);
	sendto_one(sptr, ":%s NOTICE %s :Güvenlik kodu kapatıldı.", me.name, sptr->name);
	return 0;
}
Easily:
I want to stop user's login at
[20:25:05] -irc.server.org- *** Looking up your hostname...
[20:25:05] -irc.server.org- *** Found your hostname

and ask a code for login. and he use /GCODE code to login.
xwerswoodx
Posts: 3
Joined: Sun Jun 26, 2016 6:59 pm

Re: [How to] Adding command before pre-connect

Post by xwerswoodx »

I can't edit my post and I forgot to send parse.c

Line: 353:

Code: Select all

if (!IsRegistered(cptr) && stricmp(ch, "NOTICE") && stricmp(ch, "GCODE")) {
xwerswoodx
Posts: 3
Joined: Sun Jun 26, 2016 6:59 pm

Re: [How to] Adding command before pre-connect

Post by xwerswoodx »

Sorry for flood, but I can't edit my posts, so I solved my problem with;

Code: Select all

		add_CommandX(MSG_GCODE, TOK_GCODE, m_giris, 1, M_USER|M_SERVER|M_RESETIDLE|M_VIRUS|M_UNREGISTERED);
I just want to post here maybe someone need it.
Post Reply