[IRCServices] Some help on cooding

Pinto, Joao Luis (J.) jpinto9 at visteon.com
Fri Nov 12 00:08:56 PST 1999


One of the firts things I changed from Church Services was to make the
identify and nick change on Ghost command, I have been using this for 6
months with a 7 ircd network and I had no problems with it.
Notice that this function will replace release, since it will call
ghost_release when needed.

*Log2() - is a file/channel log function, you can replace it with the the
log() function
/*************************************************************************/

static void do_ghost(User *u)
{
    char *nick = strtok(NULL, " ");
    char *pass = strtok(NULL, " ");
    NickInfo *ni;
    User *u2;

    if (!nick) {
	syntax_error(s_NickServ, u, "GHOST", NICK_GHOST_SYNTAX);
    } else if (!(u2 = finduser(nick))) {
	if ((ni = findnick(nick)) && (ni->status & NS_KILL_HELD))
do_ghost_release(u, ni, nick, pass);
	    else notice_lang(s_NickServ, u, NICK_X_NOT_IN_USE, nick);
    } else if (!(ni = u2->real_ni)) {
	notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED, nick);
    } else if (stricmp(nick, u->nick) == 0) {
	notice_lang(s_NickServ, u, NICK_NO_GHOST_SELF);
    } else if (pass) {
	int res = check_password(pass, ni->pass);
	if (res == 1) {
	    char buf[NICKMAX+32];
	    snprintf(buf, sizeof(buf), "GHOST command used by %s", u->nick);
	    kill_user(s_NickServ, nick, buf);
	    notice_lang(s_NickServ, u, NICK_GHOST_KILLED, nick);
	    ni->status |= (NS_IDENTIFIED | NS_RECOGNIZED);	   
	    ni->id_timestamp = u->signon;
	    ni->last_seen = time(NULL);
	    if (ni->last_usermask)
	      free(ni->last_usermask);
	    ni->last_usermask =
smalloc(strlen(u->username)+strlen(u->host)+2);
	    sprintf(ni->last_usermask, "%s@%s", u->username, u->host);
	    if (ni->last_realname)
		free(ni->last_realname);
	    ni->last_realname = sstrdup(u->realname);
	    log2("%s: %s!%s@%s identified on ghost for nick %s", s_NickServ,
			u->nick, u->username, u->host, nick);
	    send_cmd(MODE_SENDER(s_NickServ), "SVSNICK %s %s %ld", 
	    	u->nick,nick,time(NULL));
	    send_cmd(MODE_SENDER(s_NickServ), "SVS2MODE %s +r", 
	    	nick);	
		/* PTlink Services only
	    if ((ni->flags & NI_AUTO_JOIN) && (ni->ajoincount>0))

		autojoin(u,ni); /* should ajoin on ghost - noticed by
Bubinhas */
		*/ -------------------
	    check_memos(u);
	} else {
	    notice_lang(s_NickServ, u, ACCESS_DENIED);
	    if (res == 0) {
		log2("%s: GHOST: invalid password for %s by %s!%s@%s",
			s_NickServ, nick, u->nick, u->username, u->host);
		bad_password(u);
	    }
	}
    } else {
	if (!(ni->flags & NI_SECURE) && is_on_access(u, ni)) {
	    char buf[NICKMAX+32];
	    snprintf(buf, sizeof(buf), "GHOST command used by %s", u->nick);
	    kill_user(s_NickServ, nick, buf);
	    notice_lang(s_NickServ, u, NICK_GHOST_KILLED, nick);
	    ni->status |= (NS_IDENTIFIED | NS_RECOGNIZED);	   
	    ni->id_timestamp = u->signon;
	    ni->last_seen = time(NULL);
	    if (ni->last_usermask)
	      free(ni->last_usermask);
	    ni->last_usermask =
smalloc(strlen(u->username)+strlen(u->host)+2);
	    sprintf(ni->last_usermask, "%s@%s", u->username, u->host);
	    if (ni->last_realname)
		free(ni->last_realname);
	    ni->last_realname = sstrdup(u->realname);
	    log2("%s: %s!%s@%s identified on ghost for nick %s", s_NickServ,
			u->nick, u->username, u->host, u->nick);
	    send_cmd(MODE_SENDER(s_NickServ), "SVSNICK %s %s %ld", 
	    	u->nick,nick,time(NULL));
	    send_cmd(MODE_SENDER(s_NickServ), "SVS2MODE %s +r %s", 
	    	u->nick,nick);		
	    if ((ni->status & NS_RECOGNIZED))
	    	  check_memos(u);
	} else {
	    notice_lang(s_NickServ, u, ACCESS_DENIED);
	}
    }
}

/*************************************************************************/

/*************************************************************************/
static void do_ghost_release(User *u, NickInfo *ni,char* nick, char* pass) {
    int res;
    if (!pass) {
    	syntax_error(s_NickServ, u, "GHOST", NICK_GHOST_SYNTAX);
	return;
    }
    res = check_password(pass, ni->pass);
    if (res == 1) {
	    release(ni, 0);
	    notice_lang(s_NickServ, u, NICK_RELEASED);
	    ni->status |= (NS_IDENTIFIED | NS_RECOGNIZED);
	    ni->id_timestamp = u->signon;
	    ni->last_seen = time(NULL);
	    if (ni->last_usermask)
	      free(ni->last_usermask);
	    ni->last_usermask =
smalloc(strlen(u->username)+strlen(u->host)+2);
	    sprintf(ni->last_usermask, "%s@%s", u->username, u->host);
	    if (ni->last_realname)
		free(ni->last_realname);
	    ni->last_realname = sstrdup(u->realname);
	    log2("%s: %s!%s@%s identified on release for nick %s",
s_NickServ,
			u->nick, u->username, u->host, nick);
	    send_cmd(MODE_SENDER(s_NickServ), "SVSNICK %s %s %ld", 
	    	u->nick,nick,time(NULL));
	    send_cmd(MODE_SENDER(s_NickServ), "SVS2MODE %s +r", nick);

	    if ((ni->flags & NI_AUTO_JOIN) && (ni->ajoincount>0)) 
		    autojoin(u,ni); /* should ajoin on ghost - reported by
Bubinhas */
	    check_memos(u);	    
	    
	}
    else { log2("%s: GHOST RELEASE: invalid password for %s by %s!%s@%s",
		s_NickServ, nick, u->nick, u->username, u->host);
		bad_password(u);		
	}
}



João Luís Marques Pinto
PTlink Tech - Lamego at PTlink.net
PTlink Coders - Coders at PTlink.net
http://www.PTlink.net  




-----Original Message-----
From: root of all evil [<A  HREF="mailto:climber at rionet.com.br">mailto:climber at rionet.com.br</A>]
Sent: quinta-feira, 11 de novembro de 1999 18:48
To: ircservices at ender.shadowfire.org
Subject: [IRCServices] Some help on cooding


Hi guys

 i dontknow if this is oftopyc, but the nickserv release and ghost seems a
quiteanoying to me, you have to use 3 comands to getyour nick back
/m nickserv release (nick) (pass)
/nick nick
/mnickserv identify (pass)

so, i tried todo things easyerwhitthis code :
static void do_release(User *u)
{
    char *nick = strtok(NULL, " ");
    char *pass = strtok(NULL, " ");    
    NickInfo *ni;
    

    if (!nick) {
	syntax_error(s_NickServ, u, "RELEASE", NICK_RELEASE_SYNTAX);
    } else if (!(ni = findnick(nick))) {
	notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED, nick);
    } else if (!(ni->status & NS_KILL_HELD)) {
	notice_lang(s_NickServ, u, NICK_RELEASE_NOT_HELD, nick);
    } else if (pass) {
	int res = check_password(pass, ni->pass);
	if (res == 1) {	  
	    release(ni, 0);
	    notice_lang(s_NickServ, u, NICK_RELEASED);
	    send_cmd(s_NickServ, "SVSNICK %s %s :%lu", u->nick, nick,
		time(NULL));
 	    change_user_nick(u, nick); /* placede on Extern.h this function
is
                                                        * from users.c */
	    /* indentify */
            ni->status |= NS_IDENTIFIED;
            ni->id_timestamp = u->signon;
            ni->last_seen = time(NULL);
            if (ni->last_usermask)
              free(ni->last_usermask);
            ni->last_usermask =
smalloc(strlen(u->username)+strlen(u->host)+2);
            sprintf(ni->last_usermask, "%s@%s", u->username, u->host);
            if (ni->last_realname)
                free(ni->last_realname);
            ni->last_realname = sstrdup(u->realname);	    
	    send_cmd(s_NickServ,"SVSMODE %s :+r", u->nick);
            u->mode |= UMODE_R;            
            notice(s_NickServ, nick, "Password accepted - you are now
recognized");
	log("%s: %s!%s@%s identified on RELEASE for nick %s", s_NickServ,
u->nick, u->username, u->host, nick);
	check_memos(u);
             } else {
             notice_lang(s_NickServ, u, ACCESS_DENIED);               
	    if (res == 0) {
		log("%s: RELEASE: invalid password for %s by %s!%s@%s",
			s_NickServ, nick, u->nick, u->username, u->host);
		bad_password(u);
	    }
	}
    } 
}

/*end*/

Well, the problem is : this orks well on my testnet, (only onde ircd and
services ) on main network,  the SVSNICK may take a litle  time, so the
SVSMODE
and the notice dont ket sent to the righ user (ircd returns User not found),
but the new nick is identifyed , only the +r flag and notice to user dont
works)

Anyone knows a beter way to do this ? 
      
Realy sory for my english, and a keyboard whith broken space bar ( no joke
:))
FiGhTER
Irc.rionet.com.br
BrasIRC.com.br (irc.brasirc.com.br)
 
---------------------------------------------------------------
To unsubscribe, send email to majordomo at ender.shadowfire.org
with "unsubscribe ircservices" in the body, without the quotes.
---------------------------------------------------------------
To unsubscribe, send email to majordomo at ender.shadowfire.org
with "unsubscribe ircservices" in the body, without the quotes.