store devnull classes by their (new) id instead of their names
[srvx.git] / src / opserv.c
index 0702a1072e9cebbf1783cc85429df6ab2271c1df..c4844b7604a67c8b53cd0767445bb72a1d3db4c2 100644 (file)
@@ -22,6 +22,7 @@
 #include "gline.h"
 #include "global.h"
 #include "nickserv.h"
+#include "chanserv.h"
 #include "modcmd.h"
 #include "opserv.h"
 #include "timeq.h"
 #define KEY_EXPIRES "expires"
 #define KEY_STAFF_AUTH_CHANNEL "staff_auth_channel"
 #define KEY_STAFF_AUTH_CHANNEL_MODES "staff_auth_channel_modes"
+#define KEY_STAFF_AUTH_FORCE_OPS "staff_auth_force_opers"
 #define KEY_CLONE_GLINE_DURATION "clone_gline_duration"
 #define KEY_BLOCK_GLINE_DURATION "block_gline_duration"
 #define KEY_ISSUER "issuer"
 #define KEY_ISSUED "issued"
 #define KEY_DEVNULL_CLASSES "classes"
+#define KEY_DEVNULL_LASTID "lastid"
+#define KEY_DEVNULL_ID "id"
 #define KEY_DEVNULL_NAME "class"
 #define KEY_DEVNULL_MODE "modes"
 #define KEY_DEVNULL_MAXCHAN "chanlimit"
@@ -262,6 +266,14 @@ static const struct message_entry msgtab[] = {
     { "OSMSG_CSEARCH_CHANNEL_INFO", "%s [%d users] %s %s" },
     { "OSMSG_TRACE_MAX_CHANNELS", "You may not use the 'channel' criterion more than %d times." },
     { "OSMSG_FORCEKICK_LOCAL", "You cannot kick $b%s$b forcefully." },
+    { "OSMSG_SVSNONICK", "$b%s$b is not a valid nick." },
+    { "OSMSG_SVSNICKUSED", "$b%s$b is an already used nickname." },
+    { "OSMSG_SVSNICK", "You have renamed $b%s$b to $b%s$b." },
+    { "OSMSG_SVSJOIN", "$b%s$b joined $b%s$b." },
+    { "OSMSG_SVSPART", "$b%s$b parted $b%s$b." },
+    { "OSMSG_SVSKILL", "$b%s$b killed: $b%s$b." },
+    { "OSMSG_SVSMODE", "You have set mode $b%s$b for $b%s$b." },
+    { "OSMSG_SIMUL", "You have simuled $b%s$b: %s" },
     { "OSMSG_DEVNULL_USER" , "[%s] %s  %s" },
     { "OSMSG_DEVNULL_MATCH" , "%d Users found." },
     { "OSMSG_DEVNULL_CLASS" , "%s is not a valid DevNull class." },
@@ -289,6 +301,7 @@ static const struct message_entry msgtab[] = {
     { "OSMSG_DEVNULL_SET_M", "OverrideNoAmsg:   %s" },
     { "OSMSG_DEVNULL_SET_N", "MaxSendQ:         %s" },
     { "OSMSG_DEVNULL_SET_N_i", "MaxSendQ:         %i" },
+    { "OSMSG_DEVNULL_SET_OPME", "OpMe:             %s" },
     { "OSMSG_DEVNULL_SET_DONE", "Done." },
     { "OSMSG_DEVNULL_RENAMED", "Devnull class %s renamed to %s" },
     { "OSMSG_DEVNULL_SET_INVALID", "Invalid Option for setting %s" },
@@ -318,11 +331,15 @@ static unsigned int new_user_flood;
 const char *devnull_modes = DEVNULL_MODES;
 static char *level_strings[1001];
 static char devnull_inverse_modes[256];
+unsigned int devnull_last_id = 1;
+
+void *devnull_check_priv_func = NULL;
 
 static struct {
     struct chanNode *debug_channel;
     struct chanNode *alert_channel;
     struct chanNode *staff_auth_channel;
+    int staff_auth_force;
     struct policer_params *join_policer_params;
     struct policer new_user_policer;
     unsigned long untrusted_max;
@@ -423,13 +440,13 @@ opserv_free_user_alert(void *data)
 }
 
 #if defined(GCC_VARMACROS)
-# define opserv_debug(ARGS...) do { if (opserv_conf.debug_channel) send_channel_notice(opserv_conf.debug_channel, opserv, ARGS); } while (0)
-# define opserv_alert(ARGS...) do { if (opserv_conf.alert_channel) send_channel_notice(opserv_conf.alert_channel, opserv, ARGS); } while (0)
-# define opserv_custom_alert(CHAN, ARGS...) do { if (CHAN) send_target_message(4, (CHAN), opserv, ARGS); else if (opserv_conf.alert_channel) send_channel_notice(opserv_conf.alert_channel, opserv, ARGS); } while (0)
+# define opserv_debug(ARGS...) do { if (opserv_conf.debug_channel) send_channel_message(opserv_conf.debug_channel, opserv, ARGS); } while (0)
+# define opserv_alert(ARGS...) do { if (opserv_conf.alert_channel) send_channel_message(opserv_conf.alert_channel, opserv, ARGS); } while (0)
+# define opserv_custom_alert(CHAN, ARGS...) do { if (CHAN) send_target_message(5, (CHAN), opserv, ARGS); else if (opserv_conf.alert_channel) send_channel_message(opserv_conf.alert_channel, opserv, ARGS); } while (0)
 #elif defined(C99_VARMACROS)
-# define opserv_debug(...) do { if (opserv_conf.debug_channel) send_channel_notice(opserv_conf.debug_channel, opserv, __VA_ARGS__); } while (0)
-# define opserv_alert(...) do { if (opserv_conf.alert_channel) send_channel_notice(opserv_conf.alert_channel, opserv, __VA_ARGS__); } while (0)
-# define opserv_custom_alert(chan, ...) do { if (chan) send_target_message(4, chan, opserv, __VA_ARGS__); else if (opserv_conf.alert_channel) send_channel_notice(opserv_conf.alert_channel, opserv, __VA_ARGS__); } while (0)
+# define opserv_debug(...) do { if (opserv_conf.debug_channel) send_channel_message(opserv_conf.debug_channel, opserv, __VA_ARGS__); } while (0)
+# define opserv_alert(...) do { if (opserv_conf.alert_channel) send_channel_message(opserv_conf.alert_channel, opserv, __VA_ARGS__); } while (0)
+# define opserv_custom_alert(chan, ...) do { if (chan) send_target_message(5, chan, opserv, __VA_ARGS__); else if (opserv_conf.alert_channel) send_channel_message(opserv_conf.alert_channel, opserv, __VA_ARGS__); } while (0)
 #endif
 
 /* A lot of these commands are very similar to what ChanServ can do,
@@ -1230,7 +1247,7 @@ static MODCMD_FUNC(cmd_part)
 
 static MODCMD_FUNC(cmd_mode)
 {
-    if (!modcmd_chanmode(argv+1, argc-1, MCP_ALLOW_OVB|MCP_KEY_FREE|MC_ANNOUNCE)) {
+    if (!modcmd_chanmode(argv+1, argc-1, MCP_ALLOW_OVB|MCP_KEY_FREE|MC_ANNOUNCE|MCP_OPERMODE)) {
         reply("MSG_INVALID_MODES", unsplit_string(argv+1, argc-1, NULL));
         return 0;
     }
@@ -1329,7 +1346,7 @@ static MODCMD_FUNC(cmd_whois)
     reply("OSMSG_WHOIS_ACCOUNT", (target->handle_info ? target->handle_info->handle : "Not authenticated"));
     intervalString(buffer, now - target->timestamp, user->handle_info);
     reply("OSMSG_WHOIS_NICK_AGE", buffer);
-    if (target->channels.used <= MAX_CHANNELS_WHOIS)
+    if (target->channels.used <= MAX_CHANNELS_WHOIS || HANDLE_FLAGGED(user->handle_info, BOT))
         opserv_ison(user, target, "OSMSG_WHOIS_CHANNELS");
     else
         reply("OSMSG_WHOIS_HIDECHANS");
@@ -2802,12 +2819,16 @@ trusted_host_read(const char *host, void *data, UNUSED_ARG(void *extra))
 }
 
 static void
-opserv_add_devnull_class(const char *name, unsigned long modes, unsigned long maxchan, unsigned long maxsendq)
+opserv_add_devnull_class(const char *name, unsigned int id, unsigned long modes, unsigned long maxchan, unsigned long maxsendq)
 {
     struct devnull_class *th;
     th = calloc(1, sizeof(*th));
     if (!th)
         return;
+    if(id)
+        th->id = id;
+    else
+        th->id = (++devnull_last_id);
     th->name = strdup(name);
     th->modes = modes;
     th->maxchan = maxchan;
@@ -2829,12 +2850,16 @@ devnull_class_read(const char *name, void *data, UNUSED_ARG(void *extra))
     struct record_data *rd = data;
     const char *nameb = name, *str;
     unsigned long modes, maxchan, maxsendq;
-    unsigned int ii;
+    unsigned int id, ii;
 
     if (rd->type == RECDB_OBJECT) {
         dict_t obj = GET_RECORD_OBJECT(rd);
         /* new style structure */
-        nameb = database_get_data(obj, KEY_DEVNULL_NAME, RECDB_QSTRING);
+        str = database_get_data(obj, KEY_DEVNULL_ID, RECDB_QSTRING);
+        if(str)
+            id = atoi(str);
+        else
+            id = 0;
         str = database_get_data(obj, KEY_DEVNULL_MODE, RECDB_QSTRING);
         modes = 0;
         if (str) {
@@ -2848,7 +2873,7 @@ devnull_class_read(const char *name, void *data, UNUSED_ARG(void *extra))
     } else
         return 0;
 
-    opserv_add_devnull_class(nameb, modes, maxchan, maxsendq);
+    opserv_add_devnull_class(name, id, modes, maxchan, maxsendq);
     return 0;
 }
 
@@ -2859,6 +2884,7 @@ opserv_saxdb_read(struct dict *conf_db)
     struct record_data *rd;
     dict_iterator_t it;
     unsigned int nn;
+    char *str;
 
     if ((object = database_get_data(conf_db, KEY_RESERVES, RECDB_OBJECT)))
         dict_foreach(object, add_reserved, opserv_reserved_nick_dict);
@@ -2888,12 +2914,13 @@ opserv_saxdb_read(struct dict *conf_db)
             dict_insert(opserv_exempt_channels, strdup(rd->d.slist->list[nn]), NULL);
     }
     if ((object = database_get_data(conf_db, KEY_MAX_CLIENTS, RECDB_OBJECT))) {
-        char *str;
         if ((str = database_get_data(object, KEY_MAX, RECDB_QSTRING)))
             max_clients = atoi(str);
         if ((str = database_get_data(object, KEY_TIME, RECDB_QSTRING)))
             max_clients_time = atoi(str);
     }
+    if ((str = database_get_data(object, KEY_DEVNULL_LASTID, RECDB_QSTRING)))
+        devnull_last_id = atoi(str);
     if ((object = database_get_data(conf_db, KEY_TRUSTED_HOSTS, RECDB_OBJECT)))
         dict_foreach(object, trusted_host_read, opserv_trusted_hosts);
     if ((object = database_get_data(conf_db, KEY_DEVNULL_CLASSES, RECDB_OBJECT)))
@@ -2960,8 +2987,8 @@ opserv_saxdb_write(struct saxdb_context *ctx)
         saxdb_start_record(ctx, KEY_DEVNULL_CLASSES, 1);
         for (it = dict_first(opserv_devnull_classes); it; it = iter_next(it)) {
             struct devnull_class *th = iter_data(it);
-            saxdb_start_record(ctx, iter_key(it), 0);
-            if (th->name) saxdb_write_string(ctx, KEY_DEVNULL_NAME, th->name);
+            saxdb_start_record(ctx, th->name, 0);
+            saxdb_write_int(ctx, KEY_DEVNULL_ID, th->id);
             if (th->modes) {
                 int ii, flen;
                 char flags[50];
@@ -2977,6 +3004,7 @@ opserv_saxdb_write(struct saxdb_context *ctx)
         }
         saxdb_end_record(ctx);
     }
+    saxdb_write_int(ctx, KEY_DEVNULL_LASTID, devnull_last_id);
     /* gags */
     if (gagList) {
         struct gag_entry *gag;
@@ -4084,6 +4112,8 @@ opserv_staff_alert(struct userNode *user, UNUSED_ARG(struct handle_info *old_han
         || user->uplink->burst
         || !user->handle_info)
         return;
+    else if (IsBot(user))
+        return;
     else if (user->handle_info->opserv_level)
         type = "OPER";
     else if (IsNetworkHelper(user))
@@ -4094,9 +4124,9 @@ opserv_staff_alert(struct userNode *user, UNUSED_ARG(struct handle_info *old_han
         return;
 
     if (irc_in_addr_is_valid(user->ip))
-        send_channel_notice(opserv_conf.staff_auth_channel, opserv, IDENT_FORMAT" authed to %s account %s", IDENT_DATA(user), type, user->handle_info->handle);
+        send_channel_message(opserv_conf.staff_auth_channel, opserv, IDENT_FORMAT" authed to %s account %s", IDENT_DATA(user), type, user->handle_info->handle);
     else
-        send_channel_notice(opserv_conf.staff_auth_channel, opserv, "%s [%s@%s] authed to %s account %s", user->nick, user->ident, user->hostname, type, user->handle_info->handle);
+        send_channel_message(opserv_conf.staff_auth_channel, opserv, "%s [%s@%s] authed to %s account %s", user->nick, user->ident, user->hostname, type, user->handle_info->handle);
 }
 
 static void
@@ -4262,7 +4292,7 @@ static MODCMD_FUNC(cmd_listdevnull)
         count++;
     }
     tbl.length = count+1;
-    tbl.width = 14;
+    tbl.width = 15;
     tbl.flags = 0;
     tbl.flags = TABLE_NO_FREE;
     tbl.contents = malloc(tbl.length * sizeof(tbl.contents[0]));
@@ -4281,6 +4311,7 @@ static MODCMD_FUNC(cmd_listdevnull)
     tbl.contents[0][11] = "+S";
     tbl.contents[0][12] = "+X";
     tbl.contents[0][13] = "MaxQ";
+    tbl.contents[0][14] = "OpMe";
     if(!count)
     {
         table_send(cmd->parent->bot, user->nick, 0, NULL, tbl);
@@ -4293,73 +4324,78 @@ static MODCMD_FUNC(cmd_listdevnull)
         struct devnull_class *th = iter_data(it);
         tbl.contents[++ii] = malloc(tbl.width * sizeof(tbl.contents[0][0]));
         tbl.contents[ii][0] = th->name;
-        if(DEVNULL_FLAGGED(th, MODE_A)) {
+        if(DEVNULL_HAS_PRIV(th, CHANLIMIT)) {
             tbl.contents[ii][1] = strtab(th->maxchan);
         } else {
             tbl.contents[ii][1] = off;
         }
-        if(DEVNULL_FLAGGED(th, MODE_B)) {
+        if(DEVNULL_HAS_PRIV(th, UNLIMITTARGET)) {
             tbl.contents[ii][2] = on;
         } else {
             tbl.contents[ii][2] = off;
         }
-        if(DEVNULL_FLAGGED(th, MODE_D)) {
+        if(DEVNULL_HAS_PRIV(th, NOFLOOD)) {
             tbl.contents[ii][3] = on;
-        } else if(DEVNULL_FLAGGED(th, MODE_C)) {
+        } else if(DEVNULL_HAS_PRIV(th, HALFFLOOD)) {
             tbl.contents[ii][3] = half;
         } else {
             tbl.contents[ii][3] = off;
         }
-        if(DEVNULL_FLAGGED(th, MODE_E)) {
+        if(DEVNULL_HAS_PRIV(th, CHANHIDE)) {
             tbl.contents[ii][4] = on;
         } else {
             tbl.contents[ii][4] = off;
         }
-        if(DEVNULL_FLAGGED(th, MODE_F)) {
+        if(DEVNULL_HAS_PRIV(th, IDLEHIDE)) {
             tbl.contents[ii][5] = on;
         } else {
             tbl.contents[ii][5] = off;
         }
-        if(DEVNULL_FLAGGED(th, MODE_J)) {
+        if(DEVNULL_HAS_PRIV(th, CHSERVMODE)) {
             tbl.contents[ii][6] = on;
         } else {
             tbl.contents[ii][6] = off;
         }
-        if(DEVNULL_FLAGGED(th, MODE_K)) {
+        if(DEVNULL_HAS_PRIV(th, XTRAOPMODE)) {
             tbl.contents[ii][7] = on;
         } else {
             tbl.contents[ii][7] = off;
         }
-        if(DEVNULL_FLAGGED(th, MODE_L)) {
+        if(DEVNULL_HAS_PRIV(th, NETSERVMODE)) {
             tbl.contents[ii][8] = on;
         } else {
             tbl.contents[ii][8] = off;
         }
-        if(DEVNULL_FLAGGED(th, MODE_M)) {
+        if(DEVNULL_HAS_PRIV(th, SEEIDLE)) {
             tbl.contents[ii][9] = on;
         } else {
             tbl.contents[ii][9] = off;
         }
-        if(DEVNULL_FLAGGED(th, MODE_G)) {
+        if(DEVNULL_HAS_PRIV(th, FORCEIDLEHIDE)) {
             tbl.contents[ii][10] = on;
         } else {
             tbl.contents[ii][10] = off;
         }
-        if(DEVNULL_FLAGGED(th, MODE_I)) {
+        if(DEVNULL_HAS_PRIV(th, OVERRIDECC)) {
             tbl.contents[ii][11] = on;
         } else {
             tbl.contents[ii][11] = off;
         }
-        if(DEVNULL_FLAGGED(th, MODE_H)) {
+        if(DEVNULL_HAS_PRIV(th, OVERRIDENOAMSG)) {
             tbl.contents[ii][12] = on;
         } else {
             tbl.contents[ii][12] = off;
         }
-        if(DEVNULL_FLAGGED(th, MODE_N)) {
+        if(DEVNULL_HAS_PRIV(th, MAXSENDQ)) {
             tbl.contents[ii][13] = on;
         } else {
             tbl.contents[ii][13] = off;
         }
+        if(DEVNULL_HAS_PRIV(th, OPME)) {
+            tbl.contents[ii][14] = on;
+        } else {
+            tbl.contents[ii][14] = off;
+        }
     }
     table_send(cmd->parent->bot, user->nick, 0, NULL, tbl);
     for(ii = 1; ii < tbl.length; ++ii)
@@ -4396,6 +4432,7 @@ static MODCMD_FUNC(cmd_listdevnull)
        send_message_type(4, user, opserv,"+k = ChanServ Mode (mode +k)");
     send_message_type(4, user, opserv,"+S = NetServ Mode (mode +S)");
     send_message_type(4, user, opserv,"+X = XtraOp Mode (mode +X)");
+    send_message_type(4, user, opserv,"OpMe = ChanServ opme command");
     return 1;
 }
 
@@ -4407,7 +4444,7 @@ static MODCMD_FUNC(cmd_adddevnull)
         return 0;
     }
     
-    opserv_add_devnull_class(argv[1], 0, 0, 0);
+    opserv_add_devnull_class(argv[1], (++devnull_last_id), 0, 0, 0);
     reply("OSMSG_DEVNULL_ADDED",argv[1]);
     return 1;
 }
@@ -4421,7 +4458,7 @@ static MODCMD_FUNC(cmd_deldevnull)
         struct devnull_class *th = dict_find(opserv_devnull_classes, argv[n], NULL);
         if (!th)
             continue;
-        nickserv_devnull_delete(th->name);
+        nickserv_devnull_delete(th->id);
         dict_remove(opserv_devnull_classes, argv[n]);
         reply("OSMSG_DEVNULL_REMOVED",argv[n]);
     }
@@ -4436,8 +4473,7 @@ static MODCMD_FUNC(cmd_renamedevnull)
         return 0;
     }
     if ((th = dict_find(opserv_devnull_classes, argv[1], NULL))) {
-        opserv_add_devnull_class(argv[2], th->modes, th->maxchan, th->maxsendq);
-        nickserv_devnull_rename(th->name,argv[2]);
+        opserv_add_devnull_class(argv[2], th->id, th->modes, th->maxchan, th->maxsendq);
         dict_remove(opserv_devnull_classes, argv[1]);
         reply("OSMSG_DEVNULL_RENAMED",argv[1],argv[2]);
     } else {
@@ -4458,224 +4494,229 @@ static MODCMD_FUNC(cmd_setdevnull)
                 argv[offset+2][ ii ] = toupper( argv[offset+2][ ii ] );
             for( ii = 0; argv[offset+3][ ii ]; ii++)
                 argv[offset+3][ ii ] = toupper( argv[offset+3][ ii ] );
+            
             if(!strcmp("CHANLIMIT",argv[offset+2])) {
-                 if (!strcmp("OFF",argv[offset+3])) {
-                  DEVNULL_CLEAR_FLAG(th, MODE_A);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else {
-                  DEVNULL_SET_FLAG(th, MODE_A);
-                  th->maxchan = strtoul(argv[offset+3], NULL, 0);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 }
-            }
-            else if(!strcmp("UNLIMITTARGET",argv[offset+2]) || !strcmp("UNLIMITEDTARGET",argv[offset+2])) {
-                 if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
-                  DEVNULL_CLEAR_FLAG(th, MODE_B);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
-                  DEVNULL_SET_FLAG(th, MODE_B);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else {
-                  reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
-                 }
-            }
-            else if(!strcmp("FLOOD",argv[offset+2])) {
-                 if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
-                  DEVNULL_CLEAR_FLAG(th, MODE_C);
-                  DEVNULL_CLEAR_FLAG(th, MODE_D);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
-                  DEVNULL_SET_FLAG(th, MODE_D);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else if (!strcmp("HALF",argv[offset+3]) || !strcmp("2",argv[offset+3]) || !strcmp("1/2",argv[offset+3])) {
-                  DEVNULL_SET_FLAG(th, MODE_C);
-                  DEVNULL_CLEAR_FLAG(th, MODE_D);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else {
-                  reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
-                 }
-            }
-            else if(!strcmp("CHANHIDE",argv[offset+2])) {
-                 if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
-                  DEVNULL_CLEAR_FLAG(th, MODE_E);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
-                  DEVNULL_SET_FLAG(th, MODE_E);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else {
-                  reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
-                 }
-            }
-            else if(!strcmp("IDLEHIDE",argv[offset+2])) {
-                 if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
-                  DEVNULL_CLEAR_FLAG(th, MODE_F);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
-                  DEVNULL_SET_FLAG(th, MODE_F);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else {
-                  reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
-                 }
-            }
-            else if(!strcmp("CHSERVMODE",argv[offset+2])) {
-                 if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
-                  DEVNULL_CLEAR_FLAG(th, MODE_G);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
-                  DEVNULL_SET_FLAG(th, MODE_G);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else {
-                  reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
-                 }
-            }
-            else if(!strcmp("XTRAOPMODE",argv[offset+2])) {
-                 if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
-                  DEVNULL_CLEAR_FLAG(th, MODE_H);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
-                  DEVNULL_SET_FLAG(th, MODE_H);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else {
-                  reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
-                 }
-            }
-            else if(!strcmp("NETSERVMODE",argv[offset+2])) {
-                 if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
-                  DEVNULL_CLEAR_FLAG(th, MODE_I);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
-                  DEVNULL_SET_FLAG(th, MODE_I);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else {
-                  reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
-                 }
-            }
-            else if(!strcmp("SEEIDLE",argv[offset+2])) {
-                 if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
-                  DEVNULL_CLEAR_FLAG(th, MODE_J);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
-                  DEVNULL_SET_FLAG(th, MODE_J);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else {
-                  reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
-                 }
-            }
-            else if(!strcmp("FORCEIDLEHIDE",argv[offset+2])) {
-                 if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
-                  DEVNULL_CLEAR_FLAG(th, MODE_K);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
-                  DEVNULL_SET_FLAG(th, MODE_K);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else {
-                  reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
-                 }
-            }
-            else if(!strcmp("OVERRIDECC",argv[offset+2])) {
-                 if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
-                  DEVNULL_CLEAR_FLAG(th, MODE_L);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
-                  DEVNULL_SET_FLAG(th, MODE_L);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else {
-                  reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
-                 }
-            }
-            else if(!strcmp("OVERRIDENOAMSG",argv[offset+2])) {
-                 if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
-                  DEVNULL_CLEAR_FLAG(th, MODE_M);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
-                  DEVNULL_SET_FLAG(th, MODE_M);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else {
-                  reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
-                 }
-            }
-            else if(!strcmp("MAXSENDQ",argv[offset+2])) {
-                 if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
-                  DEVNULL_CLEAR_FLAG(th, MODE_N);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 } else {
-                  DEVNULL_SET_FLAG(th, MODE_N);
-                  th->maxsendq = strtoul(argv[offset+3], NULL, 0);
-                  reply("OSMSG_DEVNULL_SET_DONE");
-                 }
+                if (!strcmp("OFF",argv[offset+3])) {
+                    DEVNULL_CLEAR_PRIV(th, CHANLIMIT);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else {
+                    DEVNULL_SET_PRIV(th, CHANLIMIT);
+                    th->maxchan = strtoul(argv[offset+3], NULL, 0);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                }
+            } else if(!strcmp("UNLIMITTARGET",argv[offset+2]) || !strcmp("UNLIMITEDTARGET",argv[offset+2])) {
+                if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
+                    DEVNULL_CLEAR_PRIV(th, UNLIMITTARGET);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
+                    DEVNULL_SET_PRIV(th, UNLIMITTARGET);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else {
+                    reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
+                }
+            } else if(!strcmp("FLOOD",argv[offset+2])) {
+                if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
+                    DEVNULL_CLEAR_PRIV(th, HALFFLOOD);
+                    DEVNULL_CLEAR_PRIV(th, NOFLOOD);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
+                    DEVNULL_SET_PRIV(th, NOFLOOD);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else if (!strcmp("HALF",argv[offset+3]) || !strcmp("2",argv[offset+3]) || !strcmp("1/2",argv[offset+3])) {
+                    DEVNULL_SET_PRIV(th, HALFFLOOD);
+                    DEVNULL_CLEAR_PRIV(th, NOFLOOD);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else {
+                    reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
+                }
+            } else if(!strcmp("CHANHIDE",argv[offset+2])) {
+                if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
+                    DEVNULL_CLEAR_PRIV(th, CHANHIDE);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
+                    DEVNULL_SET_PRIV(th, CHANHIDE);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else {
+                    reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
+                }
+            } else if(!strcmp("IDLEHIDE",argv[offset+2])) {
+                if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
+                    DEVNULL_CLEAR_PRIV(th, IDLEHIDE);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
+                    DEVNULL_SET_PRIV(th, IDLEHIDE);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else {
+                    reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
+                }
+            } else if(!strcmp("CHSERVMODE",argv[offset+2])) {
+                if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
+                    DEVNULL_CLEAR_PRIV(th, CHSERVMODE);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
+                    DEVNULL_SET_PRIV(th, CHSERVMODE);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else {
+                    reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
+                }
+            } else if(!strcmp("XTRAOPMODE",argv[offset+2])) {
+                if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
+                    DEVNULL_CLEAR_PRIV(th, XTRAOPMODE);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
+                    DEVNULL_SET_PRIV(th, XTRAOPMODE);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else {
+                    reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
+                }
+            } else if(!strcmp("NETSERVMODE",argv[offset+2])) {
+                if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
+                    DEVNULL_CLEAR_PRIV(th, NETSERVMODE);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
+                    DEVNULL_SET_PRIV(th, NETSERVMODE);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else {
+                    reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
+                }
+            } else if(!strcmp("SEEIDLE",argv[offset+2])) {
+                if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
+                    DEVNULL_CLEAR_PRIV(th, SEEIDLE);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
+                    DEVNULL_SET_PRIV(th, SEEIDLE);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else {
+                    reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
+                }
+            } else if(!strcmp("FORCEIDLEHIDE",argv[offset+2])) {
+                if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
+                    DEVNULL_CLEAR_PRIV(th, FORCEIDLEHIDE);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
+                    DEVNULL_SET_PRIV(th, FORCEIDLEHIDE);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else {
+                    reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
+                }
+            } else if(!strcmp("OVERRIDECC",argv[offset+2])) {
+                if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
+                    DEVNULL_CLEAR_PRIV(th, OVERRIDECC);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
+                    DEVNULL_SET_PRIV(th, OVERRIDECC);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else {
+                    reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
+                }
+            } else if(!strcmp("OVERRIDENOAMSG",argv[offset+2])) {
+                if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
+                    DEVNULL_CLEAR_PRIV(th, OVERRIDENOAMSG);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
+                    DEVNULL_SET_PRIV(th, OVERRIDENOAMSG);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else {
+                    reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
+                }
+            } else if(!strcmp("MAXSENDQ",argv[offset+2])) {
+                if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
+                    DEVNULL_CLEAR_PRIV(th, MAXSENDQ);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else {
+                    DEVNULL_SET_PRIV(th, MAXSENDQ);
+                    th->maxsendq = strtoul(argv[offset+3], NULL, 0);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                }
+            } 
+            else if(!strcmp("OPME",argv[offset+2])) {
+                if (!strcmp("OFF",argv[offset+3]) || !strcmp("0",argv[offset+3])) {
+                    DEVNULL_CLEAR_PRIV(th, OPME);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else if (!strcmp("ON",argv[offset+3]) || !strcmp("1",argv[offset+3])) {
+                    DEVNULL_SET_PRIV(th, OPME);
+                    reply("OSMSG_DEVNULL_SET_DONE");
+                } else {
+                    reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+3]);
+                }
             } else {
-                 reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+2]);
+                reply("OSMSG_DEVNULL_SET_INVALID", argv[offset+2]);
             }
             
         } else {
             reply("OSMSG_DEVNULL_SET", th->name);
-            if(DEVNULL_FLAGGED(th, MODE_A)) {
+            if(DEVNULL_HAS_PRIV(th, CHANLIMIT)) {
                 reply("OSMSG_DEVNULL_SET_A_i", th->maxchan);
             } else {
                 reply("OSMSG_DEVNULL_SET_A", "off");
             }
-            if(DEVNULL_FLAGGED(th, MODE_B)) {
+            if(DEVNULL_HAS_PRIV(th, UNLIMITTARGET)) {
                 reply("OSMSG_DEVNULL_SET_B", "on");
             } else {
                 reply("OSMSG_DEVNULL_SET_B", "off");
             }
-            if(DEVNULL_FLAGGED(th, MODE_D)) {
+            if(DEVNULL_HAS_PRIV(th, NOFLOOD)) {
                 reply("OSMSG_DEVNULL_SET_C", "on");
-            } else if(DEVNULL_FLAGGED(th, MODE_C)) {
+            } else if(DEVNULL_HAS_PRIV(th, HALFFLOOD)) {
                 reply("OSMSG_DEVNULL_SET_C", "half");
             } else {
                 reply("OSMSG_DEVNULL_SET_C", "off");
             }
-            if(DEVNULL_FLAGGED(th, MODE_E)) {
+            if(DEVNULL_HAS_PRIV(th, CHANHIDE)) {
                 reply("OSMSG_DEVNULL_SET_E", "on");
             } else {
                 reply("OSMSG_DEVNULL_SET_E", "off");
             }
-            if(DEVNULL_FLAGGED(th, MODE_F)) {
+            if(DEVNULL_HAS_PRIV(th, IDLEHIDE)) {
                 reply("OSMSG_DEVNULL_SET_F", "on");
             } else {
                 reply("OSMSG_DEVNULL_SET_F", "off");
             }
-            if(DEVNULL_FLAGGED(th, MODE_G)) {
+            if(DEVNULL_HAS_PRIV(th, CHSERVMODE)) {
                 reply("OSMSG_DEVNULL_SET_G", "on");
             } else {
                 reply("OSMSG_DEVNULL_SET_G", "off");
             }
-            if(DEVNULL_FLAGGED(th, MODE_H)) {
+            if(DEVNULL_HAS_PRIV(th, XTRAOPMODE)) {
                 reply("OSMSG_DEVNULL_SET_H", "on");
             } else {
                 reply("OSMSG_DEVNULL_SET_H", "off");
             }
-            if(DEVNULL_FLAGGED(th, MODE_I)) {
+            if(DEVNULL_HAS_PRIV(th, NETSERVMODE)) {
                 reply("OSMSG_DEVNULL_SET_I", "on");
             } else {
                 reply("OSMSG_DEVNULL_SET_I", "off");
             }
-            if(DEVNULL_FLAGGED(th, MODE_J)) {
+            if(DEVNULL_HAS_PRIV(th, SEEIDLE)) {
                 reply("OSMSG_DEVNULL_SET_J", "on");
             } else {
                 reply("OSMSG_DEVNULL_SET_J", "off");
             }
-            if(DEVNULL_FLAGGED(th, MODE_K)) {
+            if(DEVNULL_HAS_PRIV(th, FORCEIDLEHIDE)) {
                 reply("OSMSG_DEVNULL_SET_K", "on");
             } else {
                 reply("OSMSG_DEVNULL_SET_K", "off");
             }
-            if(DEVNULL_FLAGGED(th, MODE_L)) {
+            if(DEVNULL_HAS_PRIV(th, OVERRIDECC)) {
                 reply("OSMSG_DEVNULL_SET_L", "on");
             } else {
                 reply("OSMSG_DEVNULL_SET_L", "off");
             }
-            if(DEVNULL_FLAGGED(th, MODE_M)) {
+            if(DEVNULL_HAS_PRIV(th, OVERRIDENOAMSG)) {
                 reply("OSMSG_DEVNULL_SET_M", "on");
             } else {
                 reply("OSMSG_DEVNULL_SET_M", "off");
             }
-            if(DEVNULL_FLAGGED(th, MODE_N)) {
+            if(DEVNULL_HAS_PRIV(th, MAXSENDQ)) {
                 reply("OSMSG_DEVNULL_SET_N_i", th->maxsendq);
             } else {
                 reply("OSMSG_DEVNULL_SET_N", "off");
             }
+            if(DEVNULL_HAS_PRIV(th, OPME)) {
+                reply("OSMSG_DEVNULL_SET_OPME", "on");
+            } else {
+                reply("OSMSG_DEVNULL_SET_OPME", "off");
+            }
         }
     } else {
         reply("OSMSG_DEVNULL_NOTFOUND", argv[offset+1]);
@@ -4684,16 +4725,192 @@ static MODCMD_FUNC(cmd_setdevnull)
     return 1;
 }
 
-int devnull_check(const char *name) { 
-    if (dict_find(opserv_devnull_classes, name, NULL)) {
-        return 1;
+struct devnull_class *devnull_find_id(unsigned int id) {
+    dict_iterator_t it;
+    for (it = dict_first(opserv_devnull_classes); it; it = iter_next(it)) {
+        struct devnull_class *th = iter_data(it);
+        if(th->id == id)
+            return th;
+    }
+    return NULL;
+}
+
+struct devnull_class *devnull_find_name(const char *name) {
+    struct devnull_class *th;
+    if ((th = dict_find(opserv_devnull_classes, name, NULL))) {
+        return th;
+    }
+    return NULL;
+}
+
+int devnull_user_has_priv(struct handle_info *hi, int devnull_priv) {
+    if(devnull_check_priv_func) {
+        int ext_privs = ((struct devnull_class (*)(struct handle_info *))devnull_check_priv_func)(hi, devnull_priv);
+        if((ext_privs & devnull_priv))
+            return (ext_privs & devnull_priv);
+    }
+    
+    if(!hi->devnull)
+        return 0;
+    struct devnull_class *th;
+    if(!(th = dict_find(opserv_devnull_classes, hi->devnull, NULL)))
+        return 0;
+    
+    return (th->modes & devnull_priv);
+}
+
+struct devnull_class devnull_user_get_class(struct handle_info *hi) {
+    struct devnull_class th;
+    th.name = NULL;
+    th.modes = 0;
+    
+    if(hi->devnull) {
+        struct devnull_class *thp;
+        if((thp = dict_find(opserv_devnull_classes, hi->devnull, NULL))) {
+            if(DEVNULL_HAS_PRIV(thp, CHANLIMIT) && (!DEVNULL_HAS_PRIV(&th, CHANLIMIT) || th.maxchan < thp->maxchan))
+                th.maxchan = thp->maxchan;
+            if(DEVNULL_HAS_PRIV(thp, MAXSENDQ) && (!DEVNULL_HAS_PRIV(&th, MAXSENDQ) || th.maxsendq < thp->maxsendq))
+                th.maxsendq = thp->maxsendq;
+            th.modes |= thp->maxsendq;
+            th.name = thp->name;
+        }
+    }
+    return th;
+}
+
+void operpart(struct chanNode *chan, struct userNode *user)
+{
+    if(opserv_conf.alert_channel && opserv_conf.staff_auth_force > 0 &&
+      !(irccasecmp(chan->name,opserv_conf.alert_channel->name))) {
+        struct mod_chanmode *change;
+        change = find_matching_bans(&chan->banlist, user, NULL); //don't join them if they're banned (exceptions from forced join)
+        if(change)
+            return;
+        irc_svsjoin(opserv,user,chan);
+    }
+}
+
+void operadd(struct userNode *user)
+{
+    if(opserv_conf.alert_channel && opserv_conf.staff_auth_force > 0)
+        irc_svsjoin(opserv,user,opserv_conf.alert_channel);
+}
+
+void operdel(struct userNode *user)
+{
+    if(opserv_conf.alert_channel && opserv_conf.staff_auth_force == 2)
+        irc_kick(opserv, user, opserv_conf.alert_channel, "mode -o");
+}
+
+static MODCMD_FUNC(cmd_svsjoin)
+{
+    struct userNode *target;
+    if(!(target=GetUserH(argv[1]))) {
+        reply("OSMSG_SVSNONICK", argv[1]);
+        return 0;
+    }
+    if(!IsChannelName(argv[2]))
+    {
+        reply("MSG_NOT_CHANNEL_NAME");
+        return 0;
+    }
+    irc_svsjoinchan(opserv,target,argv[2]);
+    reply("OSMSG_SVSJOIN",target->nick,argv[2]);
+    return 1;
+}
+
+static MODCMD_FUNC(cmd_svspart)
+{
+    struct userNode *target;
+    if(!(target=GetUserH(argv[1]))) {
+        reply("OSMSG_SVSNONICK", argv[1]);
+        return 0;
+    }
+    if(!IsChannelName(argv[2]))
+    {
+        reply("MSG_NOT_CHANNEL_NAME");
+        return 0;
+    }
+    irc_svspartchan(opserv,target,argv[2]);
+    reply("OSMSG_SVSPART",target->nick,argv[2]);
+    return 1;
+}
+
+static MODCMD_FUNC(cmd_svskill)
+{
+    struct userNode *target;
+    if(!(target=GetUserH(argv[1]))) {
+        reply("OSMSG_SVSNONICK", argv[1]);
+        return 0;
+    }
+    DelUser(target, opserv, 1, argv[2]);
+    reply("OSMSG_SVSKILL",target->nick,argv[2]);
+    return 1;
+}
+static MODCMD_FUNC(cmd_svsnick)
+{
+    struct userNode *target;
+    if(!(target=GetUserH(argv[1]))) {
+        reply("OSMSG_SVSNONICK", argv[1]);
+        return 0;
+    }
+    if(GetUserH(argv[2]))
+    {
+        reply("OSMSG_SVSNICKUSED",argv[2]);
+        return 0;
+    }
+    irc_svsnick(opserv,target,argv[2]);
+    reply("OSMSG_SVSNICK",target->nick,argv[2]);
+    return 1;
+}
+
+static MODCMD_FUNC(cmd_svsmode)
+{
+    struct userNode *target;
+    char *modestr;
+    if(!(target=GetUserH(argv[1]))) {
+        reply("OSMSG_SVSNONICK", argv[1]);
+        return 0;
+    }
+    modestr = unsplit_string(argv + 2, argc - 2, NULL);
+    irc_svsmode(opserv,target,modestr);
+    reply("OSMSG_SVSMODE",modestr,target->nick);
+    return 1;
+}
+
+static MODCMD_FUNC(cmd_simul)
+{
+    struct userNode *target;
+    char *line;
+    if(argc > 2) {
+               if(!(target=GetUserH(argv[1]))) {
+                       reply("OSMSG_SVSNONICK", argv[1]);
+                       return 0;
+               }
+               line = unsplit_string(argv + 2, argc - 2, NULL);
+               irc_simul(target,line);
+               reply("OSMSG_SIMUL",target->nick,line);
+               return 1;
     }
     return 0;
 }
 
-struct devnull_class* 
-    devnull_get(const char *name) {
-    return dict_find(opserv_devnull_classes, name, NULL);
+static MODCMD_FUNC(cmd_relay)
+{
+    struct userNode *target;
+    char *line;
+    if(!(target=GetUserH(argv[1]))) {
+        reply("OSMSG_SVSNONICK", argv[1]);
+        return 0;
+    }
+    line = unsplit_string(argv + 2, argc - 2, NULL);
+    char sendline[512];
+    if(channel)
+        sprintf(sendline, "relay %s %s :%s",user->nick,channel->name,line);
+    else
+        sprintf(sendline, "relay %s query :%s",user->nick,line);
+    irc_privmsg(opserv,target->numeric,sendline);
+    return 1;
 }
 
 static void
@@ -4738,8 +4955,11 @@ opserv_conf_read(void)
             str2 = "+timns";
         opserv_conf.staff_auth_channel = AddChannel(str, now, str2, NULL);
         AddChannelUser(opserv, opserv_conf.staff_auth_channel)->modes |= MODE_CHANOP;
+        str2 = database_get_data(conf_node, KEY_STAFF_AUTH_FORCE_OPS, RECDB_QSTRING);
+        opserv_conf.staff_auth_force = str2 ? atoi(str2) : 0;
     } else {
         opserv_conf.staff_auth_channel = NULL;
+        opserv_conf.staff_auth_force = 0;
     }
     str = database_get_data(conf_node, KEY_UNTRUSTED_MAX, RECDB_QSTRING);
     opserv_conf.untrusted_max = str ? strtoul(str, NULL, 0) : 5;
@@ -4939,6 +5159,13 @@ init_opserv(const char *nick)
     opserv_define_func("DEVNULL RENAME", cmd_renamedevnull, 200, 0, 3);
     opserv_define_func("DEVNULL SET", cmd_setdevnull, 200, 0, 2);
     opserv_define_func("DEVNULL LIST", cmd_listdevnull, 200, 0, 0);
+    opserv_define_func("SVSJOIN", cmd_svsjoin, 800, 0, 3);
+    opserv_define_func("SVSPART", cmd_svspart, 800, 0, 3);
+    opserv_define_func("SVSKILL", cmd_svskill, 800, 0, 3);
+    opserv_define_func("SVSMODE", cmd_svsmode, 800, 0, 3);
+    opserv_define_func("SVSNICK", cmd_svsnick, 800, 0, 3);
+    opserv_define_func("RELAY", cmd_relay, 800, 0, 0);
+    opserv_define_func("SIMUL", cmd_simul, 999, 0, 3);
     opserv_define_func("TRACE", cmd_trace, 100, 0, 3);
     opserv_define_func("TRACE PRINT", NULL, 0, 0, 0);
     opserv_define_func("TRACE COUNT", NULL, 0, 0, 0);