]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/global.c
Added RCHANNELS which will send notices to all registered channels. Also changed...
[irc/evilnet/x3.git] / src / global.c
index ad325c5639e82387b518afd9551661617bdaa876..2a50d50e9aa198408ac6a3e7410c2ad25c9fa10a 100644 (file)
@@ -33,6 +33,7 @@
 
 /* Global options */
 #define KEY_DB_BACKUP_FREQ     "db_backup_freq"
+#define KEY_ANNOUNCEMENTS_DEFAULT "announcements_default"
 #define KEY_NICK               "nick"
 
 /* Message data */
@@ -137,6 +138,7 @@ static struct log_type *G_LOG;
 static struct
 {
     unsigned long db_backup_frequency;
+    unsigned int announcements_default : 1;
 } global_conf;
 
 #define global_notice(target, format...) send_message(target , global , ## format)
@@ -243,6 +245,8 @@ message_create(struct userNode *user, unsigned int argc, char *argv[])
 
            if(!irccasecmp(argv[i], "all")) {
                flags |= MESSAGE_RECIPIENT_ALL;
+            } else if(!irccasecmp(argv[i], "authed")) {
+                flags |= MESSAGE_RECIPIENT_AUTHED;
            } else if(!irccasecmp(argv[i], "users")) {
                flags |= MESSAGE_RECIPIENT_LUSERS;
            } else if(!irccasecmp(argv[i], "helpers")) {
@@ -253,6 +257,10 @@ message_create(struct userNode *user, unsigned int argc, char *argv[])
                flags |= MESSAGE_RECIPIENT_STAFF;
            } else if(!irccasecmp(argv[i], "channels")) {
                flags |= MESSAGE_RECIPIENT_CHANNELS;
+           } else if(!irccasecmp(argv[i], "rchannels")) {
+               flags |= MESSAGE_RECIPIENT_RCHANNELS;
+            } else if(!irccasecmp(argv[i], "announcement") || !irccasecmp(argv[i], "announce")) {
+                flags |= MESSAGE_RECIPIENT_ANNOUNCE;
            } else {
                global_notice(user, "GMSG_INVALID_TARGET", argv[i]);
                return NULL;
@@ -291,6 +299,10 @@ messageType(const struct globalMessage *message)
     {
        return "staff";
     }
+    else if(message->flags & MESSAGE_RECIPIENT_ANNOUNCE)
+    {
+        return "announcement";
+    }
     else if(message->flags & MESSAGE_RECIPIENT_OPERS)
     {
        return "opers";
@@ -303,6 +315,14 @@ messageType(const struct globalMessage *message)
     {
        return "users";
     }
+    else if(message->flags & MESSAGE_RECIPIENT_AUTHED)
+    {
+        return "authed";
+    }
+    else if(message->flags & MESSAGE_RECIPIENT_RCHANNELS)
+    {
+        return "rchannels";
+    }
     else
     {
        return "channels";
@@ -342,10 +362,29 @@ message_send(struct globalMessage *message)
 {
     struct userNode *user;
     unsigned long n;
+    dict_iterator_t it;
 
     if(message->flags & MESSAGE_RECIPIENT_CHANNELS)
     {
-       dict_foreach(channels, notice_channel, message);
+        dict_iterator_t it;
+
+        for (it = dict_first(channels); it; it = iter_next(it)) {
+            struct chanNode *chan = iter_data(it);
+
+            notice_target(chan->name, message);
+        }
+    }
+
+    if(message->flags & MESSAGE_RECIPIENT_RCHANNELS)
+    {
+        dict_iterator_t it;
+
+        for (it = dict_first(channels); it; it = iter_next(it)) {
+            struct chanNode *chan = iter_data(it);
+
+            if (chan->channel_info)
+                notice_target(chan->name, message);
+        }
     }
 
     if(message->flags & MESSAGE_RECIPIENT_LUSERS)
@@ -354,6 +393,20 @@ message_send(struct globalMessage *message)
        return;
     }
 
+    if(message->flags & MESSAGE_RECIPIENT_ANNOUNCE)
+    {
+        char announce;
+
+        for (it = dict_first(clients); it; it = iter_next(it)) {
+            user = iter_data(it);
+            if (user->uplink == self) continue;
+            announce = user->handle_info ? user->handle_info->announcements : '?';
+            if (announce == 'n') continue;
+            if ((announce == '?') && !global_conf.announcements_default) continue;
+            notice_target(user->nick, message);
+        }
+    }
+
     if(message->flags & MESSAGE_RECIPIENT_OPERS)
     {
        for(n = 0; n < curr_opers.used; n++)
@@ -377,6 +430,16 @@ message_send(struct globalMessage *message)
            notice_target(user->nick, message);
        }
     }
+
+    if(message->flags & MESSAGE_RECIPIENT_AUTHED)
+    {
+        dict_iterator_t it;
+        for (it = dict_first(clients); it; it = iter_next(it)) {
+            struct userNode *luser = iter_data(it);
+            if (luser->handle_info)
+              notice_target(luser->nick, message);
+        }
+    }
 }
 
 void
@@ -415,7 +478,8 @@ global_message_args(long targets, const char *language_entry, ...)
             if(luser->uplink != self)
                 notice_target(luser->nick, message);
 
-            if ((message->flags & MESSAGE_RECIPIENT_LUSERS) || (message->flags & MESSAGE_RECIPIENT_HELPERS))
+            if ((message->flags & MESSAGE_RECIPIENT_LUSERS) || (message->flags & MESSAGE_RECIPIENT_HELPERS) || 
+                (message->flags & MESSAGE_RECIPIENT_AUTHED))
                 continue;
         }
 
@@ -423,13 +487,23 @@ global_message_args(long targets, const char *language_entry, ...)
         if (message->flags & MESSAGE_RECIPIENT_HELPERS && IsHelper(luser)) {
            notice_target(luser->nick, message);
 
-            if (message->flags & MESSAGE_RECIPIENT_LUSERS)
+            if ((message->flags & MESSAGE_RECIPIENT_LUSERS) || (message->flags & MESSAGE_RECIPIENT_AUTHED))
                 continue;
        }
 
+        /* authed */
+        if ((message->flags & MESSAGE_RECIPIENT_AUTHED) && luser->handle_info) {
+            notice_target(luser->nick, message);
+
+            if (message->flags & MESSAGE_RECIPIENT_LUSERS)
+                continue;
+        }
+
         /* users */
-        if (message->flags & MESSAGE_RECIPIENT_LUSERS)
+        if (message->flags & MESSAGE_RECIPIENT_LUSERS) {
            notice_target(luser->nick, message);
+
+        }
     }
 
     message_del(message);
@@ -464,14 +538,20 @@ static GLOBAL_FUNC(cmd_notice)
        target = MESSAGE_RECIPIENT_ALL;
     } else if(!irccasecmp(argv[1], "users")) {
        target = MESSAGE_RECIPIENT_LUSERS;
+    } else if(!irccasecmp(argv[1], "authed")) {
+        target = MESSAGE_RECIPIENT_AUTHED;
     } else if(!irccasecmp(argv[1], "helpers")) {
        target = MESSAGE_RECIPIENT_HELPERS;
     } else if(!irccasecmp(argv[1], "opers")) {
        target = MESSAGE_RECIPIENT_OPERS;
     } else if(!irccasecmp(argv[1], "staff") || !irccasecmp(argv[1], "privileged")) {
        target |= MESSAGE_RECIPIENT_HELPERS | MESSAGE_RECIPIENT_OPERS;
+    } else if(!irccasecmp(argv[1], "announcement") || !irccasecmp(argv[1], "announce")) {
+        target |= MESSAGE_RECIPIENT_ANNOUNCE;
     } else if(!irccasecmp(argv[1], "channels")) {
        target = MESSAGE_RECIPIENT_CHANNELS;
+    } else if(!irccasecmp(argv[1], "rchannels")) {
+       target = MESSAGE_RECIPIENT_RCHANNELS;
     } else {
        global_notice(user, "GMSG_INVALID_TARGET", argv[1]);
        return 0;
@@ -625,7 +705,7 @@ send_messages(struct userNode *user, long mask, int obstreperize)
 
 static GLOBAL_FUNC(cmd_messages)
 {
-    long mask = MESSAGE_RECIPIENT_LUSERS | MESSAGE_RECIPIENT_CHANNELS;
+    long mask = MESSAGE_RECIPIENT_AUTHED | MESSAGE_RECIPIENT_LUSERS | MESSAGE_RECIPIENT_CHANNELS | MESSAGE_RECIPIENT_RCHANNELS;
     unsigned int count;
 
     if(IsOper(user))
@@ -693,6 +773,8 @@ global_conf_read(void)
 
     str = database_get_data(conf_node, KEY_DB_BACKUP_FREQ, RECDB_QSTRING);
     global_conf.db_backup_frequency = str ? ParseInterval(str) : 7200;
+    str = database_get_data(conf_node, KEY_ANNOUNCEMENTS_DEFAULT, RECDB_QSTRING);
+    global_conf.announcements_default = str ? enabled_string(str) : 1;
 
     str = database_get_data(conf_node, KEY_NICK, RECDB_QSTRING);
     if(global && str)
@@ -783,7 +865,7 @@ init_global(const char *nick)
     if(nick)
     {
         const char *modes = conf_get_data("services/global/modes", RECDB_QSTRING);
-        global = AddLocalUser(nick, nick, NULL, "Global Services", modes);
+        global = AddService(nick, modes ? modes : NULL, "Global Services", NULL);
         global_service = service_register(global);
     }