+ case ChannelState:
+ {
+ channel_t *ch_itr, *parent, *newchan;
+ int leave_id;
+ /* Don't allow any changes to existing channels */
+ if (msg->payload.channelState->has_channel_id) {
+ sendPermissionDenied(client, "Not supported by uMurmur");
+ break;
+ }
+ /* Must have parent */
+ if (!msg->payload.channelState->has_parent) {
+ sendPermissionDenied(client, "Not supported by uMurmur");
+ break;
+ }
+ /* Must have name */
+ if (msg->payload.channelState->name == NULL) {
+ sendPermissionDenied(client, "Not supported by uMurmur");
+ break;
+ }
+ /* Must be temporary channel */
+ if (msg->payload.channelState->temporary != true) {
+ sendPermissionDenied(client, "Only temporary channels are supported by uMurmur");
+ break;
+ }
+ /* Check channel name is OK */
+ if (strlen(msg->payload.channelState->name) > MAX_TEXT) {
+ sendPermissionDenied(client, "Channel name too long");
+ break;
+ }
+
+ parent = Chan_fromId(msg->payload.channelState->parent);
+ if (parent == NULL)
+ break;
+ ch_itr = NULL;
+ while (Chan_iterate_siblings(parent, &ch_itr) != NULL) {
+ if (strcmp(ch_itr->name, msg->payload.channelState->name) == 0) {
+ sendPermissionDenied(client, "Channel already exists");
+ break;
+ }
+ }
+ if (ch_itr != NULL)
+ break;
+
+ /* Disallow temporary channels as siblings to temporary channels */
+ if (parent->temporary) {
+ sendPermissionDenied(client, "Parent channel is temporary channel");
+ break;
+ }
+
+ /* XXX - Murmur looks for "\\w" and sends perm denied if not found.
+ * I don't know why so I don't do that here...
+ */
+
+ /* Create the channel */
+ newchan = Chan_createChannel(msg->payload.channelState->name,
+ msg->payload.channelState->description);
+ newchan->temporary = true;
+ if (msg->payload.channelState->has_position)
+ newchan->position = msg->payload.channelState->position;
+ Chan_addChannel(parent, newchan);
+ msg->payload.channelState->has_channel_id = true;
+ msg->payload.channelState->channel_id = newchan->id;
+ Msg_inc_ref(msg);
+ Client_send_message_except(NULL, msg);
+
+ /* Join the creating user */
+ sendmsg = Msg_create(UserState);
+ sendmsg->payload.userState->has_session = true;
+ sendmsg->payload.userState->session = client->sessionId;
+ sendmsg->payload.userState->has_channel_id = true;
+ sendmsg->payload.userState->channel_id = newchan->id;
+
+ if (client->isSuppressed) {
+ sendmsg->payload.userState->has_suppress = true;
+ sendmsg->payload.userState->suppress = false;
+ client->isSuppressed = false;
+ }
+
+ Client_send_message_except(NULL, sendmsg);
+
+ leave_id = Chan_userJoin(newchan, client);
+ if (leave_id > 0) {
+ Log_debug("Removing channel ID %d", leave_id);
+ sendmsg = Msg_create(ChannelRemove);
+ sendmsg->payload.channelRemove->channel_id = leave_id;
+ Client_send_message_except(NULL, sendmsg);
+ }
+ }
+ break;
+
+ case UserStats:
+ {
+ client_t *target = NULL;
+ codec_t *codec_itr = NULL;
+ int i;
+ bool_t details = true;
+
+ if (msg->payload.userStats->has_stats_only)
+ details = !msg->payload.userStats->stats_only;
+
+ if (!msg->payload.userStats->has_session)
+ sendPermissionDenied(client, "Not supported by uMurmur");
+ while (Client_iterate(&target) != NULL) {
+ if (!IS_AUTH(target))
+ continue;
+ if (target->sessionId == msg->payload.userStats->session)
+ break;
+ }
+ if (!target) /* Not found */
+ break;
+
+ /*
+ * Differences from Murmur:
+ * o Ignoring certificates intentionally
+ * o Ignoring channel local determining
+ */
+
+ sendmsg = Msg_create(UserStats);
+ sendmsg->payload.userStats->session = msg->payload.userStats->session;
+ sendmsg->payload.userStats->from_client->has_good = true;
+ sendmsg->payload.userStats->from_client->good = target->cryptState.uiGood;
+ sendmsg->payload.userStats->from_client->has_late = true;
+ sendmsg->payload.userStats->from_client->late = target->cryptState.uiLate;
+ sendmsg->payload.userStats->from_client->has_lost = true;
+ sendmsg->payload.userStats->from_client->lost = target->cryptState.uiLost;
+ sendmsg->payload.userStats->from_client->has_resync = true;
+ sendmsg->payload.userStats->from_client->resync = target->cryptState.uiResync;
+
+ sendmsg->payload.userStats->from_server->has_good = true;
+ sendmsg->payload.userStats->from_server->good = target->cryptState.uiRemoteGood;
+ sendmsg->payload.userStats->from_server->has_late = true;
+ sendmsg->payload.userStats->from_server->late = target->cryptState.uiRemoteLate;
+ sendmsg->payload.userStats->from_server->has_lost = true;
+ sendmsg->payload.userStats->from_server->lost = target->cryptState.uiRemoteLost;
+ sendmsg->payload.userStats->from_server->has_resync = true;
+ sendmsg->payload.userStats->from_server->resync = target->cryptState.uiRemoteResync;
+
+ sendmsg->payload.userStats->has_udp_packets = true;
+ sendmsg->payload.userStats->udp_packets = target->UDPPackets;
+ sendmsg->payload.userStats->has_udp_ping_avg = true;
+ sendmsg->payload.userStats->udp_ping_avg = target->UDPPingAvg;
+ sendmsg->payload.userStats->has_udp_ping_var = true;
+ sendmsg->payload.userStats->udp_ping_var = target->UDPPingVar;
+
+ sendmsg->payload.userStats->has_tcp_ping_avg = true;
+ sendmsg->payload.userStats->tcp_ping_avg = target->TCPPingAvg;
+ sendmsg->payload.userStats->has_tcp_ping_var = true;
+ sendmsg->payload.userStats->tcp_ping_var = target->TCPPingVar;
+ sendmsg->payload.userStats->has_tcp_packets = true;
+ sendmsg->payload.userStats->tcp_packets = target->TCPPackets;
+
+ if (details) {
+
+ sendmsg->payload.userStats->version->has_version = true;
+ sendmsg->payload.userStats->version->version = target->version;
+ if (target->release)
+ sendmsg->payload.userStats->version->release = strdup(target->release);
+ if (target->os)
+ sendmsg->payload.userStats->version->os = strdup(target->os);
+ if (target->os_version)
+ sendmsg->payload.userStats->version->os_version = strdup(target->os_version);
+
+ sendmsg->payload.userStats->n_celt_versions = target->codec_count;
+ sendmsg->payload.userStats->celt_versions = malloc(sizeof(int32_t) * target->codec_count);
+ if (!sendmsg->payload.userStats->celt_versions)
+ Log_fatal("Out of memory");
+ i = 0;
+ while (Client_codec_iterate(target, &codec_itr) != NULL)
+ sendmsg->payload.userStats->celt_versions[i++] = codec_itr->codec;
+
+ sendmsg->payload.userStats->has_opus = true;
+ sendmsg->payload.userStats->opus = target->bOpus;
+
+ /* Address */
+ sendmsg->payload.userStats->has_address = true;
+ sendmsg->payload.userStats->address.data = malloc(sizeof(uint8_t) * 16);
+ if (!sendmsg->payload.userStats->address.data)
+ Log_fatal("Out of memory");
+ memset(sendmsg->payload.userStats->address.data, 0, 16);
+ /* ipv4 representation as ipv6 address. Supposedly correct. */
+ memset(&sendmsg->payload.userStats->address.data[10], 0xff, 2); /* IPv4 */
+ if(target->remote_tcp.ss_family == AF_INET)
+ memcpy(&sendmsg->payload.userStats->address.data[12], &((struct sockaddr_in*)&target->remote_tcp)->sin_addr, 4);
+ else
+ memcpy(&sendmsg->payload.userStats->address.data[0], &((struct sockaddr_in6*)&target->remote_tcp)->sin6_addr, 16);
+ sendmsg->payload.userStats->address.len = 16;
+ }
+ /* BW */
+ sendmsg->payload.userStats->has_bandwidth = true;
+ sendmsg->payload.userStats->bandwidth = target->availableBandwidth;
+
+ /* Onlinesecs */
+ sendmsg->payload.userStats->has_onlinesecs = true;
+ sendmsg->payload.userStats->onlinesecs = Timer_elapsed(&target->connectTime) / 1000000LL;
+ /* Idlesecs */
+ sendmsg->payload.userStats->has_idlesecs = true;
+ sendmsg->payload.userStats->idlesecs = Timer_elapsed(&target->idleTime) / 1000000LL;
+ Client_send_message(client, sendmsg);
+ }
+ break;
+ case UserRemove:
+ target = NULL;
+ /* Only admin can issue this */
+ if (!client->isAdmin) {
+ sendPermissionDenied(client, "Permission denied");
+ break;
+ }
+ while (Client_iterate(&target) != NULL) {
+ if (target->sessionId == msg->payload.userRemove->session)
+ break;
+ }
+ if (target == NULL) {
+ Log_warn("Client with sessionId %d not found", msg->payload.userRemove->session);
+ break;
+ }
+ msg->payload.userRemove->session = target->sessionId;
+ msg->payload.userRemove->has_actor = true;
+ msg->payload.userRemove->actor = client->sessionId;
+
+ if (msg->payload.userRemove->has_ban && msg->payload.userRemove->ban) {
+ if (!getBoolConf(ENABLE_BAN))
+ sendPermissionDenied(client, "Permission denied");
+ else
+ Ban_UserBan(target, msg->payload.userRemove->reason);
+ } else {
+ Log_info_client(target, "User kicked. Reason: '%s'",
+ strlen(msg->payload.userRemove->reason) == 0 ? "N/A" : msg->payload.userRemove->reason);
+ }
+ /* Re-use message */
+ Msg_inc_ref(msg);
+
+ Client_send_message_except(NULL, msg);
+ Client_close(target);
+ break;
+ case BanList:
+ /* Only admin can issue this */
+ if (!client->isAdmin) {
+ sendPermissionDenied(client, "Permission denied");
+ break;
+ }
+ if (!getBoolConf(ENABLE_BAN)) {
+ sendPermissionDenied(client, "Permission denied");
+ break;
+ }
+ if (msg->payload.banList->has_query && msg->payload.banList->query) {
+ /* Create banlist message and add banentrys */
+ sendmsg = Ban_getBanList();
+ Client_send_message(client, sendmsg);
+ } else {
+ /* Clear banlist and set the new one */
+ Ban_clearBanList();
+ Ban_putBanList(msg, msg->payload.banList->n_bans);
+ }
+ break;
+