]> jfr.im git - irc/evilnet/x3.git/commitdiff
global message function that will deal with multi languages. Made use of it with...
authorsirvulcan <redacted>
Tue, 1 Aug 2006 03:12:10 +0000 (03:12 +0000)
committersirvulcan <redacted>
Tue, 1 Aug 2006 03:12:10 +0000 (03:12 +0000)
ChangeLog
src/global.c
src/global.h
src/opserv.c
x3.conf.example

index 352ec44ef28fdeff7d51760497172b88b1eb4941..b223ee4287ddd5933af05f2457c2fd85915e57fd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,22 @@
 /***********************************************************************
  X3 ChangeLog
 
+2006-08-01  Neil Spierling  <sirvulcan@gmail.com>
+
+       * src/x3.conf.example: Removed the targets option.
+
+       * src/global.c: Wrote new function that will global message users
+       and/or opers and/or helpers messages in their own langauge. The
+       strings are set either in language files or in the global.c message
+       struct. This allows us to send defcon notices to people and they
+       will get them in their own language if they have it set.
+
+       * src/global.h: global_message_args decleration.
+
+       * src/opserv.c: Removed targets option for defcon as its too hard
+       to send messages to people in channels if the people have different
+       language settings.
+
 2006-07-31  Neil Spierling  <sirvulcan@gmail.com>
 
        * src/opserv.c: TODO stuff.
index dd275c2441e49f7ae9ad58d536643b7e4dcc32c7..716de9b080d7d5ddcb1ffde7477d19b6f96f2cda 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "conf.h"
 #include "global.h"
+#include "hash.h"
 #include "modcmd.h"
 #include "nickserv.h"
 #include "saxdb.h"
@@ -61,6 +62,15 @@ static const struct message_entry msgtab[] = {
     { "GMSG_MOTD_HEADER", "$bNetwork Announcements$b" },
     { "GMSG_MOTD_BAR",    "---------------------------------------" },
     { "GMSG_MOTD_FOOTER", "--------------- Thank You--------------" },
+
+ /* These definitions are for other files that make use of global
+  * notices. Make sure you grep for them if you ever add args
+  * to the notice.
+  */
+    { "DEFCON_NETWORK_CHANGED", "Network DefCon level has changed to level %d" }, /* opserv.c */
+    { "DEFCON_OPER_LEVEL_CHANGE", "%s is changing the DefCon level to %d" }, /* opserv.c */
+    { "DEFCON_TIMEOUT_LEVEL_CHANGE", "The DefCon has changed back to level %d (timeout)" }, /* opserv.c */
+
     { NULL, NULL }
 };
 
@@ -360,6 +370,55 @@ message_send(struct globalMessage *message)
     }
 }
 
+void
+global_message_args(long targets, const char *language_entry, ...)
+{
+    struct globalMessage *message;
+    va_list arg_list;
+    dict_iterator_t it;
+    char response[MAXLEN];
+    const char *fmt;
+
+    if(!targets || !global)
+       return;
+
+    fmt = strdup(language_entry);
+
+    /* Notice users/opers/helpers */
+    for (it = dict_first(clients); it; it = iter_next(it)) {
+        struct userNode *luser = iter_data(it);
+
+        language_entry = user_find_message(luser, fmt);
+
+        va_start(arg_list, language_entry);
+        vsnprintf(response, MAXLEN-2, language_entry, arg_list);
+        response[MAXLEN-1] = 0;
+
+        message = message_add(targets | MESSAGE_OPTION_SOURCELESS, now, 0, "", response);
+        if (!message)
+           continue;
+
+        /* opers */
+        if(message->flags & MESSAGE_RECIPIENT_OPERS && IsOper(luser)) {
+            if(luser->uplink != self)
+                notice_target(luser->nick, message);
+        }
+
+        /* helpers */
+        if (message->flags & MESSAGE_RECIPIENT_HELPERS && IsHelper(luser)) {
+            if (IsOper(luser))
+                continue;
+           notice_target(luser->nick, message);
+       }
+
+        /* users */
+        if (message->flags & MESSAGE_RECIPIENT_LUSERS)
+           notice_target(luser->nick, message);
+    }
+
+    message_del(message);
+}
+
 void
 global_message(long targets, char *text)
 {
index 0c645b38a75b8e82c13da482fb8e087f56eb432a..30af23f633b8ac4f0c1a2a7903487ed1f0af7da9 100644 (file)
@@ -36,5 +36,6 @@
 void init_global(const char *nick);
 
 void global_message(long targets, char *text);
+void global_message_args(long targets, const char *language_entry, ...);
 
 #endif
index d6e1f6343a0c7524e7d31234f6b3cdf9d8fd9a68..3566c9aa5562a5dfd2125c0e25f35e370fd21c34 100644 (file)
 #define KEY_DEFCON_CHANMODES "DefConChanModes"
 #define KEY_DEFCON_SESSION_LIMIT "DefConSessionLimit"
 #define KEY_DEFCON_TIMEOUT "DefConTimeOut"
-#define KEY_DEFCON_GLOBAL_TARGET "DefConGlobalTarget"
 #define KEY_DEFCON_GLOBAL "GlobalOnDefcon"
 #define KEY_DEFCON_GLOBAL_MORE "GlobalOnDefconMore"
 #define KEY_DEFCON_MESSAGE "DefconMessage"
@@ -405,7 +404,6 @@ int GlobalOnDefcon = 0;
 int GlobalOnDefconMore = 0;
 int DefConGlineExpire;
 int DefConModesSet = 0;
-int DefConGlobalTarget = 3;
 unsigned int DefConSessionLimit;
 char *DefConChanModes;
 char *DefConGlineReason;
@@ -658,43 +656,20 @@ void do_mass_mode(char *modes)
 void DefConProcess(struct userNode *user)
 {
     char *newmodes;
-    long targets;
-
-    /* TODO
-     * global_message needs to be able to pull language entries for
-     * users. The way it is now an english message is sent out built
-     * from sprintf. We need to make global_message be able to get
-     * user languages and change the message accordingly */
-
-    if (DefConGlobalTarget == 1)
-        targets = MESSAGE_RECIPIENT_LUSERS;
-    else if (DefConGlobalTarget == 2)
-        targets = MESSAGE_RECIPIENT_CHANNELS;
-    else
-        targets = MESSAGE_RECIPIENT_ALL;
 
-    if (GlobalOnDefcon) {
-        char *globalmsg;
-        globalmsg = alloca(44);
-        sprintf(globalmsg, "Network DefCon level has changed to level %d", DefConLevel);
-        global_message(targets, globalmsg);
-    }
+    if (GlobalOnDefcon)
+        global_message_args(MESSAGE_RECIPIENT_LUSERS, "DEFCON_NETWORK_CHANGED", DefConLevel);
 
-    if (GlobalOnDefconMore)
-        global_message(targets, DefConMessage);
+    if (GlobalOnDefconMore && GlobalOnDefcon)
+        global_message(MESSAGE_RECIPIENT_LUSERS, DefConMessage);
 
     if ((DefConLevel == 5) && !GlobalOnDefconMore && !GlobalOnDefcon)
-        global_message(targets, DefConOffMessage);
+        global_message(MESSAGE_RECIPIENT_LUSERS, DefConOffMessage);
 
-    char *opermsg;
-    if (user) {
-        opermsg = alloca(strlen(user->nick) + 35);
-        sprintf(opermsg, "%s is changing the DefCon level to %d", user->nick, DefConLevel);
-    } else {
-        opermsg = alloca(49);
-        sprintf(opermsg, "The DefCon has changed back to level %d (timeout)", DefConLevel);
-    }
-    global_message(MESSAGE_RECIPIENT_OPERS, opermsg);
+    if (user)
+       global_message_args(MESSAGE_RECIPIENT_OPERS, "DEFCON_OPER_LEVEL_CHANGE", user->nick, DefConLevel);
+    else
+       global_message_args(MESSAGE_RECIPIENT_OPERS, "DEFCON_TIMEOUT_LEVEL_CHANGE", DefConLevel);
 
     if (checkDefCon(DEFCON_FORCE_CHAN_MODES)) {
         if (DefConChanModes && !DefConModesSet) {
@@ -6263,9 +6238,6 @@ opserv_conf_read(void)
     str = database_get_data(conf_node, KEY_DEFCON_GLINE_DURATION, RECDB_QSTRING);
     DefConGlineExpire = str ? ParseInterval(str) : 300;
 
-    str = database_get_data(conf_node, KEY_DEFCON_GLOBAL_TARGET, RECDB_QSTRING);
-    DefConGlobalTarget = str ? atoi(str) : 3;
-
     str = database_get_data(conf_node, KEY_DEFCON_GLOBAL, RECDB_QSTRING);
     GlobalOnDefcon = str ? atoi(str) : 0;
 
index fbba2896aeae2f7fd609eef6aa7d510e811faa26..2f47a38e83653f64c38b6fccb7f5458263ca0cbb 100644 (file)
         // If not set to 0, defcon will set back to level 5 after this time
         "DefConTimeOut" "15m";
 
-        // Where will the user global notices go to?
-        // 1 - Users Only
-        // 2 - Channels Only
-        // 3 - Both Users and Channels
-        "DefConGlobalTarget" "3";
-
         // Set to 1 to send a notice to all users when defcon levels are changed
         "GlobalOnDefcon" "0";