/*! \brief NICK command handler (called by already registered, * locally connected clients) * * \param client_p Pointer to allocated Client struct with physical connection * to this server, i.e. with an open socket connected. * \param source_p Pointer to allocated Client struct from which the message * originally comes from. This can be a local or remote client. * \param parc Integer holding the number of supplied arguments. * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL * pointers. * \note Valid arguments for this command are: * - parv[0] = sender prefix * - parv[1] = nickname */ static void m_nick(struct Client *client_p, struct Client *source_p, int parc, char *parv[]) { char nick[NICKLEN + 1] = { '\0' }; struct Client *target_p = NULL; struct MaskItem *conf = NULL; assert(source_p == client_p); if (parc < 2 || EmptyString(parv[1])) { sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), me.name, source_p->name); return; } /* mark end of grace period, to prevent nickflooding */ if (!IsFloodDone(source_p)) flood_endgrace(source_p); /* terminate nick to NICKLEN */ strlcpy(nick, parv[1], IRCD_MIN(sizeof(nick), ServerInfo.max_nick_length + 1)); /* check the nickname is ok */ if (!valid_nickname(nick, 1)) { sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name, source_p->name, nick, "Erroneous Nickname"); return; } if (!IsExemptResv(source_p) && !(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv) && (conf = find_matching_name_conf(CONF_NRESV, nick, NULL, NULL, 0))) { ++conf->count; sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name, source_p->name, nick, conf->reason); sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE, "Forbidding reserved nick [%s] from user %s", nick, get_client_name(client_p, HIDE_IP)); return; } if ((target_p = hash_find_client(nick)) == NULL) change_local_nick(source_p, nick); else if (target_p == source_p) { /* * If (target_p == source_p) the client is changing nicks between * equivalent nicknames ie: [nick] -> {nick} */ /* Check the nick isn't exactly the same */ if (strcmp(target_p->name, nick)) change_local_nick(source_p, nick); } else if (IsUnknown(target_p)) { /* * If the client that has the nick isn't registered yet (nick but no * user) then drop the unregged client */ exit_client(target_p, &me, "Overridden"); change_local_nick(source_p, nick); } else sendto_one(source_p, form_str(ERR_NICKNAMEINUSE), me.name, source_p->name, nick); }
/*! \brief NICK command handler (called by already registered, * locally connected clients) * * \param client_p Pointer to allocated Client struct with physical connection * to this server, i.e. with an open socket connected. * \param source_p Pointer to allocated Client struct from which the message * originally comes from. This can be a local or remote client. * \param parc Integer holding the number of supplied arguments. * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL * pointers. * \note Valid arguments for this command are: * - parv[0] = sender prefix * - parv[1] = nickname */ static void m_nick(struct Client *client_p, struct Client *source_p, int parc, char *parv[]) { char nick[NICKLEN]; struct Client *target_p = NULL; if (parc < 2 || EmptyString(parv[1])) { sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), me.name, source_p->name); return; } /* mark end of grace period, to prevent nickflooding */ if (!IsFloodDone(source_p)) flood_endgrace(source_p); /* terminate nick to NICKLEN */ strlcpy(nick, parv[1], sizeof(nick)); /* check the nickname is ok */ if (!clean_nick_name(nick, 1)) { sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name, source_p->name, nick); return; } if (find_matching_name_conf(NRESV_TYPE, nick, NULL, NULL, 0) && !IsExemptResv(source_p) && !(IsOper(source_p) && ConfigFileEntry.oper_pass_resv)) { sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name, source_p->name, nick); return; } if ((target_p = find_client(nick)) == NULL) change_local_nick(client_p, source_p, nick); else if (target_p == source_p) { /* * If (target_p == source_p) the client is changing nicks between * equivalent nicknames ie: [nick] -> {nick} */ /* check the nick isnt exactly the same */ if (strcmp(target_p->name, nick)) change_local_nick(client_p, source_p, nick); } else if (IsUnknown(target_p)) { /* * if the client that has the nick isn't registered yet (nick but no * user) then drop the unregged client */ exit_client(target_p, &me, "Overridden"); change_local_nick(client_p, source_p, nick); } else sendto_one(source_p, form_str(ERR_NICKNAMEINUSE), me.name, source_p->name, nick); }
/* * m_nick() * * parv[0] = sender prefix * parv[1] = nickname */ static void m_nick(struct Client *client_p, struct Client *source_p, int parc, char *parv[]) { char nick[NICKLEN]; struct Client *target_p; if(parc < 2 || BadPtr(parv[1])) { sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), me.name, parv[0]); return; } /* mark end of grace period, to prevent nickflooding */ if(!IsFloodDone(source_p)) flood_endgrace(source_p); /* terminate nick to NICKLEN */ strlcpy(nick, parv[1], sizeof(nick)); /* check the nickname is ok */ if(!clean_nick_name(nick)) { sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name, parv[0], nick); return; } if(find_nick_resv(nick)) { sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name, parv[0], nick); return; } if((target_p = find_client(nick))) { /* If(target_p == source_p) the client is changing nicks between * equivalent nicknames ie: [nick] -> {nick} */ if(target_p == source_p) { /* check the nick isnt exactly the same */ if(strcmp(target_p->name, nick)) { change_local_nick(client_p, source_p, nick); return; } else { /* client is doing :old NICK old * ignore it.. */ return; } } /* if the client that has the nick isnt registered yet (nick but no * user) then drop the unregged client */ if(IsUnknown(target_p)) { /* the old code had an if(MyConnect(target_p)) here.. but I cant see * how that can happen, m_nick() is local only --fl_ */ exit_client(NULL, target_p, &me, "Overridden"); change_local_nick(client_p, source_p, nick); return; } else { sendto_one(source_p, form_str(ERR_NICKNAMEINUSE), me.name, parv[0], nick); return; } } else { change_local_nick(client_p, source_p, nick); return; } }
/*! \brief NICK command handler * * \param source_p Pointer to allocated Client struct from which the message * originally comes from. This can be a local or remote client. * \param parc Integer holding the number of supplied arguments. * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL * pointers. * \note Valid arguments for this command are: * - parv[0] = command * - parv[1] = nickname */ static int m_nick(struct Client *source_p, int parc, char *parv[]) { char nick[NICKLEN + 1] = ""; struct Client *target_p = NULL; struct MaskItem *conf = NULL; assert(MyClient(source_p)); if (parc < 2 || EmptyString(parv[1])) { sendto_one_numeric(source_p, &me, ERR_NONICKNAMEGIVEN); return 0; } /* Mark end of grace period, to prevent nickflooding */ if (!IsFloodDone(source_p)) flood_endgrace(source_p); /* Terminate nick to NICKLEN */ strlcpy(nick, parv[1], IRCD_MIN(sizeof(nick), ConfigServerInfo.max_nick_length + 1)); /* Check the nickname is ok */ if (!valid_nickname(nick, 1)) { sendto_one_numeric(source_p, &me, ERR_ERRONEUSNICKNAME, nick, "Erroneous Nickname"); return 0; } if (!HasFlag(source_p, FLAGS_EXEMPTRESV) && !(HasUMode(source_p, UMODE_OPER) && HasOFlag(source_p, OPER_FLAG_NICK_RESV)) && (conf = find_matching_name_conf(CONF_NRESV, nick, NULL, NULL, 0))) { ++conf->count; sendto_one_numeric(source_p, &me, ERR_ERRONEUSNICKNAME, nick, conf->reason); sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE, "Forbidding reserved nick %s from user %s", nick, get_client_name(source_p, HIDE_IP)); return 0; } if ((target_p = hash_find_client(nick)) == NULL) change_local_nick(source_p, nick); else if (target_p == source_p) { /* * If (target_p == source_p) the client is changing nicks between * equivalent nicknames ie: [nick] -> {nick} */ /* Check the nick isn't exactly the same */ if (strcmp(target_p->name, nick)) change_local_nick(source_p, nick); } else if (IsUnknown(target_p)) { /* * If the client that has the nick isn't registered yet (nick but no * user) then drop the unregged client */ exit_client(target_p, "Overridden by other sign on"); change_local_nick(source_p, nick); } else sendto_one_numeric(source_p, &me, ERR_NICKNAMEINUSE, target_p->name); return 0; }
/* * ms_svsnick() * * parv[0] = sender prefix * parv[1] = oldnick * parv[2] = newnick */ static void ms_svsnick(struct Client *client_p, struct Client *source_p, int parc, char *parv[]) { char oldnick[NICKLEN]; char newnick[NICKLEN]; struct Client *oldnickname; struct Client *newnickname; if (!IsServer(source_p)) return; /* XXX BadPtr is needed */ if(parc < 3 || BadPtr(parv[1]) || BadPtr(parv[2])) { sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), me.name, parv[0]); return; } /* terminate nick to NICKLEN */ strlcpy(oldnick, parv[1], NICKLEN); strlcpy(newnick, parv[2], NICKLEN); if(!clean_nick_name(oldnick)) { sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name, parv[0], oldnick); return; } /* check the nickname is ok */ if(!clean_nick_name(newnick)) { sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name, parv[0], newnick); return; } if(find_nick_resv(newnick) && !(IsOper(source_p) && ConfigChannel.oper_pass_resv)) { sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), me.name, parv[0], newnick); return; } if(!(oldnickname = find_client(oldnick))) { sendto_one(source_p, form_str(ERR_NOSUCHNICK), me.name, source_p->name, oldnick); return; } if(newnickname = find_client(newnick)) { sendto_one(source_p, form_str(ERR_NICKNAMEINUSE), me.name, parv[0], newnick); return; } if(MyConnect(oldnickname)) { if(!IsFloodDone(oldnickname)) flood_endgrace(oldnickname); if (newnickname = find_client(oldnick)) { if(newnickname == oldnickname) { /* check the nick isnt exactly the same */ if(strcmp(oldnickname->name, newnick)) { change_local_nick(oldnickname->servptr, oldnickname, newnick); return; } else { /* client is doing :old NICK old * ignore it.. */ return; } } /* if the client that has the nick isnt registered yet (nick but no * user) then drop the unregged client */ if(IsUnknown(newnickname)) { /* the old code had an if(MyConnect(target_p)) here.. but I cant see * how that can happen, m_nick() is local only --fl_ */ exit_client(NULL, newnickname, &me, "Overridden"); change_local_nick(oldnickname->servptr, oldnickname, newnick); return; } else { sendto_one(source_p, form_str(ERR_NICKNAMEINUSE), me.name, parv[0], newnick); return; } } else { if(!ServerInfo.hub && uplink && IsCapable(uplink, CAP_LL)) { /* The uplink might know someone by this name already. */ sendto_one(uplink, ":%s NBURST %s %s %s", me.name, newnick, newnick, oldnickname->name); return; } else { change_local_nick(oldnickname->servptr, oldnickname, newnick); return; } } } else { sendto_server(client_p, source_p, NULL, CAP_SVNICK, NOCAPS, NOFLAGS, ":%s SVSNICK %s %s", me.name, oldnick, newnick); return; } }