miscellaneous bugfixes and indentation fixes
[srvx.git] / src / opserv.c
index e1467fa3dd28d5b57a6c4a75faeb3679f2bc3728..26dab12415b486e4941e7de64899ffd4fd46fc0b 100644 (file)
@@ -1,11 +1,12 @@
 /* opserv.c - IRC Operator assistance service
  * 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 "conf.h"
@@ -113,6 +115,7 @@ static const struct message_entry msgtab[] = {
     { "OSMSG_WHOIS_IDENT", "%s (%s@%s) from %d.%d.%d.%d" },
     { "OSMSG_WHOIS_NICK", "Nick    : %s" },
     { "OSMSG_WHOIS_HOST", "Host    : %s@%s" },
+    { "OSMSG_WHOIS_FAKEHOST", "Fakehost: %s" },
     { "OSMSG_WHOIS_IP",   "Real IP : %s" },
     { "OSMSG_WHOIS_MODES", "Modes   : +%s " },
     { "OSMSG_WHOIS_INFO", "Info    : %s" },
@@ -160,6 +163,7 @@ static const struct message_entry msgtab[] = {
     { "OSMSG_RAW_PARSE_ERROR", "Error parsing raw line (not dumping to uplink)." },
     { "OSMSG_COLLIDED_NICK", "Now temporarily holding nick $b%s$b." },
     { "OSMSG_RESERVED_NICK", "Now reserving nick $b%s$b." },
+    { "OSMSG_NICK_UNRESERVED", "Nick $b%s$b is no longer reserved." },
     { "OSMSG_NOT_RESERVED", "Nick $b%s$b is not reserved." },
     { "OSMSG_ILLEGAL_REASON", "This channel is illegal." },
     { "OSMSG_ILLEGAL_KILL_REASON", "Joined an illegal modeless channel - do not repeat." },
@@ -240,7 +244,7 @@ static const struct message_entry msgtab[] = {
     { "OSMSG_CHANINFO_TOPIC_UNKNOWN", "Topic: (none / not gathered)" },
     { "OSMSG_CHANINFO_BAN_COUNT", "Bans (%d):" },
     { "OSMSG_CHANINFO_BAN", "%%s by %%s (%a %b %d %H:%M:%S %Y)" },
-    { "OSMSG_CHANINFO_MANY_USERS", "%d users (\"/msg $s %s %s users\" for the list)" },
+    { "OSMSG_CHANINFO_MANY_USERS", "%d users (\"/msg $S %s %s users\" for the list)" },
     { "OSMSG_CHANINFO_USER_COUNT", "Users (%d):" },
     { "OSMSG_CSEARCH_CHANNEL_INFO", "%s [%d users] %s %s" },
     { NULL, NULL }
@@ -394,7 +398,7 @@ static MODCMD_FUNC(cmd_ban)
     struct mod_chanmode change;
     struct userNode *victim;
 
-    change.modes_set = change.modes_clear = 0;
+    mod_chanmode_init(&change);
     change.argc = 1;
     change.args[0].mode = MODE_BAN;
     if (is_ircmask(argv[1]))
@@ -442,7 +446,7 @@ static MODCMD_FUNC(cmd_chaninfo)
        for (n = 0; n < channel->banlist.used; n++) {
            ban = channel->banlist.list[n];
            strftime(buffer, sizeof(buffer), fmt, localtime(&ban->set));
-           reply(buffer, ban->ban, ban->who);
+           send_message_type(4, user, cmd->parent->bot, buffer, ban->ban, ban->who);
        }
     }
     if ((argc < 2) && (channel->members.used >= 50)) {
@@ -534,9 +538,8 @@ static MODCMD_FUNC(cmd_clearmodes)
        reply("OSMSG_NO_CHANNEL_MODES", channel->name);
         return 0;
     }
-    change.modes_set = 0;
+    mod_chanmode_init(&change);
     change.modes_clear = channel->modes;
-    change.argc = 0;
     modcmd_chanmode_announce(&change);
     reply("OSMSG_CLEARMODES_DONE", channel->name);
     return 1;
@@ -917,7 +920,7 @@ static MODCMD_FUNC(cmd_join)
         return 0;
     } else {
         struct mod_chanmode change;
-        change.modes_set = change.modes_clear = 0;
+        mod_chanmode_init(&change);
         change.argc = 1;
         change.args[0].mode = MODE_CHANOP;
         change.args[0].member = AddChannelUser(bot, channel);
@@ -963,7 +966,7 @@ static MODCMD_FUNC(cmd_kickall)
      * channel, we have to join it in temporarily. */
     if (!(inchan = GetUserMode(channel, bot) ? 1 : 0)) {
         struct mod_chanmode change;
-        memset(&change, 0, sizeof(change));
+        mod_chanmode_init(&change);
         change.args[0].mode = MODE_CHANOP;
         change.args[0].member = AddChannelUser(bot, channel);
         modcmd_chanmode_announce(&change);
@@ -1012,7 +1015,7 @@ static MODCMD_FUNC(cmd_kickban)
        reply("OSMSG_NOT_ON_CHANNEL", target->nick, channel->name);
        return 0;
     }
-    change.modes_set = change.modes_clear = 0;
+    mod_chanmode_init(&change);
     change.argc = 1;
     change.args[0].mode = MODE_BAN;
     change.args[0].hostmask = mask = generate_hostmask(target, 0);
@@ -1039,11 +1042,12 @@ static MODCMD_FUNC(cmd_kickbanall)
         change->args[1].mode = MODE_BAN;
         change->args[1].hostmask = "*!*@*";
     } else {
-        change = mod_chanmode_alloc(2);
+        change = mod_chanmode_alloc(1);
         change->args[0].mode = MODE_BAN;
         change->args[0].hostmask = "*!*@*";
     }
     modcmd_chanmode_announce(change);
+    mod_chanmode_free(change);
     if (argc < 2) {
        reason = alloca(strlen(OSMSG_KICK_REQUESTED)+strlen(user->nick)+1);
        sprintf(reason, OSMSG_KICK_REQUESTED, user->nick);
@@ -1110,7 +1114,7 @@ static MODCMD_FUNC(cmd_op)
             continue;
         if (!(mn =  GetUserMode(channel, victim)))
             continue;
-        if (!(mn->modes & MODE_CHANOP))
+        if (mn->modes & MODE_CHANOP)
             continue;
         change->args[count].mode = MODE_CHANOP;
         change->args[count++].member = mn;
@@ -1166,6 +1170,8 @@ static MODCMD_FUNC(cmd_whois)
     }
     reply("OSMSG_WHOIS_NICK", target->nick);
     reply("OSMSG_WHOIS_HOST", target->ident, target->hostname);
+    if (IsFakeHost(target))
+        reply("OSMSG_WHOIS_FAKEHOST", target->fakehost);
     reply("OSMSG_WHOIS_IP", inet_ntoa(target->ip));
     if (target->modes) {
        bpos = 0;
@@ -1180,6 +1186,7 @@ static MODCMD_FUNC(cmd_whois)
        if (IsDeaf(target)) buffer[bpos++] = 'd';
         if (IsHiddenHost(target)) buffer[bpos++] = 'x';
         if (IsGagged(target)) buffer_cat(" (gagged)");
+       if (IsRegistering(target)) buffer_cat(" (registered account)");
        buffer[bpos] = 0;
        if (bpos > 0)
             reply("OSMSG_WHOIS_MODES", buffer);
@@ -1190,7 +1197,7 @@ static MODCMD_FUNC(cmd_whois)
 #endif
     reply("OSMSG_WHOIS_SERVER", target->uplink->name);
     reply("OSMSG_WHOIS_ACCOUNT", (target->handle_info ? target->handle_info->handle : "Not authenticated"));
-    intervalString(buffer, now - target->timestamp);
+    intervalString(buffer, now - target->timestamp, user->handle_info);
     reply("OSMSG_WHOIS_NICK_AGE", buffer);
     if (target->channels.used <= MAX_CHANNELS_WHOIS)
        opserv_ison(user, target, "OSMSG_WHOIS_CHANNELS");
@@ -1202,7 +1209,7 @@ static MODCMD_FUNC(cmd_whois)
 static MODCMD_FUNC(cmd_unban)
 {
     struct mod_chanmode change;
-    change.modes_set = change.modes_clear = 0;
+    mod_chanmode_init(&change);
     change.argc = 1;
     change.args[0].mode = MODE_REMOVE | MODE_BAN;
     change.args[0].hostmask = argv[1];
@@ -1241,7 +1248,7 @@ static MODCMD_FUNC(cmd_devoiceall)
     change = mod_chanmode_alloc(channel->members.used);
     for (ii = count = 0; ii < channel->members.used; ++ii) {
        struct modeNode *mn = channel->members.list[ii];
-       if (mn->modes & MODE_VOICE)
+       if (!(mn->modes & MODE_VOICE))
             continue;
         change->args[count].mode = MODE_REMOVE | MODE_VOICE;
         change->args[count++].member = mn;
@@ -1392,8 +1399,9 @@ static MODCMD_FUNC(cmd_stats_network2) {
 #endif
         tbl.contents[nn][1] = buffer;
         ofs = strlen(buffer) + 1;
-        intervalString(buffer + ofs, now - server->link);
-        if (server->self_burst) strcat(buffer + ofs, " Bursting");
+        intervalString(buffer + ofs, now - server->link, user->handle_info);
+        if (server->self_burst)
+            strcat(buffer + ofs, " Bursting");
         tbl.contents[nn][2] = buffer + ofs;
         nn++;
     }
@@ -1425,9 +1433,9 @@ static MODCMD_FUNC(cmd_stats_trusted) {
         th = dict_find(opserv_trusted_hosts, argv[1], NULL);
         if (th) {
             if (th->issued)
-                intervalString(issued, now - th->issued);
+                intervalString(issued, now - th->issued, user->handle_info);
             if (th->expires)
-                intervalString(length, th->expires - now);
+                intervalString(length, th->expires - now, user->handle_info);
             if (th->limit)
                 sprintf(limit, "limit %lu", th->limit);
             reply("OSMSG_HOST_IS_TRUSTED",
@@ -1445,9 +1453,9 @@ static MODCMD_FUNC(cmd_stats_trusted) {
         for (it = dict_first(opserv_trusted_hosts); it; it = iter_next(it)) {
             th = iter_data(it);
             if (th->issued)
-                intervalString(issued, now - th->issued);
+                intervalString(issued, now - th->issued, user->handle_info);
             if (th->expires)
-                intervalString(length, th->expires - now);
+                intervalString(length, th->expires - now, user->handle_info);
             if (th->limit)
                 sprintf(limit, "limit %lu", th->limit);
             reply("OSMSG_HOST_IS_TRUSTED", iter_key(it),
@@ -1488,7 +1496,7 @@ static MODCMD_FUNC(cmd_stats_uptime) {
             clocks_per_sec = CLOCKS_PER_SEC;
         }
     }
-    intervalString(uptime, time(NULL)-boot_time);
+    intervalString(uptime, time(NULL)-boot_time, user->handle_info);
     times(&buf);
     reply("OSMSG_UPTIME_STATS",
           uptime, lines_processed,
@@ -1537,8 +1545,10 @@ static MODCMD_FUNC(cmd_stats_gags) {
     table.contents[0][3] = "Reason";
     for (nn=1, gag=gagList; gag; nn++, gag=gag->next) {
         char expstr[INTERVALLEN];
-        if (gag->expires) intervalString(expstr, gag->expires - now);
-        else strcpy(expstr, "Never");
+        if (gag->expires)
+            intervalString(expstr, gag->expires - now, user->handle_info);
+        else
+            strcpy(expstr, "Never");
         table.contents[nn] = calloc(table.width, sizeof(char*));
         table.contents[nn][0] = gag->mask;
         table.contents[nn][1] = gag->owner;
@@ -1802,7 +1812,7 @@ opserv_shutdown_channel(struct chanNode *channel, const char *reason)
         struct modeNode *mNode = channel->members.list[--nn];
         if (IsService(mNode->user))
             continue;
-        KickChannelUser(mNode->user, channel, opserv, reason);
+        KickChannelUser(mNode->user, channel, opserv, user_find_message(mNode->user, reason));
     }
     timeq_add(now + opserv_conf.purge_lock_delay, opserv_part_channel, channel);
 }
@@ -1826,6 +1836,12 @@ opserv_channel_check(struct chanNode *newchan)
     newchan->bad_channel = opserv_bad_channel(newchan->name);
 }
 
+static void
+opserv_channel_delete(struct chanNode *chan)
+{
+    timeq_del(0, opserv_part_channel, chan, TIMEQ_IGNORE_WHEN);
+}
+
 static int
 opserv_join_check(struct modeNode *mNode)
 {
@@ -1843,7 +1859,7 @@ opserv_join_check(struct modeNode *mNode)
         if (channel->name[0] != '#')
             DelUser(user, opserv, 1, "OSMSG_ILLEGAL_KILL_REASON");
         else if (!GetUserMode(channel, opserv))
-            opserv_shutdown_channel(channel, user_find_message(user, "OSMSG_ILLEGAL_REASON"));
+            opserv_shutdown_channel(channel, "OSMSG_ILLEGAL_REASON");
         else {
             send_message(user, opserv, "OSMSG_ILLEGAL_CHANNEL", channel->name);
             msg = user_find_message(user, "OSMSG_ILLEGAL_REASON");
@@ -1862,7 +1878,7 @@ opserv_join_check(struct modeNode *mNode)
         /* Don't moderate the channel unless it is activated and
            the number of users in the channel is over the threshold. */
         struct mod_chanmode change;
-        change.modes_set = change.modes_clear = change.argc = 0;
+        mod_chanmode_init(&change);
         channel->join_flooded = 1;
         if (opserv_conf.join_flood_moderate && (channel->members.used > opserv_conf.join_flood_moderate_threshold)) {
             if (!GetUserMode(channel, opserv)) {
@@ -1875,7 +1891,7 @@ opserv_join_check(struct modeNode *mNode)
                 change.modes_set |= MODE_MODERATED;
             if (change.modes_set || change.argc)
                 mod_chanmode_announce(opserv, channel, &change);
-            send_channel_notice(channel, opserv, "OSMSG_FLOOD_MODERATE");
+            send_target_message(0, channel->name, opserv, "OSMSG_FLOOD_MODERATE");
             opserv_alert("Warning: Possible join flood in %s (currently %d users; channel moderated).", channel->name, channel->members.used);
         } else {
             opserv_alert("Warning: Possible join flood in %s (currently %d users).", channel->name, channel->members.used);
@@ -2081,7 +2097,7 @@ static MODCMD_FUNC(cmd_addtrust)
     unsigned long interval;
     char *reason, *tmp;
     struct in_addr tmpaddr;
-    int count;
+    unsigned int count;
 
     if (dict_find(opserv_trusted_hosts, argv[1], NULL)) {
         reply("OSMSG_ALREADY_TRUSTED", argv[1]);
@@ -2094,7 +2110,7 @@ static MODCMD_FUNC(cmd_addtrust)
     }
 
     count = strtoul(argv[2], &tmp, 10);
-    if (!count || *tmp != '\0') {
+    if (*tmp != '\0') {
         reply("OSMSG_BAD_NUMBER", argv[2]);
         return 0;
     }
@@ -2116,7 +2132,7 @@ static MODCMD_FUNC(cmd_edittrust)
     unsigned long interval;
     struct trusted_host *th;
     char *reason, *tmp;
-    int count;
+    unsigned int count;
 
     th = dict_find(opserv_trusted_hosts, argv[1], NULL);
     if (!th) {
@@ -2267,7 +2283,7 @@ static MODCMD_FUNC(cmd_clone)
            reply("MSG_CHANNEL_UNKNOWN", argv[3]);
            return 0;
        }
-        change.modes_set = change.modes_clear = 0;
+        mod_chanmode_init(&change);
         change.argc = 1;
         change.args[0].mode = MODE_CHANOP;
         change.args[0].member = GetUserMode(channel, clone);
@@ -4007,8 +4023,10 @@ void
 init_opserv(const char *nick)
 {
     OS_LOG = log_register_type("OpServ", "file:opserv.log");
-    if (nick)
-        opserv = AddService(nick, "Oper Services");
+    if (nick) {
+        const char *modes = conf_get_data("services/opserv/modes", RECDB_QSTRING);
+        opserv = AddService(nick, modes ? modes : NULL, "Oper Services", NULL);
+    }
     conf_register_reload(opserv_conf_read);
 
     memset(level_strings, 0, sizeof(level_strings));
@@ -4112,13 +4130,14 @@ init_opserv(const char *nick)
     reg_nick_change_func(opserv_alert_check_nick);
     reg_del_user_func(opserv_user_cleanup);
     reg_new_channel_func(opserv_channel_check);
+    reg_del_channel_func(opserv_channel_delete);
     reg_join_func(opserv_join_check);
     reg_auth_func(opserv_staff_alert);
 
     opserv_db_init();
     saxdb_register("OpServ", opserv_saxdb_read, opserv_saxdb_write);
     if (nick)
-        service_register(opserv, '?');
+        service_register(opserv)->trigger = '?';
 
     reg_exit_func(opserv_db_cleanup);
     message_register_table(msgtab);