/***********************************************************************
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.
#include "conf.h"
#include "global.h"
+#include "hash.h"
#include "modcmd.h"
#include "nickserv.h"
#include "saxdb.h"
{ "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 }
};
}
}
+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)
{
void init_global(const char *nick);
void global_message(long targets, char *text);
+void global_message_args(long targets, const char *language_entry, ...);
#endif
#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"
int GlobalOnDefconMore = 0;
int DefConGlineExpire;
int DefConModesSet = 0;
-int DefConGlobalTarget = 3;
unsigned int DefConSessionLimit;
char *DefConChanModes;
char *DefConGlineReason;
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) {
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;
// 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";