X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fmessagehandler.c;h=4111d4980d0ba9b3dedccffab90d224cc77208c7;hb=797ef770d8ccc7e94dd7fef15d3659ef814baddd;hp=8d188652308c158f89862bf5ae53553c668f051d;hpb=a72efcd9b1c000c47bbe363f51c9123528e41d84;p=umurmur.git diff --git a/src/messagehandler.c b/src/messagehandler.c index 8d18865..4111d49 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; @@ -98,11 +104,14 @@ void Mh_handle_message(client_t *client, message_t *msg) } } if (strlen(getStrConf(PASSPHRASE)) > 0) { - if (!msg->payload.authenticate->password || strncmp(getStrConf(PASSPHRASE), msg->payload.authenticate->password, MAX_TEXT) != 0) { + if (!msg->payload.authenticate->password || + (msg->payload.authenticate->password && + strncmp(getStrConf(PASSPHRASE), msg->payload.authenticate->password, MAX_TEXT) != 0)) { char buf[64]; sprintf(buf, "Wrong server password"); sendServerReject(client, buf, MUMBLE_PROTO__REJECT__REJECT_TYPE__WrongServerPW); - Log_debug("Wrong server password: %s", msg->payload.authenticate->password); + Log_debug("Wrong server password: '%s'", msg->payload.authenticate->password != NULL ? + msg->payload.authenticate->password : "(null)"); goto disconnect; } } @@ -143,22 +152,22 @@ void Mh_handle_message(client_t *client, message_t *msg) /* Channel stuff */ Chan_userJoin(defaultChan, client); /* Join default channel */ - /* Codec version */ - if (msg->payload.authenticate->n_celt_versions > MAX_CODECS) - Log_warn("Client has more than %d CELT codecs. Ignoring %d codecs", - MAX_CODECS, msg->payload.authenticate->n_celt_versions - MAX_CODECS); - - Log_debug("Client %d has %d CELT codecs", client->sessionId, msg->payload.authenticate->n_celt_versions); + /* Codec version */ + Log_debug("Client %d has %d CELT codecs", client->sessionId, + msg->payload.authenticate->n_celt_versions); if (msg->payload.authenticate->n_celt_versions > 0) { int i; - client->codec_count = msg->payload.authenticate->n_celt_versions > MAX_CODECS ? - MAX_CODECS : msg->payload.authenticate->n_celt_versions; - for (i = 0; i < client->codec_count; i++) { - client->codecs[i] = msg->payload.authenticate->celt_versions[i]; - Log_debug("Client %d CELT codec ver 0x%x", client->sessionId, client->codecs[i]); - } + codec_t *codec_itr; + client->codec_count = msg->payload.authenticate->n_celt_versions; + + for (i = 0; i < client->codec_count; i++) + Client_codec_add(client, msg->payload.authenticate->celt_versions[i]); + codec_itr = NULL; + while (Client_codec_iterate(client, &codec_itr) != NULL) + Log_debug("Client %d CELT codec ver 0x%x", client->sessionId, codec_itr->codec); + } else { - client->codecs[0] = (int32_t)0x8000000a; + Client_codec_add(client, (int32_t)0x8000000a); client->codec_count = 1; } @@ -172,8 +181,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 +193,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 +330,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 +370,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 */ @@ -413,9 +449,12 @@ void Mh_handle_message(client_t *client, message_t *msg) for (j = 0; j < target->n_session; j++) Voicetarget_add_session(client, targetId, target->session[j]); if (target->has_channel_id) { - if (target->has_links || target->has_children) - Log_warn("Whisper to children or linked channels not implemented. Ignoring."); - Voicetarget_add_channel(client, targetId, target->channel_id); + bool_t linked = false, children = false; + if (target->has_links) + linked = target->links; + if (target->has_children) + children = target->children; + Voicetarget_add_channel(client, targetId, target->channel_id, linked, children); } } break; @@ -445,6 +484,7 @@ void Mh_handle_message(client_t *client, message_t *msg) Client_send_message(client, msg); break; case UDPTunnel: + client->bUDP = false; Client_voiceMsg(client, msg->payload.UDPTunnel->packet.data, msg->payload.UDPTunnel->packet.len); break; case ChannelState: