Reworked the property system and fixed a crash
This commit is contained in:
@@ -131,7 +131,7 @@ bool VirtualServerManager::initialize(bool autostart) {
|
||||
this->instances.push_back(server);
|
||||
}
|
||||
|
||||
if(autostart && server->properties()[property::VIRTUALSERVER_AUTOSTART].as<bool>()) {
|
||||
if(autostart && server->properties()[property::VIRTUALSERVER_AUTOSTART].as_or<bool>(false)) {
|
||||
logMessage(server->getServerId(), "Starting server");
|
||||
string msg;
|
||||
try {
|
||||
@@ -201,7 +201,7 @@ uint16_t VirtualServerManager::next_available_port(const std::string& host_strin
|
||||
unallowed_ports.reserve(instances.size());
|
||||
|
||||
for(const auto& instance : instances) {
|
||||
unallowed_ports.push_back(instance->properties()[property::VIRTUALSERVER_PORT].as<uint16_t>());
|
||||
unallowed_ports.push_back(instance->properties()[property::VIRTUALSERVER_PORT].as_or<uint16_t>(0));
|
||||
|
||||
auto vserver = instance->getVoiceServer();
|
||||
if(instance->running() && vserver) {
|
||||
@@ -249,7 +249,7 @@ uint16_t VirtualServerManager::next_available_port(const std::string& host_strin
|
||||
}
|
||||
|
||||
ts::ServerId VirtualServerManager::next_available_server_id(bool& success) {
|
||||
auto server_id_base = this->handle->properties()[property::SERVERINSTANCE_VIRTUAL_SERVER_ID_INDEX].as<ServerId>();
|
||||
auto server_id_base = this->handle->properties()[property::SERVERINSTANCE_VIRTUAL_SERVER_ID_INDEX].as_or<ServerId>(0);
|
||||
/* ensure we're not using 0xFFFF (This is the snapshot server) */
|
||||
if(server_id_base > 65530) {
|
||||
success = false;
|
||||
@@ -292,7 +292,7 @@ ServerReport VirtualServerManager::report() {
|
||||
result.avariable++;
|
||||
if(sr->running()) {
|
||||
result.online++;
|
||||
result.slots += sr->properties()[property::VIRTUALSERVER_MAXCLIENTS].as<size_t>();
|
||||
result.slots += sr->properties()[property::VIRTUALSERVER_MAXCLIENTS].as_or<size_t>(0);
|
||||
result.onlineClients += sr->onlineClients();
|
||||
result.onlineChannels += sr->onlineChannels();
|
||||
}
|
||||
@@ -324,7 +324,7 @@ size_t VirtualServerManager::runningServers() {
|
||||
size_t VirtualServerManager::usedSlots() {
|
||||
size_t res = 0;
|
||||
for(const auto& sr : this->serverInstances())
|
||||
res += sr->properties()[property::VIRTUALSERVER_MAXCLIENTS].as<size_t>();
|
||||
res += sr->properties()[property::VIRTUALSERVER_MAXCLIENTS].as_or<size_t>(0);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -410,7 +410,7 @@ bool VirtualServerManager::deleteServer(shared_ptr<VirtualServer> server) {
|
||||
server->state = ServerState::DELETING;
|
||||
}
|
||||
|
||||
this->handle->properties()[property::SERVERINSTANCE_SPOKEN_TIME_DELETED] += server->properties()[property::VIRTUALSERVER_SPOKEN_TIME].as<uint64_t>();
|
||||
this->handle->properties()[property::SERVERINSTANCE_SPOKEN_TIME_DELETED].increment_by(server->properties()[property::VIRTUALSERVER_SPOKEN_TIME].as_or<uint64_t>(0));
|
||||
this->delete_server_in_db(server->serverId, false);
|
||||
this->handle->databaseHelper()->handleServerDelete(server->serverId);
|
||||
|
||||
@@ -441,7 +441,7 @@ void VirtualServerManager::executeAutostart() {
|
||||
threads::MutexLock l(this->instanceLock);
|
||||
auto lastStart = system_clock::time_point();
|
||||
for(const auto& server : this->instances){
|
||||
if(!server->running() && server->properties()[property::VIRTUALSERVER_AUTOSTART].as<bool>()){
|
||||
if(!server->running() && server->properties()[property::VIRTUALSERVER_AUTOSTART].as_or<bool>(false)){
|
||||
threads::self::sleep_until(lastStart + milliseconds(10)); //Don't start all server at the same point (otherwise all servers would tick at the same moment)
|
||||
lastStart = system_clock::now();
|
||||
logMessage(server->getServerId(), "Starting server");
|
||||
|
||||
Reference in New Issue
Block a user