From: fatbob313 Date: Sun, 3 Jan 2010 10:14:32 +0000 (+0000) Subject: More work toward 1.2.0: X-Git-Url: http://git.code-monkey.de/?p=umurmur.git;a=commitdiff_plain;h=820c23b9acd55999cc2e5777d5beeec8efd8970d More work toward 1.2.0: * PermissionQuery message handling * CodecVersion message handling * + other random updates --- diff --git a/src/client.c b/src/client.c index 79300ca..ceaacf6 100644 --- a/src/client.c +++ b/src/client.c @@ -53,8 +53,8 @@ static int clientcount; /* = 0 */ static int session = 1; static int maxBandwidth; -static int iCodecAlpha, iCodecBeta; -static bool_t bPreferAlpha; +int iCodecAlpha, iCodecBeta; +bool_t bPreferAlpha; extern int udpsock; @@ -152,9 +152,12 @@ void recheckCodecVersions() sendmsg = Msg_create(CodecVersion); sendmsg->payload.codecVersion->alpha = version; sendmsg->payload.codecVersion->beta = version; - sendmsg->payload.codecVersion->beta = bPreferAlpha; + sendmsg->payload.codecVersion->prefer_alpha = bPreferAlpha; Client_send_message_except(NULL, sendmsg); - + + Log_info("CELT codec switch 0x%x 0x%x (prefer 0x%x)", iCodecAlpha, iCodecBeta, + bPreferAlpha ? iCodecAlpha : iCodecBeta); + } int Client_add(int fd, struct sockaddr_in *remote) @@ -227,6 +230,8 @@ void Client_free(client_t *client) free(client->release); if (client->os) free(client->os); + if (client->playerName) + free(client->playerName); free(client); } diff --git a/src/client.h b/src/client.h index 358993e..ba2082f 100644 --- a/src/client.h +++ b/src/client.h @@ -69,8 +69,7 @@ typedef struct { uint32_t rxcount, msgsize, drainleft, txcount, txsize; int sessionId; uint64_t key; - char playerName[MAX_TEXT]; - int playerId; + char *playerName; bool_t authenticated, deaf, mute; char *os, *release; uint32_t version; diff --git a/src/main.c b/src/main.c index 8aa6c8d..5139291 100644 --- a/src/main.c +++ b/src/main.c @@ -45,8 +45,7 @@ #include "log.h" #include "client.h" #include "conf.h" - -#define UMURMUR_VERSION "0.1.3" +#include "version.h" void lockfile(const char *pidfile) { @@ -57,7 +56,7 @@ void lockfile(const char *pidfile) if (lfp < 0) Log_fatal("Cannot open PID-file %s for writing", pidfile); - sprintf(str,"%d\n",getpid()); + sprintf(str,"%d\n", getpid()); write(lfp, str, strlen(str)); /* record pid to lockfile */ Log_info("PID-file: %s", pidfile); } @@ -119,7 +118,7 @@ void setscheduler() void printhelp() { - printf("uMurmur version %s. Mumble protocol %d\n", UMURMUR_VERSION, MESSAGE_STREAM_VERSION); + printf("uMurmur version %s. Mumble protocol %d.%d.%d\n", UMURMUR_VERSION, PROTVER_MAJOR, PROTVER_MINOR, PROTVER_PATCH); printf("Usage: umurmurd [-d] [-p ] [-c ] [-h]\n"); printf(" -d - Do not deamonize\n"); printf(" -p - Write PID to this file\n"); diff --git a/src/messagehandler.c b/src/messagehandler.c index 7da04d1..d0c24e9 100644 --- a/src/messagehandler.c +++ b/src/messagehandler.c @@ -40,6 +40,8 @@ #include "conf.h" extern channel_t *defaultChan; +extern int iCodecAlpha, iCodecBeta; +extern bool_t bPreferAlpha; static void sendServerReject(client_t *client, const char *reason, MumbleProto__Reject__RejectType type) { @@ -89,7 +91,7 @@ void Mh_handle_message(client_t *client, message_t *msg) while (Client_iterate(&client_itr) != NULL) { if (!IS_AUTH(client_itr)) continue; - if (strncmp(client_itr->playerName, msg->payload.authenticate->username, MAX_TEXT) == 0) { + if (client_itr->playerName && strncmp(client_itr->playerName, msg->payload.authenticate->username, MAX_TEXT) == 0) { char buf[64]; sprintf(buf, "Username already in use"); Log_debug("Username already in use"); @@ -121,9 +123,7 @@ void Mh_handle_message(client_t *client, message_t *msg) } /* Name & password */ - strncpy(client->playerName, msg->payload.authenticate->username, MAX_TEXT); - client->playerId = client->sessionId; - + client->playerName = strdup(msg->payload.authenticate->username); /* Setup UDP encryption */ CryptState_init(&client->cryptState); @@ -147,18 +147,29 @@ void Mh_handle_message(client_t *client, message_t *msg) 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); 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++) + 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]); + } } else { client->codecs[0] = (int32_t)0x8000000a; client->codec_count = 1; } + recheckCodecVersions(); - + + sendmsg = Msg_create(CodecVersion); + sendmsg->payload.codecVersion->alpha = iCodecAlpha; + sendmsg->payload.codecVersion->beta = iCodecBeta; + sendmsg->payload.codecVersion->prefer_alpha = bPreferAlpha; + Client_send_message(client, sendmsg); + /* Iterate channels and send channel info */ ch_itr = NULL; Chan_iterate(&ch_itr); @@ -187,7 +198,7 @@ void Mh_handle_message(client_t *client, message_t *msg) 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->playerId; + sendmsg->payload.userState->user_id = client->sessionId; sendmsg->payload.userState->name = strdup(client->playerName); sendmsg->payload.userState->has_channel_id = true; sendmsg->payload.userState->channel_id = ((channel_t *)client->channel)->id; @@ -225,15 +236,13 @@ void Mh_handle_message(client_t *client, message_t *msg) sendmsg->payload.serverSync->has_max_bandwidth = true; sendmsg->payload.serverSync->max_bandwidth = getIntConf(MAX_BANDWIDTH); sendmsg->payload.serverSync->has_allow_html = true; - sendmsg->payload.serverSync->allow_html = false; /* Support this? */ + sendmsg->payload.serverSync->allow_html = true; /* Support this? */ Client_send_message(client, sendmsg); Log_info("User %s authenticated", client->playerName); break; case Ping: - { - uint64_t timestamp; if (msg->payload.ping->has_good) client->cryptState.uiRemoteGood = msg->payload.ping->good; if (msg->payload.ping->has_late) @@ -251,10 +260,9 @@ void Mh_handle_message(client_t *client, message_t *msg) /* Ignoring the double values since they don't seem to be used */ sendmsg = Msg_create(Ping); - timestamp = msg->payload.ping->timestamp; - sendmsg->payload.ping->timestamp = timestamp; - + sendmsg->payload.ping->timestamp = msg->payload.ping->timestamp; + sendmsg->payload.ping->has_timestamp = true; sendmsg->payload.ping->good = client->cryptState.uiGood; sendmsg->payload.ping->has_good = true; sendmsg->payload.ping->late = client->cryptState.uiLate; @@ -270,7 +278,6 @@ void Mh_handle_message(client_t *client, message_t *msg) client->cryptState.uiLost, client->cryptState.uiResync); break; - } case CryptSetup: Log_debug("Voice channel crypt resync requested"); if (!msg->payload.cryptSetup->has_client_nonce) { @@ -357,10 +364,11 @@ void Mh_handle_message(client_t *client, message_t *msg) while (Client_iterate(&itr) != NULL) { if (!IS_AUTH(itr)) continue; - if (itr->playerId == msg->payload.textMessage->session[i]) { + if (itr->sessionId == msg->payload.textMessage->session[i]) { if (!itr->deaf) { Msg_inc_ref(msg); Client_send_message(itr, msg); + Log_debug("Text message to session ID %d", itr->sessionId); } break; } @@ -392,10 +400,10 @@ void Mh_handle_message(client_t *client, message_t *msg) Log_debug("Client OS %s", client->os); } break; - case CodecVersion: + case PermissionQuery: Msg_inc_ref(msg); /* Re-use message */ - - /* XXX - fill in version */ + msg->payload.permissionQuery->has_permissions = true; + msg->payload.permissionQuery->permissions = PERM_DEFAULT; Client_send_message(client, msg); break; diff --git a/src/messages.c b/src/messages.c index 9cd4dc7..77a1a1d 100644 --- a/src/messages.c +++ b/src/messages.c @@ -196,6 +196,15 @@ int Msg_messageToNetwork(message_t *msg, uint8_t *buffer) Msg_addPreamble(buffer, msg->messageType, len); mumble_proto__codec_version__pack(msg->payload.codecVersion, bufptr); break; + case PermissionQuery: + len = mumble_proto__permission_query__get_packed_size(msg->payload.permissionQuery); + if (len > MAX_MSGSIZE) { + Log_warn("Too big tx message. Discarding"); + break; + } + Msg_addPreamble(buffer, msg->messageType, len); + mumble_proto__permission_query__pack(msg->payload.permissionQuery, bufptr); + break; default: Log_warn("Unsupported message %d", msg->messageType); @@ -276,6 +285,10 @@ message_t *Msg_create(messageType_t messageType) msg->payload.channelState = malloc(sizeof(MumbleProto__ChannelState)); mumble_proto__channel_state__init(msg->payload.channelState); break; + case PermissionQuery: + msg->payload.permissionQuery = malloc(sizeof(MumbleProto__PermissionQuery)); + mumble_proto__permission_query__init(msg->payload.permissionQuery); + break; default: Log_warn("Msg_create: Unsupported message %d", msg->messageType); @@ -413,6 +426,13 @@ void Msg_free(message_t *msg) free(msg->payload.channelState); } break; + case PermissionQuery: + if (msg->unpacked) + mumble_proto__permission_query__free_unpacked(msg->payload.permissionQuery, NULL); + else { + free(msg->payload.permissionQuery); + } + break; default: Log_warn("Msg_free: Unsupported message %d", msg->messageType); diff --git a/src/messages.h b/src/messages.h index 2e7d1a7..55a7433 100644 --- a/src/messages.h +++ b/src/messages.h @@ -36,8 +36,35 @@ #include "list.h" #include "types.h" -#define MAX_TEXT 256 -#define MESSAGE_STREAM_VERSION 4 +#define PROTVER_MAJOR 1 +#define PROTVER_MINOR 2 +#define PROTVER_PATCH 0 +#define PROTOCOL_VERSION (((PROTVER_MAJOR << 16) | (PROTVER_MINOR << 8) | PROTVER_PATCH)) + +#define MAX_TEXT 512 + + +#define PERM_NONE 0x0 +#define PERM_WRITE 0x1 +#define PERM_TRAVERSE 0x2 +#define PERM_ENTER 0x4 +#define PERM_SPEAK 0x8 +#define PERM_MUTEDEAFEN 0x10 +#define PERM_MOVE 0x20 +#define PERM_MAKECHANNEL 0x40 +#define PERM_LINKCHANNEL 0x80 +#define PERM_WHISPER 0x100 +#define PERM_TEXTMESSAGE 0x200 +#define PERM_MAKETEMPCHANNEL 0x400 +// Root channel only +#define PERM_KICK 0x10000 +#define PERM_BAN 0x20000 +#define PERM_REGISTER 0x40000 +#define PERM_SELFREGISTER 0x80000 +#define PERM_CACHED 0x8000000 +#define PERM_ALL 0xf07ff + +#define PERM_DEFAULT (PERM_TRAVERSE | PERM_ENTER | PERM_SPEAK | PERM_WHISPER | PERM_TEXTMESSAGE) typedef enum { Version, @@ -50,7 +77,7 @@ typedef enum { ChannelState, UserRemove, UserState, - BanList, + BanList, /* 10 */ TextMessage, PermissionDenied, ACL, @@ -60,7 +87,7 @@ typedef enum { ContextAction, UserList, VoiceTarget, - PermissionQuery, + PermissionQuery, /* 20 */ CodecVersion, } messageType_t; @@ -110,7 +137,6 @@ typedef struct message { } message_t; - int Msg_messageToNetwork(message_t *msg, uint8_t *buffer); message_t *Msg_networkToMessage(uint8_t *data, int size); void Msg_free(message_t *msg); diff --git a/src/server.c b/src/server.c index 7cabfb3..d719f37 100644 --- a/src/server.c +++ b/src/server.c @@ -109,6 +109,8 @@ void Server_run() Timer_init(&janitorTimer); + Log_info("uMurmur voicechat server started -- http://code.google.com/p/umurmur/"); + /* Main server loop */ while (!shutdown_server) { struct sockaddr_in remote; diff --git a/src/ssl.c b/src/ssl.c index 42f9610..09510c0 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -300,10 +300,10 @@ void SSL_init(void) sk_SSL_CIPHER_push(cipherlist_new, cipher); } } - Log_info("List of ciphers:"); + Log_debug("List of ciphers:"); if (cipherlist_new) { for ( i = 0; (cipher = sk_SSL_CIPHER_value(cipherlist_new, i)) != NULL; i++) { - Log_info("%s", SSL_CIPHER_get_name(cipher)); + Log_debug("%s", SSL_CIPHER_get_name(cipher)); offset += snprintf(cipherstring + offset, 1024 - offset, "%s:", SSL_CIPHER_get_name(cipher)); } cipherstring[offset - 1] = '\0'; diff --git a/src/version.h b/src/version.h new file mode 100644 index 0000000..e3dce30 --- /dev/null +++ b/src/version.h @@ -0,0 +1,7 @@ +#ifndef VERSION_H_989876 +#define VERSION_H_989876 + +#define UMURMUR_VERSION "1.2.0-beta1" + +#endif +