Page 1 of 1

Need help with HOOKTYPE_LOCAL_NICKCHANGE and m_saname

Posted: Fri Sep 23, 2005 6:09 am
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);

Posted: Fri Sep 23, 2005 4:29 pm
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.
 */

Posted: Fri Sep 23, 2005 4:39 pm
by Fussi
Yay, thanks!
Well that was kinda easy :P

Posted: Fri Sep 23, 2005 8:25 pm
by Syzop
(unnecessary comment from myself removed, don't ask ;p)

Yup ;p

Posted: Sat Sep 24, 2005 6:25 am
by aquanight
Out of curiosity, do token strings work? (If so, is it always or only for IsServer(cptr)?)

Posted: Sat Sep 24, 2005 2:22 pm
by Syzop
Yeah tokens work (in all cases), though.. I would say.. just use normal commands, since that's more clear :P.

Posted: Sat Sep 24, 2005 4:19 pm
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.

Posted: Sat Sep 24, 2005 4:31 pm
by Syzop
Actually it will be slower, but I'm getting a bit tired about this ""discussion"" :P

hi

Posted: Wed Feb 22, 2006 12:51 pm
by pstruh22
Hi, can you send me this module ?? on email

thanks a lot

[MODERATOR: Email removed, use forum PMs]