[srvx-commits] CVS: services/src tools.h,1.9,1.10 tools.c,1.89,1.90 proto_ircu_p10.h,1.2,1.3 proto_i
Brought to you by:
entrope
Update of /cvsroot/srvx/services/src In directory usw-pr-cvs1:/tmp/cvs-serv20851/src Modified Files: tools.h tools.c proto_ircu_p10.h proto_ircu_p10.c proto_bahamut.h proto_bahamut.c proto.h hash.h Log Message: start supporting different sets of user/channel modes for different protocols Index: tools.h =================================================================== RCS file: /cvsroot/srvx/services/src/tools.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -r1.9 -r1.10 *** tools.h 2001/08/12 20:47:38 1.9 --- tools.h 2001/08/19 01:28:39 1.10 *************** *** 76,78 **** --- 76,81 ---- void string_buffer_replace(struct string_buffer *buf, unsigned int from, unsigned int len, const char *repl); + int make_chanmode(struct chanNode *chan, char *out, int len); + int make_usermode(struct userNode *user, char *out, int len); + #endif /* ifdef _TOOLS_H_ */ Index: tools.c =================================================================== RCS file: /cvsroot/srvx/services/src/tools.c,v retrieving revision 1.89 retrieving revision 1.90 diff -C2 -r1.89 -r1.90 *** tools.c 2001/08/12 20:47:38 1.89 --- tools.c 2001/08/19 01:28:39 1.90 *************** *** 53,57 **** static oper_func_t *of_list; ! static unsigned int of_size = 0, of_used = 0; void --- 53,57 ---- static oper_func_t *of_list; ! static unsigned int of_size, of_used; void *************** *** 81,85 **** } ! void mod_usermode(struct userNode *user, const char *mode_change) { int add = 1; if (!user || !mode_change || !*mode_change) return; --- 81,93 ---- } ! static const char *user_modes = PROTO_USER_MODE_CHARS; ! static unsigned char user_inverse_modes[256]; ! static const char *channel_modes = PROTO_CHANNEL_MODE_CHARS; ! static unsigned char channel_inverse_modes[256]; ! ! static int ! ! void ! mod_usermode(struct userNode *user, const char *mode_change) { int add = 1; if (!user || !mode_change || !*mode_change) return; *************** *** 108,112 **** } break; - case 'O': do_user_mode(FLAGS_LOCOP); break; case 'i': do_user_mode(FLAGS_INVISIBLE); if (add) invis_clients++; else invis_clients--; --- 116,119 ---- *************** *** 122,127 **** } } ! void mod_chanmode(struct chanNode *channel, const char *mode_change, const char *key, int limit) { int add = 1, n; --- 129,141 ---- } } + + int + make_usermode(struct userNode *user, char *out, int len) + { + + } ! void ! mod_chanmode(struct chanNode *channel, const char *mode_change, const char *key, int limit) { int add = 1, n; *************** *** 179,184 **** } } ! int verify_chanmode(const char *modes) { const char *word = modes; --- 193,205 ---- } } + + int + make_chanmode(struct chanMode *chan, char *out, int len) + { + + } ! int ! verify_chanmode(const char *modes) { const char *word = modes; *************** *** 187,192 **** res = 1; ! if(!modes) return 0; ! if(!*modes) return 1; while (*word != ' ' && *word) word++; --- 208,213 ---- res = 1; ! if (!modes) return 0; ! if (!*modes) return 1; while (*word != ' ' && *word) word++; Index: proto_ircu_p10.h =================================================================== RCS file: /cvsroot/srvx/services/src/proto_ircu_p10.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** proto_ircu_p10.h 2001/07/15 23:21:29 1.2 --- proto_ircu_p10.h 2001/08/19 01:28:39 1.3 *************** *** 22,33 **** #define PROTO_IRCU_P10_H ! #define SERVER_NUMERIC_LEN 1 ! #define USER_NUMERIC_LEN 2 ! #define COMBO_NUMERIC_LEN (SERVER_NUMERIC_LEN+USER_NUMERIC_LEN) ! #define MAXMODEPARAMS 6 ! #define MAXBANS 30 ! #define USERARRAYSIZE 4096 ! #define PROTO_HAS_NUMERIC 1 struct userNode_proto { --- 22,36 ---- #define PROTO_IRCU_P10_H ! #define MAXMODEPARAMS 6 ! #define MAXBANS 30 ! #define USERARRAYSIZE 4096 ! #define SERVER_NUMERIC_LEN 1 ! #define USER_NUMERIC_LEN 2 ! #define COMBO_NUMERIC_LEN (SERVER_NUMERIC_LEN+USER_NUMERIC_LEN) ! ! #define PROTO_HAS_NUMERIC 1 ! #define PROTO_USER_MODES (RFC1459_USER_MODES|FLAGS_DEAF|FLAGS_SERVICE|FLAGS_GLOBAL|FLAGS_HELPER) ! #define PROTO_USER_MODE_CHARS RFC1459_USER_MODE_CHARS"dkgh" struct userNode_proto { Index: proto_ircu_p10.c =================================================================== RCS file: /cvsroot/srvx/services/src/proto_ircu_p10.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -r1.17 -r1.18 *** proto_ircu_p10.c 2001/08/11 17:47:43 1.17 --- proto_ircu_p10.c 2001/08/19 01:28:39 1.18 *************** *** 318,321 **** --- 318,323 ---- int modelen = 0; char modes[9]; + + if (IsOper(user)) modes[modelen++] = 'o'; if (IsInvisible(user)) modes[modelen++] = 'i'; *************** *** 1170,1173 **** --- 1172,1177 ---- struct modeNode *mn; chan_mode_t mode; + char orig_key[KEYLEN+1]; + unsigned int orig_limit; if (!cn) { *************** *** 1177,1180 **** --- 1181,1186 ---- mchange = argv[3]; mode = cn->modes; + strcpy(orig_key, cn->key); + orig_limit = cn->limit; while (*mchange) { switch (*mchange++) { *************** *** 1192,1207 **** case 'l': if (add) { - mode |= MODE_LIMIT; cn->limit = atoi(argv[next_arg++]); } else { ! mode &= ~MODE_LIMIT; } break; case 'k': if (add) { - mode |= MODE_KEY; safestrncpy(cn->key, argv[next_arg++], sizeof(cn->key)); } else { ! mode &= ~MODE_KEY; } break; --- 1198,1211 ---- case 'l': if (add) { cn->limit = atoi(argv[next_arg++]); } else { ! cn->limit = 0; } break; case 'k': if (add) { safestrncpy(cn->key, argv[next_arg++], sizeof(cn->key)); } else { ! cn->key[0] = 0; } break; *************** *** 1224,1235 **** if (add) mn->modes |= bit; else mn->modes &= ~bit; ! if(bit != MODE_CHANOP) break; ! if(un) call_mode_change_funcs(cn, un, add ? MODE_CHANGE_OP : MODE_CHANGE_DEOP, vic); break;} case 'b': { char *ban = argv[next_arg++]; ! if (add) ! { AddChannelBan(1, &ban, cn, GetUserX(argv[0]), now, 0); if (un) call_mode_change_funcs(cn, un, MODE_CHANGE_BAN, ban); --- 1228,1238 ---- if (add) mn->modes |= bit; else mn->modes &= ~bit; ! if (bit != MODE_CHANOP) break; ! if (un) call_mode_change_funcs(cn, un, add ? MODE_CHANGE_OP : MODE_CHANGE_DEOP, vic); break;} case 'b': { char *ban = argv[next_arg++]; ! if (add) { AddChannelBan(1, &ban, cn, GetUserX(argv[0]), now, 0); if (un) call_mode_change_funcs(cn, un, MODE_CHANGE_BAN, ban); *************** *** 1240,1251 **** } ! if(mode != cn->modes && un) ! { cn->modes = mode; call_mode_change_funcs(cn, un, MODE_CHANGE_MISC, NULL); - } - else - { - cn->modes = mode; } return res; --- 1243,1249 ---- } ! if (un && ((mode != cn->modes) || (cn->limit != orig_limit) || (strcmp(cn->key, orig_key)))) { cn->modes = mode; call_mode_change_funcs(cn, un, MODE_CHANGE_MISC, NULL); } return res; Index: proto_bahamut.h =================================================================== RCS file: /cvsroot/srvx/services/src/proto_bahamut.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** proto_bahamut.h 2001/08/11 16:37:36 1.4 --- proto_bahamut.h 2001/08/19 01:28:39 1.5 *************** *** 24,33 **** #include "dict.h" ! #define SERVER_NUMERIC_LEN 1 ! #define USER_NUMERIC_LEN 2 ! #define COMBO_NUMERIC_LEN (SERVER_NUMERIC_LEN+USER_NUMERIC_LEN) ! #define MAXMODEPARAMS 512 ! #define MAXBANS 30 ! #define USERARRAYSIZE 4096 struct userNode_proto { --- 24,32 ---- #include "dict.h" ! #define PROTO_CHANNEL_MODES (RFC1459_CHANNEL_MODES|MODE_REGISTERED|MODE_REGONLY|MODE_NOCOLOR|MODE_OPERONLY) ! /* note the spaces in *_MODE_CHARS; they are to cover for modes that ! * Bahamut doesn't support, but exist in successive bits of the mask ! */ ! #define PROTO_CHANNEL_MODE_CHARS RFC1459_CHANNEL_MODE_CHARS" rRcO" struct userNode_proto { Index: proto_bahamut.c =================================================================== RCS file: /cvsroot/srvx/services/src/proto_bahamut.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** proto_bahamut.c 2001/08/11 17:47:43 1.7 --- proto_bahamut.c 2001/08/19 01:28:39 1.8 *************** *** 534,539 **** burst_send_channel(const char *key, void *data, void *extra) { ! (void)key; (void)data; (void)extra; ! /* TODO */ return 0; } --- 534,569 ---- burst_send_channel(const char *key, void *data, void *extra) { ! struct chanNode *channel = data; ! struct modeNode *mn; ! unsigned int pos, base_len, nn; ! char burst_line[510]; ! ! (void)key; (void)extra; ! base_len = snprintf(burst_line, sizeof(burst_line), ":%s SJOIN "FMT_TIME_T" %s ", self->name, channel->timestamp, channel->name); ! pos = base_len + irc_make_chanmode(channel, burst_line+base_len) - 1; ! burst_line[pos++] = ' '; ! burst_line[pos++] = ':'; ! /* send the user list */ ! for (nn=0; nn<channel->members.used; nn++) { ! mn = channel->members.list[nn]; ! if (pos + strlen(mn->user->nick) > 505) { ! burst_line[pos-1] = 0; /* -1 to back up over the space */ ! putsock("%s", burst_line); ! if (burst_line[base_len] == '+') { ! /* if this was the first line, rewrite it to have modes 0 */ ! burst_line[base_len++] = '0'; ! burst_line[base_len++] = ' '; ! } ! pos = base_len; ! } ! if (mn->modes & MODE_CHANOP) burst_line[pos++] = '@'; ! if (mn->modes & MODE_VOICE) burst_line[pos++] = '+'; ! strcpy(burst_line+pos, mn->user->nick); ! pos += strlen(mn->user->nick); ! burst_line[pos++] = ' '; ! } ! burst_line[pos-1] = 0; /* -1 to back up over the space */ ! putsock("%s", burst_line); ! /* TODO: send the ban list */ return 0; } *************** *** 549,555 **** /* burst local nicks */ dict_foreach(self->proto.clients, burst_send_nick, 0); - - /* burst channels */ - dict_foreach(channels, burst_send_channel, 0); } --- 579,582 ---- *************** *** 711,737 **** } /* Ignore argv[3] */ ! /* TODO: argv[4] is uplink's idea of current time. Fake our responses appropriately. */ return 1; } ! /* NICK <nick> <hops> <timestamp> <modes> <username> <hostname> <server> <ip> :<Clientinfo> */ static CMD_FUNC(cmd_nick) { struct server *uplink; struct userNode *user; ! if (argc < 10) return 0; ! if ((user = GetUser(argv[1]))) { ! /* Nick collision - what to do? */ ! log(MAIN_LOG, LOG_ERROR, "Nick collision for new user %s\n", argv[1]); ! return 0; ! } ! if (!(uplink = GetServer(argv[7]))) { ! /* Unknown server - what to do? */ ! log(MAIN_LOG, LOG_ERROR, "Unknown server %s for new user %s\n", argv[7], argv[1]); ! return 0; } ! user = AddUser(uplink, argv[1], argv[5], argv[6], argv[4], argv[9], atoi(argv[3])); ! if (user) user->ip = atoi(argv[8]); ! return 1; } --- 738,775 ---- } /* Ignore argv[3] */ ! /* TODO: argv[4] is uplink's idea of current time. Skew our responses appropriately. */ return 1; } ! /* Announced by server: ! * NICK <nick> <hops> <timestamp> <modes> <username> <hostname> <server> <ip> :<Clientinfo> ! * Client nick change: ! * :<User> NICK <NewNick> :<TS> ! */ static CMD_FUNC(cmd_nick) { struct server *uplink; struct userNode *user; ! if (argc == 3) { ! /* Client nick change */ ! NickChange(GetUser(argv[-1]), argv[1]); ! return 1; ! } else if (argc == 10) { ! /* Announced by server */ ! if ((user = GetUser(argv[1]))) { ! /* Nick collision - what to do? */ ! log(MAIN_LOG, LOG_ERROR, "Nick collision for new user %s\n", argv[1]); ! return 0; ! } ! if (!(uplink = GetServer(argv[7]))) { ! /* Unknown server - what to do? */ ! log(MAIN_LOG, LOG_ERROR, "Unknown server %s for new user %s\n", argv[7], argv[1]); ! return 0; ! } ! user = AddUser(uplink, argv[1], argv[5], argv[6], argv[4], argv[9], atoi(argv[3])); ! if (user) user->ip = atoi(argv[8]); ! return 1; } ! return 0; } *************** *** 754,758 **** } if (argc != n+1) return 0; ! channel = AddChannel(argv[2], strtoul(argv[1], NULL, 0), modes, key, limit); names = argv[n]; for (i=0; names[i]; ) { --- 792,801 ---- } if (argc != n+1) return 0; ! if (modes[0] != '0') { ! /* modes of "0" means a continuation line */ ! channel = AddChannel(argv[2], strtoul(argv[1], NULL, 0), modes, key, limit); ! } else { ! channel = GetChannel(argv[2]); ! } names = argv[n]; for (i=0; names[i]; ) { *************** *** 777,780 **** --- 820,829 ---- } } + /* If this is the first line, send our user/ban list. + * TODO: Doing so makes ChanServ do bad things, since it tries to op itself above + * (in AddChannel()), which is _before_ it's "in" the channel. */ + if (modes[0] != '0') { + burst_send_channel(channel->name, channel, 0); + } return pass; } *************** *** 831,834 **** --- 880,885 ---- struct modeNode *mn; chan_mode_t mode; + char orig_key[KEYLEN+1]; + unsigned int orig_limit; if (!cn) { *************** *** 838,841 **** --- 889,894 ---- mchange = argv[2]; mode = cn->modes; + strcpy(orig_key, cn->key); + orig_limit = cn->limit; while (*mchange) { switch (*mchange++) { *************** *** 853,868 **** case 'l': if (add) { - mode |= MODE_LIMIT; cn->limit = atoi(argv[next_arg++]); } else { ! mode &= ~MODE_LIMIT; } break; case 'k': if (add) { - mode |= MODE_KEY; safestrncpy(cn->key, argv[next_arg++], sizeof(cn->key)); } else { ! mode &= ~MODE_KEY; } break; --- 906,919 ---- case 'l': if (add) { cn->limit = atoi(argv[next_arg++]); } else { ! cn->limit = 0; } break; case 'k': if (add) { safestrncpy(cn->key, argv[next_arg++], sizeof(cn->key)); } else { ! cn->key[0] = 0; } break; *************** *** 899,907 **** } ! if (mode != cn->modes && un) { cn->modes = mode; call_mode_change_funcs(cn, un, MODE_CHANGE_MISC, NULL); - } else { - cn->modes = mode; } return res; --- 950,956 ---- } ! if (un && ((mode != cn->modes) || (cn->limit != orig_limit) || (strcmp(cn->key, orig_key)))) { cn->modes = mode; call_mode_change_funcs(cn, un, MODE_CHANGE_MISC, NULL); } return res; Index: proto.h =================================================================== RCS file: /cvsroot/srvx/services/src/proto.h,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -r1.36 -r1.37 *** proto.h 2001/08/09 12:41:40 1.36 --- proto.h 2001/08/19 01:28:39 1.37 *************** *** 45,52 **** #define MODE_CHANGE_BAN 0x008 - #define MAXLEN 512 /* This is used all over as a maximum string lenth - keep it large */ - #define MAXNUMPARAMS 200 #include PROTO_INCLUDE /********************/ /* PROTOCOL SPEWING */ --- 45,85 ---- #define MODE_CHANGE_BAN 0x008 #include PROTO_INCLUDE + #ifndef PROTO_HAS_NUMERIC + #define PROTO_HAS_NUMERIC 0 + #endif + + #ifndef MAXLEN + #define MAXLEN 512 + #endif + + #ifndef MAXNUMPARAMS + #define MAXNUMPARAMS 200 + #endif + + #ifndef MAXBANS + #define MAXBANS 30 + #endif + + #ifndef MAXMODEPARAMS + #define MAXMODEPARAMS MAXNUMPARAMS + #endif + + #ifndef PROTO_MODENODE_MODES + #define PROTO_MODENODE_MODES RFC1459_MODENODE_MODES + #define PROTO_MODENODE_MODE_CHARS RFC1459_MODENODE_MODE_CHARS + #endif + + #ifndef PROTO_CHANNEL_MODES + #define PROTO_CHANNEL_MODES RFC1459_CHANNEL_MODES + #define PROTO_CHANNEL_MODE_CHARS RFC1459_CHANNEL_MODE_CHARS + #endif + + #ifndef PROTO_USER_MODES + #define PROTO_USER_MODES RFC1459_USER_MODES + #define PROTO_USER_MODE_CHARS RFC1459_USER_MODE_CHARS + #endif + /********************/ /* PROTOCOL SPEWING */ *************** *** 73,77 **** void irc_join(struct userNode *who, struct chanNode *what); void irc_invite(struct userNode *from, struct userNode *who, struct chanNode *to); - int irc_make_chanmode(struct chanNode *chan, char *out); void irc_mode(struct userNode *from, struct chanNode *target, const char *modes); void irc_kick(struct userNode *actor, struct userNode *who, struct chanNode *from, const char *msg); --- 106,109 ---- Index: hash.h =================================================================== RCS file: /cvsroot/srvx/services/src/hash.h,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -r1.66 -r1.67 *** hash.h 2001/08/11 16:37:36 1.66 --- hash.h 2001/08/19 01:28:39 1.67 *************** *** 34,37 **** --- 34,39 ---- #define MODE_CHANOP 0x0001 #define MODE_VOICE 0x0002 + #define RFC1459_MODENODE_MODES (MODE_CHANOP|MODE_VOICE) + #define RFC1459_MODENODE_MODE_CHARS "ov" /* in chanNode->modes */ *************** *** 48,69 **** #define MODE_NOCOLOR 0x0400 /* No colored msgs to channel (Bahamut; +c) */ #define MODE_OPERONLY 0x0800 /* Only irc operators may join (Bahamut; +O) */ /* in userNode->modes */ ! #define FLAGS_OPER 0x0001 /* IRC Operator +O */ ! #define FLAGS_LOCOP 0x0002 /* Local Operator +o */ ! #define FLAGS_INVISIBLE 0x0004 /* invisible +i */ ! #define FLAGS_WALLOP 0x0008 /* receives wallops +w */ ! #define FLAGS_SERVNOTICE 0x0010 /* receives server notices +s */ ! #define FLAGS_DEAF 0x0020 /* deaf +d */ ! #define FLAGS_SERVICE 0x0040 /* cannot be kicked, killed or deoped +k */ ! #define FLAGS_GLOBAL 0x0080 /* receives global messages +g */ ! #define FLAGS_HELPER 0x0100 /* (network?) helper +h */ ! #define FLAGS_PERSISTENT 0x0200 /* for reserved nicks, this isn't just one-shot */ ! #define FLAGS_GAGGED 0x0400 /* for gagged users */ ! #define FLAGS_AWAY 0x0800 /* for away users */ #define IsOper(x) ((x)->modes & FLAGS_OPER) #define IsService(x) ((x)->modes & FLAGS_SERVICE) - #define IsDeaf(x) ((x)->modes & FLAGS_DEAF) #define IsInvisible(x) ((x)->modes & FLAGS_INVISIBLE) #define IsGlobal(x) ((x)->modes & FLAGS_GLOBAL) --- 50,73 ---- #define MODE_NOCOLOR 0x0400 /* No colored msgs to channel (Bahamut; +c) */ #define MODE_OPERONLY 0x0800 /* Only irc operators may join (Bahamut; +O) */ + #define RFC1459_CHANNEL_MODES (MODE_PRIVATE|MODE_SECRET|MODE_MODERATED|MODE_TOPICLIMIT|MODE_INVITEONLY|MODE_NOPRIVMSGS) + #define RFC1459_CHANNEL_MODE_CHARS "psmtin" /* in userNode->modes */ ! #define FLAGS_OPER 0x0001 /* IRC Operator +o */ ! #define FLAGS_INVISIBLE 0x0002 /* invisible +i */ ! #define FLAGS_WALLOP 0x0004 /* receives wallops +w */ ! #define FLAGS_SERVNOTICE 0x0008 /* receives server notices +s */ ! #define FLAGS_DEAF 0x0010 /* deaf +d */ ! #define FLAGS_SERVICE 0x0020 /* cannot be kicked, killed or deoped +k */ ! #define FLAGS_GLOBAL 0x0040 /* receives global messages +g */ ! #define FLAGS_HELPER 0x0080 /* (network?) helper +h */ ! #define FLAGS_PERSISTENT 0x0100 /* for reserved nicks, this isn't just one-shot */ ! #define FLAGS_GAGGED 0x0200 /* for gagged users */ ! #define FLAGS_AWAY 0x0400 /* for away users */ ! #define RFC1459_USER_MODES (FLAGS_OPER|FLAGS_INVISIBLE|FLAGS_WALLOP|FLAGS_SERVNOTICE) ! #define RFC1459_USER_MODE_CHARS "oiws" #define IsOper(x) ((x)->modes & FLAGS_OPER) #define IsService(x) ((x)->modes & FLAGS_SERVICE) #define IsInvisible(x) ((x)->modes & FLAGS_INVISIBLE) #define IsGlobal(x) ((x)->modes & FLAGS_GLOBAL) |