X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fchannel.c;h=26e21b913511f05f409f79e6e1eeae7e26615fd6;hb=60aae12f64796bca7e8aed516f2b294120245957;hp=3524a966f9c958dfe52ca70eefc296596c0172ed;hpb=14a67bc74c81651015bbbad075f7eb1c41218cf7;p=umurmur.git diff --git a/src/channel.c b/src/channel.c index 3524a96..26e21b9 100644 --- a/src/channel.c +++ b/src/channel.c @@ -1,5 +1,5 @@ -/* Copyright (C) 2009-2010, Martin Johansson - Copyright (C) 2005-2010, Thorvald Natvig +/* Copyright (C) 2009-2011, Martin Johansson + Copyright (C) 2005-2011, Thorvald Natvig All rights reserved. @@ -161,9 +161,12 @@ void Chan_init() channel_t *ch, *ch_itr = NULL; ch = Chan_createChannel(chdesc.name, chdesc.description); ch->noenter = chdesc.noenter; - + if (chdesc.password) { + Log_info("Setting password on channel '%s'", ch->name); + ch->password = strdup(chdesc.password); + } if (strcmp(defaultChannelName, chdesc.name) == 0) { - Log_info("Setting default channel %s", ch->name); + Log_info("Setting default channel '%s'", ch->name); defaultChan = ch; } @@ -172,7 +175,7 @@ void Chan_init() } while (ch_itr != NULL && strcmp(ch_itr->name, chdesc.parent) != 0); if (ch_itr == NULL) - Log_fatal("Error in channel configuration: parent not found"); + Log_fatal("Error in channel configuration: parent '%s' not found", chdesc.parent); else { Chan_addChannel(ch_itr, ch); Log_info("Adding channel '%s' parent '%s'", ch->name, chdesc.parent); @@ -184,6 +187,8 @@ void Chan_init() if (defaultChan->noenter) Log_fatal("Error in channel configuration: default channel is marked as noenter"); + if (defaultChan->password) + Log_fatal("Error in channel configuration: default channel has a password"); /* Channel links */ for (i = 0; ; i++) { @@ -230,6 +235,8 @@ void Chan_free() free(ch->name); if (ch->desc) free(ch->desc); + if (ch->password) + free(ch->password); free(ch); } } @@ -276,9 +283,12 @@ int Chan_userLeave(client_t *client) int Chan_userJoin(channel_t *ch, client_t *client) { int leaving_id; + + /* 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_userLeave(client); list_add_tail(&client->chan_node, &ch->clients); @@ -300,7 +310,7 @@ int Chan_userJoin_id(int channelid, client_t *client) return Chan_userJoin(ch_itr, client); } -bool_t Chan_userJoin_id_test(int channelid) +channelJoinResult_t Chan_userJoin_id_test(int channelid, client_t *client) { channel_t *ch_itr = NULL; do { @@ -308,12 +318,13 @@ bool_t Chan_userJoin_id_test(int channelid) } while (ch_itr != NULL && ch_itr->id != channelid); if (ch_itr == NULL) { Log_warn("Channel id %d not found - ignoring.", channelid); - return false; + return CHJOIN_NOTFOUND; } - if (ch_itr->noenter) - return false; - else - return true; + else if (ch_itr->noenter) + return CHJOIN_NOENTER; + else if (ch_itr->password && !Client_token_match(client, ch_itr->password)) + return CHJOIN_WRONGPW; + else return CHJOIN_OK; } #if 0