diff --git a/Changelog b/Changelog index ed3779e..6b7907d 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,7 @@ [Changes 1.2c01] +* Add half-op support to /topic and /untopic. (caf) + * Tidy up the URL grabber, fixing a memory leak. (caf) * Cleanup the /BHELP code, fixing a potential crash. Apply updates to diff --git a/include/commands.h b/include/commands.h index 9ee35dc..abc6372 100644 --- a/include/commands.h +++ b/include/commands.h @@ -60,6 +60,7 @@ extern void cd (char *, char *, char *, char *); extern void e_wall (char *, char *, char *, char *); extern void send_2comm (char *, char *, char *, char *); extern void send_comm (char *, char *, char *, char *); +extern void untopic (char *, char *, char *, char *); extern void e_topic (char *, char *, char *, char *); extern void send_kick (char *, char *, char *, char *); extern void send_channel_com (char *, char *, char *, char *); diff --git a/include/misc.h b/include/misc.h index 7145d26..5d29309 100644 --- a/include/misc.h +++ b/include/misc.h @@ -36,6 +36,7 @@ enum color_attributes { }; #define DONT_CARE 3 +#define PC_TOPIC 2 #define NEED_OP 1 #define NO_OP 0 diff --git a/source/commands.c b/source/commands.c index 5f71132..32d3d7e 100644 --- a/source/commands.c +++ b/source/commands.c @@ -690,7 +690,7 @@ IrcCommand irc_command[] = { "UNSHIT", "UnShit", add_shit, 0, "%Y<%nnick%Y> <%nchannel%Y>%n" }, #endif { "UNTIL", "UNTIL", whilecmd, 0, scripting_command }, - { "UNTOPIC", "UNTOPIC", e_topic, 0, "- Unsets a channel topic" }, + { "UNTOPIC", "UNTOPIC", untopic, 0, "- Unsets a channel topic" }, #ifdef WANT_USERLIST { "UNUSER", "UnUser", add_user, 0, "%Y<%nnick%W|%nnick!user@hostname%Y> <%n#channel%W|%n*%Y>%n" }, #endif @@ -3532,46 +3532,47 @@ char *str = NULL; send_to_server("%s %s %s", command, new_flag, serv); } -BUILT_IN_COMMAND(e_topic) +BUILT_IN_COMMAND(untopic) { - char *arg = NULL; - char *arg2; + char *channel = NULL; ChannelList *chan; int server; - int unset = 0; - - arg = next_arg(args, &args); - if (!my_stricmp(command, "UNTOPIC")) - unset = 1; - if (!(chan = prepare_command(&server, arg?(is_channel(arg)?arg:NULL):NULL, NO_OP))) + args = sindex(args, "^ "); + + if (is_channel(args)) + channel = next_arg(args, &args); + + if (!(chan = prepare_command(&server, channel, PC_TOPIC))) return; - if (unset) + + my_send_to_server(server, "TOPIC %s :", chan->channel); +} + +BUILT_IN_COMMAND(e_topic) +{ + char *channel = NULL; + ChannelList *chan; + int server; + + args = sindex(args, "^ "); + + if (is_channel(args)) { - my_send_to_server(server, "TOPIC %s :", chan->channel); - return; + channel = next_arg(args, &args); + args = sindex(args, "^ "); } - if (arg && (!(chan->mode & MODE_TOPIC) || chan->have_op)) + + if (!(chan = prepare_command(&server, channel, args ? PC_TOPIC : NO_OP))) + return; + + if (args) { - if (is_channel(arg)) - { - add_last_type(&last_sent_topic[0], 1, NULL, NULL, chan->channel, args); - if ((arg2 = next_arg(args, &args))) - my_send_to_server(server, "%s %s :%s %s", command, chan->channel, arg2, args); - else - my_send_to_server(server, "%s %s", command, chan->channel); - } - else - { - char *p = NULL; - p = m_sprintf("%s%s%s", arg, arg?space:empty_string, args?args:empty_string); - my_send_to_server(server, "%s %s :%s%s%s", command, chan->channel, arg, args?space:empty_string, args?args:empty_string); - add_last_type(&last_sent_topic[0], 1, NULL, NULL, chan->channel, p); - new_free(&p); - } + add_last_type(&last_sent_topic[0], 1, NULL, NULL, chan->channel, args); + my_send_to_server(server, "TOPIC %s :%s", chan->channel, args); } else - my_send_to_server(server, "%s %s", command, chan->channel); + my_send_to_server(server, "TOPIC %s", chan->channel); } /* MTOPIC by singe_ stolen from an idea by MHacker @@ -3593,7 +3594,7 @@ BUILT_IN_COMMAND(do_mtopic) count++; } if (!count) - bitchsay("Your not an op on any channels"); + bitchsay("You're not an op on any channels"); } else bitchsay("No server for this window"); } diff --git a/source/misc.c b/source/misc.c index 3a075d8..0cbe6ca 100644 --- a/source/misc.c +++ b/source/misc.c @@ -4831,16 +4831,17 @@ int matchmcommand(char *origline,int count) return(0); } -ChannelList *BX_prepare_command(int *active_server, char *channel, int need_op) +ChannelList *BX_prepare_command(int *active_server, char *channel, int flags) { int server = 0; ChannelList *chan = NULL; + int need_op; if (!channel) { channel = get_current_channel_by_refnum(0); if (!channel) { - if (need_op != 3) { + if (flags != 3) { if (current_window) message_to(current_window->refnum); bitchsay("You're not on a channel!"); @@ -4853,7 +4854,7 @@ ChannelList *chan = NULL; *active_server = server; if (!(chan = lookup_channel(channel, server, 0))) { - if (need_op != 3) { + if (flags != 3) { if (current_window) message_to(current_window->refnum); bitchsay("You're not on the channel: %s", channel); @@ -4861,7 +4862,9 @@ ChannelList *chan = NULL; } return NULL; } - if (need_op == NEED_OP && chan && !chan->have_op && !chan->hop) + + need_op = flags == NEED_OP || (flags == PC_TOPIC && (chan->mode & MODE_TOPIC)); + if (need_op && !chan->have_op && !chan->hop) { error_not_opped(chan->channel); return NULL;