From: fatbob313 Date: Wed, 6 Jan 2010 16:52:11 +0000 (+0000) Subject: Add channel links. X-Git-Url: http://git.code-monkey.de/?p=umurmur.git;a=commitdiff_plain;h=e86df9764efd8caa27aa0a2dec0092889aa87c91 Add channel links. --- diff --git a/src/channel.c b/src/channel.c index e4ec9ad..5c562fb 100644 --- a/src/channel.c +++ b/src/channel.c @@ -55,6 +55,7 @@ static channel_t *createChannel(int id, const char *name, const char *desc) init_list_entry(&ch->node); init_list_entry(&ch->clients); init_list_entry(&ch->flatlist_node); + init_list_entry(&ch->channel_links); return ch; } @@ -90,8 +91,6 @@ void Chan_iterate(channel_t **channelpptr) 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; @@ -101,6 +100,7 @@ void Chan_init() { int i; conf_channel_t chdesc; + conf_channel_link_t chlink; const char *defaultChannelName; defaultChannelName = getStrConf(DEAFULT_CHANNEL); @@ -134,12 +134,42 @@ void Chan_init() 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() @@ -206,11 +236,22 @@ void Chan_addChannel_id(int parentId, channel_t *ch) 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); diff --git a/src/channel.h b/src/channel.h index 3fdd940..29c28d3 100644 --- a/src/channel.h +++ b/src/channel.h @@ -44,6 +44,8 @@ typedef struct channel { struct dlist subs; struct dlist clients; struct dlist flatlist_node; + struct dlist channel_links; + struct dlist link_node; } channel_t; void Chan_init(); @@ -56,6 +58,7 @@ void Chan_playerJoin(channel_t *ch, client_t *client); 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 diff --git a/src/client.c b/src/client.c index 7cc4d0c..3a7217d 100644 --- a/src/client.c +++ b/src/client.c @@ -649,6 +649,22 @@ int Client_voiceMsg(client_t *client, uint8_t *data, int len) 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; diff --git a/src/conf.c b/src/conf.c index 540928b..63e209c 100644 --- a/src/conf.c +++ b/src/conf.c @@ -212,3 +212,23 @@ int Conf_getNextChannel(conf_channel_t *chdesc, int index) 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; +} diff --git a/src/conf.h b/src/conf.h index a42daad..3a469b2 100644 --- a/src/conf.h +++ b/src/conf.h @@ -51,11 +51,17 @@ typedef struct { 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