/* global.c - Global notice service
* Copyright 2000-2004 srvx Development Team
*
- * This program is free software; you can redistribute it and/or modify
+ * This file is part of srvx.
+ *
+ * srvx 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. Important limitations are
- * listed in the COPYING file that accompanies this software.
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, email srvx-maintainers@srvx.net.
+ * along with srvx; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "conf.h"
/* Global options */
#define KEY_DB_BACKUP_FREQ "db_backup_freq"
-#define KEY_ANNOUNCEMENTS_DEFAULT "announcements_default"
#define KEY_NICK "nick"
/* Message data */
#define GLOBAL_SYNTAX() svccmd_send_help(user, global, cmd)
#define GLOBAL_FUNC(NAME) MODCMD_FUNC(NAME)
+struct globalMessage
+{
+ unsigned long id;
+ long flags;
+
+ time_t posted;
+ char posted_s[24];
+ unsigned long duration;
+
+ char *from;
+ char *message;
+
+ struct globalMessage *prev;
+ struct globalMessage *next;
+};
+
struct userNode *global;
static struct module *global_module;
static struct
{
unsigned long db_backup_frequency;
- unsigned int announcements_default : 1;
} global_conf;
#define global_notice(target, format...) send_message(target , global , ## format)
message_add(long flags, time_t posted, unsigned long duration, char *from, const char *msg)
{
struct globalMessage *message;
+ struct tm tm;
message = malloc(sizeof(struct globalMessage));
-
if(!message)
{
return NULL;
message->from = strdup(from);
message->message = strdup(msg);
+ if ((flags & MESSAGE_OPTION_IMMEDIATE) == 0) {
+ localtime_r(&message->posted, &tm);
+ strftime(message->posted_s, sizeof(message->posted_s),
+ "%I:%M %p, %m/%d/%Y", &tm);
+ }
+
if(messageList)
{
messageList->prev = message;
}
-
message->prev = NULL;
message->next = messageList;
{
unsigned long duration = 0;
char *text = NULL;
+ char *sender;
long flags = 0;
unsigned int i;
+ sender = user->handle_info->handle;
+
for(i = 0; i < argc; i++)
{
if((i + 1) > argc)
flags |= MESSAGE_RECIPIENT_STAFF;
} else if(!irccasecmp(argv[i], "channels")) {
flags |= MESSAGE_RECIPIENT_CHANNELS;
- } 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;
}
} else if (irccasecmp(argv[i], "duration") == 0) {
duration = ParseInterval(argv[++i]);
+ } else if (irccasecmp(argv[i], "from") == 0) {
+ sender = argv[++i];
} else {
global_notice(user, "MSG_INVALID_CRITERIA", argv[i]);
return NULL;
return NULL;
}
- return message_add(flags, now, duration, user->handle_info->handle, text);
+ return message_add(flags, now, duration, sender, text);
}
static const char *
{
return "staff";
}
- else if(message->flags & MESSAGE_RECIPIENT_ANNOUNCE)
- {
- return "announcement";
- }
else if(message->flags & MESSAGE_RECIPIENT_OPERS)
{
return "opers";
}
else
{
- char posted[24];
- struct tm tm;
-
- localtime_r(&message->posted, &tm);
- strftime(posted, sizeof(posted), "%I:%M %p, %m/%d/%Y", &tm);
- send_target_message(0, target, global, "GMSG_MESSAGE_SOURCE", messageType(message), message->from, posted);
+ send_target_message(0, target, global, "GMSG_MESSAGE_SOURCE", messageType(message), message->from, message->posted_s);
}
}
{
struct userNode *user;
unsigned long n;
- dict_iterator_t it;
if(message->flags & MESSAGE_RECIPIENT_CHANNELS)
{
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++)
{
struct globalMessage *message = NULL;
const char *recipient = NULL, *text;
+ char *sender;
long target = 0;
assert(argc >= 3);
+ sender = user->handle_info->handle;
if(!irccasecmp(argv[1], "all")) {
target = MESSAGE_RECIPIENT_ALL;
} else if(!irccasecmp(argv[1], "users")) {
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 {
global_notice(user, "GMSG_INVALID_TARGET", argv[1]);
return 0;
}
+ if(!irccasecmp(argv[2], "from")) {
+ if (argc < 5) {
+ reply("MSG_MISSING_PARAMS", argv[0]);
+ GLOBAL_SYNTAX();
+ return 0;
+ }
+ sender = argv[3];
+ text = unsplit_string(argv + 4, argc - 4, NULL);
+ } else {
+ text = unsplit_string(argv + 2, argc - 2, NULL);
+ }
- text = unsplit_string(argv + 2, argc - 2, NULL);
- message = message_add(target | MESSAGE_OPTION_IMMEDIATE, now, 0, user->handle_info->handle, text);
-
+ message = message_add(target | MESSAGE_OPTION_IMMEDIATE, now, 0, sender, text);
if(!message)
- {
return 0;
- }
recipient = messageType(message);
-
message_send(message);
message_del(message);
table.contents[nn][0] = strdup(buffer);
table.contents[nn][1] = messageType(message);
if(message->duration)
- {
- intervalString(buffer, message->posted + message->duration - now);
- }
+ intervalString(buffer, message->posted + message->duration - now, user->handle_info);
else
- {
strcpy(buffer, "Never.");
- }
table.contents[nn][2] = strdup(buffer);
table.contents[nn][3] = message->from;
length = strlen(message->message);
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)
if(nick)
{
- global = AddService(nick, "Global Services");
- global_service = service_register(global, 0);
+ const char *modes = conf_get_data("services/global/modes", RECDB_QSTRING);
+ global = AddLocalUser(nick, nick, NULL, "Global Services", modes);
+ global_service = service_register(global);
}
saxdb_register("Global", global_saxdb_read, global_saxdb_write);
reg_exit_func(global_db_cleanup);