X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fmessagehandler.c;h=d20ccba1504cb08f598ced4eadd4299767cf1904;hb=c54d474786faff7a4ddf8a835600b26770a1630b;hp=98a9953b2996256e351a6619b534c38cff8b1d84;hpb=477a4a1b836a9693338dd2ef76782013f3fb0a16;p=umurmur.git diff --git a/src/messagehandler.c b/src/messagehandler.c index 98a9953..d20ccba 100644 --- a/src/messagehandler.c +++ b/src/messagehandler.c @@ -29,7 +29,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include -#include +#include #include "log.h" #include "list.h" @@ -79,9 +79,15 @@ void Mh_handle_message(client_t *client, message_t *msg) } switch (msg->messageType) { case Authenticate: - Log_debug("Authenticate message received"); - Log_debug("Username: %s", msg->payload.authenticate->username); + + if (IS_AUTH(client) || !msg->payload.authenticate->username) { + /* Authenticate message might be sent when a token is set by the user.*/ + if (msg->payload.authenticate->n_tokens > 0) { + Log_debug("Tokens in auth message from %s", client->username); + } + break; + } client->authenticated = true; @@ -172,8 +178,7 @@ void Mh_handle_message(client_t *client, message_t *msg) /* Iterate channels and send channel info */ ch_itr = NULL; - Chan_iterate(&ch_itr); - do { + while (Chan_iterate(&ch_itr) != NULL) { sendmsg = Msg_create(ChannelState); sendmsg->payload.channelState->has_channel_id = true; sendmsg->payload.channelState->channel_id = ch_itr->id; @@ -185,19 +190,37 @@ void Mh_handle_message(client_t *client, message_t *msg) if (ch_itr->desc) sendmsg->payload.channelState->description = strdup(ch_itr->desc); Log_debug("Send channel info: %s", sendmsg->payload.channelState->name); - Client_send_message(client, sendmsg); - - Chan_iterate(&ch_itr); - } while (ch_itr != NULL); + Client_send_message(client, sendmsg); + } - /* Not supporting channel links yet */ + /* Iterate channels and send channel links info */ + ch_itr = NULL; + while (Chan_iterate(&ch_itr) != NULL) { + if (ch_itr->linkcount > 0) { /* Has links */ + uint32_t *links; + int i = 0; + struct dlist *itr; + + sendmsg = Msg_create(ChannelState); + sendmsg->payload.channelState->has_channel_id = true; + sendmsg->payload.channelState->channel_id = ch_itr->id; + sendmsg->payload.channelState->n_links = ch_itr->linkcount; + + links = (uint32_t *)malloc(ch_itr->linkcount * sizeof(uint32_t)); + list_iterate(itr, &ch_itr->channel_links) { /* Iterate links */ + channel_t *ch; + ch = list_get_entry(itr, channel_t, link_node); + links[i++] = ch->id; + } + sendmsg->payload.channelState->links = links; + Client_send_message(client, sendmsg); + } + } /* Send user state for connecting user to other users */ sendmsg = Msg_create(UserState); sendmsg->payload.userState->has_session = true; sendmsg->payload.userState->session = client->sessionId; - sendmsg->payload.userState->has_user_id = true; - sendmsg->payload.userState->user_id = client->sessionId; sendmsg->payload.userState->name = strdup(client->username); sendmsg->payload.userState->has_channel_id = true; sendmsg->payload.userState->channel_id = ((channel_t *)client->channel)->id; @@ -304,11 +327,22 @@ void Mh_handle_message(client_t *client, message_t *msg) sendPermissionDenied(client, "Not supported by uMurmur"); break; } + + msg->payload.userState->has_session = true; + msg->payload.userState->session = client->sessionId; + msg->payload.userState->has_actor = true; + msg->payload.userState->actor = client->sessionId; + if (msg->payload.userState->has_self_deaf) { client->deaf = msg->payload.userState->self_deaf; } if (msg->payload.userState->has_self_mute) { - client->mute = msg->payload.userState->self_mute; + client->mute = msg->payload.userState->self_mute; + if (!client->mute) { + msg->payload.userState->has_self_deaf = true; + msg->payload.userState->self_deaf = false; + client->deaf = false; + } } if (msg->payload.userState->has_channel_id) { int leave_id; @@ -333,8 +367,7 @@ void Mh_handle_message(client_t *client, message_t *msg) /* Re-use message */ Msg_inc_ref(msg); - msg->payload.userState->has_actor = true; - msg->payload.userState->actor = client->sessionId; + Client_send_message_except(NULL, msg); /* Need to send remove channel message _after_ UserState message */