X-Git-Url: https://jfr.im/git/irc/rqf/shadowircd.git/blobdiff_plain/212380e3f42f585dc1ea927402252eb943f91f7b..90a3c35b295b07ebe3793bf5d3b882c3c1a5dc7c:/modules/core/m_join.c diff --git a/modules/core/m_join.c b/modules/core/m_join.c index de001cd..fbb2e4a 100644 --- a/modules/core/m_join.c +++ b/modules/core/m_join.c @@ -21,11 +21,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * - * $Id: m_join.c 3131 2007-01-21 15:36:31Z jilles $ + * $Id: m_join.c 3494 2007-05-27 13:07:27Z jilles $ */ #include "stdinc.h" -#include "tools.h" #include "channel.h" #include "client.h" #include "common.h" @@ -62,7 +61,7 @@ mapi_hlist_av1 join_hlist[] = { { NULL, NULL }, }; -DECLARE_MODULE_AV1(join, NULL, NULL, join_clist, join_hlist, NULL, "$Revision: 3131 $"); +DECLARE_MODULE_AV1(join, NULL, NULL, join_clist, join_hlist, NULL, "$Revision: 3494 $"); static void do_join_0(struct Client *client_p, struct Client *source_p); static int check_channel_name_loc(struct Client *source_p, const char *name); @@ -150,7 +149,7 @@ m_join(struct Client *client_p, struct Client *source_p, int parc, const char *p } /* join 0 parts all channels */ - if(*name == '0' && !atoi(name)) + if(*name == '0' && (name[1] == ',' || name[1] == '\0') && name == chanlist) { (void) strcpy(jbuf, "0"); continue; @@ -175,7 +174,7 @@ m_join(struct Client *client_p, struct Client *source_p, int parc, const char *p sendto_realops_snomask(SNO_SPY, L_NETWIDE, "User %s (%s@%s) is attempting to join locally juped channel %s (%s)", source_p->name, source_p->username, - source_p->host, name, aconf->passwd); + source_p->orighost, name, aconf->passwd); /* dont update tracking for jupe exempt users, these * are likely to be spamtrap leaves */ @@ -236,7 +235,7 @@ m_join(struct Client *client_p, struct Client *source_p, int parc, const char *p call_hook(h_can_create_channel, &moduledata); - if(moduledata.approved != 0 && !IsOper(source_p)) + if(moduledata.approved != 0) { sendto_one(source_p, form_str(moduledata.approved), me.name, source_p->name, name); @@ -254,10 +253,10 @@ m_join(struct Client *client_p, struct Client *source_p, int parc, const char *p flags = CHFL_CHANOP; } - if((dlink_list_length(&source_p->user->channel) >= + if((rb_dlink_list_length(&source_p->user->channel) >= (unsigned long) ConfigChannel.max_chans_per_user) && (!IsOper(source_p) || - (dlink_list_length(&source_p->user->channel) >= + (rb_dlink_list_length(&source_p->user->channel) >= (unsigned long) ConfigChannel.max_chans_per_user * 3))) { sendto_one(source_p, form_str(ERR_TOOMANYCHANNELS), @@ -342,17 +341,15 @@ m_join(struct Client *client_p, struct Client *source_p, int parc, const char *p } else { - const char *modes = channel_modes(chptr, &me); - sendto_server(client_p, chptr, CAP_TS6, NOCAPS, - ":%s JOIN %ld %s %s", + ":%s JOIN %ld %s +", use_id(source_p), (long) chptr->channelts, - chptr->chname, modes); + chptr->chname); sendto_server(client_p, chptr, NOCAPS, CAP_TS6, - ":%s SJOIN %ld %s %s :%s", + ":%s SJOIN %ld %s + :%s", me.name, (long) chptr->channelts, - chptr->chname, modes, source_p->name); + chptr->chname, source_p->name); } del_invite(chptr, source_p); @@ -396,16 +393,13 @@ static int ms_join(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { struct Channel *chptr; - static struct Mode mode, *oldmode; - const char *s; - const char *modes; + static struct Mode mode; time_t oldts; time_t newts; int isnew; - int args = 0; int keep_our_modes = YES; int keep_new_modes = YES; - dlink_node *ptr, *next_ptr; + rb_dlink_node *ptr, *next_ptr; /* special case for join 0 */ if((parv[1][0] == '0') && (parv[1][1] == '\0') && parc == 2) @@ -428,89 +422,11 @@ ms_join(struct Client *client_p, struct Client *source_p, int parc, const char * mode.key[0] = mode.forward[0] = '\0'; mode.mode = mode.limit = mode.join_num = mode.join_time = 0; - s = parv[3]; - while(*s) - { - switch (*(s++)) - { - case 'i': - mode.mode |= MODE_INVITEONLY; - break; - case 'n': - mode.mode |= MODE_NOPRIVMSGS; - break; - case 'p': - mode.mode |= MODE_PRIVATE; - break; - case 's': - mode.mode |= MODE_SECRET; - break; - case 'm': - mode.mode |= MODE_MODERATED; - break; - case 't': - mode.mode |= MODE_TOPICLIMIT; - break; - case 'r': - mode.mode |= MODE_REGONLY; - break; - case 'L': - mode.mode |= MODE_EXLIMIT; - break; - case 'P': - mode.mode |= MODE_PERMANENT; - break; - case 'c': - mode.mode |= MODE_NOCOLOR; - break; - case 'g': - mode.mode |= MODE_FREEINVITE; - break; - case 'z': - mode.mode |= MODE_OPMODERATE; - break; - case 'F': - mode.mode |= MODE_FREETARGET; - break; - case 'Q': - mode.mode |= MODE_DISFORWARD; - break; - case 'f': - if(parc < 5 + args) - return 0; - strlcpy(mode.forward, parv[4 + args], sizeof(mode.forward)); - args++; - break; - case 'j': - /* sent a +j without an arg. */ - if(parc < 5 + args) - return 0; - sscanf(parv[4 + args], "%d:%d", &mode.join_num, &mode.join_time); - args++; - break; - case 'k': - /* sent a +k without a key, eek. */ - if(parc < 5 + args) - return 0; - strlcpy(mode.key, parv[4 + args], sizeof(mode.key)); - args++; - break; - case 'l': - /* sent a +l without a limit. */ - if(parc < 5 + args) - return 0; - mode.limit = atoi(parv[4 + args]); - args++; - break; - } - } - if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL) return 0; newts = atol(parv[1]); oldts = chptr->channelts; - oldmode = &chptr->mode; #ifdef IGNORE_BOGUS_TS if(newts < 800000000) @@ -547,55 +463,33 @@ ms_join(struct Client *client_p, struct Client *source_p, int parc, const char * else keep_new_modes = NO; - if(!keep_new_modes) - mode = *oldmode; - else if(keep_our_modes) - { - mode.mode |= oldmode->mode; - if(oldmode->limit > mode.limit) - mode.limit = oldmode->limit; - if(strcmp(mode.key, oldmode->key) < 0) - strcpy(mode.key, oldmode->key); - if(oldmode->join_num > mode.join_num || - (oldmode->join_num == mode.join_num && - oldmode->join_time > mode.join_time)) - { - mode.join_num = oldmode->join_num; - mode.join_time = oldmode->join_time; - } - if(irccmp(mode.forward, oldmode->forward) < 0) - strcpy(mode.forward, oldmode->forward); - } - else - { - /* If setting -j, clear join throttle state -- jilles */ - if (!mode.join_num) - chptr->join_count = chptr->join_delta = 0; - } - - set_final_mode(&mode, oldmode); - chptr->mode = mode; - /* Lost the TS, other side wins, so remove modes on this side */ if(!keep_our_modes) { + set_final_mode(&mode, &chptr->mode); + chptr->mode = mode; remove_our_modes(chptr, source_p); - DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head) + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head) { del_invite(chptr, ptr->data); } + /* If setting -j, clear join throttle state -- jilles */ + chptr->join_count = chptr->join_delta = 0; sendto_channel_local(ALL_MEMBERS, chptr, ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld", me.name, chptr->chname, chptr->chname, (long) oldts, (long) newts); + /* Update capitalization in channel name, this makes the + * capitalization timestamped like modes are -- jilles */ + strcpy(chptr->chname, parv[2]); + if(*modebuf != '\0') + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s", + source_p->servptr->name, + chptr->chname, modebuf, parabuf); + *modebuf = *parabuf = '\0'; } - if(*modebuf != '\0') - sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s %s %s", - source_p->user->server, chptr->chname, modebuf, parabuf); - - *modebuf = *parabuf = '\0'; - if(!IsMember(source_p, chptr)) { add_user_to_channel(chptr, source_p, CHFL_PEON); @@ -611,14 +505,14 @@ ms_join(struct Client *client_p, struct Client *source_p, int parc, const char * source_p->host, chptr->chname); } - modes = channel_modes(chptr, client_p); sendto_server(client_p, chptr, CAP_TS6, NOCAPS, - ":%s JOIN %ld %s %s", - source_p->id, (long) chptr->channelts, chptr->chname, modes); + ":%s JOIN %ld %s +", + source_p->id, (long) chptr->channelts, chptr->chname); sendto_server(client_p, chptr, NOCAPS, CAP_TS6, ":%s SJOIN %ld %s %s :%s", - source_p->user->server, (long) chptr->channelts, - chptr->chname, modes, source_p->name); + source_p->servptr->name, (long) chptr->channelts, + chptr->chname, keep_new_modes ? "+" : "0", + source_p->name); return 0; } @@ -637,14 +531,15 @@ do_join_0(struct Client *client_p, struct Client *source_p) { struct membership *msptr; struct Channel *chptr = NULL; - dlink_node *ptr; + rb_dlink_node *ptr; /* Finish the flood grace period... */ if(MyClient(source_p) && !IsFloodDone(source_p)) flood_endgrace(source_p); - sendto_server(client_p, NULL, NOCAPS, NOCAPS, ":%s JOIN 0", source_p->name); + sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s JOIN 0", use_id(source_p)); + sendto_server(client_p, NULL, NOCAPS, CAP_TS6, ":%s JOIN 0", source_p->name); if(source_p->user->channel.head && MyConnect(source_p) && !IsOper(source_p) && !IsExemptSpambot(source_p)) @@ -688,30 +583,6 @@ check_channel_name_loc(struct Client *source_p, const char *name) return 1; } -struct mode_letter -{ - int mode; - char letter; -}; - -static struct mode_letter flags[] = { - {MODE_NOPRIVMSGS, 'n'}, - {MODE_TOPICLIMIT, 't'}, - {MODE_SECRET, 's'}, - {MODE_MODERATED, 'm'}, - {MODE_INVITEONLY, 'i'}, - {MODE_PRIVATE, 'p'}, - {MODE_REGONLY, 'r'}, - {MODE_EXLIMIT, 'L'}, - {MODE_PERMANENT, 'P'}, - {MODE_NOCOLOR, 'c'}, - {MODE_FREEINVITE, 'g'}, - {MODE_OPMODERATE, 'z'}, - {MODE_FREETARGET, 'F'}, - {MODE_DISFORWARD, 'Q'}, - {0, 0} -}; - static void set_final_mode(struct Mode *mode, struct Mode *oldmode) { @@ -721,30 +592,30 @@ set_final_mode(struct Mode *mode, struct Mode *oldmode) int i; /* ok, first get a list of modes we need to add */ - for(i = 0; flags[i].letter; i++) + for(i = 0; chmode_flags[i].letter; i++) { - if((mode->mode & flags[i].mode) && !(oldmode->mode & flags[i].mode)) + if((mode->mode & chmode_flags[i].mode) && !(oldmode->mode & chmode_flags[i].mode)) { if(dir != MODE_ADD) { *mbuf++ = '+'; dir = MODE_ADD; } - *mbuf++ = flags[i].letter; + *mbuf++ = chmode_flags[i].letter; } } /* now the ones we need to remove. */ - for(i = 0; flags[i].letter; i++) + for(i = 0; chmode_flags[i].letter; i++) { - if((oldmode->mode & flags[i].mode) && !(mode->mode & flags[i].mode)) + if((oldmode->mode & chmode_flags[i].mode) && !(mode->mode & chmode_flags[i].mode)) { if(dir != MODE_DEL) { *mbuf++ = '-'; dir = MODE_DEL; } - *mbuf++ = flags[i].letter; + *mbuf++ = chmode_flags[i].letter; } } @@ -765,7 +636,7 @@ set_final_mode(struct Mode *mode, struct Mode *oldmode) dir = MODE_DEL; } *mbuf++ = 'k'; - len = ircsprintf(pbuf, "%s ", oldmode->key); + len = rb_sprintf(pbuf, "%s ", oldmode->key); pbuf += len; } if(oldmode->join_num && !mode->join_num) @@ -794,7 +665,7 @@ set_final_mode(struct Mode *mode, struct Mode *oldmode) dir = MODE_ADD; } *mbuf++ = 'l'; - len = ircsprintf(pbuf, "%d ", mode->limit); + len = rb_sprintf(pbuf, "%d ", mode->limit); pbuf += len; } if(mode->key[0] && strcmp(oldmode->key, mode->key)) @@ -805,7 +676,7 @@ set_final_mode(struct Mode *mode, struct Mode *oldmode) dir = MODE_ADD; } *mbuf++ = 'k'; - len = ircsprintf(pbuf, "%s ", mode->key); + len = rb_sprintf(pbuf, "%s ", mode->key); pbuf += len; } if(mode->join_num && (oldmode->join_num != mode->join_num || oldmode->join_time != mode->join_time)) @@ -816,7 +687,7 @@ set_final_mode(struct Mode *mode, struct Mode *oldmode) dir = MODE_ADD; } *mbuf++ = 'j'; - len = ircsprintf(pbuf, "%d:%d ", mode->join_num, mode->join_time); + len = rb_sprintf(pbuf, "%d:%d ", mode->join_num, mode->join_time); pbuf += len; } if(mode->forward[0] && strcmp(oldmode->forward, mode->forward) && ConfigChannel.use_forward) @@ -827,7 +698,7 @@ set_final_mode(struct Mode *mode, struct Mode *oldmode) dir = MODE_ADD; } *mbuf++ = 'f'; - len = ircsprintf(pbuf, "%s ", mode->forward); + len = rb_sprintf(pbuf, "%s ", mode->forward); pbuf += len; } *mbuf = '\0'; @@ -844,7 +715,7 @@ static void remove_our_modes(struct Channel *chptr, struct Client *source_p) { struct membership *msptr; - dlink_node *ptr; + rb_dlink_node *ptr; char lmodebuf[MODEBUFLEN]; char *lpara[MAXMODEPARAMS]; int count = 0; @@ -856,7 +727,7 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p) for(i = 0; i < MAXMODEPARAMS; i++) lpara[i] = NULL; - DLINK_FOREACH(ptr, chptr->members.head) + RB_DLINK_FOREACH(ptr, chptr->members.head) { msptr = ptr->data;