X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fchannel.c;h=77ee4157dfe3fba941e29a76a6561c2d5b8e55b8;hb=454ad122eb158b4391e2690fe6a7e127d24c525b;hp=c308dc4d403959ab02ce68bc22ce05c2d8573ba3;hpb=db60a2942eed420d693edea15e1db982184ff03d;p=umurmur.git diff --git a/src/channel.c b/src/channel.c index c308dc4..77ee415 100644 --- a/src/channel.c +++ b/src/channel.c @@ -29,6 +29,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include +#include +#include #include "log.h" #include "list.h" #include "client.h" @@ -212,6 +214,7 @@ void Chan_init() ch_dst = ch_itr; list_add_tail(&ch_dst->link_node, &ch_src->channel_links); + ch_src->linkcount++; Log_info("Adding channel link '%s' -> '%s'", ch_src->name, ch_dst->name); } } @@ -254,7 +257,7 @@ void Chan_addChannel(channel_t *parent, channel_t *ch) } -int Chan_playerLeave(client_t *client) +int Chan_userLeave(client_t *client) { channel_t *leaving = NULL; int leaving_id = -1; @@ -270,20 +273,23 @@ int Chan_playerLeave(client_t *client) return leaving_id; } -int Chan_playerJoin(channel_t *ch, client_t *client) +int Chan_userJoin(channel_t *ch, client_t *client) { int leaving_id; - - Log_debug("Add player %s to channel %s", client->playerName, ch->name); + /* Do nothing if user already is in this channel */ + if ((channel_t *)client->channel == ch) + return 0; + + Log_debug("Add user %s to channel %s", client->username, ch->name); /* Only allowed in one channel at a time */ - leaving_id = Chan_playerLeave(client); + leaving_id = Chan_userLeave(client); list_add_tail(&client->chan_node, &ch->clients); client->channel = (void *)ch; return leaving_id; } -int Chan_playerJoin_id(int channelid, client_t *client) +int Chan_userJoin_id(int channelid, client_t *client) { channel_t *ch_itr = NULL; do { @@ -294,10 +300,10 @@ int Chan_playerJoin_id(int channelid, client_t *client) return -1; } else - return Chan_playerJoin(ch_itr, client); + return Chan_userJoin(ch_itr, client); } -bool_t Chan_playerJoin_id_test(int channelid) +bool_t Chan_userJoin_id_test(int channelid) { channel_t *ch_itr = NULL; do { @@ -342,3 +348,28 @@ void Chan_removeChannel(channel_t *ch) { list_del(&ch->node); } + +void Chan_buildTreeList(channel_t *ch, struct dlist *head) +{ + channellist_t *chl; + struct dlist *itr; + channel_t *sub; + + chl = malloc(sizeof(channellist_t)); + chl->chan = ch; + init_list_entry(&chl->node); + list_add_tail(&chl->node, head); + + list_iterate(itr, &ch->subs) { + sub = list_get_entry(itr, channel_t, node); + Chan_buildTreeList(sub, head); + } +} + +void Chan_freeTreeList(struct dlist *head) +{ + struct dlist *itr, *save; + list_iterate_safe(itr, save, head) { + free(list_get_entry(itr, channellist_t, node)); + } +}