Reworked the voice IP part
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "src/client/ConnectedClient.h"
|
||||
#include <ThreadPool/ThreadHelper.h>
|
||||
#include <files/FileServer.h>
|
||||
#include <set>
|
||||
|
||||
using namespace std;
|
||||
using namespace std::chrono;
|
||||
@@ -14,11 +15,7 @@ using namespace ts::server;
|
||||
|
||||
VirtualServerManager::VirtualServerManager(InstanceHandler* handle) : handle(handle) {
|
||||
this->puzzles = new udp::PuzzleManager{};
|
||||
this->handshakeTickers = new threads::Scheduler(1, "handshake ticker");
|
||||
//this->join_loop = new event::EventExecutor("joiner #");
|
||||
this->_ioManager = new io::VoiceIOManager();
|
||||
|
||||
this->handshakeTickers->schedule("ticker", [&](){ this->tickHandshakeClients(); }, seconds(1));
|
||||
}
|
||||
|
||||
VirtualServerManager::~VirtualServerManager() {
|
||||
@@ -39,17 +36,6 @@ VirtualServerManager::~VirtualServerManager() {
|
||||
delete this->puzzles;
|
||||
this->puzzles = nullptr;
|
||||
|
||||
if(this->join_loop)
|
||||
this->join_loop->shutdown();
|
||||
delete this->join_loop;
|
||||
this->join_loop = nullptr;
|
||||
|
||||
if(this->handshakeTickers) {
|
||||
this->handshakeTickers->shutdown();
|
||||
}
|
||||
delete this->handshakeTickers;
|
||||
this->handshakeTickers = nullptr;
|
||||
|
||||
if(this->_ioManager) this->_ioManager->shutdownGlobally();
|
||||
delete this->_ioManager;
|
||||
this->_ioManager = nullptr;
|
||||
@@ -187,26 +173,24 @@ shared_ptr<VirtualServer> VirtualServerManager::findServerById(ServerId sid) {
|
||||
|
||||
shared_ptr<VirtualServer> VirtualServerManager::findServerByPort(uint16_t port) {
|
||||
for(const auto& server : this->serverInstances()){
|
||||
if(server->properties()[property::VIRTUALSERVER_PORT] == port) return server;
|
||||
if(server->running() && server->getVoiceServer())
|
||||
for(const auto& binding : server->getVoiceServer()->activeBindings())
|
||||
if(binding->address_port() == port) return server;
|
||||
if(server->properties()[property::VIRTUALSERVER_PORT] == port) {
|
||||
return server;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint16_t VirtualServerManager::next_available_port(const std::string& host_string) {
|
||||
auto instances = this->serverInstances();
|
||||
std::vector<uint16_t> unallowed_ports{};
|
||||
unallowed_ports.reserve(instances.size());
|
||||
auto instances_ = this->serverInstances();
|
||||
std::set<uint16_t> unallowed_ports{};
|
||||
|
||||
for(const auto& instance : instances) {
|
||||
unallowed_ports.push_back(instance->properties()[property::VIRTUALSERVER_PORT].as_or<uint16_t>(0));
|
||||
for(const auto& instance : instances_) {
|
||||
unallowed_ports.insert(instance->properties()[property::VIRTUALSERVER_PORT].as_or<uint16_t>(0));
|
||||
|
||||
auto vserver = instance->getVoiceServer();
|
||||
if(instance->running() && vserver) {
|
||||
for(const auto& binding : vserver->activeBindings()) {
|
||||
unallowed_ports.push_back(binding->address_port());
|
||||
for(const auto& socket : vserver->getSockets()) {
|
||||
unallowed_ports.insert(net::port(socket->address()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,8 +201,9 @@ uint16_t VirtualServerManager::next_available_port(const std::string& host_strin
|
||||
if(port < 1024) goto next_port;
|
||||
|
||||
for(auto& p : unallowed_ports) {
|
||||
if(p == port)
|
||||
if(p == port) {
|
||||
goto next_port;
|
||||
}
|
||||
}
|
||||
|
||||
for(auto& binding : bindings) {
|
||||
@@ -470,14 +455,6 @@ void VirtualServerManager::shutdownAll(const std::string& msg) {
|
||||
}
|
||||
}
|
||||
|
||||
void VirtualServerManager::tickHandshakeClients() {
|
||||
for(const auto& server : this->serverInstances()) {
|
||||
auto vserver = server->getVoiceServer();
|
||||
if(vserver)
|
||||
vserver->tickHandshakingClients();
|
||||
}
|
||||
}
|
||||
|
||||
void VirtualServerManager::delete_server_in_db(ts::ServerId server_id, bool data_only) {
|
||||
#define execute_delete(statement) \
|
||||
result = sql::command(this->handle->getSql(), statement, variable{":sid", server_id}).execute(); \
|
||||
|
||||
Reference in New Issue
Block a user