summaryrefslogtreecommitdiff
path: root/src/map/channel.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/channel.c')
-rw-r--r--src/map/channel.c70
1 files changed, 30 insertions, 40 deletions
diff --git a/src/map/channel.c b/src/map/channel.c
index f1946385d..e27e9fb0b 100644
--- a/src/map/channel.c
+++ b/src/map/channel.c
@@ -276,7 +276,9 @@ static void channel_send(struct channel_data *chan, struct map_session_data *sd,
if (sd && chan->msg_delay != 0
&& DIFF_TICK(sd->hchsysch_tick + chan->msg_delay*1000, timer->gettick()) > 0
&& !pc_has_permission(sd, PC_PERM_HCHSYS_ADMIN)) {
- clif->messagecolor_self(sd->fd, COLOR_RED, msg_sd(sd,1455));
+ char output[CHAT_SIZE_MAX];
+ sprintf(output, msg_sd(sd, 1455), DIFF_TICK(sd->hchsysch_tick + chan->msg_delay * 1000, timer->gettick()) / 1000); // "You cannot send a message to this channel for another %d seconds."
+ clif->messagecolor_self(sd->fd, COLOR_RED, output);
return;
} else if (sd) {
int i;
@@ -317,8 +319,8 @@ static void channel_join_sub(struct channel_data *chan, struct map_session_data
if (idb_put(chan->users, sd->status.char_id, sd))
return;
- RECREATE(sd->channels, struct channel_data *, ++sd->channel_count);
- sd->channels[sd->channel_count - 1] = chan;
+ VECTOR_ENSURE(sd->channels, 1, 1);
+ VECTOR_PUSH(sd->channels, chan);
if (!stealth && (chan->options&HCS_OPT_ANNOUNCE_JOIN)) {
char message[60];
@@ -327,7 +329,7 @@ static void channel_join_sub(struct channel_data *chan, struct map_session_data
}
/* someone is cheating, we kindly disconnect the bastard */
- if (sd->channel_count > 200) {
+ if (VECTOR_LENGTH(sd->channels) > 200) {
sockt->eof(sd->fd);
}
@@ -409,32 +411,16 @@ static enum channel_operation_status channel_join(struct channel_data *chan, str
*/
static void channel_leave_sub(struct channel_data *chan, struct map_session_data *sd)
{
- unsigned char i;
+ int i;
nullpo_retv(chan);
nullpo_retv(sd);
- for (i = 0; i < sd->channel_count; i++) {
- if (sd->channels[i] == chan) {
- sd->channels[i] = NULL;
- break;
- }
- }
- if (i < sd->channel_count) {
- unsigned char cursor = 0;
- for (i = 0; i < sd->channel_count; i++) {
- if (sd->channels[i] == NULL)
- continue;
- if (cursor != i) {
- sd->channels[cursor] = sd->channels[i];
- }
- cursor++;
- }
- if (!(sd->channel_count = cursor)) {
- aFree(sd->channels);
- sd->channels = NULL;
- }
+ ARR_FIND(0, VECTOR_LENGTH(sd->channels), i, VECTOR_INDEX(sd->channels, i) == chan);
+ if (i < VECTOR_LENGTH(sd->channels)) {
+ VECTOR_ERASE(sd->channels, i);
}
}
+
/**
* Leaves a channel.
*
@@ -473,14 +459,9 @@ static void channel_leave(struct channel_data *chan, struct map_session_data *sd
static void channel_quit(struct map_session_data *sd)
{
nullpo_retv(sd);
- while (sd->channel_count > 0) {
+ while (VECTOR_LENGTH(sd->channels) > 0) {
// Loop downward to avoid unnecessary array compactions by channel_leave
- struct channel_data *chan = sd->channels[sd->channel_count-1];
-
- if (chan == NULL) {
- sd->channel_count--;
- continue;
- }
+ struct channel_data *chan = VECTOR_LAST(sd->channels);
channel->leave(chan, sd);
}
@@ -583,13 +564,12 @@ static void channel_guild_leave_alliance(const struct guild *g_source, const str
*/
static void channel_quit_guild(struct map_session_data *sd)
{
- unsigned char i;
-
nullpo_retv(sd);
- for (i = 0; i < sd->channel_count; i++) {
- struct channel_data *chan = sd->channels[i];
+ for (int i = VECTOR_LENGTH(sd->channels) - 1; i >= 0; i--) {
+ // Loop downward to avoid issues when channel->leave() compacts the array
+ struct channel_data *chan = VECTOR_INDEX(sd->channels, i);
- if (chan == NULL || chan->type != HCS_TYPE_ALLY)
+ if (chan->type != HCS_TYPE_ALLY)
continue;
channel->leave(chan, sd);
@@ -622,7 +602,8 @@ static void read_channels_config(void)
irc_autojoin = 0,
irc_flood_protection_rate = 0,
irc_flood_protection_burst = 0,
- irc_flood_protection_enabled = 0;
+ irc_flood_protection_enabled = 0,
+ channel_opt_msg_delay = 10;
if( !libconfig->setting_lookup_string(settings, "map_local_channel_name", &local_name) )
local_name = "map";
@@ -818,6 +799,16 @@ static void read_channels_config(void)
}
}
+ libconfig->setting_lookup_int(settings, "channel_opt_msg_delay", &channel_opt_msg_delay);
+ if (channel_opt_msg_delay < 0) {
+ ShowWarning("channels.conf: channel_opt_msg_delay value '%d' must be from 0-255. Defaulting to 0...\n", channel_opt_msg_delay);
+ channel_opt_msg_delay = 0;
+ } else if (channel_opt_msg_delay > 255) {
+ ShowWarning("channels.conf: channel_opt_msg_delay value '%d' must be from 0-255. Defaulting to 255...\n", channel_opt_msg_delay);
+ channel_opt_msg_delay = 255;
+ }
+ channel->config->channel_opt_msg_delay = channel_opt_msg_delay;
+
ShowStatus("Done reading '"CL_WHITE"%u"CL_RESET"' channels in '"CL_WHITE"%s"CL_RESET"'.\n", db_size(channel->db), config_filename);
}
libconfig->destroy(&channels_conf);
@@ -842,7 +833,6 @@ static void do_final_channel(void)
{
struct DBIterator *iter = db_iterator(channel->db);
struct channel_data *chan;
- unsigned char i;
for( chan = dbi_first(iter); dbi_exists(iter); chan = dbi_next(iter) ) {
channel->delete(chan);
@@ -850,7 +840,7 @@ static void do_final_channel(void)
dbi_destroy(iter);
- for(i = 0; i < channel->config->colors_count; i++) {
+ for (int i = 0; i < channel->config->colors_count; i++) {
aFree(channel->config->colors_name[i]);
}