Fixed some bugs
This commit is contained in:
parent
0d456eea5d
commit
e81e21f00e
@ -15,6 +15,7 @@
|
|||||||
#include "./client/voice/VoiceClient.h"
|
#include "./client/voice/VoiceClient.h"
|
||||||
#include "./client/InternalClient.h"
|
#include "./client/InternalClient.h"
|
||||||
#include "./client/music/MusicClient.h"
|
#include "./client/music/MusicClient.h"
|
||||||
|
#include "./client/query/QueryClient.h"
|
||||||
#include "music/MusicBotManager.h"
|
#include "music/MusicBotManager.h"
|
||||||
#include "server/VoiceServer.h"
|
#include "server/VoiceServer.h"
|
||||||
#include "server/file/FileServer.h"
|
#include "server/file/FileServer.h"
|
||||||
@ -318,12 +319,12 @@ bool VirtualServer::start(std::string& error) {
|
|||||||
|
|
||||||
if(host.empty()){
|
if(host.empty()){
|
||||||
error = "invalid host (\"" + host + "\")";
|
error = "invalid host (\"" + host + "\")";
|
||||||
this->stop("failed to start");
|
this->stop("failed to start", true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(this->properties()[property::VIRTUALSERVER_PORT].as<uint16_t>() <= 0){
|
if(this->properties()[property::VIRTUALSERVER_PORT].as<uint16_t>() <= 0){
|
||||||
error = "invalid port";
|
error = "invalid port";
|
||||||
this->stop("failed to start");
|
this->stop("failed to start", true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,7 +361,7 @@ bool VirtualServer::start(std::string& error) {
|
|||||||
}
|
}
|
||||||
if(bindings.empty()) {
|
if(bindings.empty()) {
|
||||||
error = "failed to resole any host!";
|
error = "failed to resole any host!";
|
||||||
this->stop("failed to start");
|
this->stop("failed to start", false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,7 +369,7 @@ bool VirtualServer::start(std::string& error) {
|
|||||||
udpVoiceServer = make_shared<VoiceServer>(self.lock());
|
udpVoiceServer = make_shared<VoiceServer>(self.lock());
|
||||||
if(!udpVoiceServer->start(bindings, error)) {
|
if(!udpVoiceServer->start(bindings, error)) {
|
||||||
error = "could not start voice server. Message: " + error;
|
error = "could not start voice server. Message: " + error;
|
||||||
this->stop("failed to start");
|
this->stop("failed to start", false);
|
||||||
return 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);
|
logMessage(this->serverId, "[Web] Starting server on {}:{}", web_host_string, web_port);
|
||||||
if(!webControlServer->start(bindings, error)) {
|
if(!webControlServer->start(bindings, error)) {
|
||||||
error = "could not start web server. Message: " + error;
|
error = "could not start web server. Message: " + error;
|
||||||
this->stop("failed to start");
|
this->stop("failed to start", false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#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();
|
auto self_lock = this->self.lock();
|
||||||
assert(self_lock);
|
assert(self_lock);
|
||||||
{
|
{
|
||||||
@ -484,9 +485,10 @@ void VirtualServer::stop(const std::string& reason) {
|
|||||||
threads::MutexLock lock(cl->command_lock);
|
threads::MutexLock lock(cl->command_lock);
|
||||||
cl->currentChannel = nullptr;
|
cl->currentChannel = nullptr;
|
||||||
|
|
||||||
continue; //We dont need to disconnect the query
|
if(disconnect_query) {
|
||||||
cl->server = nullptr;
|
auto qc = dynamic_pointer_cast<QueryClient>(cl);
|
||||||
cl->loadDataForCurrentServer();
|
qc->disconnect_from_virtual_server();
|
||||||
|
}
|
||||||
} else if(cl->getType() == CLIENT_MUSIC) {
|
} else if(cl->getType() == CLIENT_MUSIC) {
|
||||||
cl->disconnect("");
|
cl->disconnect("");
|
||||||
cl->currentChannel = nullptr;
|
cl->currentChannel = nullptr;
|
||||||
|
@ -144,7 +144,7 @@ namespace ts {
|
|||||||
bool start(std::string& error);
|
bool start(std::string& error);
|
||||||
bool running();
|
bool running();
|
||||||
void preStop(const std::string&);
|
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();
|
size_t onlineClients();
|
||||||
OnlineClientReport onlineStats();
|
OnlineClientReport onlineStats();
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include <log/LogUtils.h>
|
#include <log/LogUtils.h>
|
||||||
#include "VirtualServerManager.h"
|
#include "VirtualServerManager.h"
|
||||||
#include "src/server/VoiceServer.h"
|
#include "src/server/VoiceServer.h"
|
||||||
|
#include "src/client/query/QueryClient.h"
|
||||||
#include "InstanceHandler.h"
|
#include "InstanceHandler.h"
|
||||||
#include "src/server/file/FileServer.h"
|
#include "src/server/file/FileServer.h"
|
||||||
#include "src/client/ConnectedClient.h"
|
#include "src/client/ConnectedClient.h"
|
||||||
@ -361,7 +362,21 @@ bool VirtualServerManager::deleteServer(shared_ptr<VirtualServer> server) {
|
|||||||
this->adjust_executor_threads();
|
this->adjust_executor_threads();
|
||||||
|
|
||||||
if(server->getState() != ServerState::OFFLINE)
|
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()) {
|
for(const shared_ptr<ConnectedClient>& client : server->getClients()) {
|
||||||
if(client && client->getType() == ClientType::CLIENT_QUERY) {
|
if(client && client->getType() == ClientType::CLIENT_QUERY) {
|
||||||
@ -419,7 +434,7 @@ void VirtualServerManager::shutdownAll(const std::string& msg) {
|
|||||||
for(const auto &server : this->serverInstances())
|
for(const auto &server : this->serverInstances())
|
||||||
server->preStop(msg);
|
server->preStop(msg);
|
||||||
for(const auto &server : this->serverInstances()){
|
for(const auto &server : this->serverInstances()){
|
||||||
if(server->running()) server->stop(msg);
|
if(server->running()) server->stop(msg, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->execute_loop->shutdown();
|
this->execute_loop->shutdown();
|
||||||
|
@ -956,8 +956,29 @@ command_result ConnectedClient::handleCommandMusicBotQueueList(Command& cmd) {
|
|||||||
if(!bulked)
|
if(!bulked)
|
||||||
notify = Command(this->notify_response_command("notifymusicqueueentry"));
|
notify = Command(this->notify_response_command("notifymusicqueueentry"));
|
||||||
|
|
||||||
//TODO!
|
auto song = *it;
|
||||||
//apply_song(notify, *it, command_index);
|
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++;
|
notify[command_index]["queue_index"] = begin_index++;
|
||||||
|
|
||||||
if(!bulked)
|
if(!bulked)
|
||||||
@ -966,7 +987,6 @@ command_result ConnectedClient::handleCommandMusicBotQueueList(Command& cmd) {
|
|||||||
command_index++;
|
command_index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
debugMessage(this->getServerId(),"Send: {}",notify.build());
|
|
||||||
if(bulked) {
|
if(bulked) {
|
||||||
if(command_index > 0) {
|
if(command_index > 0) {
|
||||||
this->sendCommand(notify);
|
this->sendCommand(notify);
|
||||||
|
@ -562,3 +562,24 @@ bool QueryClient::notifyChannelUnsubscribed(const deque<shared_ptr<BasicChannel>
|
|||||||
bool QueryClient::ignoresFlood() {
|
bool QueryClient::ignoresFlood() {
|
||||||
return this->whitelisted || ConnectedClient::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 <pipes/ssl.h>
|
||||||
#include "misc/queue.h"
|
#include "misc/queue.h"
|
||||||
|
|
||||||
namespace ts {
|
namespace ts::server {
|
||||||
namespace server {
|
|
||||||
class QueryServer;
|
class QueryServer;
|
||||||
|
class QueryAccount;
|
||||||
|
|
||||||
class QueryClient : public ConnectedClient {
|
class QueryClient : public ConnectedClient {
|
||||||
friend class QueryServer;
|
friend class QueryServer;
|
||||||
@ -37,6 +37,7 @@ namespace ts {
|
|||||||
void resetEventMask();
|
void resetEventMask();
|
||||||
|
|
||||||
bool ignoresFlood() override;
|
bool ignoresFlood() override;
|
||||||
|
void disconnect_from_virtual_server();
|
||||||
|
|
||||||
inline std::shared_ptr<QueryAccount> getQueryAccount() { return this->query_account; }
|
inline std::shared_ptr<QueryAccount> getQueryAccount() { return this->query_account; }
|
||||||
protected:
|
protected:
|
||||||
@ -179,5 +180,4 @@ namespace ts {
|
|||||||
|
|
||||||
command_result handleCommandSetCompressionMode(Command&);
|
command_result handleCommandSetCompressionMode(Command&);
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
@ -316,21 +316,7 @@ command_result QueryClient::handleCommandServerSelect(Command &cmd) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
this->disconnect_from_virtual_server();
|
||||||
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->resetEventMask();
|
this->resetEventMask();
|
||||||
|
|
||||||
//register at current server
|
//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)))
|
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);
|
ACTION_REQUIRES_INSTANCE_PERMISSION(permission::b_virtualserver_stop_any, 1);
|
||||||
|
|
||||||
server->stop("server stopped");
|
server->stop("server stopped", false);
|
||||||
return command_result{error::ok};
|
return command_result{error::ok};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user