A lot of updates

This commit is contained in:
WolverinDEV
2019-08-20 13:46:23 +02:00
parent 7c490d2180
commit 787f911b6f
15 changed files with 95 additions and 33 deletions
@@ -364,6 +364,7 @@ CommandResult ConnectedClient::handleCommand(Command &cmd) {
else if (command == "dummy_ipchange") return this->handleCommandDummy_IpChange(cmd);
else if (command == "conversationhistory") return this->handleCommandConversationHistory(cmd);
else if (command == "conversationfetch") return this->handleCommandConversationFetch(cmd);
else if (command == "conversationmessagedelete") return this->handleCommandConversationMessageDelete(cmd);
if (this->getType() == ClientType::CLIENT_QUERY) return CommandResult::NotImplemented; //Dont log query invalid commands
if (this->getType() == ClientType::CLIENT_TEAMSPEAK)
@@ -699,9 +700,13 @@ CommandResult ConnectedClient::handleCommandServerRequestConnectionInfo(Command
notify[0]["connection_filetransfer_bandwidth_sent"] = report.file_send;
notify[0]["connection_filetransfer_bandwidth_received"] = report.file_recv;
notify[0]["connection_filetransfer_bytes_sent_total"] = (*statistics)[property::CONNECTION_FILETRANSFER_BYTES_SENT_TOTAL].as<string>();
notify[0]["connection_filetransfer_bytes_received_total"] = (*statistics)[property::CONNECTION_FILETRANSFER_BYTES_RECEIVED_TOTAL].as<string>();
notify[0]["connection_filetransfer_bytes_sent_month"] = this->server->properties()[property::VIRTUALSERVER_MONTH_BYTES_DOWNLOADED].as<string>();
notify[0]["connection_filetransfer_bytes_received_month"] = this->server->properties()[property::VIRTUALSERVER_MONTH_BYTES_UPLOADED].as<string>();
notify[0]["connection_packets_sent_total"] = (*statistics)[property::CONNECTION_PACKETS_SENT_TOTAL].as<string>();
notify[0]["connection_bytes_sent_total"] = (*statistics)[property::CONNECTION_BYTES_SENT_TOTAL].as<string>();
notify[0]["connection_packets_received_total"] = (*statistics)[property::CONNECTION_PACKETS_RECEIVED_TOTAL].as<string>();
@@ -3237,6 +3242,7 @@ CommandResult ConnectedClient::handleCommandSendTextMessage(Command &cmd) {
CMD_RESET_IDLE;
CMD_CHK_AND_INC_FLOOD_POINTS(5);
auto timestamp = system_clock::now();
if (cmd["targetmode"].as<ChatMessageMode>() == ChatMessageMode::TEXTMODE_PRIVATE) {
auto target = this->server->findClient(cmd["target"].as<ClientId>());
if (!target) return {findError("client_invalid_id"), "invalid target clid"};
@@ -3274,8 +3280,8 @@ CommandResult ConnectedClient::handleCommandSendTextMessage(Command &cmd) {
}
if(this->handleTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, cmd["msg"], target)) return CommandResult::Success;
target->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, _this.lock(), target->getClientId(), 0, cmd["msg"].string());
this->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, _this.lock(), target->getClientId(), 0, cmd["msg"].string());
target->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, _this.lock(), target->getClientId(), 0, timestamp, cmd["msg"].string());
this->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, _this.lock(), target->getClientId(), 0, timestamp, cmd["msg"].string());
} else if (cmd["targetmode"] == ChatMessageMode::TEXTMODE_CHANNEL) {
if(!cmd[0].has("cid"))
cmd["cid"] = 0;
@@ -3327,14 +3333,14 @@ CommandResult ConnectedClient::handleCommandSendTextMessage(Command &cmd) {
if(!client->calculate_and_get_join_state(channel))
continue;
}
client->notifyTextMessage(ChatMessageMode::TEXTMODE_CHANNEL, _this, client_id, channel_id, message);
client->notifyTextMessage(ChatMessageMode::TEXTMODE_CHANNEL, _this, client_id, channel_id, timestamp, message);
}
}
if(!conversation_private) {
auto conversations = this->server->conversation_manager();
auto conversation = conversations->get_or_create(channel->channelId());
conversation->register_message(this->getClientDatabaseId(), this->getUid(), this->getDisplayName(), cmd["msg"].string());
conversation->register_message(this->getClientDatabaseId(), this->getUid(), this->getDisplayName(), timestamp, cmd["msg"].string());
}
} else if (cmd["targetmode"] == ChatMessageMode::TEXTMODE_SERVER) {
CACHED_PERM_CHECK(permission::b_client_server_textmessage_send, 1);
@@ -3348,13 +3354,13 @@ CommandResult ConnectedClient::handleCommandSendTextMessage(Command &cmd) {
if (type == ClientType::CLIENT_INTERNAL || type == ClientType::CLIENT_MUSIC)
continue;
client->notifyTextMessage(ChatMessageMode::TEXTMODE_SERVER, _this.lock(), this->getClientId(), 0, cmd["msg"].string());
client->notifyTextMessage(ChatMessageMode::TEXTMODE_SERVER, _this.lock(), this->getClientId(), 0, timestamp, cmd["msg"].string());
}
{
auto conversations = this->server->conversation_manager();
auto conversation = conversations->get_or_create(0);
conversation->register_message(this->getClientDatabaseId(), this->getUid(), this->getDisplayName(), cmd["msg"].string());
conversation->register_message(this->getClientDatabaseId(), this->getUid(), this->getDisplayName(), timestamp, cmd["msg"].string());
}
} else return {findError("parameter_invalid"), "invalid target mode"};
@@ -4682,7 +4688,7 @@ CommandResult ConnectedClient::handleCommandClientMute(Command &cmd) {
}
if (config::voice::notifyMuted)
client->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, _this.lock(), client->getClientId(), 0, config::messages::mute_notify_message);
client->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, _this.lock(), client->getClientId(), 0, system_clock::now(), config::messages::mute_notify_message);
return CommandResult::Success;
}
@@ -4703,7 +4709,7 @@ CommandResult ConnectedClient::handleCommandClientUnmute(Command &cmd) {
}
if (config::voice::notifyMuted)
client->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, _this.lock(), client->getClientId(), 0, config::messages::unmute_notify_message);
client->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, _this.lock(), client->getClientId(), 0, system_clock::now(), config::messages::unmute_notify_message);
return CommandResult::Success;
}
@@ -7611,7 +7617,6 @@ CommandResult ConnectedClient::handleCommandConversationFetch(ts::Command &cmd)
return CommandResult::Success;
}
CommandResult ConnectedClient::handleCommandConversationMessageDelete(ts::Command &cmd) {
CMD_REF_SERVER(ref_server);
CMD_CHK_AND_INC_FLOOD_POINTS(25);
@@ -7667,13 +7672,22 @@ CommandResult ConnectedClient::handleCommandConversationMessageDelete(ts::Comman
if(!current_conversation) continue;
auto timestamp_begin = system_clock::time_point{} + milliseconds{bulk["timestamp_begin"]};
auto timestamp_end = system_clock::time_point{} + milliseconds{bulk.has("timestamp_begin") ? bulk["timestamp_begin"].as<uint64_t>() : 0};
auto timestamp_end = system_clock::time_point{} + milliseconds{bulk.has("timestamp_end") ? bulk["timestamp_end"].as<uint64_t>() : 0};
auto limit = bulk.has("limit") ? bulk["limit"].as<uint64_t>() : 1;
if(limit > 100)
limit = 100;
auto delete_count = current_conversation->delete_messages(timestamp_begin, limit, timestamp_end, bulk["cldbid"]);
auto delete_count = current_conversation->delete_messages(timestamp_end, limit, timestamp_begin, bulk["cldbid"]);
if(delete_count > 0) {
//TODO: Notify
for(const auto& client : ref_server->getClients()) {
if(client->connectionState() != ConnectionState::CONNECTED)
continue;
auto type = client->getType();
if(type == ClientType::CLIENT_INTERNAL || type == ClientType::CLIENT_MUSIC)
continue;
client->notifyConversationMessageDelete(current_conversation_id, timestamp_begin, timestamp_end, bulk["cldbid"], delete_count);
}
}
}