-/* Copyright (C) 2009-2010, Martin Johansson <martin@fatbob.nu>
- Copyright (C) 2005-2010, Thorvald Natvig <thorvald@natvig.com>
+/* Copyright (C) 2009-2011, Martin Johansson <martin@fatbob.nu>
+ Copyright (C) 2005-2011, Thorvald Natvig <thorvald@natvig.com>
All rights reserved.
#include "voicetarget.h"
#define MAX_TEXT 512
+#define MAX_USERNAME 128
extern channel_t *defaultChan;
extern int iCodecAlpha, iCodecBeta;
Client_send_message(client, msg);
}
+static void addTokens(client_t *client, message_t *msg)
+{
+ int i;
+ if (client->tokencount + msg->payload.authenticate->n_tokens < MAX_TOKENS) {
+ /* Check lengths first */
+ for (i = 0; i < msg->payload.authenticate->n_tokens; i++) {
+ if (strlen(msg->payload.authenticate->tokens[i]) > MAX_TOKENSIZE - 1) {
+ sendPermissionDenied(client, "Too long token");
+ return;
+ }
+ }
+
+ for (i = 0; i < msg->payload.authenticate->n_tokens; i++) {
+ Log_debug("Adding token '%s' to client '%s'", msg->payload.authenticate->tokens[i], client->username);
+ Client_token_add(client, msg->payload.authenticate->tokens[i]);
+ }
+ }
+ else
+ sendPermissionDenied(client, "Too many tokens");
+}
+
void Mh_handle_message(client_t *client, message_t *msg)
{
message_t *sendmsg = NULL;
Log_debug("Authenticate message received");
if (IS_AUTH(client) || !msg->payload.authenticate->username) {
- /* Authenticate message might be sent when a token is set by the user.*/
+ /* Authenticate message might be sent when a tokens are changed by the user.*/
+ Client_token_free(client); /* Clear the token list */
if (msg->payload.authenticate->n_tokens > 0) {
- Log_debug("Tokens in auth message from %s", client->username);
+ Log_debug("Tokens in auth message from '%s'. n_tokens = %d", client->username,
+ msg->payload.authenticate->n_tokens);
+ addTokens(client, msg);
}
break;
}
while (Client_iterate(&client_itr) != NULL) {
if (!IS_AUTH(client_itr))
continue;
- if (client_itr->username && strncmp(client_itr->username, msg->payload.authenticate->username, MAX_TEXT) == 0) {
+ if (client_itr->username && strncmp(client_itr->username, msg->payload.authenticate->username, MAX_USERNAME) == 0) {
char buf[64];
sprintf(buf, "Username already in use");
Log_debug("Username already in use");
}
}
if (strlen(msg->payload.authenticate->username) == 0 ||
- strlen(msg->payload.authenticate->username) >= MAX_TEXT) { /* XXX - other invalid names? */
+ strlen(msg->payload.authenticate->username) >= MAX_USERNAME) { /* XXX - other invalid names? */
char buf[64];
sprintf(buf, "Invalid username");
Log_debug("Invalid username");
if (Client_count() >= getIntConf(MAX_CLIENTS)) {
char buf[64];
- sprintf(buf, "Server is full (max %d users)", getIntConf(MAX_CLIENTS));
+ snprintf(buf, 64, "Server is full (max %d users)", getIntConf(MAX_CLIENTS));
sendServerReject(client, buf, MUMBLE_PROTO__REJECT__REJECT_TYPE__ServerFull);
goto disconnect;
}
- /* Name & password */
+ /* Name */
client->username = strdup(msg->payload.authenticate->username);
+
+ /* Tokens */
+ if (msg->payload.authenticate->n_tokens > 0)
+ addTokens(client, msg);
+
/* Setup UDP encryption */
CryptState_init(&client->cryptState);
sendmsg->payload.userState->name = strdup(client->username);
sendmsg->payload.userState->has_channel_id = true;
sendmsg->payload.userState->channel_id = ((channel_t *)client->channel)->id;
-
+
Client_send_message_except(client, sendmsg);
client_itr = NULL;
sendmsg->payload.userState->has_self_mute = true;
sendmsg->payload.userState->self_mute = true;
}
+ if (client_itr->recording) {
+ sendmsg->payload.userState->has_recording = true;
+ sendmsg->payload.userState->recording = true;
+ }
Client_send_message(client, sendmsg);
}
client->deaf = false;
}
}
+ if (msg->payload.userState->has_recording &&
+ msg->payload.userState->recording != client->recording) {
+ client->recording = msg->payload.userState->recording;
+ char *message;
+ uint32_t *tree_id;
+
+ message = malloc(strlen(client->username) + 32);
+ if (!message)
+ Log_fatal("Out of memory");
+ tree_id = malloc(sizeof(uint32_t));
+ if (!tree_id)
+ Log_fatal("Out of memory");
+ *tree_id = 0;
+ sendmsg = Msg_create(TextMessage);
+ sendmsg->payload.textMessage->message = message;
+ sendmsg->payload.textMessage->n_tree_id = 1;
+ sendmsg->payload.textMessage->tree_id = tree_id;
+ if (client->recording)
+ sprintf(message, "User %s started recording", client->username);
+ else
+ sprintf(message, "User %s stopped recording", client->username);
+ Client_send_message_except_ver(NULL, sendmsg, ~0x010203);
+ sendmsg = NULL;
+ }
if (msg->payload.userState->has_channel_id) {
int leave_id;
- if (!Chan_userJoin_id_test(msg->payload.userState->channel_id))
+ channelJoinResult_t chjoin_rc = Chan_userJoin_id_test(msg->payload.userState->channel_id, client);
+
+ if (chjoin_rc != CHJOIN_OK) {
+ if (chjoin_rc == CHJOIN_WRONGPW) {
+ sendPermissionDenied(client, "Wrong channel password");
+ }
break;
+ }
+
leave_id = Chan_userJoin_id(msg->payload.userState->channel_id, client);
if (leave_id > 0) {
Log_debug("Removing channel ID %d", leave_id);
break; /* Don't inform other users about this state */
}
-
/* Re-use message */
Msg_inc_ref(msg);