summaryrefslogtreecommitdiff
path: root/src/map/atcommand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/atcommand.c')
-rw-r--r--src/map/atcommand.c48
1 files changed, 19 insertions, 29 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 179b96c32..6cfa86163 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -8996,9 +8996,7 @@ static void atcommand_channel_help(int fd, const char *command, bool can_create)
clif->message(fd, msg_fd(fd,1428));// - binds global chat to <channel name>, making anything you type in global be sent to the channel
safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1429),command);// -- %s unbind
clif->message(fd, atcmd_output);
- clif->message(fd, msg_fd(fd,1430));// - unbinds your global chat from its attached channel (if binded)
- safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1429),command);// -- %s unbind
- clif->message(fd, atcmd_output);
+ clif->message(fd, msg_fd(fd,1430));// - unbinds your global chat from its attached channel (if bound)
if( can_create ) {
safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1456),command);// -- %s ban <channel name> <character name>
clif->message(fd, atcmd_output);
@@ -9023,7 +9021,6 @@ ACMD(channel)
{
struct channel_data *chan;
char subcmd[HCS_NAME_LENGTH], sub1[HCS_NAME_LENGTH], sub2[HCS_NAME_LENGTH], sub3[HCS_NAME_LENGTH];
- unsigned char k = 0;
sub1[0] = sub2[0] = sub3[0] = '\0';
if (!*message || sscanf(message, "%19s %19s %19s %19s", subcmd, sub1, sub2, sub3) < 1) {
@@ -9060,7 +9057,7 @@ ACMD(channel)
} else if (strcmpi(subcmd,"list") == 0) {
// sub1 = list type; sub2 = unused; sub3 = unused
if (sub1[0] != '\0' && strcmpi(sub1,"colors") == 0) {
- for (k = 0; k < channel->config->colors_count; k++) {
+ for (int k = 0; k < channel->config->colors_count; k++) {
safesnprintf(atcmd_output, sizeof(atcmd_output), "[ %s list colors ] : %s", command, channel->config->colors_name[k]);
clif->messagecolor_self(fd, channel->config->colors[k], atcmd_output);
@@ -9089,6 +9086,7 @@ ACMD(channel)
}
} else if (strcmpi(subcmd,"setcolor") == 0) {
// sub1 = channel name; sub2 = color; sub3 = unused
+ int k;
if (sub1[0] != '#') {
clif->message(fd, msg_fd(fd,1405));// Channel name must start with a '#'
return false;
@@ -9106,10 +9104,7 @@ ACMD(channel)
return false;
}
- for (k = 0; k < channel->config->colors_count; k++) {
- if (strcmpi(sub2, channel->config->colors_name[k]) == 0)
- break;
- }
+ ARR_FIND(0, channel->config->colors_count, k, strcmpi(sub2, channel->config->colors_name[k]) == 0);
if (k == channel->config->colors_count) {
safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1411), sub2);// Unknown color '%s'
clif->message(fd, atcmd_output);
@@ -9120,51 +9115,45 @@ ACMD(channel)
clif->message(fd, atcmd_output);
} else if (strcmpi(subcmd,"leave") == 0) {
// sub1 = channel name; sub2 = unused; sub3 = unused
+ int k;
if (sub1[0] != '#') {
clif->message(fd, msg_fd(fd,1405));// Channel name must start with a '#'
return false;
}
- for (k = 0; k < sd->channel_count; k++) {
- if (strcmpi(sub1+1,sd->channels[k]->name) == 0)
- break;
- }
- if (k == sd->channel_count) {
+ ARR_FIND(0, VECTOR_LENGTH(sd->channels), k, strcmpi(sub1 + 1, VECTOR_INDEX(sd->channels, k)->name) == 0);
+ if (k == VECTOR_LENGTH(sd->channels)) {
safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1425),sub1);// You're not part of the '%s' channel
clif->message(fd, atcmd_output);
return false;
}
- if (sd->channels[k]->type == HCS_TYPE_ALLY) {
- do {
- for (k = 0; k < sd->channel_count; k++) {
- if (sd->channels[k]->type == HCS_TYPE_ALLY) {
- channel->leave(sd->channels[k],sd);
- break;
- }
+ if (VECTOR_INDEX(sd->channels, k)->type == HCS_TYPE_ALLY) {
+ for (k = VECTOR_LENGTH(sd->channels) - 1; k >= 0; k--) {
+ // Loop downward to avoid issues when channel->leave() compacts the array
+ if (VECTOR_INDEX(sd->channels, k)->type == HCS_TYPE_ALLY) {
+ channel->leave(VECTOR_INDEX(sd->channels, k), sd);
}
- } while (k != sd->channel_count);
+ }
} else {
- channel->leave(sd->channels[k],sd);
+ channel->leave(VECTOR_INDEX(sd->channels, k), sd);
}
safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1426),sub1); // You've left the '%s' channel
clif->message(fd, atcmd_output);
} else if (strcmpi(subcmd,"bindto") == 0) {
// sub1 = channel name; sub2 = unused; sub3 = unused
+ int k;
if (sub1[0] != '#') {
clif->message(fd, msg_fd(fd,1405));// Channel name must start with a '#'
return false;
}
- for (k = 0; k < sd->channel_count; k++) {
- if (strcmpi(sub1+1,sd->channels[k]->name) == 0)
- break;
- }
- if (k == sd->channel_count) {
+ ARR_FIND(0, VECTOR_LENGTH(sd->channels), k, strcmpi(sub1 + 1, VECTOR_INDEX(sd->channels, k)->name) == 0);
+ if (k == VECTOR_LENGTH(sd->channels)) {
safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1425),sub1);// You're not part of the '%s' channel
clif->message(fd, atcmd_output);
return false;
}
- sd->gcbind = sd->channels[k];
+ sd->gcbind = VECTOR_INDEX(sd->channels, k);
safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1431),sub1); // Your global chat is now bound to the '%s' channel
clif->message(fd, atcmd_output);
} else if (strcmpi(subcmd,"unbind") == 0) {
@@ -9336,6 +9325,7 @@ ACMD(channel)
dbi_destroy(iter);
} else if (strcmpi(subcmd,"setopt") == 0) {
// sub1 = channel name; sub2 = option name; sub3 = value
+ int k;
const char* opt_str[3] = {
"None",
"JoinAnnounce",