diff options
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/atcommand.c | 28 | ||||
-rw-r--r-- | src/map/channel.c | 37 | ||||
-rw-r--r-- | src/map/channel.h | 2 | ||||
-rw-r--r-- | src/map/clif.c | 28 |
4 files changed, 51 insertions, 44 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 0f33a387c..a6e4d7265 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -8623,20 +8623,8 @@ ACMD(join) clif->message(fd, atcmd_output); return false; } - if (channel->config->local && strcmpi(name + 1, channel->config->local_name) == 0) { - if( !map->list[sd->bl.m].channel ) { - channel->map_join(sd); - if( map->list[sd->bl.m].channel ) /* join might have refused, map has chatting capabilities disabled */ - return true; - } else - chan = map->list[sd->bl.m].channel; - } else if (channel->config->ally && sd->status.guild_id && strcmpi(name + 1, channel->config->ally_name) == 0) { - struct guild *g = sd->guild; - if( !g ) return false;/* unlikely, but we wont let it crash anyway. */ - chan = g->channel; - } else { - chan = strdb_get(channel->db, name + 1); - } + + chan = channel->search(name, sd); if(!chan) { sprintf(atcmd_output, msg_txt(1400),name,command); // Unknown Channel '%s' (usage: %s <#channel_name>) @@ -8799,7 +8787,7 @@ ACMD(channel) { return false; } - if (!(chan = strdb_get(channel->db, sub1 + 1))) { + if (!(chan = channel->search(sub1, sd))) { sprintf(atcmd_output, msg_txt(1407), sub1);// Channel '%s' is not available clif->message(fd, atcmd_output); return false; @@ -8894,7 +8882,7 @@ ACMD(channel) { return false; } - if (!(chan = strdb_get(channel->db, sub1 + 1))) { + if (!(chan = channel->search(sub1, sd))) { sprintf(atcmd_output, msg_txt(1407), sub1);// Channel '%s' is not available clif->message(fd, atcmd_output); return false; @@ -8943,7 +8931,7 @@ ACMD(channel) { clif->message(fd, msg_txt(1405));// Channel name must start with a '#' return false; } - if (!(chan = strdb_get(channel->db, sub1 + 1))) { + if (!(chan = channel->search(sub1, sd))) { sprintf(atcmd_output, msg_txt(1407), sub1);// Channel '%s' is not available clif->message(fd, atcmd_output); return false; @@ -8980,7 +8968,7 @@ ACMD(channel) { clif->message(fd, msg_txt(1405));// Channel name must start with a '#' return false; } - if (!(chan = strdb_get(channel->db, sub1 + 1))) { + if (!(chan = channel->search(sub1, sd))) { sprintf(atcmd_output, msg_txt(1407), sub1);// Channel '%s' is not available clif->message(fd, atcmd_output); return false; @@ -9009,7 +8997,7 @@ ACMD(channel) { clif->message(fd, msg_txt(1405));// Channel name must start with a '#' return false; } - if (!(chan = strdb_get(channel->db, sub1 + 1))) { + if (!(chan = channel->search(sub1, sd))) { sprintf(atcmd_output, msg_txt(1407), sub1);// Channel '%s' is not available clif->message(fd, atcmd_output); return false; @@ -9050,7 +9038,7 @@ ACMD(channel) { clif->message(fd, msg_txt(1405));// Channel name must start with a '#' return false; } - if (!(chan = strdb_get(channel->db, sub1 + 1))) { + if (!(chan = channel->search(sub1, sd))) { sprintf(atcmd_output, msg_txt(1407), sub1);// Channel '%s' is not available clif->message(fd, atcmd_output); return false; diff --git a/src/map/channel.c b/src/map/channel.c index 49f5c9daa..e3cc789e4 100644 --- a/src/map/channel.c +++ b/src/map/channel.c @@ -32,6 +32,42 @@ struct channel_interface channel_s; static struct Channel_Config channel_config; /** + * Returns the named channel. + * + * @param name The channel name + * @param sd The issuer character, for character-specific channels (i.e. map, ally) + * @return a pointer to the channel, or NULL. + */ +struct channel_data *channel_search(const char *name, struct map_session_data *sd) +{ + const char *realname = name; + if (!realname || !*realname) + return NULL; + if (*realname == '#') { + realname++; + if (!*realname) + return NULL; + } + + if (channel->config->local && strcmpi(realname, channel->config->local_name) == 0) { + if (!sd) + return NULL; + if (!map->list[sd->bl.m].channel) { + channel->map_join(sd); + } + return map->list[sd->bl.m].channel; + } + + if (channel->config->ally && strcmpi(realname, channel->config->ally_name) == 0) { + if (!sd || !sd->status.guild_id || !sd->guild) + return NULL; + return sd->guild->channel; + } + + return strdb_get(channel->db, realname); +} + +/** * Creates a chat channel. * * If the channel type isn't HCS_TYPE_MAP or HCS_TYPE_ALLY, the channel is added to the channel->db. @@ -776,6 +812,7 @@ void channel_defaults(void) channel->final = do_final_channel; channel->config = &channel_config; + channel->search = channel_search; channel->create = channel_create; channel->set_password = channel_set_password; channel->ban = channel_ban; diff --git a/src/map/channel.h b/src/map/channel.h index 8709a9f96..39127f3b9 100644 --- a/src/map/channel.h +++ b/src/map/channel.h @@ -86,7 +86,7 @@ struct channel_interface { int (*init) (bool minimal); void (*final) (void); - struct channel_data *(*search) (const char *name); + struct channel_data *(*search) (const char *name, struct map_session_data *sd); struct channel_data *(*create) (enum channel_types type, const char *name, unsigned char color); void (*set_password) (struct channel_data *chan, const char *password); enum channel_operation_status (*ban) (struct channel_data *chan, const struct map_session_data *ssd, struct map_session_data *tsd); diff --git a/src/map/clif.c b/src/map/clif.c index c66176d45..269b72ae1 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -10040,31 +10040,13 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd) return; } } else if( target[0] == '#' ) { - // TODO: Split to channel.c - struct channel_data *chan = NULL; - char* chname = target; + char *chname = target; + struct channel_data *chan = channel->search(chname, sd); - chname++; - - if (channel->config->local && strcmpi(chname, channel->config->local_name) == 0) { - if( !map->list[sd->bl.m].channel ) { - channel->map_join(sd); - } - chan = map->list[sd->bl.m].channel; - } else if (channel->config->ally && sd->status.guild_id && strcmpi(chname, channel->config->ally_name) == 0) { - struct guild *g = sd->guild; - if( !g ) return; - chan = g->channel; - } - if( chan || (chan = strdb_get(channel->db,chname)) ) { + if (chan) { int k; - for( k = 0; k < sd->channel_count; k++ ) { - if( sd->channels[k] == chan ) - break; - } - if (k < sd->channel_count) { - channel->send(chan,sd,message); - } else if (channel->join(chan, sd, NULL, true) == HCS_STATUS_OK) { + ARR_FIND(0, sd->channel_count, k, sd->channels[k] == chan); + if (k < sd->channel_count || channel->join(chan, sd, NULL, true) == HCS_STATUS_OK) { channel->send(chan,sd,message); } else { clif->message(fd, msg_txt(1402)); |