Add channel links.
authorfatbob313 <martin@fatbob.nu>
Wed, 6 Jan 2010 16:52:11 +0000 (16:52 +0000)
committerfatbob313 <martin@fatbob.nu>
Wed, 6 Jan 2010 16:52:11 +0000 (16:52 +0000)
src/channel.c
src/channel.h
src/client.c
src/conf.c
src/conf.h

index e4ec9ad8fe97344838839276dc11d00c8c26c040..5c562fbbc566a613c7e1d1a4f7fad9b098f8ad9c 100644 (file)
@@ -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);
index 3fdd9409282d462f325f92d5179008234789f987..29c28d32cc42f70403d55eba9f6eaeb1a64ff48c 100644 (file)
@@ -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
index 7cc4d0c475d0cbf72f8fba959713c9b3724b6544..3a7217d93924f8a40d1ac3b5376b74d98c1587d8 100644 (file)
@@ -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;
index 540928bac58476fc0fa2aa9f07d568b5adf997a9..63e209c285e57c28046e87934073432af10dae75 100644 (file)
@@ -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;
+}
index a42daadb68d429b2cdda5bee6228cea327245e86..3a469b27e6e41f2ee9d6b40c8932232dd9510b1c 100644 (file)
@@ -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