[X2serv-cvs] [CVS] Module x2: Change committed
Brought to you by:
sirvulcan
From: Matthias C. <ul...@us...> - 2003-06-14 13:16:19
|
Committer : Matthias Crauwels <ul...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2003-06-14 13:16:18 UTC Modified files: source/config.h source/main.c source/misc.c source/parse.c source/send.c source/server.c source/server.h Log message: Author: Matthias Crauwels <ult...@wo...> Log message: * Added Extended-numerics support ( this service will now only link to ircu2.10.08 or above!! ) * Added 'Account' handler ---------------------- diff included ---------------------- Index: x2/source/config.h diff -u x2/source/config.h:1.72 x2/source/config.h:1.73 --- x2/source/config.h:1.72 Sat May 17 21:04:09 2003 +++ x2/source/config.h Sat Jun 14 06:16:05 2003 @@ -21,9 +21,11 @@ /* If there are problems and you want all X2 output to go to x2.debug, define * this. Note that it gets very big, very fast... + * * #define LOGALLDEBUG */ + /* This is the CTCP character. (^A) */ #define CTCP '\001' @@ -65,8 +67,9 @@ #define GATEURL "http://www.afternet.org/support/proxy.html" /* Uncomment the following for debugging. - #define debugon -*/ + * + * #define debugon + */ /* Older afternet ircu had a mode (+g) added that made * IRC Ops able to override X2 security (God mode) @@ -145,7 +148,7 @@ #define OPERSEGSIZE 401 #define SERVNAMESEGSIZE 21 #define NETCHANMAXSIZE 21 -#define MAXNUMNICKNUM 65 +#define MAXNUMNICKNUM 4096 #define MAXLOGINLEN 10 /* This is the max # of lines of accounting.log @@ -167,7 +170,9 @@ * The default is 9. AfterNET runs 30. */ #define MAXNICKLEN 31 #define MAXCIDLEN 10 /* TS4 Connection ID (no idea whats reasonable). */ -#define NUMNICKLEN 4 /* 1 char (server number) + 2 char (user number) + '\0' */ +#define SERVNUMLEN 3 /* 2 char (server number) + '\0' */ +#define NUMNICKLEN 6 /* 2 char (server number) + 3 char (user number) + '\0' */ +#define NUMNICKMASK 63 /* (NUMNICKBASE-1) */ #define PASSWORDLEN 16 /* we're now using md5 for encryption, so MUCH longer passwords can be used. */ /* I do believe that 16 should be long enough for everyone, though (: */ #define MAXPASS 200 /* No longer used for ban reason. Shrinking... */ @@ -552,7 +557,7 @@ char *Name; char *LinkName; char *Description; - char numnick; + char numnick[SERVNUMLEN]; int NumOfUsers; int Deleted; struct ServStruct *NextA; /* jump by nAme */ @@ -649,6 +654,7 @@ extern int ServiceNumeric; extern char NumNick[NUMNICKLEN]; +extern char ServNum[SERVNUMLEN]; extern u_short Port, SERVERPORT; extern int Sock, NewSock; Index: x2/source/main.c diff -u x2/source/main.c:1.59 x2/source/main.c:1.60 --- x2/source/main.c:1.59 Sat May 17 20:43:45 2003 +++ x2/source/main.c Sat Jun 14 06:16:05 2003 @@ -44,7 +44,8 @@ IrcNick[MAXNICKLEN] = "X2", CommandMark = '.', HomeDir[2048]="", AccessLog[2048]=""; int ServiceNumeric = 53; -char NumNick[NUMNICKLEN] = "1X2"; +char ServNum[SERVNUMLEN] = "A1"; +char NumNick[NUMNICKLEN] = "A1AAA"; u_short Port, SERVERPORT; int Sock, NewSock; @@ -189,13 +190,15 @@ fscanf(ConfFile, "%s", StrBuffr); - /* Numeric must be 0-63 */ - if ( (i = atol(StrBuffr)) & ~(64-1) ) { + /* Numeric must be 0-4095 */ + if ( (i = atol(StrBuffr)) & ~(4096-1) ) { printf("Invalid numeric (%d) in NUMERIC line. \n", i); exit(1); } - NumNick[0] = convert2y[i]; + inttobase64(ServNum, i, 2); + strcpy(NumNick, ServNum); + strcat(NumNick, "AAA"); ServiceNumeric = i; } else if (!strcmp(StrBuffr, "PASSWORD")) Index: x2/source/misc.c diff -u x2/source/misc.c:1.48 x2/source/misc.c:1.49 --- x2/source/misc.c:1.48 Sat May 17 20:43:45 2003 +++ x2/source/misc.c Sat Jun 14 06:16:05 2003 @@ -131,6 +131,17 @@ return i; } +/* taken from ircu2.10.05 */ +const char* inttobase64(char* buf, unsigned int v, unsigned int count) +{ + buf[count] = '\0'; + while (count > 0) { + buf[--count] = convert2y[(v & NUMNICKMASK)]; + v >>= NUMNICKLOG; + } + return buf; +} + char *NickToNum(char *nick) { Index: x2/source/parse.c diff -u x2/source/parse.c:1.78 x2/source/parse.c:1.79 --- x2/source/parse.c:1.78 Thu Jun 12 20:03:50 2003 +++ x2/source/parse.c Sat Jun 14 06:16:06 2003 @@ -88,6 +88,7 @@ { "WA", m_noop, TRUE, TRUE }, { "R", m_noop, TRUE, TRUE }, { "SE", m_settime, TRUE, FALSE }, + { "AC", m_noop, TRUE, FALSE }, /* this won't be used in this service */ { NULL, NULL, FALSE, FALSE } }; /* *INDENT-ON* */ @@ -124,7 +125,7 @@ { return(0); /* Msg to channel */ } - else if(to[0] == convert2y[ServiceNumeric]) + else if(strcmp(to, NumNick) == 0) { Debug(DBGINFO, "m_privmsg() %s(%s) sent privmsg to %s [%s]", uptr->Nick, uptr->Numnick, to, rest); /* Check for CTCP */ @@ -186,10 +187,7 @@ sprintf(CSHOST, "%s@%s", IrcNick, ServiceName); if(!strcasecmp(to, CSHOST)) - { - strcpy(to, "?X2"); - to[0] = convert2y[ServiceNumeric]; - } + strcpy(to, NumNick); if(to[0] == '#') { if(rest[0] == CommandMark) @@ -197,7 +195,7 @@ ProcessCommand(uptr, to, rest); } } - else if(to[0] == convert2y[ServiceNumeric]) + else if(strcmp(to, NumNick) == 0) { Debug(DBGINFO, "m_privmsg() %s(%s) sent privmsg to %s [%s]", uptr->Nick, uptr->Numnick, to, rest); /* Check for CTCP */ @@ -224,6 +222,9 @@ int m_server(M_PARAMS) { char* Arg[8]; + char numnick[SERVNUMLEN]; + int i; + Arg[0] = (char *) strtok(rest, " "); /* Name */ Arg[1] = (char *) strtok(NULL, " "); /* hopes */ Arg[2] = (char *) strtok(NULL, " "); /* ts 1 */ @@ -238,7 +239,11 @@ Debug(DBGWARNING, "Incorrect syntax in SERVER line"); return(0); } - AddServer(Arg[0], sptr->Name, Arg[5][0]); + + for(i = 0; i < SERVNUMLEN - 1; i++) + numnick[i] = Arg[5][i]; + + AddServer(Arg[0], sptr->Name, numnick); return (0); } /* E.G.: @@ -370,7 +375,7 @@ int m_nick(M_PARAMS) { char* Arg[9]; - char* modes; + char* modes, *account; UserListType UserPtr; unsigned int IP; Arg[0] = (char *) strtok(rest, " "); /* nick */ @@ -393,8 +398,17 @@ modes = (char *) strtok(NULL, " "); /* modes */ if(modes[0] == '+') { - Arg[5] = modes; - Arg[6] = (char *) strtok(NULL, " "); /* Compressed IP */ + if(strchr(modes, 'r')) + { + Arg[5] = modes; + account = (char *) strtok(NULL, " "); /* This user has an account set from another service */ + Arg[6] = (char *) strtok(NULL, " "); /* Compressed IP */ + } + else + { + Arg[5] = modes; + Arg[6] = (char *) strtok(NULL, " "); /* Compressed IP */ + } } else { @@ -1383,8 +1397,8 @@ char *Arg[MAXLEN]; static char RemotePass[MAXPASS]; /* should be this or just '10'? */ - Arg[0] = (char *) strtok(LineBuff, " "); - Arg[1] = (char *) strtok(NULL, " "); + Arg[0] = (char *) strtok(LineBuff, " "); /* sender numeric */ + Arg[1] = (char *) strtok(NULL, " "); if(!strcmp(Arg[0], "PING")) { /* Respond with a ping reply */ @@ -1410,8 +1424,9 @@ { /* Beginning of burst. validate password and name, authenticate and send our burst * if we were listning for the link */ UpLinkList *UpLinkPtr; - char Numnick[NUMNICKLEN]; - + char numnick[SERVNUMLEN]; + int i; + Debug(DBGNOTICE, "Got SERVER line from uplink. Processing."); Arg[2] = (char *) strtok(NULL, " "); /* Hops */ Arg[3] = (char *) strtok(NULL, " "); /* TS #1 */ @@ -1426,7 +1441,7 @@ return; } Debug(DBGINFO, "PROTOCOL: %s", Arg[5]); - if(strcmp(Arg[5], "J10")) /* If Arg[5] is not "J10" then.. */ + if(strcmp(Arg[5], "J10")) /* If Arg5] is not "J10" then.. */ { Debug(DBGWARNING, "UNKNOWN protocol. This is NOT a compatable irc daemon."); Debug(DBGWARNING, "Currently X2 works with the following irc servers:"); @@ -1452,8 +1467,11 @@ #endif return; } - Debug(DBGINFO, "Adding server %s %s %c", Arg[1], ServiceName, Arg[6][0]); - AddServer(Arg[1], ServiceName, Arg[6][0]); + + for(i = 0; i < SERVNUMLEN - 1; i++) + numnick[i] = Arg[6][i]; + Debug(DBGINFO, "Adding server %s %s %s", Arg[1], ServiceName, numnick); + AddServer(Arg[1], ServiceName, numnick); NETBURSTING = TRUE; /* Ignore incomming users for a while*/ REMOTE_AUTHENTICATED = TRUE; /* Stop parsing PASS/SERVER etc */ bantimer = time(NULL); /* Start ban timer over */ @@ -1470,9 +1488,7 @@ } } - strcpy(Numnick, "?X2"); - Numnick[0] = convert2y[ServiceNumeric]; /* Server numnick is first letter of user numnick */ - AddUser(Numnick, IrcNick, IrcNick, "X2", ServiceName, + AddUser(NumNick, IrcNick, IrcNick, "X2", ServiceName, LOCALIP, ServiceName, (UMODEk & UMODEo)); ProcessUserMode(FindNick(IrcNick, UsersN), "+kows"); @@ -1508,58 +1524,22 @@ UserListType UserPtr = NULL; ServerListType ServerPtr = NULL; int i; - /* prefix hack is because when sending numerics you have to parse the - * target differently, depending if its sent as <numnick> or :server. - * if prefix_hack is 1, it was sent as :server, and numeric target - * must be nick. Otherwise, prefix_hack is 0, and prefix was a proper - * prefix and target is a numnick. (ircu2.10.08 sends :server) - */ - int prefix_hack = 0; Sender = (char *) strtok(LineBuff, " "); - if(Sender[0] == ':') - { - prefix_hack++; /* See above comment */ - Sender++; - if(!(ServerPtr = GetServer(Sender))) - { - if(!(UserPtr = FindNick(Sender, UsersN))) - Debug(DBGINFO, "Sender %s not found", Sender); - } - } - else - { /* Find by numnicks */ - if(!((!Sender[1]) && (ServerPtr = GetServerByNumnick(Sender[0])))) - { - if(!(UserPtr = FindNumnick(Sender, UsersU))) - Debug(DBGINFO, "Sender %s not found", Sender); - } - } Command = (char *) strtok(NULL, " "); rest = (char *) strtok(NULL, "\r\n\0"); -/*** Check if maybe its a numeric ***/ - if(isdigit(Command[0]) && ServerPtr) /* If first letter is a number and a server sent it.. */ - { - int num = 0; - if((num = atoi(Command))) /* if num is non zero.. */ - { - char* target; - UserListType TmpUserPtr; - target = (char *) strtok(rest, " "); - rest = (char *) strtok(NULL, "\r\n"); - if(prefix_hack) - TmpUserPtr = FindNick(target, UsersN); - else - TmpUserPtr = FindNumnick(target, UsersU); - ProcessNumeric(ServerPtr, num, TmpUserPtr, rest); - return(0); - } - } + + if((strlen(Sender) < 5) && !(ServerPtr = GetServerByNumnick(Sender))) + Debug(DBGINFO, "Sender %s not found", Sender); + + if((strlen(Sender) > 2) && !(UserPtr = FindNumnick(Sender, UsersU))) + Debug(DBGINFO, "Sender %s not found", Sender); + for(i=0;server_commands[i].name;i++) { if(!strcasecmp(server_commands[i].name, Command)) { - if(UserPtr) + if(UserPtr) { if(server_commands[i].usercmd == FALSE) { @@ -1567,7 +1547,7 @@ return(0); } } - else if(ServerPtr) + else if(ServerPtr) { if(server_commands[i].servercmd == FALSE) { Index: x2/source/send.c diff -u x2/source/send.c:1.35 x2/source/send.c:1.36 --- x2/source/send.c:1.35 Thu Jun 12 20:03:51 2003 +++ x2/source/send.c Sat Jun 14 06:16:06 2003 @@ -30,14 +30,11 @@ { va_list args; char buff[LINEBUFFSIZE]; - char numnick[NUMNICKLEN]; va_start(args, format); vsprintf(buff, format, args); va_end(args); - strcpy(numnick, " "); - numnick[0] = convert2y[ServiceNumeric]; - send_command(numnick, "%s", buff); + send_command(ServNum, "%s", buff); } void send_command_from_nick(char *format, ...) @@ -437,7 +434,6 @@ void Authenticate(UpLinkList *UpLinkPtr) { - /* This is now done in parse.c * * AddServer(Uplink,ServiceName); * */ @@ -447,17 +443,16 @@ ConnectTime = ServerTimeStamp = time(NULL); sendtosock(Sock, "PASS :%s", UpLinkPtr->ServPass); LinkTimeStamp = NetTime()- 10000; - sendtosock(Sock, "SERVER %s 1 %lu %lu J10 %cD] 0 :%s", ServiceName, LinkTimeStamp, ServerTimeStamp, - convert2y[ServiceNumeric], - "X2 Channel Service"); + sendtosock(Sock, "SERVER %s 1 %lu %lu J10 %s]]] 0 :%s", ServiceName, LinkTimeStamp, ServerTimeStamp, + ServNum, "X2 Channel Service"); /* <server> NICK <nick> <hops> <timestamp> <user> <host> <compressed ip> <3 letter numeric> :<username> */ - sendtosock(Sock, "%c N %s 1 %lu %s %s +%s %s %c%s :\002%c\002) /MSG %s Help (\002%c\002", - convert2y[ServiceNumeric], IrcNick, LinkTimeStamp, + sendtosock(Sock, "%s N %s 1 %lu %s %s +%s %s %s%s :\002%c\002) /MSG %s Help (\002%c\002", + ServNum, IrcNick, LinkTimeStamp, IrcNick, /* user */ ServiceName, /* host */ "ko", /* Modes */ "B]AAAB", /* compressed ip (127.0.0.1) */ - convert2y[ServiceNumeric], "X2", /* ?X2 is our numnick where ? is server num */ + ServNum, "AAA", /* lets use the first available numeric :) */ CommandMark, IrcNick, CommandMark); #ifdef pinging PingStamp = time(NULL); Index: x2/source/server.c diff -u x2/source/server.c:1.19 x2/source/server.c:1.20 --- x2/source/server.c:1.19 Mon Feb 24 01:19:55 2003 +++ x2/source/server.c Sat Jun 14 06:16:06 2003 @@ -325,14 +325,14 @@ } } -ServerListType GetServerByNumnick(char numnick) +ServerListType GetServerByNumnick(char *numnick) { ServerListType TempPtr; - TempPtr = Servers->TableU[convert2n[(int)numnick]]; + TempPtr = Servers->TableU[base64toint(numnick)]; while (TempPtr) { - if (numnick == TempPtr->numnick) + if (strcmp(numnick, TempPtr->numnick) == 0) { return (TempPtr); } @@ -363,7 +363,7 @@ return (NULL); } -int AddServer(char *ServName, char *ServLink, char numnick) +int AddServer(char *ServName, char *ServLink, char *numnick) { static int ServerSegWarning = 1; ServerListType NewServ; @@ -395,7 +395,8 @@ strcpy(NewServ->Name, ServName); strcpy(NewServ->LinkName, ServLink); - NewServ->numnick = numnick; + numnick[2] = '\0'; /* make sure we only have 2 chars as servernum */ + strcpy(NewServ->numnick, numnick); NewServ->NumOfUsers = 0; NewServ->Deleted = FALSE; @@ -404,7 +405,7 @@ NewServ->NextA = Servers->Table[Pos]; Servers->Table[Pos] = NewServ; - Servers->TableU[convert2n[(int)numnick]] = NewServ; + Servers->TableU[base64toint(numnick)] = NewServ; ServerCount++; return (1); } Index: x2/source/server.h diff -u x2/source/server.h:1.8 x2/source/server.h:1.9 --- x2/source/server.h:1.8 Wed Feb 28 02:11:29 2001 +++ x2/source/server.h Sat Jun 14 06:16:06 2003 @@ -11,9 +11,9 @@ void ProcessRemoveGline(char *Address); void ProcessAddSGline(char *Address, time_t gtime, char *Reason); void ProcessRemoveSGline(char *Address); -int AddServer(char *ServName, char *ServLink, char numnick); +int AddServer(char *ServName, char *ServLink, char *numnick); ServerListType GetServer(char *Name); -ServerListType GetServerByNumnick(char numnick); +ServerListType GetServerByNumnick(char *numnick); void RemoveServer(char *Name); void RemoveDownLinks(char *Name); void KillServerList(); ----------------------- End of diff ----------------------- |