License update
[srvx.git] / src / proto-p10.c
index 2fc7fac7d964928ff56abdf8c30dfb885b3efca8..565b828b87d4ff443e4c5517a99fe2a89bdfbf1d 100644 (file)
@@ -1,11 +1,12 @@
 /* proto-p10.c - IRC protocol output
  * Copyright 2000-2004 srvx Development Team
  *
- * This program is free software; you can redistribute it and/or modify
+ * This file is part of srvx.
+ *
+ * srvx is free software; 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 2 of the License, or
- * (at your option) any later version.  Important limitations are
- * listed in the COPYING file that accompanies this software.
+ * (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
@@ -13,7 +14,8 @@
  * 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, email srvx-maintainers@srvx.net.
+ * along with srvx; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
 
 #include "proto-common.c"
@@ -832,14 +834,18 @@ static CMD_FUNC(cmd_eob_ack)
 
 static CMD_FUNC(cmd_ping)
 {
+    struct server *srv;
+    struct userNode *un;
+
     if(argc > 3)
-    {
         irc_pong(argv[2], argv[1]);
-    }
+    else if ((srv = GetServerH(origin)))
+        irc_pong(self->name, srv->numeric);
+    else if ((un = GetUserH(origin)))
+        irc_pong(self->name, un->numeric);
     else
-    {
         irc_pong(self->name, origin);
-    }
+
     timeq_del(0, timed_send_ping, 0, TIMEQ_IGNORE_WHEN|TIMEQ_IGNORE_DATA);
     timeq_del(0, timed_ping_timeout, 0, TIMEQ_IGNORE_WHEN|TIMEQ_IGNORE_DATA);
     timeq_add(now + ping_freq, timed_send_ping, 0);
@@ -871,20 +877,14 @@ static void
 create_helper(char *name, void *data)
 {
     struct create_desc *cd = data;
-    /* We can't assume the channel create was allowed because of the
-     * bad-word channel checking.
-     */
-    struct chanNode *cn;
-    struct modeNode *mn;
+
     if (!strcmp(name, "0")) {
         while (cd->user->channels.used > 0)
             DelChannelUser(cd->user, cd->user->channels.list[0]->channel, 0, 0);
         return;
     }
-    cn = AddChannel(name, cd->when, NULL, NULL);
-    mn = AddChannelUser(cd->user, cn);
-    if (mn && (cn->members.used == 1))
-        mn->modes = MODE_CHANOP;
+
+    AddChannelUser(cd->user, AddChannel(name, cd->when, NULL, NULL));
 }
 
 static CMD_FUNC(cmd_create)
@@ -1120,7 +1120,8 @@ static CMD_FUNC(cmd_clearmode)
 
 static CMD_FUNC(cmd_topic)
 {
-    static struct chanNode *cn;
+    struct chanNode *cn;
+    time_t chan_ts, topic_ts;
 
     if (argc < 3)
         return 0;
@@ -1128,7 +1129,16 @@ static CMD_FUNC(cmd_topic)
         log_module(MAIN_LOG, LOG_ERROR, "Unable to find channel %s whose topic is being set", argv[1]);
         return 0;
     }
-    SetChannelTopic(cn, GetUserH(origin), argv[2], 0);
+    if (argc >= 5) {
+        /* Looks like an Asuka style topic burst. */
+        chan_ts = atoi(argv[2]);
+        topic_ts = atoi(argv[3]);
+    } else {
+        chan_ts = cn->timestamp;
+        topic_ts = now;
+    }
+    SetChannelTopic(cn, GetUserH(origin), argv[argc-1], 0);
+    cn->topic_time = topic_ts;
     return 1;
 }
 
@@ -1975,7 +1985,7 @@ mod_chanmode_parse(struct chanNode *channel, char **modes, unsigned int argc, un
         case '-':
             add = 0;
             break;
-#define do_chan_mode(FLAG) do { if (add) change->modes_set |= FLAG, change->modes_clear &= ~FLAG; else change->modes_clear |= FLAG, change->modes_set &= ~FLAG; } while(0)
+#define do_chan_mode(FLAG) do { if (add) change->modes_set |= (FLAG), change->modes_clear &= ~(FLAG); else change->modes_clear |= (FLAG), change->modes_set &= ~(FLAG); } while(0)
         case 'C': do_chan_mode(MODE_NOCTCPS); break;
         case 'D': do_chan_mode(MODE_DELAYJOINS); break;
         case 'c': do_chan_mode(MODE_NOCOLORS); break;
@@ -2037,6 +2047,8 @@ mod_chanmode_parse(struct chanNode *channel, char **modes, unsigned int argc, un
                 victim = GetUserN(modes[in_arg++]);
             else
                 victim = GetUserH(modes[in_arg++]);
+            if (!victim)
+                continue;
             if ((change->args[ch_arg].member = GetUserMode(channel, victim)))
                 ch_arg++;
             break;
@@ -2044,6 +2056,13 @@ mod_chanmode_parse(struct chanNode *channel, char **modes, unsigned int argc, un
         }
     }
     change->argc = ch_arg; /* in case any turned out to be ignored */
+    if (change->modes_set & MODE_SECRET) {
+        change->modes_set &= ~(MODE_PRIVATE);
+        change->modes_clear |= MODE_PRIVATE;
+    } else if (change->modes_set & MODE_PRIVATE) {
+        change->modes_set &= ~(MODE_SECRET);
+        change->modes_clear |= MODE_SECRET;
+    }
     return change;
   error:
     mod_chanmode_free(change);
@@ -2066,7 +2085,8 @@ static void
 mod_chanmode_append(struct chanmode_buffer *buf, char ch, const char *arg)
 {
     size_t arg_len = strlen(arg);
-    if (buf->modes_used + buf->args_used + buf->chname_len + arg_len > 450) {
+    if (buf->modes_used > (MAXMODEPARAMS) ||
+        buf->modes_used + buf->args_used + buf->chname_len + arg_len > 450) {
         memcpy(buf->modes + buf->modes_used, buf->args, buf->args_used);
         buf->modes[buf->modes_used + buf->args_used] = '\0';
         irc_mode((buf->is_chanop ? buf->actor : NULL), buf->channel, buf->modes);
@@ -2088,6 +2108,7 @@ mod_chanmode_announce(struct userNode *who, struct chanNode *channel, struct mod
     struct modeNode *mn;
     char int_buff[32], mode = '\0';
 
+    assert(change->argc <= change->alloc_argc);
     memset(&chbuf, 0, sizeof(chbuf));
     chbuf.channel = channel;
     chbuf.actor = who;
@@ -2189,6 +2210,7 @@ char *
 mod_chanmode_format(struct mod_chanmode *change, char *outbuff)
 {
     unsigned int used = 0;
+    assert(change->argc <= change->alloc_argc);
     if (change->modes_clear) {
         outbuff[used++] = '-';
 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) outbuff[used++] = CHAR