Fixed some bugs
This commit is contained in:
parent
0d456eea5d
commit
e81e21f00e
@ -15,6 +15,7 @@
|
||||
#include "./client/voice/VoiceClient.h"
|
||||
#include "./client/InternalClient.h"
|
||||
#include "./client/music/MusicClient.h"
|
||||
#include "./client/query/QueryClient.h"
|
||||
#include "music/MusicBotManager.h"
|
||||
#include "server/VoiceServer.h"
|
||||
#include "server/file/FileServer.h"
|
||||
@ -318,12 +319,12 @@ bool VirtualServer::start(std::string& error) {
|
||||
|
||||
if(host.empty()){
|
||||
error = "invalid host (\"" + host + "\")";
|
||||
this->stop("failed to start");
|
||||
this->stop("failed to start", true);
|
||||
return false;
|
||||
}
|
||||
if(this->properties()[property::VIRTUALSERVER_PORT].as<uint16_t>() <= 0){
|
||||
error = "invalid port";
|
||||
this->stop("failed to start");
|
||||
this->stop("failed to start", true);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -360,7 +361,7 @@ bool VirtualServer::start(std::string& error) {
|
||||
}
|
||||
if(bindings.empty()) {
|
||||
error = "failed to resole any host!";
|
||||
this->stop("failed to start");
|
||||
this->stop("failed to start", false);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -368,7 +369,7 @@ bool VirtualServer::start(std::string& error) {
|
||||
udpVoiceServer = make_shared<VoiceServer>(self.lock());
|
||||
if(!udpVoiceServer->start(bindings, error)) {
|
||||
error = "could not start voice server. Message: " + error;
|
||||
this->stop("failed to start");
|
||||
this->stop("failed to start", false);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -405,7 +406,7 @@ bool VirtualServer::start(std::string& error) {
|
||||
logMessage(this->serverId, "[Web] Starting server on {}:{}", web_host_string, web_port);
|
||||
if(!webControlServer->start(bindings, error)) {
|
||||
error = "could not start web server. Message: " + error;
|
||||
this->stop("failed to start");
|
||||
this->stop("failed to start", false);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
@ -466,7 +467,7 @@ void VirtualServer::preStop(const std::string& reason) {
|
||||
}
|
||||
}
|
||||
|
||||
void VirtualServer::stop(const std::string& reason) {
|
||||
void VirtualServer::stop(const std::string& reason, bool disconnect_query) {
|
||||
auto self_lock = this->self.lock();
|
||||
assert(self_lock);
|
||||
{
|
||||
@ -484,9 +485,10 @@ void VirtualServer::stop(const std::string& reason) {
|
||||
threads::MutexLock lock(cl->command_lock);
|
||||
cl->currentChannel = nullptr;
|
||||
|
||||
continue; //We dont need to disconnect the query
|
||||
cl->server = nullptr;
|
||||
cl->loadDataForCurrentServer();
|
||||
if(disconnect_query) {
|
||||
auto qc = dynamic_pointer_cast<QueryClient>(cl);
|
||||
qc->disconnect_from_virtual_server();
|
||||
}
|
||||
} else if(cl->getType() == CLIENT_MUSIC) {
|
||||
cl->disconnect("");
|
||||
cl->currentChannel = nullptr;
|
||||
|
@ -144,7 +144,7 @@ namespace ts {
|
||||
bool start(std::string& error);
|
||||
bool running();
|
||||
void preStop(const std::string&);
|
||||
void stop(const std::string& reason = ts::config::messages::serverStopped);
|
||||
void stop(const std::string& reason, bool /* disconnect query */);
|
||||
|
||||
size_t onlineClients();
|
||||
OnlineClientReport onlineStats();
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <log/LogUtils.h>
|
||||
#include "VirtualServerManager.h"
|
||||
#include "src/server/VoiceServer.h"
|
||||
#include "src/client/query/QueryClient.h"
|
||||
#include "InstanceHandler.h"
|
||||
#include "src/server/file/FileServer.h"
|
||||
#include "src/client/ConnectedClient.h"
|
||||
@ -361,7 +362,21 @@ bool VirtualServerManager::deleteServer(shared_ptr<VirtualServer> server) {
|
||||
this->adjust_executor_threads();
|
||||
|
||||
if(server->getState() != ServerState::OFFLINE)
|
||||
server->stop("server deleted");
|
||||
server->stop("server deleted", true);
|
||||
for(const auto& cl : server->getClients()) { //start disconnecting
|
||||
if(cl->getType() == CLIENT_TEAMSPEAK || cl->getType() == CLIENT_TEASPEAK || cl->getType() == CLIENT_WEB) {
|
||||
cl->close_connection(chrono::system_clock::now());
|
||||
} else if(cl->getType() == CLIENT_QUERY){
|
||||
auto qc = dynamic_pointer_cast<QueryClient>(cl);
|
||||
qc->disconnect_from_virtual_server();
|
||||
} else if(cl->getType() == CLIENT_MUSIC) {
|
||||
cl->disconnect("");
|
||||
cl->currentChannel = nullptr;
|
||||
} else if(cl->getType() == CLIENT_INTERNAL) {
|
||||
|
||||
} else {
|
||||
}
|
||||
}
|
||||
{
|
||||
for(const shared_ptr<ConnectedClient>& client : server->getClients()) {
|
||||
if(client && client->getType() == ClientType::CLIENT_QUERY) {
|
||||
@ -419,7 +434,7 @@ void VirtualServerManager::shutdownAll(const std::string& msg) {
|
||||
for(const auto &server : this->serverInstances())
|
||||
server->preStop(msg);
|
||||
for(const auto &server : this->serverInstances()){
|
||||
if(server->running()) server->stop(msg);
|
||||
if(server->running()) server->stop(msg, true);
|
||||
}
|
||||
|
||||
this->execute_loop->shutdown();
|
||||
|
@ -956,8 +956,29 @@ command_result ConnectedClient::handleCommandMusicBotQueueList(Command& cmd) {
|
||||
if(!bulked)
|
||||
notify = Command(this->notify_response_command("notifymusicqueueentry"));
|
||||
|
||||
//TODO!
|
||||
//apply_song(notify, *it, command_index);
|
||||
auto song = *it;
|
||||
notify[command_index]["song_id"] = song->id;
|
||||
notify[command_index]["song_url"] = song->url;
|
||||
notify[command_index]["song_invoker"] = song->invoker;
|
||||
notify[command_index]["song_loaded"] = song->loaded;
|
||||
|
||||
auto entry = song->load_future ? song->load_future->getValue({}) : nullptr;
|
||||
if(entry) {
|
||||
notify[command_index]["song_loaded"] = true;
|
||||
if(entry->type != ::music::TYPE_STREAM && entry->type != ::music::TYPE_VIDEO)
|
||||
continue;
|
||||
|
||||
auto info = reinterpret_pointer_cast<::music::UrlSongInfo>(entry);
|
||||
if(info) {
|
||||
notify[command_index]["song_title"] = info->title;
|
||||
notify[command_index]["song_description"] = info->description;
|
||||
if(auto thumbnail = reinterpret_pointer_cast<::music::ThumbnailUrl>(info->thumbnail); thumbnail && thumbnail->type() == ::music::THUMBNAIL_URL)
|
||||
notify[command_index]["song_thumbnail"] = thumbnail->url();
|
||||
else
|
||||
notify[command_index]["song_thumbnail"] = "";
|
||||
notify[command_index]["song_length"] = info->length.count();
|
||||
}
|
||||
}
|
||||
notify[command_index]["queue_index"] = begin_index++;
|
||||
|
||||
if(!bulked)
|
||||
@ -966,7 +987,6 @@ command_result ConnectedClient::handleCommandMusicBotQueueList(Command& cmd) {
|
||||
command_index++;
|
||||
}
|
||||
|
||||
debugMessage(this->getServerId(),"Send: {}",notify.build());
|
||||
if(bulked) {
|
||||
if(command_index > 0) {
|
||||
this->sendCommand(notify);
|
||||
|
@ -562,3 +562,24 @@ bool QueryClient::notifyChannelUnsubscribed(const deque<shared_ptr<BasicChannel>
|
||||
bool QueryClient::ignoresFlood() {
|
||||
return this->whitelisted || ConnectedClient::ignoresFlood();
|
||||
}
|
||||
|
||||
void QueryClient::disconnect_from_virtual_server() {
|
||||
threads::MutexLock lock(this->command_lock);
|
||||
|
||||
auto server_locked = this->server;
|
||||
if(server_locked) {
|
||||
//unregister manager from old server
|
||||
{
|
||||
unique_lock tree_lock(this->server->channel_tree_lock);
|
||||
if(this->currentChannel)
|
||||
this->server->client_move(this->ref(), nullptr, nullptr, "", ViewReasonId::VREASON_USER_ACTION, false, tree_lock);
|
||||
this->server->unregisterClient(_this.lock(), "server switch", tree_lock);
|
||||
}
|
||||
server_locked->groups->disableCache(this->getClientDatabaseId());
|
||||
this->channels->reset();
|
||||
this->currentChannel = nullptr;
|
||||
this->server = nullptr;
|
||||
this->loadDataForCurrentServer();
|
||||
}
|
||||
serverInstance->getGroupManager()->enableCache(this->getClientDatabaseId());
|
||||
}
|
@ -6,9 +6,9 @@
|
||||
#include <pipes/ssl.h>
|
||||
#include "misc/queue.h"
|
||||
|
||||
namespace ts {
|
||||
namespace server {
|
||||
namespace ts::server {
|
||||
class QueryServer;
|
||||
class QueryAccount;
|
||||
|
||||
class QueryClient : public ConnectedClient {
|
||||
friend class QueryServer;
|
||||
@ -37,6 +37,7 @@ namespace ts {
|
||||
void resetEventMask();
|
||||
|
||||
bool ignoresFlood() override;
|
||||
void disconnect_from_virtual_server();
|
||||
|
||||
inline std::shared_ptr<QueryAccount> getQueryAccount() { return this->query_account; }
|
||||
protected:
|
||||
@ -179,5 +180,4 @@ namespace ts {
|
||||
|
||||
command_result handleCommandSetCompressionMode(Command&);
|
||||
};
|
||||
}
|
||||
}
|
@ -316,21 +316,7 @@ command_result QueryClient::handleCommandServerSelect(Command &cmd) {
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto server_locked = this->server;
|
||||
if(server_locked) {
|
||||
//unregister manager from old server
|
||||
{
|
||||
unique_lock tree_lock(this->server->channel_tree_lock);
|
||||
if(this->currentChannel)
|
||||
this->server->client_move(this->ref(), nullptr, nullptr, "", ViewReasonId::VREASON_USER_ACTION, false, tree_lock);
|
||||
this->server->unregisterClient(_this.lock(), "server switch", tree_lock);
|
||||
}
|
||||
server_locked->groups->disableCache(this->getClientDatabaseId());
|
||||
this->channels->reset();
|
||||
} else
|
||||
serverInstance->getGroupManager()->disableCache(this->getClientDatabaseId());
|
||||
}
|
||||
this->disconnect_from_virtual_server();
|
||||
this->resetEventMask();
|
||||
|
||||
//register at current server
|
||||
@ -713,7 +699,7 @@ command_result QueryClient::handleCommandServerStop(Command& cmd) {
|
||||
if(!permission::v2::permission_granted(1, server->calculate_permission(permission::b_virtualserver_stop, this->getClientDatabaseId(), ClientType::CLIENT_QUERY, 0)))
|
||||
ACTION_REQUIRES_INSTANCE_PERMISSION(permission::b_virtualserver_stop_any, 1);
|
||||
|
||||
server->stop("server stopped");
|
||||
server->stop("server stopped", false);
|
||||
return command_result{error::ok};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user