+ }
+ 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);
+ }