static struct dict *services;
static struct pending_template *pending_templates;
static struct module *modcmd_module;
static struct dict *services;
static struct pending_template *pending_templates;
static struct module *modcmd_module;
-static struct modcmd *bind_command, *help_command, *version_command;
+static struct modcmd *bind_command, *help_command, *version_command, *credits_command;
static const struct message_entry msgtab[] = {
{ "MCMSG_BARE_FLAG", "Flag %.*s must be preceded by a + or -." },
{ "MCMSG_UNKNOWN_FLAG", "Unknown module flag %.*s." },
static const struct message_entry msgtab[] = {
{ "MCMSG_BARE_FLAG", "Flag %.*s must be preceded by a + or -." },
{ "MCMSG_UNKNOWN_FLAG", "Unknown module flag %.*s." },
{ "acceptchan", MODCMD_ACCEPT_CHANNEL },
{ "acceptpluschan", MODCMD_ACCEPT_PCHANNEL },
{ "authed", MODCMD_REQUIRE_AUTHED },
{ "acceptchan", MODCMD_ACCEPT_CHANNEL },
{ "acceptpluschan", MODCMD_ACCEPT_PCHANNEL },
{ "authed", MODCMD_REQUIRE_AUTHED },
-DEFINE_LIST(svccmd_list, struct svccmd*);
-DEFINE_LIST(module_list, struct module*);
+DEFINE_LIST(svccmd_list, struct svccmd*)
+DEFINE_LIST(module_list, struct module*)
- flag = bsearch(value, flags, ArrayLength(flags)-1, sizeof(flags[0]), flags_bsearch);
+ flag = bsearch(value, modcmd_flags, ArrayLength(modcmd_flags)-1, sizeof(modcmd_flags[0]), flags_bsearch);
if (!flag) {
if (user)
send_message(user, bot, "MCMSG_UNKNOWN_FLAG", end, value);
if (!flag) {
if (user)
send_message(user, bot, "MCMSG_UNKNOWN_FLAG", end, value);
*/
int
svccmd_can_invoke(struct userNode *user, struct userNode *bot, struct svccmd *cmd, struct chanNode *channel, int options) {
*/
int
svccmd_can_invoke(struct userNode *user, struct userNode *bot, struct svccmd *cmd, struct chanNode *channel, int options) {
unsigned int uData_checked = 0;
struct userData *uData = NULL;
int rflags = 0, flags = cmd->effective_flags;
unsigned int uData_checked = 0;
struct userData *uData = NULL;
int rflags = 0, flags = cmd->effective_flags;
if (options & SVCCMD_NOISY)
send_message(user, bot, "MCMSG_CHAN_NOT_REGISTERED", channel->name);
return 0;
} else if (IsSuspended(channel->channel_info) && !(flags & MODCMD_IGNORE_CSUSPEND)) {
if (options & SVCCMD_NOISY)
send_message(user, bot, "MCMSG_CHAN_NOT_REGISTERED", channel->name);
return 0;
} else if (IsSuspended(channel->channel_info) && !(flags & MODCMD_IGNORE_CSUSPEND)) {
- /* allow security-override users to always ignore channel suspensions, but flag it as a staff command */
- if (!user->handle_info
- || !HANDLE_FLAGGED(user->handle_info, HELPING)
- || (flags & MODCMD_NEVER_CSUSPEND)) {
+ /* Allow security-override users to ignore most channel
+ * suspensions, but flag that use as a staff command.
+ */
+ if (!IsHelping(user) || (flags & MODCMD_NEVER_CSUSPEND)) {
if (options & SVCCMD_NOISY)
send_message(user, bot, "MCMSG_CHAN_SUSPENDED", channel->name, channel->channel_info->suspended->reason);
return 0;
if (options & SVCCMD_NOISY)
send_message(user, bot, "MCMSG_CHAN_SUSPENDED", channel->name, channel->channel_info->suspended->reason);
return 0;
if (flags & MODCMD_REQUIRE_CHANUSER) {
if (!uData_checked)
uData = _GetChannelUser(channel->channel_info, user->handle_info, 1, 0), uData_checked = 1;
if (flags & MODCMD_REQUIRE_CHANUSER) {
if (!uData_checked)
uData = _GetChannelUser(channel->channel_info, user->handle_info, 1, 0), uData_checked = 1;
if (options & SVCCMD_NOISY)
send_message(user, bot, "MCMSG_NO_CHANNEL_ACCESS", channel->name);
return 0;
if (options & SVCCMD_NOISY)
send_message(user, bot, "MCMSG_NO_CHANNEL_ACCESS", channel->name);
return 0;
static int
svccmd_expand_alias(struct svccmd *cmd, struct userNode *user, unsigned int old_argc, char *old_argv[], char *new_argv[]) {
unsigned int ii, new_argc;
static int
svccmd_expand_alias(struct svccmd *cmd, struct userNode *user, unsigned int old_argc, char *old_argv[], char *new_argv[]) {
unsigned int ii, new_argc;
lbound = strtoul(arg+1, &end_num, 10);
switch (end_num[0]) {
case 0: ubound = lbound; break;
lbound = strtoul(arg+1, &end_num, 10);
switch (end_num[0]) {
case 0: ubound = lbound; break;
+ case 'a':
+ altarg = (user && user->handle_info) ? user->handle_info->handle : "(account)";
+ break;
+ case 'n':
+ altarg = user ? user->nick : "(nick)";
+ break;
+ case 'm':
+#ifdef WITH_PROTOCOL_P10
+ altarg = user ? user->numeric : "(numnick)";
+#else
+ altarg = "(This ircd protocol has no numnicks!)";
+#endif
+ break;
log_module(MAIN_LOG, LOG_ERROR, "Alias expansion parse error in %s (near %s; %s.%s arg %d).", arg, end_num, cmd->parent->bot->nick, cmd->name, ii);
return 0;
}
log_module(MAIN_LOG, LOG_ERROR, "Alias expansion parse error in %s (near %s; %s.%s arg %d).", arg, end_num, cmd->parent->bot->nick, cmd->name, ii);
return 0;
}
+ if (altarg != NULL) {
+ if (end_num[1] != 0) {
+ if ((end_num[1] == '-') && (end_num[2] == 0))
+ ubound = old_argc - 1;
+ else if ((end_num[1] == '-') && (isdigit(end_num[2])))
+ ubound = strtoul(end_num+2, NULL, 10);
+ else {
+ log_module(MAIN_LOG, LOG_ERROR, "Alias expansion parse error in %s (near %s; %s.%s arg %d).", arg, end_num, cmd->parent->bot->nick, cmd->name, ii);
+ return 0;
+ }
+ } else {
+ ubound = lbound;
+ }
+ if (lbound >= old_argc)
+ new_argv[new_argc++] = altarg;
+ }
/* Expand the alias arguments, if there are any. */
if (cmd->alias.used) {
char *new_argv[MAXNUMPARAMS];
/* Expand the alias arguments, if there are any. */
if (cmd->alias.used) {
char *new_argv[MAXNUMPARAMS];
- argc = svccmd_expand_alias(cmd, user, argc, argv, new_argv);
- if (!argc) {
+ int res;
+
+ res = svccmd_expand_alias(cmd, user, argc, argv, new_argv);
+ if (res < 0) {
+ send_message(user, service->bot, "MSG_MISSING_PARAMS", cmd->name);
+ return 0;
+ } else if (res == 0) {
send_message(user, service->bot, "MCMSG_ALIAS_ERROR", cmd->name);
return 0;
}
send_message(user, service->bot, "MCMSG_ALIAS_ERROR", cmd->name);
return 0;
}
return argc ? svccmd_invoke_argv(user, service, channel, argc, argv, server_qualified) : 0;
}
return argc ? svccmd_invoke_argv(user, service, channel, argc, argv, server_qualified) : 0;
}
+char *cvs_verstring() {
+ static char verstring[MAXLEN] = { 0 };
+
+ if(!*verstring) {
+ char *svn = NULL, *svnver = NULL, *svndate = NULL, *v = 0, ver[MAXLEN];
+ int vc = 0;
+
+ strcpy(ver, CVS_VERSION);
+ for (svn = x3_strtok(&v, ver, " "); svn;
+ svn = x3_strtok(&v, 0, " ")) {
+ if (vc == 2)
+ svnver = svn;
+ else if (vc == 3)
+ svndate = svn;
+ vc++;
+ }
+ sprintf(verstring, "%s %s", svnver, svndate);
+ }
+ return verstring;
+}
+
+
void
modcmd_privmsg(struct userNode *user, struct userNode *bot, const char *text, int server_qualified) {
struct service *service;
void
modcmd_privmsg(struct userNode *user, struct userNode *bot, const char *text, int server_qualified) {
struct service *service;
snprintf(response, sizeof(response), "\x01USERINFO %s\x01", bot->info);
irc_notice_user(bot, user, response);
} else if (!irccasecmp(text, "VERSION")) {
snprintf(response, sizeof(response), "\x01USERINFO %s\x01", bot->info);
irc_notice_user(bot, user, response);
} else if (!irccasecmp(text, "VERSION")) {
- /* This function provides copyright management information
- * to end users of X3. You should not alter, disable or
- * remove this command or its accessibility to normal IRC
- * users, except to add copyright information pertaining
- * to changes you make to X3.
- */
- snprintf(response, sizeof(response), "\x01VERSION %s\x01", PACKAGE_STRING);
+ snprintf(response, sizeof(response), "\x01VERSION %s+[%s]\x01", PACKAGE_STRING, cvs_version);
irc_notice_user(bot, user, response);
} else if (!irccasecmp(text, "GENDER")) {
snprintf(response, sizeof(response), "\x01GENDER ummm im still deciding\x01");
irc_notice_user(bot, user, response);
} else if (!irccasecmp(text, "GENDER")) {
snprintf(response, sizeof(response), "\x01GENDER ummm im still deciding\x01");
-modcmd_chanmsg(struct userNode *user, struct chanNode *chan, const char *text, struct userNode *bot) {
+modcmd_chanmsg(struct userNode *user, struct chanNode *chan, const char *text, struct userNode *bot, unsigned int is_notice, UNUSED_ARG(void *extra)) {
svccmd_invoke(user, service, chan, text, 0);
svccmd_invoke(user, service, chan, text, 0);
if (suf_used == suf_size) {
if (suf_size) {
suf_size <<= 1;
suf_list = realloc(suf_list, suf_size*sizeof(svccmd_unbind_func_t));
if (suf_used == suf_size) {
if (suf_size) {
suf_size <<= 1;
suf_list = realloc(suf_list, suf_size*sizeof(svccmd_unbind_func_t));
/* If this command binding is removing itself, we must take care
* not to dereference it after the dict_remove.
*/
/* If this command binding is removing itself, we must take care
* not to dereference it after the dict_remove.
*/
snprintf(buf1, sizeof(buf1), "%s.%s", target->command->parent->name, target->command->name);
reply("MCMSG_COMMAND_BINDING", target->name, buf1);
}
snprintf(buf1, sizeof(buf1), "%s.%s", target->command->parent->name, target->command->name);
reply("MCMSG_COMMAND_BINDING", target->name, buf1);
}
- for (ii = buf1_used = buf2_used = 0; flags[ii].name; ++ii) {
- if (target->flags & flags[ii].flag) {
+ for (ii = buf1_used = buf2_used = 0; modcmd_flags[ii].name; ++ii) {
+ const struct modcmd_flag *flag = &modcmd_flags[ii];
+ if (target->flags & flag->flag) {
- len = strlen(flags[ii].name);
- memcpy(buf1 + buf1_used, flags[ii].name, len);
+ len = strlen(flag->name);
+ memcpy(buf1 + buf1_used, flag->name, len);
- len = strlen(flags[ii].name);
- memcpy(buf2 + buf2_used, flags[ii].name, len);
+ len = strlen(flag->name);
+ memcpy(buf2 + buf2_used, flag->name, len);
- access = strtab(svccmd->min_channel_access);
- tbl.contents[ii+1][1+show_opserv_level] = access;
+ access_name = strtab(svccmd->min_channel_access);
+ tbl.contents[ii+1][1+show_opserv_level] = access_name;
- reg_chanmsg_func(service->trigger, NULL, NULL);
+ reg_chanmsg_func(service->trigger, NULL, NULL, NULL);
if (!irccasecmp(argv[2], "none") || !irccasecmp(argv[2], "remove")) {
service->trigger = 0;
reply("MCMSG_REMOVED_TRIGGER", service->bot->nick);
if (!irccasecmp(argv[2], "none") || !irccasecmp(argv[2], "remove")) {
service->trigger = 0;
reply("MCMSG_REMOVED_TRIGGER", service->bot->nick);
- reg_chanmsg_func(service->trigger, service->bot, modcmd_chanmsg);
+ reg_chanmsg_func(service->trigger, service->bot, modcmd_chanmsg, NULL);
- if ((res = setjmp(ctx->jbuf)) != 0) {
- ctx->complex.used = 0; /* to avoid false assert()s in close */
- saxdb_close_context(ctx);
- fclose(pf);
+
+ if ((res = setjmp(*saxdb_jmp_buf(ctx))) != 0) {
+ saxdb_close_context(ctx, 1);
reply("MCMSG_MESSAGE_DUMP_FAILED", strerror(res));
return 0;
} else {
for (it = dict_first(lang_C->messages); it; it = iter_next(it))
saxdb_write_string(ctx, iter_key(it), iter_data(it));
reply("MCMSG_MESSAGE_DUMP_FAILED", strerror(res));
return 0;
} else {
for (it = dict_first(lang_C->messages); it; it = iter_next(it))
saxdb_write_string(ctx, iter_key(it), iter_data(it));
reply("MCMSG_MESSAGES_DUMPED", fname);
return 1;
}
}
static MODCMD_FUNC(cmd_version) {
reply("MCMSG_MESSAGES_DUMPED", fname);
return 1;
}
}
static MODCMD_FUNC(cmd_version) {
- /* This function provides copyright management information to end
- * users of X3. You should not alter, disable or remove this
- * command or its accessibility to normal IRC users, except to add
- * copyright information pertaining to changes you make to X3.
- */
-
- char *svn = NULL, *svnver = NULL, *svndate = NULL, *v = 0, ver[MAXLEN];
- int vc = 0;
-
- strcpy(ver, CVS_VERSION);
- for (svn = x3_strtok(&v, ver, " "); svn;
- svn = x3_strtok(&v, 0, " ")) {
- if (vc == 2)
- svnver = svn;
- else if (vc == 3)
- svndate = svn;
- vc++;
- }
+ send_message_type(4, user, cmd->parent->bot, "$b"PACKAGE_STRING"+[%s]$b (Based on srvx 1.3.x), Built: "__DATE__", "__TIME__".", cvs_version);
+ send_message_type(4, user, cmd->parent->bot, "See $bCREDITS$b for more information.");
+ return 1;
+}
- send_message_type(4, user, cmd->parent->bot, "$b"PACKAGE_STRING"+[%s %s]$b (Based on srvx 1.3.x), Built: "__DATE__", "__TIME__".", svnver, svndate);
- send_message_type(4, user, cmd->parent->bot, "$b$b");
+/* This function provides copyright management information to end
+ * users of X3. You should not alter, disable or remove this
+ * command or its accessibility to normal IRC users, except to add
+ * copyright information pertaining to changes you make to X3.
+ */
+static MODCMD_FUNC(cmd_credits) {
+ send_message_type(4, user, cmd->parent->bot, "$b"PACKAGE"$b is based on srvx");
send_message_type(4, user, cmd->parent->bot, "Copyright 2000-2007 srvx Development Team.");
send_message_type(4, user, cmd->parent->bot, "Copyright 2004-2007 X3 Development Team.");
send_message_type(4, user, cmd->parent->bot, "This software is OSI Certified Open Source Software.");
send_message_type(4, user, cmd->parent->bot, "Copyright 2000-2007 srvx Development Team.");
send_message_type(4, user, cmd->parent->bot, "Copyright 2004-2007 X3 Development Team.");
send_message_type(4, user, cmd->parent->bot, "This software is OSI Certified Open Source Software.");
send_message_type(4, user, cmd->parent->bot, "The X3 Development Team can be reached at http://evilnet.sourceforge.net or in #evilnet on irc.afternet.org.");
send_message_type(4, user, cmd->parent->bot, "$b$b");
send_message_type(4, user, cmd->parent->bot, "Thanks goes to ThiefMaster, Joe Hansche (joeatrr), Martijn Smit (wasted), and to any other people who have contributed to X3.");
send_message_type(4, user, cmd->parent->bot, "The X3 Development Team can be reached at http://evilnet.sourceforge.net or in #evilnet on irc.afternet.org.");
send_message_type(4, user, cmd->parent->bot, "$b$b");
send_message_type(4, user, cmd->parent->bot, "Thanks goes to ThiefMaster, Joe Hansche (joeatrr), Martijn Smit (wasted), and to any other people who have contributed to X3.");
- send_message_type(4, user, cmd->parent->bot, "This program is free software; see COPYING in the distribution.");
+ send_message_type(4, user, cmd->parent->bot, "This program is free software; see COPYING in the distribution files.");
saxdb_write_int(ctx, "channel_access", cmd->min_channel_access);
if (cmd->flags != template->flags) {
if (cmd->flags) {
saxdb_write_int(ctx, "channel_access", cmd->min_channel_access);
if (cmd->flags != template->flags) {
if (cmd->flags) {
- for (nn=pos=0; flags[nn].name; ++nn) {
- if (cmd->flags & flags[nn].flag) {
+ for (nn=pos=0; modcmd_flags[nn].name; ++nn) {
+ const struct modcmd_flag *flag = &modcmd_flags[nn];
+ if (cmd->flags & flag->flag) {
- len = strlen(flags[nn].name);
- memcpy(buf+pos, flags[nn].name, len);
+ len = strlen(flag->name);
+ memcpy(buf+pos, flag->name, len);
saxdb_start_record(ctx, "bots", 1);
for (it = dict_first(services); it; it = iter_next(it)) {
char buff[16];
saxdb_start_record(ctx, "bots", 1);
for (it = dict_first(services); it; it = iter_next(it)) {
char buff[16];
}
saxdb_write_string(ctx, "description", service->bot->info);
saxdb_write_string(ctx, "hostname", service->bot->hostname);
}
saxdb_write_string(ctx, "description", service->bot->info);
saxdb_write_string(ctx, "hostname", service->bot->hostname);
+ if (service->bot->modes) {
+ irc_user_modes(service->bot, modes, sizeof(modes));
+ saxdb_write_string(ctx, "modes", modes);
+ }
svc = service_find(nick);
desc = database_get_data(rd->d.object, "description", RECDB_QSTRING);
hostname = database_get_data(rd->d.object, "hostname", RECDB_QSTRING);
svc = service_find(nick);
desc = database_get_data(rd->d.object, "description", RECDB_QSTRING);
hostname = database_get_data(rd->d.object, "hostname", RECDB_QSTRING);
- svc = service_register(AddLocalUser(nick, nick, hostname, desc, NULL));
+ svc = service_register(AddLocalUser(nick, nick, hostname, desc, modes));
else if (hostname)
strcpy(svc->bot->hostname, hostname);
desc = database_get_data(rd->d.object, "trigger", RECDB_QSTRING);
else if (hostname)
strcpy(svc->bot->hostname, hostname);
desc = database_get_data(rd->d.object, "trigger", RECDB_QSTRING);
- qsort(flags, ArrayLength(flags)-1, sizeof(flags[0]), flags_qsort);
+ qsort(modcmd_flags, ArrayLength(modcmd_flags)-1, sizeof(modcmd_flags[0]), flags_qsort);
modules = dict_new();
dict_set_free_data(modules, free_module);
services = dict_new();
dict_set_free_data(services, free_service);
modules = dict_new();
dict_set_free_data(modules, free_module);
services = dict_new();
dict_set_free_data(services, free_service);
- reg_nick_change_func(modcmd_nick_change);
- reg_exit_func(modcmd_cleanup);
+ reg_nick_change_func(modcmd_nick_change, NULL);
+ reg_exit_func(modcmd_cleanup, NULL);
conf_register_reload(modcmd_conf_read);
modcmd_module = module_register("modcmd", MAIN_LOG, "modcmd.help", modcmd_expand);
conf_register_reload(modcmd_conf_read);
modcmd_module = module_register("modcmd", MAIN_LOG, "modcmd.help", modcmd_expand);
modcmd_register(modcmd_module, "tell", cmd_tell, 3, 0, "flags", "+oper", NULL);
modcmd_register(modcmd_module, "rebindall", cmd_rebindall, 0, MODCMD_KEEP_BOUND, "oper_level", "800", NULL);
version_command = modcmd_register(modcmd_module, "version", cmd_version, 1, 0, NULL);
modcmd_register(modcmd_module, "tell", cmd_tell, 3, 0, "flags", "+oper", NULL);
modcmd_register(modcmd_module, "rebindall", cmd_rebindall, 0, MODCMD_KEEP_BOUND, "oper_level", "800", NULL);
version_command = modcmd_register(modcmd_module, "version", cmd_version, 1, 0, NULL);
/* Bind the help and version commands to this service */
service_bind_modcmd(service, help_command, help_command->name);
service_bind_modcmd(service, version_command, version_command->name);
/* Bind the help and version commands to this service */
service_bind_modcmd(service, help_command, help_command->name);
service_bind_modcmd(service, version_command, version_command->name);
/* Now some silly hax.. (aliases that most people want) */
if (!irccasecmp(def_binds[ii].svcname, "ChanServ")) {
/* Now some silly hax.. (aliases that most people want) */
if (!irccasecmp(def_binds[ii].svcname, "ChanServ")) {
service_make_alias(service, "addop", "*chanserv.adduser", "$1", "op", "$2", NULL);
service_make_alias(service, "addhop", "*chanserv.adduser", "$1", "halfop", "$2", NULL);
service_make_alias(service, "addpeon", "*chanserv.adduser", "$1", "peon", "$2", NULL);
service_make_alias(service, "addop", "*chanserv.adduser", "$1", "op", "$2", NULL);
service_make_alias(service, "addhop", "*chanserv.adduser", "$1", "halfop", "$2", NULL);
service_make_alias(service, "addpeon", "*chanserv.adduser", "$1", "peon", "$2", NULL);
service_make_alias(service, "delowner", "*chanserv.deluser", "owner", "$1", NULL);
service_make_alias(service, "delcoowner", "*chanserv.deluser", "coowner", "$1", NULL);
service_make_alias(service, "delmanager", "*chanserv.deluser", "manager", "$1", NULL);
service_make_alias(service, "delop", "*chanserv.deluser", "op", "$1", NULL);
service_make_alias(service, "delpeon", "*chanserv.deluser", "peon", "$1", NULL);
service_make_alias(service, "delowner", "*chanserv.deluser", "owner", "$1", NULL);
service_make_alias(service, "delcoowner", "*chanserv.deluser", "coowner", "$1", NULL);
service_make_alias(service, "delmanager", "*chanserv.deluser", "manager", "$1", NULL);
service_make_alias(service, "delop", "*chanserv.deluser", "op", "$1", NULL);
service_make_alias(service, "delpeon", "*chanserv.deluser", "peon", "$1", NULL);
service_make_alias(service, "llist", "*chanserv.lamers", "$1", NULL);
service_make_alias(service, "command", "*modcmd.command", NULL);
service_make_alias(service, "god", "*modcmd.god", NULL);
service_make_alias(service, "llist", "*chanserv.lamers", "$1", NULL);
service_make_alias(service, "command", "*modcmd.command", NULL);
service_make_alias(service, "god", "*modcmd.god", NULL);
- reg_chanmsg_func(svc->trigger, svc->bot, modcmd_chanmsg);
+ reg_chanmsg_func(svc->trigger, svc->bot, modcmd_chanmsg, NULL);