X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/dee9951d5f32dee38cf29861acdb4a347931e147..09a3057ce9cc09138dd04f07e5390f49a033f2f6:/src/global.c diff --git a/src/global.c b/src/global.c index 4c0ce24..6944caa 100644 --- a/src/global.c +++ b/src/global.c @@ -3,7 +3,7 @@ * * This file is part of x3. * - * srvx is free software; you can redistribute it and/or modify + * x3 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. @@ -20,6 +20,7 @@ #include "conf.h" #include "global.h" +#include "hash.h" #include "modcmd.h" #include "nickserv.h" #include "saxdb.h" @@ -55,10 +56,30 @@ static const struct message_entry msgtab[] = { { "GMSG_ID_INVALID", "$b%s$b is an invalid message ID." }, { "GMSG_MESSAGE_COUNT", "$b%d$b messages found." }, { "GMSG_NO_MESSAGES", "There are no messages for you." }, - { "GMSG_NOTICE_SOURCE", "[$b%s$b] Notice from %s:" }, - { "GMSG_MESSAGE_SOURCE", "[$b%s$b] Notice from %s, posted %s:" }, - { "GMSG_MOTD_HEADER", "$b------------- MESSAGE(S) OF THE DAY --------------$b" }, - { "GMSG_MOTD_FOOTER", "$b---------- END OF MESSAGE(S) OF THE DAY ----------$b" }, + { "GMSG_NOTICE_SOURCE", "Notice to [$b%s$b] from %s:" }, + { "GMSG_MESSAGE_SOURCE", "Notice to [$b%s$b] from %s, posted %s:" }, + //{ "GMSG_MOTD_HEADER", "$b------------- MESSAGE(S) OF THE DAY --------------$b" }, + { "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. + */ + /* chanserv.c */ + { "CSMSG_REGISTERED_TO", "%s registered to %s by %s." }, + { "CSMSG_CHANNEL_MOVED", "%s moved to %s by %s." }, + { "CSMSG_SUSPENSION_MODIFIED", "%s suspension modified by %s." }, + { "CSMSG_SUSPENDED_BY", "%s suspended by %s." }, + { "CSMSG_UNSUSPENDED_BY", "%s unsuspended by %s." }, + { "CSMSG_OWNERSHIP_TRANSFERRED", "%s ownership transferred to %s by %s." }, + + /* opserv.c */ + { "DEFCON_NETWORK_CHANGED", "Network DefCon level has changed to level %d" }, + { "DEFCON_OPER_LEVEL_CHANGE", "%s is changing the DefCon level to %d" }, + { "DEFCON_TIMEOUT_LEVEL_CHANGE", "The DefCon has changed back to level %d (timeout)" }, + { NULL, NULL } }; @@ -86,6 +107,7 @@ struct userNode *global; static struct module *global_module; static struct service *global_service; static struct globalMessage *messageList; +extern struct string_list *autojoin_channels; static long messageCount; static time_t last_max_alert; static struct log_type *G_LOG; @@ -357,6 +379,59 @@ 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); + + if ((message->flags & MESSAGE_RECIPIENT_LUSERS) || (message->flags & MESSAGE_RECIPIENT_HELPERS)) + continue; + } + + /* helpers */ + if (message->flags & MESSAGE_RECIPIENT_HELPERS && IsHelper(luser)) { + notice_target(luser->nick, message); + + if (message->flags & MESSAGE_RECIPIENT_LUSERS) + continue; + } + + /* users */ + if (message->flags & MESSAGE_RECIPIENT_LUSERS) + notice_target(luser->nick, message); + } + + message_del(message); +} + void global_message(long targets, char *text) { @@ -532,7 +607,10 @@ send_messages(struct userNode *user, long mask, int obstreperize) if(message->flags & mask) { if (obstreperize && !count) + { send_target_message(0, user->nick, global, "GMSG_MOTD_HEADER"); + send_target_message(0, user->nick, global, "GMSG_MOTD_BAR"); + } notice_target(user->nick, message); count++; } @@ -687,6 +765,8 @@ global_db_cleanup(void) void init_global(const char *nick) { + struct chanNode *chan; + unsigned int i; G_LOG = log_register_type("Global", "file:global.log"); reg_new_user_func(global_process_user); reg_auth_func(global_process_auth); @@ -707,6 +787,14 @@ init_global(const char *nick) global = AddService(nick, modes ? modes : NULL, "Global Services", NULL); global_service = service_register(global); } + + if(autojoin_channels && global) { + for (i = 0; i < autojoin_channels->used; i++) { + chan = AddChannel(autojoin_channels->list[i], now, "+nt", NULL, NULL); + AddChannelUser(global, chan)->modes |= MODE_CHANOP; + } + } + saxdb_register("Global", global_saxdb_read, global_saxdb_write); reg_exit_func(global_db_cleanup); message_register_table(msgtab);