?? m_nick.c
字號:
/* m_nick.c - Because s_user.c was just crazy. * Copyright (C) 1990 Jarkko Oikarinen and * University of Oulu, Computing Center * * See file AUTHORS in IRC package for additional names of * the programmers. * * This program is free softwmare; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 1, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#include "struct.h"#include "common.h"#include "sys.h"#include "numeric.h"#include "msg.h"#include "channel.h"#include <sys/stat.h>#include <utmp.h>#include <fcntl.h>#include "h.h"#include "userban.h"#include "hooks.h"extern int do_user(char *, aClient *, aClient *, char *, char *, char *, unsigned long, unsigned int, char *);extern int register_user(aClient *, aClient *, char *, char *);extern int user_modes[];/*** 'do_nick_name' ensures that the given parameter (nick) is** really a proper string for a nickname (note, the 'nick'** may be modified in the process...)**** RETURNS the length of the final NICKNAME (0, if** nickname is illegal)**** Nickname characters are in range** 'A'..'}', '_', '-', '0'..'9'** anything outside the above set will terminate nickname.** In addition, the first character cannot be '-'** or a Digit.**** Note:** '~'-character should be allowed, but** a change should be global, some confusion would** result if only few servers allowed it...*/#define NICK_GBK#if defined(NICK_GB2312) || defined(NICK_GBK) || defined(NICK_GBK_JAP)#define NICK_MULTIBYTE#endif#ifdef NICK_MULTIBYTE/* Chinese Nick Verification Code - Added by RexHsu on 08/09/00 (beta2) * Now Support All GBK Words,Thanks to Mr.WebBar <climb@guomai.sh.cn>! * Special Char Bugs Fixed by RexHsu 09/01/00 I dont know whether it is * okay now?May I am right ;p * Thanks dilly for providing me Japanese code range! * Now I am meeting a nickname conflicting problem.... * * GBK Libary Reference: * 1. GBK2312非漢字符號區(A1A1----A9FE) * 2. GBK2312漢字區(B0A1----F7FE) * 3. GBK擴充漢字區(8140----A0FE) * 4. GBK擴充漢字區(AA40----FEA0) * 5. GBK擴充非漢字區(A840----A9A0) * 6. 日文平假名編碼區(a4a1-a4f3) -->work correctly?maybe... * 7. 日文片假名編碼區(a5a1-a5f7) -->work correctly?maybe... * 8. 韓文編碼區(xxxx-yyyy) * * isvalidChinese() rewritten by Xuefer (2004-10-10), * this will probably be the last time we do it this way, * in 3.2.3 we are gonna try a more generic aproach. -- Syzop */int isvalidChinese(const unsigned char c1, const unsigned char c2){ unsigned int w = (((unsigned int)c1) << 8) | c2;/* rang of w/c1/c2 (rw never used) */#define rw(s, e) (w >= ((unsigned int )s) && w <= ((unsigned int )e))#define r1(s, e) (c1 >= ((unsigned char)s) && c1 <= ((unsigned char)e))#define r2(s, e) (c2 >= ((unsigned char)s) && c2 <= ((unsigned char)e))#define e1(e) (c1 == (unsigned char)e)#ifdef NICK_GBK_JAP /* GBK/1 */ /* JIS_PIN part 1 */ if (e1(0xA4) && r2(0xA1, 0xF3)) return 1; /* JIS_PIN part 2 */ if (e1(0xA5) && r2(0xA1, 0xF6)) return 1;#endif#if defined(NICK_GB2312) || defined(NICK_GBK) /* GBK/2 BC with GB2312 */ if (r2(0xA1, 0xFE)) { /* Block 16-55, ordered by Chinese Spelling(PinYin) 3755 chars */ if (r1(0xB0, 0xD6)) return 1; /* Block 55 is NOT full (w <= 0xd7f9) */ if (e1(0xD7) && c2 <= (unsigned char)0xF9 /* r2(0xA1, 0xF9)*/) return 1; /* Block 56-87 is level 2 chars, ordered by writing 3008 chars */ if (r1(0xD8, 0xF7)) return 1; }#endif#ifdef NICK_GBK /* GBK/3 */ if (r1(0x81, 0xA0) && r2(0x40, 0xFE)) return 1; /* GBK/4 */ if (r2(0x40, 0xA0) && r1(0xAA, 0xFE)) return 1;#endif /* all failed */ return 0;#undef rw#undef r1#undef r2#undef e1}/* Chinese Nick Supporting Code (Switch Mode) - Modified by RexHsu on 08/09/00 */int do_nick_name(char *pnick){ unsigned char *ch; unsigned char *nick = pnick; int firstChineseChar = 0; char lastChar; if (*nick == '-' || IsDigit(*nick)) /* first character in [0..9-] */ return 0; for (ch = nick; *ch && (ch - nick) < NICKLEN; ch++) { if ((!isvalid(*ch) && !((*ch) & 0x80)) || IsSpace(*ch) || (*ch) == '@' || (*ch) == '!' || (*ch) == ':' || (*ch) == ' ') break; if (firstChineseChar) { if (!isvalidChinese(lastChar, *ch)) break; firstChineseChar = 0; } else if ((*ch) & 0x80) firstChineseChar = 1; lastChar = *ch; } if (firstChineseChar) ch--; *ch = '\0'; return (ch - nick);}#elseint do_nick_name(char *nick){ char *ch; if (*nick == '-' || IsDigit(*nick)) /* first character in [0..9-] */ return 0; for (ch = nick; *ch && (ch - nick) < NICKLEN; ch++) if (!isvalid(*ch) || IsSpace(*ch)) break; *ch = '\0'; return (ch - nick);}#endif/* * m_nick * parv[0] = sender prefix * parv[1] = nickname * parv[2] = hopcount when new user; TS when nick change * parv[3] = TS * ---- new user only below ---- * parv[4] = umode * parv[5] = username * parv[6] = hostname * parv[7] = server * parv[8] = serviceid * parv[9] = IP * parv[10] = ircname * -- endif */int m_nick(aClient *cptr, aClient *sptr, int parc, char *parv[]){ struct simBan *ban; aClient *acptr, *uplink; Link *lp; char nick[NICKLEN + 2]; ts_val newts = 0; int sameuser = 0, samenick = 0; if (parc < 2) { sendto_one(sptr, err_str(ERR_NONICKNAMEGIVEN), me.name, parv[0]); return 0; } if (!IsServer(sptr) && IsServer(cptr) && parc > 2) newts = atol(parv[2]); else if (IsServer(sptr) && parc > 3) newts = atol(parv[3]); else parc = 2; /* * parc == 2 on a normal client sign on (local) and a normal client * nick change * parc == 4 on a normal server-to-server client nick change * parc == 11 on a normal TS style server-to-server NICK introduction */ if ((IsServer(sptr) || (parc > 4)) && (parc < 11)) { /* * We got the wrong number of params. Someone is trying to trick * us. Kill it. -ThemBones As discussed with ThemBones, not much * point to this code now sending a whack of global kills would * also be more annoying then its worth, just note the problem, * and continue -Dianora */ sendto_realops("IGNORING BAD NICK: %s[%s@%s] on %s (from %s)", parv[1], (parc >= 6) ? parv[5] : "-", (parc >= 7) ? parv[6] : "-", (parc >= 8) ? parv[7] : "-", parv[0]); return 0; } strncpyzt(nick, parv[1], NICKLEN + 1); /* * if do_nick_name() returns a null name OR if the server sent a * nick name and do_nick_name() changed it in some way (due to rules * of nick creation) then reject it. If from a server and we reject * it, and KILL it. -avalon 4/4/92 */ if (do_nick_name(nick) == 0 || (IsServer(cptr) && strcmp(nick, parv[1]))) { sendto_one(sptr, err_str(ERR_ERRONEUSNICKNAME), me.name, parv[0], parv[1], "Erroneous Nickname"); if (IsServer(cptr)) { ircstp->is_kill++; sendto_realops_lev(DEBUG_LEV, "Bad Nick: %s From: %s Via: %s", parv[1], parv[0], get_client_name(cptr, HIDEME)); sendto_one(cptr, ":%s KILL %s :%s (Bad Nick)", me.name, parv[1], me.name); if (sptr != cptr) { /* bad nick change */ sendto_serv_butone(cptr, ":%s KILL %s :%s (Bad Nick)", me.name, parv[0], me.name); sptr->flags |= FLAGS_KILLED; return exit_client(cptr, sptr, &me, "BadNick"); } } return 0; } /* * Check against nick name collisions. * * Put this 'if' here so that the nesting goes nicely on the screen * :) We check against server name list before determining if the * nickname is present in the nicklist (due to the way the below * for loop is constructed). -avalon */ do { if ((acptr = find_server(nick, NULL))) if (MyConnect(sptr)) { sendto_one(sptr, err_str(ERR_NICKNAMEINUSE), me.name, BadPtr(parv[0]) ? "*" : parv[0], nick); return 0; } /* * acptr already has result from find_server * Well. unless we have a capricious server on the net, a nick can * never be the same as a server name - Dianora * That's not the only case; maybe someone broke do_nick_name * or changed it so they could use "." in nicks on their network * - sedition */ if (acptr) { /* * We have a nickname trying to use the same name as a * server. Send out a nick collision KILL to remove the * nickname. As long as only a KILL is sent out, there is no * danger of the server being disconnected. Ultimate way to * jupiter a nick ? >;-). -avalon */ sendto_realops_lev(SKILL_LEV, "Nick collision on %s", sptr->name); ircstp->is_kill++; sendto_one(cptr, ":%s KILL %s :%s (Nick Collision)", me.name, sptr->name, me.name); sptr->flags |= FLAGS_KILLED; return exit_client(cptr, sptr, &me, "Nick/Server collision"); } if (!(acptr = find_client(nick, NULL))) break; /* * If acptr == sptr, then we have a client doing a nick change * between *equivalent* nicknames as far as server is concerned * (user is changing the case of his/her nickname or somesuch) */ if (acptr == sptr) { if (strcmp(acptr->name, nick) == 0) return 0; else break; } /* If user is changing nick to itself no point in propogating */ /* * Note: From this point forward it can be assumed that acptr != * sptr (point to different client structures). * * If the older one is "non-person", the new entry is just * allowed to overwrite it. Just silently drop non-person, and * proceed with the nick. This should take care of the "dormant * nick" way of generating collisions... */ if (IsUnknown(acptr)) { if (MyConnect(acptr)) { exit_client(NULL, acptr, &me, "Overridden"); break; } else if (!(acptr->user)) { sendto_realops_lev(SKILL_LEV, "Nick Collision on %s", parv[1]); sendto_serv_butone(NULL, ":%s KILL %s :%s (Nick Collision)", me.name, acptr->name, me.name); acptr->flags |= FLAGS_KILLED; /* Having no USER struct should be ok... */ return exit_client(cptr, acptr, &me, "Got TS NICK before Non-TS USER"); } } if (!IsServer(cptr)) { /* * NICK is coming from local client connection. Just send * error reply and ignore the command. * parv[0] is empty on connecting clients */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -