Some minor updates

This commit is contained in:
WolverinDEV 2021-07-23 14:59:44 +02:00
parent 1e7738bd24
commit b54c6d4e04
5 changed files with 53 additions and 51 deletions

View File

@ -51,8 +51,9 @@ command_result ConnectedClient::handleCommandClientGetVariables(Command &cmd) {
this->notifyClientUpdated(client.client, props, false);
}
if(client.client == this && this->getType() == ClientType::CLIENT_TEAMSPEAK)
this->subscribeChannel({this->currentChannel}, true, true); /* lets show the clients in the current channel because we've not done that while joining (speed improvement ;))*/
if(client.client == this && this->getType() == ClientType::CLIENT_TEAMSPEAK) {
this->subscribeChannel({this->currentChannel}, true, true); /* lets show the clients in the current channel because we've not done that while joining ("speed improvement" ;)) */
}
return command_result{error::ok};
}
@ -124,7 +125,7 @@ command_result ConnectedClient::handleCommandClientGetIds(Command &cmd) {
bool found = false;
auto client_list = this->server->getClients();
Command notify(this->getExternalType() == CLIENT_TEAMSPEAK ? "notifyclientids" : "");
Command notify(this->notify_response_command("notifyclientids"));
int result_index = 0;
for(int index = 0; index < cmd.bulkCount(); index++) {
@ -144,7 +145,6 @@ command_result ConnectedClient::handleCommandClientGetIds(Command &cmd) {
if(found) found = false;
else error = false;
}
string uid = cmd["cluid"];
if(result_index > 0) {
this->sendCommand(notify);
@ -1252,51 +1252,54 @@ command_result ConnectedClient::handleCommandClientInfo(Command &cmd) {
CMD_REQ_SERVER;
CMD_RESET_IDLE;
Command res(this->getExternalType() == ClientType::CLIENT_TEAMSPEAK ? "notifyclientinfo" : "");
bool trigger_error = false;
ts::command_result_bulk result{};
ts::command_builder notify{this->notify_response_command("notifyclientinfo")};
bool view_remote = permission::v2::permission_granted(1, this->calculate_permission(permission::b_client_remoteaddress_view, 0));
int result_index = 0;
for(int index = 0; index < cmd.bulkCount(); index++) {
for(int index{0}; index < cmd.bulkCount(); index++) {
auto client_id = cmd[index]["clid"].as<ClientId>();
if(client_id == 0) continue;
ConnectedLockedClient client{this->server->find_client_by_id(client_id)};
if(!client) {
trigger_error = true;
if(client_id == 0) {
result.emplace_result(error::client_invalid_id);
continue;
}
ConnectedLockedClient client{this->server->find_client_by_id(client_id)};
if(!client) {
result.emplace_result(error::client_invalid_id);
continue;
}
auto notify_bulk = notify.bulk(index);
for (const auto &key : client->properties()->list_properties(property::FLAG_CLIENT_VIEW | property::FLAG_CLIENT_VARIABLE | property::FLAG_CLIENT_INFO, this->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0)) {
res[result_index][std::string{key.type().name}] = key.value();
notify_bulk.put_unchecked(key.type().name, key.value());
}
res[result_index]["cid"] = client->getChannelId();
notify_bulk.put_unchecked("cid", client->getChannelId());
if(view_remote) {
res[result_index][property::CONNECTION_CLIENT_IP] = client->getPeerIp();
notify_bulk.put_unchecked(property::CONNECTION_CLIENT_IP, client->getPeerIp());
} else {
res[result_index][property::CONNECTION_CLIENT_IP] = "hidden";
notify_bulk.put_unchecked(property::CONNECTION_CLIENT_IP, "hidden");
}
res[result_index][property::CONNECTION_CONNECTED_TIME] = duration_cast<milliseconds>(system_clock::now() - client->connectTimestamp).count();
notify_bulk.put_unchecked(property::CONNECTION_CONNECTED_TIME, duration_cast<milliseconds>(system_clock::now() - client->connectTimestamp).count());
auto total_stats = this->getConnectionStatistics()->total_stats();
res["connection_packets_sent_total"] = std::accumulate(total_stats.connection_packets_sent.begin(), total_stats.connection_packets_sent.end(), (size_t) 0U);
res["connection_bytes_sent_total"] = std::accumulate(total_stats.connection_bytes_sent.begin(), total_stats.connection_bytes_sent.end(), (size_t) 0U);
res["connection_packets_received_total"] = std::accumulate(total_stats.connection_packets_received.begin(), total_stats.connection_packets_received.end(), (size_t) 0U);
res["connection_bytes_received_total"] = std::accumulate(total_stats.connection_bytes_received.begin(), total_stats.connection_bytes_received.end(), (size_t) 0U);
notify_bulk.put_unchecked(property::CONNECTION_PACKETS_SENT_TOTAL, std::accumulate(total_stats.connection_packets_sent.begin(), total_stats.connection_packets_sent.end(), (size_t) 0U));
notify_bulk.put_unchecked(property::CONNECTION_BYTES_SENT_TOTAL, std::accumulate(total_stats.connection_packets_sent.begin(), total_stats.connection_packets_sent.end(), (size_t) 0U));
notify_bulk.put_unchecked(property::CONNECTION_PACKETS_RECEIVED_TOTAL, std::accumulate(total_stats.connection_packets_received.begin(), total_stats.connection_packets_received.end(), (size_t) 0U));
notify_bulk.put_unchecked(property::CONNECTION_BYTES_RECEIVED_TOTAL, std::accumulate(total_stats.connection_bytes_received.begin(), total_stats.connection_bytes_received.end(), (size_t) 0U));
auto report_second = this->getConnectionStatistics()->second_stats();
auto report_minute = this->getConnectionStatistics()->minute_stats();
res["connection_bandwidth_sent_last_second_total"] = std::accumulate(report_second.connection_bytes_sent.begin(), report_second.connection_bytes_sent.end(), (size_t) 0U);
res["connection_bandwidth_sent_last_minute_total"] = std::accumulate(report_minute.connection_bytes_sent.begin(), report_minute.connection_bytes_sent.end(), (size_t) 0U);
res["connection_bandwidth_received_last_second_total"] = std::accumulate(report_second.connection_bytes_received.begin(), report_second.connection_bytes_received.end(), (size_t) 0U);
res["connection_bandwidth_received_last_minute_total"] = std::accumulate(report_minute.connection_bytes_received.begin(), report_minute.connection_bytes_received.end(), (size_t) 0U);
notify_bulk.put_unchecked(property::CONNECTION_BANDWIDTH_SENT_LAST_SECOND_TOTAL, std::accumulate(report_second.connection_bytes_sent.begin(), report_second.connection_bytes_sent.end(), (size_t) 0U));
notify_bulk.put_unchecked(property::CONNECTION_BANDWIDTH_SENT_LAST_MINUTE_TOTAL, std::accumulate(report_minute.connection_bytes_sent.begin(), report_minute.connection_bytes_sent.end(), (size_t) 0U));
notify_bulk.put_unchecked(property::CONNECTION_BANDWIDTH_RECEIVED_LAST_SECOND_TOTAL, std::accumulate(report_second.connection_bytes_received.begin(), report_second.connection_bytes_received.end(), (size_t) 0U));
notify_bulk.put_unchecked(property::CONNECTION_BANDWIDTH_RECEIVED_LAST_MINUTE_TOTAL, std::accumulate(report_minute.connection_bytes_received.begin(), report_minute.connection_bytes_received.end(), (size_t) 0U));
res["connection_filetransfer_bandwidth_sent"] = report_second.file_bytes_sent;
res["connection_filetransfer_bandwidth_received"] = report_second.file_bytes_received;
res["connection_filetransfer_bytes_sent_total"] = total_stats.file_bytes_sent;
res["connection_filetransfer_bytes_received_total"] = total_stats.file_bytes_received;
notify_bulk.put_unchecked(property::CONNECTION_FILETRANSFER_BANDWIDTH_SENT, report_second.file_bytes_sent);
notify_bulk.put_unchecked(property::CONNECTION_FILETRANSFER_BANDWIDTH_RECEIVED, report_second.file_bytes_received);
notify_bulk.put_unchecked(property::CONNECTION_FILETRANSFER_BYTES_SENT_TOTAL, total_stats.file_bytes_sent);
notify_bulk.put_unchecked(property::CONNECTION_FILETRANSFER_BYTES_RECEIVED_TOTAL, total_stats.file_bytes_received);
float server2client_packetloss{0};
float client2server_packetloss{0}; /* TODO: Parse from the client connect parameters? */
@ -1310,25 +1313,23 @@ command_result ConnectedClient::handleCommandClientInfo(Command &cmd) {
} catch(std::exception&) {}
}
res["connection_packetloss_total"] = (server2client_packetloss + client2server_packetloss) / 2;
res["connection_server2client_packetloss_total"] = server2client_packetloss;
res["connection_client2server_packetloss_total"] = client2server_packetloss;
notify_bulk.put_unchecked(property::CONNECTION_PACKETLOSS_TOTAL, (server2client_packetloss + client2server_packetloss) / 2);
notify_bulk.put_unchecked(property::CONNECTION_SERVER2CLIENT_PACKETLOSS_TOTAL, server2client_packetloss);
notify_bulk.put_unchecked(property::CONNECTION_CLIENT2SERVER_PACKETLOSS_TOTAL, client2server_packetloss);
/* TODO: Is this really right? It might be property::CONNECTION_IDLE_TIME. It might also be that CONNECTION_IDLE_TIME should be client_idle_time */
res[result_index]["client_idle_time"] = duration_cast<milliseconds>(system_clock::now() - client->idleTimestamp).count();
notify_bulk.put_unchecked("client_idle_time", duration_cast<milliseconds>(system_clock::now() - client->idleTimestamp).count());
result_index++;
result.emplace_result(error::ok);
}
if(result_index > 0) {
this->sendCommand(res);
this->sendCommand(notify);
}
if(trigger_error || result_index == 0)
return command_result{error::client_invalid_id};
else
return command_result{error::ok};
return ts::command_result{std::move(result)};
}
command_result ConnectedClient::handleCommandClientFind(Command &cmd) {

View File

@ -382,7 +382,7 @@ command_result ConnectedClient::handleCommandPermissionList(Command &cmd) {
auto type = this->getType();
if(type == CLIENT_TEASPEAK || type == CLIENT_TEAMSPEAK || type == CLIENT_QUERY) {
Command response(this->getExternalType() == CLIENT_TEAMSPEAK ? "notifypermissionlist" : "");
Command response{this->notify_response_command("notifypermissionlist")};
{
lock_guard lock(permission_list_string_lock);
if(permission_list_string[type].empty())
@ -391,7 +391,7 @@ command_result ConnectedClient::handleCommandPermissionList(Command &cmd) {
}
this->sendCommand(response);
} else {
this->sendCommand(build_permission_list(this->getExternalType() == CLIENT_TEAMSPEAK ? "notifypermissionlist" : "", type));
this->sendCommand(build_permission_list(this->notify_response_command("notifypermissionlist"), type));
}
return command_result{error::ok};
}
@ -411,7 +411,7 @@ do { \
} while(0)
command_result ConnectedClient::handleCommandPropertyList(ts::Command& cmd) {
Command response(this->getExternalType() == CLIENT_TEAMSPEAK ? "notifypropertylist" : "");
Command response(this->notify_response_command("notifypropertylist"));
{
string pattern;
@ -433,8 +433,6 @@ command_result ConnectedClient::handleCommandPropertyList(ts::Command& cmd) {
M(property::ClientProperties);
if(cmd.hasParm("all") || cmd.hasParm("instance"))
M(property::InstanceProperties);
if(cmd.hasParm("all") || cmd.hasParm("group"))
M(property::GroupProperties);
if(cmd.hasParm("all") || cmd.hasParm("connection"))
M(property::ConnectionProperties);
if(cmd.hasParm("all") || cmd.hasParm("playlist"))

View File

@ -58,8 +58,9 @@ else if(key == name) { \
command_result ConnectedClient::handleCommandServerEdit(Command &cmd) {
CMD_CHK_AND_INC_FLOOD_POINTS(5);
if (cmd[0].has("sid") && this->getServerId() != cmd["sid"].as<ServerId>())
if (cmd[0].has("sid") && this->getServerId() != cmd["sid"].as<ServerId>()) {
return command_result{error::server_invalid_id};
}
auto target_server = this->server;
if(cmd[0].has("sid")) {
@ -85,7 +86,7 @@ command_result ConnectedClient::handleCommandServerEdit(Command &cmd) {
return command_result{error::channel_protocol_limit_reached};
}
SERVEREDIT_CHK_PROP_CACHED("virtualserver_icon_id", permission::b_virtualserver_modify_icon_id, int64_t) }
SERVEREDIT_CHK_PROP_CACHED("virtualserver_channel_temp_delete_delay_default", permission::b_virtualserver_modify_channel_temp_delete_delay_default, ChannelId) }
SERVEREDIT_CHK_PROP_CACHED("virtualserver_channel_temp_delete_delay_default", permission::b_virtualserver_modify_channel_temp_delete_delay_default, uint32_t) }
SERVEREDIT_CHK_PROP_CACHED("virtualserver_codec_encryption_mode", permission::b_virtualserver_modify_codec_encryption_mode, int) }
SERVEREDIT_CHK_PROP_CACHED("virtualserver_default_server_group", permission::b_virtualserver_modify_default_servergroup, GroupId)
if(target_server) {
@ -161,7 +162,7 @@ command_result ConnectedClient::handleCommandServerEdit(Command &cmd) {
SERVEREDIT_CHK_PROP_CACHED("virtualserver_min_ios_version", permission::b_virtualserver_modify_min_client_version, uint64_t) }
SERVEREDIT_CHK_PROP_CACHED("virtualserver_music_bot_limit", permission::b_virtualserver_modify_music_bot_limit, int) }
SERVEREDIT_CHK_PROP_CACHED("virtualserver_music_bot_limit", permission::b_virtualserver_modify_music_bot_limit, uint64_t) }
SERVEREDIT_CHK_PROP_CACHED("virtualserver_flag_password", permission::b_virtualserver_modify_password, bool)
if (cmd["virtualserver_flag_password"].as<bool>() && !cmd[0].has("virtualserver_password"))
return command_result{error::parameter_invalid};

View File

@ -72,7 +72,7 @@ event* NetworkEventLoop::allocate_event(int fd, short events, event_callback_fn
EventLoop* event_loop{nullptr};
size_t try_count{0};
while(try_count++ < this->event_loops.size()) {
while(try_count < this->event_loops.size()) {
event_loop = this->event_loops[this->event_loop_index % this->event_loops.size()];
if(!use_list) {
@ -82,9 +82,11 @@ event* NetworkEventLoop::allocate_event(int fd, short events, event_callback_fn
auto& used_loops = (*use_list)->used_event_loops;
if(std::find(used_loops.begin(), used_loops.end(), event_loop->loop_id) == used_loops.end()) {
/* we haven't yet used that event loop */
/* we can use this event loop */
break;
}
try_count++;
}
if(try_count >= this->event_loops.size()) {

2
shared

@ -1 +1 @@
Subproject commit 9f03f33a23de2a69b2f464311838f5174f5d78ac
Subproject commit f1278941102e71b160f45f439da8c0a400d907d4