Need help with HOOKTYPE_LOCAL_NICKCHANGE and m_saname

These are old archives. They are kept for historic purposes only.
Post Reply
Fussi
Posts: 33
Joined: Fri Sep 24, 2004 9:46 pm
Location: At Home
Contact:

Need help with HOOKTYPE_LOCAL_NICKCHANGE and m_saname

Post by Fussi »

Can someone please look at this? I'm not sure if i should use hooks this way and since the documentation is not really up to date... I just dont want to crash my network :)

Thanks!

Code: Select all

DLLFUNC int m_saname(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
	aClient *acptr;
	if (!IsSAdmin(sptr) && !IsULine(sptr))
	{
		sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]);
		return 0;
	}

	if (parc != 3)
	{
		sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "SANAME");
		return 0;
	}

	if (!(acptr = find_person(parv[1], NULL)))
	{
		sendto_one(sptr, err_str(ERR_NOSUCHNICK), me.name, parv[0], parv[1]);
		return 0;
	}

	if (find_client(parv[2], NULL)) /* Collision */
	{
		sendto_one(sptr, err_str(ERR_NICKNAMEINUSE), me.name, parv[0], parv[1]);
		return 0;
	}

	sendto_realops("%s used SANAME to make %s nick %s", sptr->name, parv[1],
	    parv[2]);

	if (MyClient(acptr))
	{
		parv[0] = parv[1];
		parv[1] = parv[2];
		parv[2] = NULL;
		sendto_one(acptr,
		    ":%s %s %s :*** You were forced to change nick to %s", me.name,
		    IsWebTV(acptr) ? "PRIVMSG" : "NOTICE", acptr->name, parv[1]);
//		(void)m_nick(acptr, acptr, 2, parv); <- Old, not working m_nick call
                RunHook2(HOOKTYPE_LOCAL_NICKCHANGE, acptr, parv[2]);
	}
	else
		sendto_one(acptr, ":%s SANAME %s %s", parv[0],
		    parv[1], parv[2]);

	return 0;
}
I'm not sure about the RunHook2, since in m_svsnick there are some other calls;

Code: Select all

                        (void)strlcpy(acptr->name, parv[2], sizeof acptr->name);
                        (void)add_to_client_hash_table(parv[2], acptr);
Syzop
UnrealIRCd head coder
Posts: 2116
Joined: Sat Mar 06, 2004 8:57 pm
Location: .nl
Contact:

Post by Syzop »

(no that's bad indeed ;p)

Basically, to fix these things with newer unreals, this:
m_nick(acptr, acptr, 2, parv);
becomes:
do_cmd(acptr, acptr, "NICK", 2, parv);

Easy fix :)

More technical info..
As usual, underdocumented, though this was put in 'Changes':

Code: Select all

- [Module coders] Added new function: do_cmd(cptr, sptr, cmd, parc, parv) which is an
  uniform method to call any other commands. For more info, see description in src/packet.c.
  This will be used for any further modulization of commands that need to call other
  commands, like NICK (will be done soon).
And the relevant part it refered to from src/packet.c:

Code: Select all

/** Calls the specified command.
 * PURPOSE:
 *  This function is especially meant for calling modulized commands,
 *  both from the core and from (eg:) module A to a command in module B.
 *  An alternative to this is MOD_Dep, but this requires a lot more
 *  effort, is more error phrone and is not a general solution
 *  (but it is slightly faster).
 * PARAMETERS:
 *  Parameters are clear.. the usual cptr, sptr, parc, parv stuff.
 *  'cmd' is the command string, eg: "JOIN"
 * RETURN VALUE:
 *  The value returned by the command function, or -99 if command not found.
 * IMPORTANT NOTES:
 *  - make sure you terminate the last parv[] parameter with NULL,
 *    this can easily be forgotten, but certain functions depend on it,
 *    you risk crashes otherwise.
 *  - be sure to check for FLUSH_BUFFER (-5) return value, especially
 *    if you are calling functions that might cause an immediate kill
 *    (eg: due to spamfilter).
 *  - obvious, but... do not stuff in insane parameters, like a parameter
 *    of 1024 bytes, most of the ircd code depends on the max size of the
 *    total command being less than 512 bytes. Same for parc < MAXPARA.
 */
Fussi
Posts: 33
Joined: Fri Sep 24, 2004 9:46 pm
Location: At Home
Contact:

Post by Fussi »

Yay, thanks!
Well that was kinda easy :P
Syzop
UnrealIRCd head coder
Posts: 2116
Joined: Sat Mar 06, 2004 8:57 pm
Location: .nl
Contact:

Post by Syzop »

(unnecessary comment from myself removed, don't ask ;p)

Yup ;p
aquanight
Official supporter
Posts: 862
Joined: Tue Mar 09, 2004 10:47 pm
Location: Boise, ID

Post by aquanight »

Out of curiosity, do token strings work? (If so, is it always or only for IsServer(cptr)?)
Syzop
UnrealIRCd head coder
Posts: 2116
Joined: Sat Mar 06, 2004 8:57 pm
Location: .nl
Contact:

Post by Syzop »

Yeah tokens work (in all cases), though.. I would say.. just use normal commands, since that's more clear :P.
aquanight
Official supporter
Posts: 862
Joined: Tue Mar 09, 2004 10:47 pm
Location: Boise, ID

Post by aquanight »

do_cmd(acptr, acptr, TOK_NICK, 2, parv); isn't clear? :P

But yeah, I suppose the difference between using message vs. token when it's just a function call is probably nil.
Syzop
UnrealIRCd head coder
Posts: 2116
Joined: Sat Mar 06, 2004 8:57 pm
Location: .nl
Contact:

Post by Syzop »

Actually it will be slower, but I'm getting a bit tired about this ""discussion"" :P
pstruh22
Posts: 48
Joined: Mon Jan 31, 2005 2:14 pm

hi

Post by pstruh22 »

Hi, can you send me this module ?? on email

thanks a lot

[MODERATOR: Email removed, use forum PMs]
Post Reply