init_list_entry(&ch->node);
init_list_entry(&ch->clients);
init_list_entry(&ch->flatlist_node);
+ init_list_entry(&ch->channel_links);
return ch;
}
else
ch = list_get_entry(list_get_next(&ch->flatlist_node), channel_t, flatlist_node);
}
- if (ch)
- Log_debug("Channel %d", ch->id);
}
*channelpptr = ch;
{
int i;
conf_channel_t chdesc;
+ conf_channel_link_t chlink;
const char *defaultChannelName;
defaultChannelName = getStrConf(DEAFULT_CHANNEL);
Log_fatal("Error in channel configuration: parent not found");
else {
Chan_addChannel(ch_itr, ch);
- Log_info("Adding channel %s parent %s", ch->name, chdesc.parent);
+ Log_info("Adding channel '%s' parent '%s'", ch->name, chdesc.parent);
}
}
}
if (defaultChan == NULL)
defaultChan = rootChan;
+
+ /* Channel links */
+ for (i = 0; ; i++) {
+ channel_t *ch_src, *ch_dst, *ch_itr = NULL;
+ if (Conf_getNextChannelLink(&chlink, i) < 0) {
+ if (i == 0)
+ Log_info("No channel links found in configuration file.");
+ break;
+ }
+ ch_itr = NULL;
+ do {
+ Chan_iterate(&ch_itr);
+ } while (ch_itr != NULL && strcmp(ch_itr->name, chlink.source) != 0);
+ if (ch_itr == NULL)
+ Log_fatal("Error in channel link configuration: source channel '%s' not found.", chlink.source);
+ else
+ ch_src = ch_itr;
+
+ ch_itr = NULL;
+ do {
+ Chan_iterate(&ch_itr);
+ } while (ch_itr != NULL && strcmp(ch_itr->name, chlink.destination) != 0);
+ if (ch_itr == NULL)
+ Log_fatal("Error in channel link configuration: destination channel '%s' not found", chlink.destination);
+ else
+ ch_dst = ch_itr;
+
+ list_add_tail(&ch_dst->link_node, &ch_src->channel_links);
+ Log_debug("Adding channel link %s -> %s", ch_src->name, ch_dst->name);
+ }
}
void Chan_free()
Chan_iterate(&ch_itr);
} while (ch_itr != NULL && ch_itr->id != parentId);
if (ch_itr == NULL)
- Log_warn("Channel id %d not found - ignoring.", parentId);
+ Log_warn("Chan_addChannel_id: Channel id %d not found - ignoring.", parentId);
else
list_add_tail(&ch->node, &ch_itr->subs);
}
+channel_t *Chan_fromId(int channelid)
+{
+ channel_t *ch_itr = NULL;
+ do {
+ Chan_iterate(&ch_itr);
+ } while (ch_itr != NULL && ch_itr->id != channelid);
+ if (ch_itr == NULL)
+ Log_warn("Chan_fromId: Channel id %d not found.", channelid);
+ return ch_itr;
+}
+
void Chan_removeChannel(channel_t *ch)
{
list_del(&ch->node);
struct dlist subs;
struct dlist clients;
struct dlist flatlist_node;
+ struct dlist channel_links;
+ struct dlist link_node;
} channel_t;
void Chan_init();
void Chan_playerJoin_id(int channelid, client_t *client);
void Chan_iterate(channel_t **channelpptr);
channel_t *Chan_createChannel(const char *name, const char *desc);
+channel_t *Chan_fromId(int channelid);
void Chan_freeChannel(channel_t *ch);
#endif
Client_send_udp(c, buffer, pds->offset + 1);
}
}
+ /* Channel links */
+ if (!list_empty(&ch->channel_links)) {
+ struct dlist *ch_itr;
+ list_iterate(ch_itr, &ch->channel_links) {
+ channel_t *ch_link;
+ ch_link = list_get_entry(ch_itr, channel_t, link_node);
+ list_iterate(itr, &ch_link->clients) {
+ client_t *c;
+ c = list_get_entry(itr, client_t, chan_node);
+ if (c != client && !c->deaf) {
+ Log_debug("Linked voice from %s -> %s", ch->name, ch_link->name);
+ Client_send_udp(c, buffer, pds->offset + 1);
+ }
+ }
+ }
+ }
} else if ((vt = Voicetarget_get_id(client, target)) != NULL) { /* Targeted whisper */
int i;
channel_t *ch;
return 0;
}
+
+int Conf_getNextChannelLink(conf_channel_link_t *chlink, int index)
+{
+ config_setting_t *setting = NULL;
+ char configstr[64];
+
+ sprintf(configstr, "channel_links.[%d].source", index);
+ setting = config_lookup(&configuration, configstr);
+ if (setting == NULL)
+ return -1;
+ strncpy(chlink->source, config_setting_get_string(setting), MAX_TEXT);
+
+ sprintf(configstr, "channel_links.[%d].destination", index);
+ setting = config_lookup(&configuration, configstr);
+ if (setting == NULL)
+ return -1;
+ strncpy(chlink->destination, config_setting_get_string(setting), MAX_TEXT);
+
+ return 0;
+}
char description[MAX_TEXT];
} conf_channel_t;
+typedef struct {
+ char source[MAX_TEXT];
+ char destination[MAX_TEXT];
+} conf_channel_link_t;
+
int Conf_init(const char *conffile);
void Conf_deinit();
const char *getStrConf(param_t param);
int getIntConf(param_t param);
int Conf_getNextChannel(conf_channel_t *chdesc, int index);
+int Conf_getNextChannelLink(conf_channel_link_t *chlink, int index);
#endif