+ if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL)
+ return 0;
+
+ newts = atol(parv[1]);
+ oldts = chptr->channelts;
+
+#ifdef IGNORE_BOGUS_TS
+ if(newts < 800000000)
+ {
+ sendto_realops_snomask(SNO_DEBUG, L_ALL,
+ "*** Bogus TS %ld on %s ignored from %s",
+ (long) newts, chptr->chname, client_p->name);
+ newts = (oldts == 0) ? oldts : 800000000;
+ }
+#else
+ /* making a channel TS0 */
+ if(!isnew && !newts && oldts)
+ {
+ sendto_channel_local(ALL_MEMBERS, chptr,
+ ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0",
+ me.name, chptr->chname, chptr->chname, (long) oldts);
+ sendto_realops_snomask(SNO_GENERAL, L_ALL,
+ "Server %s changing TS on %s from %ld to 0",
+ source_p->name, chptr->chname, (long) oldts);
+ }
+#endif
+
+ if(isnew)
+ chptr->channelts = newts;
+ else if(newts == 0 || oldts == 0)
+ chptr->channelts = 0;
+ else if(newts == oldts)
+ ;
+ else if(newts < oldts)
+ {
+ keep_our_modes = NO;
+ chptr->channelts = newts;
+ }
+ else
+ keep_new_modes = NO;
+
+ /* 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);
+ 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(!IsMember(source_p, chptr))
+ {
+ add_user_to_channel(chptr, source_p, CHFL_PEON);
+ if (chptr->mode.join_num &&
+ rb_current_time() - chptr->join_delta >= chptr->mode.join_time)
+ {
+ chptr->join_count = 0;
+ chptr->join_delta = rb_current_time();
+ }
+ chptr->join_count++;
+ sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s",
+ source_p->name, source_p->username,
+ source_p->host, chptr->chname);
+ }
+
+ sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
+ ":%s JOIN %ld %s +",
+ source_p->id, (long) chptr->channelts, chptr->chname);
+ return 0;
+}
+
+static int
+ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+{
+ static char buf_uid[BUFSIZE];
+ static const char empty_modes[] = "0";
+ struct Channel *chptr;
+ struct Client *target_p, *fakesource_p;
+ time_t newts;
+ time_t oldts;
+ static struct Mode mode, *oldmode;
+ const char *modes;
+ int args = 0;
+ int keep_our_modes = 1;
+ int keep_new_modes = 1;
+ int fl;
+ int isnew;
+ int mlen_uid;
+ int len_nick;
+ int len_uid;
+ int len;
+ int joins = 0;
+ const char *s;
+ char *ptr_uid;
+ char *p;
+ int i, joinc = 0, timeslice = 0;
+ static char empty[] = "";
+ rb_dlink_node *ptr, *next_ptr;
+
+ if(!IsChannelName(parv[2]) || !check_channel_name(parv[2]))
+ return 0;
+
+ /* SJOIN's for local channels can't happen. */
+ if(*parv[2] == '&')
+ return 0;
+
+ modebuf[0] = parabuf[0] = mode.key[0] = mode.forward[0] = '\0';
+ pargs = mode.mode = mode.limit = mode.join_num = mode.join_time = 0;
+
+ /* Hide connecting server on netburst -- jilles */
+ if (ConfigServerHide.flatten_links && !HasSentEob(source_p))
+ fakesource_p = &me;
+ else
+ fakesource_p = source_p;
+
+ mbuf = modebuf;
+ newts = atol(parv[1]);
+