Starting attempt to implement the new rust time transfer server

This commit is contained in:
WolverinDEV
2021-04-21 13:19:46 +02:00
parent 45229e1e8e
commit f7039187b2
26 changed files with 898 additions and 40 deletions
+2
View File
@@ -21,9 +21,11 @@ bool FileServerHandler::initialize(std::string &error) {
}
#if 0
file::config::ssl_option_supplier = [&]{
return this->instance_->sslManager()->web_ssl_options();
};
#endif
auto server = file::server();
assert(server);
+1
View File
@@ -529,6 +529,7 @@ void VirtualServer::client_move(
if(auto client{dynamic_pointer_cast<VoiceClient>(target_client)}; client) {
/* Start normal broadcasting, what the client expects */
this->rtc_server().start_broadcast_audio(client->rtc_client_id, 1);
client->clear_video_unsupported_message_flag();
}
} else {
/* client left the server */
+1 -20
View File
@@ -400,26 +400,7 @@ bool VirtualServerManager::deleteServer(shared_ptr<VirtualServer> server) {
this->delete_server_in_db(server->serverId, false);
this->handle->databaseHelper()->handleServerDelete(server->serverId);
if(auto file_vs = file::server()->find_virtual_server(server->getServerId()); file_vs) {
using ErrorType = file::filesystem::ServerCommandErrorType;
auto delete_result = file::server()->file_system().delete_server(file_vs);
if(!delete_result->wait_for(std::chrono::seconds{5})) {
logError(LOG_INSTANCE, "Failed to wait for file directory initialisation.");
} else if(!delete_result->succeeded()) {
switch (delete_result->error().error_type) {
case ErrorType::FAILED_TO_DELETE_DIRECTORIES:
logError(LOG_INSTANCE, "Failed to delete server {} file directories ({}).", server->getServerId(), delete_result->error().error_message);
break;
case ErrorType::UNKNOWN:
case ErrorType::FAILED_TO_CREATE_DIRECTORIES:
logError(LOG_INSTANCE, "Failed to delete server {} file directory due to an unknown error: {}/{}",
server->getServerId(), (int) delete_result->error().error_type, delete_result->error().error_message);
break;
}
}
}
file::server()->unregister_server(server->getServerId(), true);
return true;
}
+2 -2
View File
@@ -756,7 +756,7 @@ command_result ConnectedClient::handleCommandFTInitUpload(ts::Command &cmd) {
result.put_unchecked(0, "ip", used_address.hostname);
result.put_unchecked(0, "port", used_address.port);
result.put_unchecked(0, "ftkey", std::string_view{transfer->transfer_key, TRANSFER_KEY_LENGTH});
result.put_unchecked(0, "ftkey", transfer->transfer_key);
result.put_unchecked(0, "seekpos", transfer->file_offset);
result.put_unchecked(0, "proto", "1");
this->sendCommand(result);
@@ -892,7 +892,7 @@ command_result ConnectedClient::handleCommandFTInitDownload(ts::Command &cmd) {
result.put_unchecked(0, "ip", used_address.hostname);
result.put_unchecked(0, "port", used_address.port);
result.put_unchecked(0, "ftkey", std::string_view{transfer->transfer_key, TRANSFER_KEY_LENGTH});
result.put_unchecked(0, "ftkey", transfer->transfer_key);
result.put_unchecked(0, "proto", "1");
result.put_unchecked(0, "size", transfer->expected_file_size);
+34
View File
@@ -463,3 +463,37 @@ void VoiceClient::processJoin() {
}
}
}
void VoiceClient::clear_video_unsupported_message_flag() {
this->video_unsupported_message_send = false;
}
constexpr static auto kUnsupportedMessage{"\n"
"[b]Somebody in your channel started video sharing!\n"
"[color=red]Your client doesn't support video sharing.[/color]\n"
"\n"
"Download the newest TeaSpeak client from [url]https://teaspeak.de[/url] or\n"
"use the TeaSpeakWeb client at [url]%web-url%[/url].[/b]"};
void VoiceClient::send_video_unsupported_message() {
if(this->video_unsupported_message_send) {
return;
}
this->video_unsupported_message_send = true;
ts::command_builder notify{"notifytextmessage"};
notify.put_unchecked(0, "targetmode", ChatMessageMode::TEXTMODE_CHANNEL);
notify.put_unchecked(0, "target", "0");
notify.put_unchecked(0, "invokerid", "0");
notify.put_unchecked(0, "invokername", "TeaSpeak - Video");
notify.put_unchecked(0, "invokeruid", "000000000000000000000000000");
std::string message{kUnsupportedMessage};
if(auto index{message.find("%web-url%")}; index != std::string::npos) {
/* TODO: generate connect url */
//this->server->getWebServer()->
message.replace(index, 9, "https://web.teaspeak.de");
}
notify.put_unchecked(0, "msg", message);
this->sendCommand(notify, false);
}
+4
View File
@@ -80,6 +80,9 @@ namespace ts {
[[nodiscard]] float current_packet_loss() const;
[[nodiscard]] const auto& server_command_queue() { return this->server_command_queue_; }
void send_video_unsupported_message();
void clear_video_unsupported_message_flag();
private:
connection::VoiceClientConnection* connection;
@@ -123,6 +126,7 @@ namespace ts {
std::unique_ptr<ServerCommandQueue> server_command_queue_{};
bool video_unsupported_message_send{false};
void finalDisconnect();
/* Used by close_connection to determine if we've successfully flushed the connection */
+10
View File
@@ -209,6 +209,16 @@ void librtc_callback_client_video_broadcast_info(const void* const* callback_dat
if(!client) { continue; }
client->sendCommand(notify);
if(client->getType() == ClientType::CLIENT_TEAMSPEAK) {
auto voice_client = std::dynamic_pointer_cast<VoiceClient>(client);
assert(voice_client);
if(broadcast_count > 0) {
voice_client->send_video_unsupported_message();
} else {
voice_client->clear_video_unsupported_message_flag();
}
}
}
}
+5
View File
@@ -236,3 +236,8 @@ void WebControlServer::unregisterConnection(const std::shared_ptr<WebClient>& co
this->clients.erase(index);
}
}
std::optional<std::string> WebControlServer::external_binding() {
/* FIXME: TODO! */
return std::nullopt;
}
+1
View File
@@ -35,6 +35,7 @@ namespace ts {
return this->clients;
}
[[nodiscard]] std::optional<std::string> external_binding();
private:
std::shared_ptr<VirtualServer> handle = nullptr;