Using this->ref() and this->weak_ref() instead of direct member access

This commit is contained in:
WolverinDEV 2021-02-21 20:28:59 +01:00
parent e9445d6568
commit 71b2d734bd
31 changed files with 220 additions and 201 deletions

View File

@ -13,12 +13,10 @@
#include <ThreadPool/Timer.h> #include <ThreadPool/Timer.h>
#include "ShutdownHelper.h" #include "ShutdownHelper.h"
#include <sys/utsname.h> #include <sys/utsname.h>
#include "build.h"
#include <misc/digest.h> #include <misc/digest.h>
#include <misc/base64.h> #include <misc/base64.h>
#include <misc/hex.h> #include <misc/hex.h>
#include <misc/rnd.h> #include <misc/rnd.h>
#include <misc/strobf.h>
#include <protocol/buffers.h> #include <protocol/buffers.h>
#ifndef _POSIX_SOURCE #ifndef _POSIX_SOURCE
@ -40,6 +38,21 @@ using namespace ts::server;
extern bool mainThreadActive; extern bool mainThreadActive;
InstanceHandler::InstanceHandler(SqlDataManager *sql) : sql(sql) { InstanceHandler::InstanceHandler(SqlDataManager *sql) : sql(sql) {
serverInstance = this; serverInstance = this;
this->general_task_executor_ = std::make_shared<task_executor>(ts::config::threads::ticking, "instance tick ");
this->general_task_executor_->set_exception_handler([](const std::string& task_name, const std::exception_ptr& exception) {
std::string message{};
try {
std::rethrow_exception(exception);
} catch (const std::exception& ex) {
message = "std::exception::what() -> " + std::string{ex.what()};
} catch(...) {
message = "unknown exception";
}
logCritical(LOG_INSTANCE, "Instance task executor received exception: {}", message);
});
this->tick_manager = make_shared<threads::Scheduler>(config::threads::ticking, "tick task "); this->tick_manager = make_shared<threads::Scheduler>(config::threads::ticking, "tick task ");
this->statistics = make_shared<stats::ConnectionStatistics>(nullptr); this->statistics = make_shared<stats::ConnectionStatistics>(nullptr);
@ -110,11 +123,11 @@ InstanceHandler::InstanceHandler(SqlDataManager *sql) : sql(sql) {
globalServerAdmin = std::make_shared<ts::server::InternalClient>(this->getSql(), nullptr, "serveradmin", true); globalServerAdmin = std::make_shared<ts::server::InternalClient>(this->getSql(), nullptr, "serveradmin", true);
static_pointer_cast<ts::server::InternalClient>(globalServerAdmin)->setSharedLock(globalServerAdmin); globalServerAdmin->initialize_weak_reference(this->globalServerAdmin);
ts::server::DatabaseHelper::assignDatabaseId(this->getSql(), 0, globalServerAdmin); ts::server::DatabaseHelper::assignDatabaseId(this->getSql(), 0, globalServerAdmin);
this->_musicRoot = std::make_shared<InternalClient>(this->getSql(), nullptr, "Music Manager", false); this->_musicRoot = std::make_shared<InternalClient>(this->getSql(), nullptr, "Music Manager", false);
static_pointer_cast<InternalClient>(this->_musicRoot)->setSharedLock(this->_musicRoot); globalServerAdmin->initialize_weak_reference(this->_musicRoot);
{ {
this->groupManager = std::make_shared<GroupManager>(nullptr, this->getSql()); this->groupManager = std::make_shared<GroupManager>(nullptr, this->getSql());

View File

@ -8,6 +8,7 @@
#include "manager/SqlDataManager.h" #include "manager/SqlDataManager.h"
#include "lincense/TeamSpeakLicense.h" #include "lincense/TeamSpeakLicense.h"
#include "server/WebIoManager.h" #include "server/WebIoManager.h"
#include <misc/task_executor.h>
namespace ts { namespace ts {
namespace weblist { namespace weblist {
@ -75,6 +76,8 @@ namespace ts {
bool resetMonthlyStats(); bool resetMonthlyStats();
[[nodiscard]] inline const auto& general_task_executor(){ return this->general_task_executor_; }
std::shared_ptr<stats::ConnectionStatistics> getStatistics(){ return statistics; } std::shared_ptr<stats::ConnectionStatistics> getStatistics(){ return statistics; }
std::shared_ptr<threads::Scheduler> scheduler(){ return this->tick_manager; } std::shared_ptr<threads::Scheduler> scheduler(){ return this->tick_manager; }
std::shared_ptr<license::InstanceLicenseInfo> generateLicenseData(); std::shared_ptr<license::InstanceLicenseInfo> generateLicenseData();
@ -87,7 +90,7 @@ namespace ts {
std::shared_ptr<permission::PermissionNameMapper> getPermissionMapper() { return this->permission_mapper; } std::shared_ptr<permission::PermissionNameMapper> getPermissionMapper() { return this->permission_mapper; }
std::shared_ptr<ts::event::EventExecutor> getConversationIo() { return this->conversation_io; } std::shared_ptr<ts::event::EventExecutor> getConversationIo() { return this->conversation_io; }
[[nodiscard]] inline auto server_command_executor() { return this->server_command_executor_; } [[nodiscard]] inline const auto& server_command_executor() { return this->server_command_executor_; }
permission::v2::PermissionFlaggedValue calculate_permission( permission::v2::PermissionFlaggedValue calculate_permission(
permission::PermissionType, permission::PermissionType,
@ -151,6 +154,8 @@ namespace ts {
std::shared_ptr<stats::ConnectionStatistics> statistics = nullptr; std::shared_ptr<stats::ConnectionStatistics> statistics = nullptr;
std::shared_ptr<threads::Scheduler> tick_manager = nullptr; std::shared_ptr<threads::Scheduler> tick_manager = nullptr;
std::shared_ptr<task_executor> general_task_executor_{nullptr};
std::shared_ptr<permission::PermissionNameMapper> permission_mapper = nullptr; std::shared_ptr<permission::PermissionNameMapper> permission_mapper = nullptr;
std::shared_ptr<TeamSpeakLicense> teamspeak_license = nullptr; std::shared_ptr<TeamSpeakLicense> teamspeak_license = nullptr;

View File

@ -532,7 +532,7 @@ void VirtualServer::client_move(
} }
if (s_target_channel) { if (s_target_channel) {
if(target->update_cached_permissions()) /* update cached calculated permissions */ if(target->update_client_needed_permissions()) /* update cached calculated permissions */
target->sendNeededPermissions(false); target->sendNeededPermissions(false);
TIMING_STEP(timings, "perm gr upd"); TIMING_STEP(timings, "perm gr upd");

View File

@ -249,14 +249,15 @@ bool VirtualServer::initialize(bool test_properties) {
server_statistics_ = make_shared<stats::ConnectionStatistics>(serverInstance->getStatistics()); server_statistics_ = make_shared<stats::ConnectionStatistics>(serverInstance->getStatistics());
this->serverRoot = std::make_shared<InternalClient>(this->sql, self.lock(), this->properties()[property::VIRTUALSERVER_NAME].as<string>(), false); this->serverRoot = std::make_shared<InternalClient>(this->sql, self.lock(), this->properties()[property::VIRTUALSERVER_NAME].as<string>(), false);
static_pointer_cast<InternalClient>(this->serverRoot)->setSharedLock(this->serverRoot); this->serverRoot->initialize_weak_reference(this->serverRoot);
this->properties().registerNotifyHandler([&](Property& property) { this->properties().registerNotifyHandler([&](Property& property) {
if(property.type() == property::VIRTUALSERVER_NAME) static_pointer_cast<InternalClient>(this->serverRoot)->properties()[property::CLIENT_NICKNAME] = property.as<string>(); if(property.type() == property::VIRTUALSERVER_NAME) static_pointer_cast<InternalClient>(this->serverRoot)->properties()[property::CLIENT_NICKNAME] = property.as<string>();
}); });
this->serverRoot->server = nullptr; this->serverRoot->server = nullptr;
this->serverAdmin = std::make_shared<InternalClient>(this->sql, self.lock(), "serveradmin", true); this->serverAdmin = std::make_shared<InternalClient>(this->sql, self.lock(), "serveradmin", true);
static_pointer_cast<InternalClient>(this->serverAdmin)->setSharedLock(this->serverAdmin); this->serverAdmin->initialize_weak_reference(this->serverAdmin);
DatabaseHelper::assignDatabaseId(this->sql, this->serverId, this->serverAdmin); DatabaseHelper::assignDatabaseId(this->sql, this->serverId, this->serverAdmin);
this->serverAdmin->server = nullptr; this->serverAdmin->server = nullptr;
this->registerInternalClient(this->serverAdmin); /* lets assign server id 0 */ this->registerInternalClient(this->serverAdmin); /* lets assign server id 0 */
@ -1212,7 +1213,7 @@ bool VirtualServer::resetPermissions(std::string& token) {
client->notifyChannelGroupList(); client->notifyChannelGroupList();
} }
if(this->notifyClientPropertyUpdates(client, this->getGroupManager()->update_server_group_property(client, true, client->getChannel()))) { if(this->notifyClientPropertyUpdates(client, this->getGroupManager()->update_server_group_property(client, true, client->getChannel()))) {
if(client->update_cached_permissions()) /* update cached calculated permissions */ if(client->update_client_needed_permissions()) /* update cached calculated permissions */
client->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ client->sendNeededPermissions(false); /* cached permissions had changed, notify the client */
} }
client->updateChannelClientProperties(true, true); client->updateChannelClientProperties(true, true);

View File

@ -36,6 +36,19 @@ ConnectedClient::~ConnectedClient() {
memtrack::freed<ConnectedClient>(this); memtrack::freed<ConnectedClient>(this);
} }
void ConnectedClient::initialize_weak_reference(const std::shared_ptr<ConnectedClient> &self) {
assert(this == &*self);
this->_this = self;
auto weak_self = std::weak_ptr{self};
this->task_update_needed_permissions = multi_shot_task{serverInstance->general_task_executor(), "update permissions for " + this->getLoggingPeerIp(), [weak_self]{
auto self = weak_self.lock();
if(self) {
self->update_client_needed_permissions();
}
}};
}
bool ConnectedClient::loadDataForCurrentServer() { bool ConnectedClient::loadDataForCurrentServer() {
auto result = DataClient::loadDataForCurrentServer(); auto result = DataClient::loadDataForCurrentServer();
if(!result) { if(!result) {
@ -177,7 +190,7 @@ void ConnectedClient::updateChannelClientProperties(bool lock_channel_tree, bool
block_flood = !permission::v2::permission_granted(1, permission_ignore_antiflood); block_flood = !permission::v2::permission_granted(1, permission_ignore_antiflood);
if(server_ref) if(server_ref)
server_ref->notifyClientPropertyUpdates(_this.lock(), notifyList, notify_self); server_ref->notifyClientPropertyUpdates(this->ref(), notifyList, notify_self);
this->updateTalkRights(permission_talk_power); this->updateTalkRights(permission_talk_power);
if((this->channels_view_power != permission_channel_view_power || this->channels_ignore_view != permission_channel_ignore_view_power) && notify_self && this->currentChannel && server_ref) { if((this->channels_view_power != permission_channel_view_power || this->channels_ignore_view != permission_channel_ignore_view_power) && notify_self && this->currentChannel && server_ref) {
@ -570,8 +583,8 @@ bool ConnectedClient::notifyClientNeededPermissions() {
Command cmd("notifyclientneededpermissions"); Command cmd("notifyclientneededpermissions");
int index = 0; int index = 0;
unique_lock cache_lock(this->cached_permissions_lock); unique_lock cache_lock(this->client_needed_permissions_lock);
auto permissions = this->cached_permissions; auto permissions = this->client_needed_permissions;
cache_lock.unlock(); cache_lock.unlock();
for(const auto& [ key, value ] : permissions) { for(const auto& [ key, value ] : permissions) {
@ -699,7 +712,7 @@ void ConnectedClient::sendChannelList(bool lock_channel_tree) {
logCritical(this->getServerId(), "ConnectedClient::sendChannelList => invalid (empty) own channel path!"); logCritical(this->getServerId(), "ConnectedClient::sendChannelList => invalid (empty) own channel path!");
send_channels(this, entry_channels.begin(), entry_channels.end(), false); send_channels(this, entry_channels.begin(), entry_channels.end(), false);
this->notifyClientEnterView(_this.lock(), nullptr, "", this->currentChannel, ViewReasonId::VREASON_SYSTEM, nullptr, false); //Notify self after path is send this->notifyClientEnterView(this->ref(), nullptr, "", this->currentChannel, ViewReasonId::VREASON_SYSTEM, nullptr, false); //Notify self after path is send
send_channels(this, channels.begin(), channels.end(), false); send_channels(this, channels.begin(), channels.end(), false);
//this->notifyClientEnterView(_this.lock(), nullptr, "", this->currentChannel, ViewReasonId::VREASON_SYSTEM, nullptr, false); //Notify self after path is send //this->notifyClientEnterView(_this.lock(), nullptr, "", this->currentChannel, ViewReasonId::VREASON_SYSTEM, nullptr, false); //Notify self after path is send
this->sendCommand(Command("channellistfinished")); this->sendCommand(Command("channellistfinished"));
@ -923,22 +936,22 @@ std::shared_ptr<BanRecord> ConnectedClient::resolveActiveBan(const std::string&
return banEntry; return banEntry;
} }
bool ConnectedClient::update_cached_permissions() { bool ConnectedClient::update_client_needed_permissions() {
auto values = this->calculate_permissions(permission::neededPermissions, this->currentChannel? this->currentChannel->channelId() : 0); /* copy the channel here so it does not change */ auto values = this->calculate_permissions(permission::neededPermissions, this->currentChannel? this->currentChannel->channelId() : 0); /* copy the channel here so it does not change */
auto updated = false; auto updated = false;
{ {
lock_guard cached_lock(this->cached_permissions_lock); lock_guard cached_lock(this->client_needed_permissions_lock);
auto old_cached_permissions{this->cached_permissions}; auto old_cached_permissions{this->client_needed_permissions};
this->cached_permissions = values; this->client_needed_permissions = values;
std::sort(this->cached_permissions.begin(), this->cached_permissions.end(), [](const auto& a, const auto& b) { return a.first < b.first; }); std::sort(this->client_needed_permissions.begin(), this->client_needed_permissions.end(), [](const auto& a, const auto& b) { return a.first < b.first; });
if(this->cached_permissions.size() != old_cached_permissions.size()) if(this->client_needed_permissions.size() != old_cached_permissions.size())
updated = true; updated = true;
else { else {
for(auto oit = old_cached_permissions.begin(), nit = this->cached_permissions.begin(); oit != old_cached_permissions.end(); oit++, nit++) { for(auto oit = old_cached_permissions.begin(), nit = this->client_needed_permissions.begin(); oit != old_cached_permissions.end(); oit++, nit++) {
if(oit->first != nit->first || oit->second != nit->second) { if(oit->first != nit->first || oit->second != nit->second) {
updated = true; updated = true;
break; break;

View File

@ -4,6 +4,7 @@
#include <misc/net.h> #include <misc/net.h>
#include <cstdint> #include <cstdint>
#include <src/music/PlayablePlaylist.h> #include <src/music/PlayablePlaylist.h>
#include <misc/task_executor.h>
#include "music/Song.h" #include "music/Song.h"
#include "../channel/ClientChannelView.h" #include "../channel/ClientChannelView.h"
#include "DataClient.h" #include "DataClient.h"
@ -273,7 +274,8 @@ namespace ts {
inline std::shared_ptr<ClientChannelView> channel_view() { return this->channels; } inline std::shared_ptr<ClientChannelView> channel_view() { return this->channels; }
inline std::shared_ptr<ConnectedClient> ref() { return _this.lock(); } [[nodiscard]] inline std::shared_ptr<ConnectedClient> ref() { return this->_this.lock(); }
[[nodiscard]] inline std::weak_ptr<ConnectedClient> weak_ref() { return this->_this; }
std::shared_mutex& get_channel_lock() { return this->channel_lock; } std::shared_mutex& get_channel_lock() { return this->channel_lock; }
@ -284,19 +286,7 @@ namespace ts {
/* /*
* permission stuff * permission stuff
*/ */
/* bool update_client_needed_permissions();
inline permission::PermissionValue cached_permission_value(permission::PermissionType type) const {
std::lock_guard lock(this->cached_permissions_lock);
auto index = this->cached_permissions.find(type);
if(index != this->cached_permissions.end())
return index->second;
We're only caching permissions which are granted to reduce memory
//logError(this->getServerId(), "{} Looked up cached permission, which hasn't been cached!", CLIENT_STR_LOG_PREFIX);
return permNotGranted;
}
*/
bool update_cached_permissions();
std::shared_lock<std::shared_mutex> require_connected_state(bool blocking = false) { std::shared_lock<std::shared_mutex> require_connected_state(bool blocking = false) {
//try_to_lock_t //try_to_lock_t
@ -373,14 +363,17 @@ namespace ts {
std::shared_ptr<ClientChannelView> channels; std::shared_ptr<ClientChannelView> channels;
std::shared_mutex channel_lock; std::shared_mutex channel_lock;
std::mutex cached_permissions_lock; /* The permission overview which the client itself has (for basic client actions ) */
std::vector<std::pair<permission::PermissionType, permission::v2::PermissionFlaggedValue>> cached_permissions; /* contains all needed permissions which are set */ std::mutex client_needed_permissions_lock;
std::vector<std::pair<permission::PermissionType, permission::v2::PermissionFlaggedValue>> client_needed_permissions;
permission::v2::PermissionFlaggedValue channels_view_power{0, false}; permission::v2::PermissionFlaggedValue channels_view_power{0, false};
permission::v2::PermissionFlaggedValue channels_ignore_view{0, false}; permission::v2::PermissionFlaggedValue channels_ignore_view{0, false};
permission::v2::PermissionFlaggedValue cpmerission_whisper_power{0, false}; permission::v2::PermissionFlaggedValue cpmerission_whisper_power{0, false};
permission::v2::PermissionFlaggedValue cpmerission_needed_whisper_power{0, false}; permission::v2::PermissionFlaggedValue cpmerission_needed_whisper_power{0, false};
virtual void initialize_weak_reference(const std::shared_ptr<ConnectedClient>& /* self reference */);
bool subscribeToAll = false; bool subscribeToAll = false;
uint16_t join_state_id = 1; /* default channel value is 0 and by default we need to calculate at least once, so we use 1 */ uint16_t join_state_id = 1; /* default channel value is 0 and by default we need to calculate at least once, so we use 1 */
permission::PermissionType calculate_and_get_join_state(const std::shared_ptr<BasicChannel>&); permission::PermissionType calculate_and_get_join_state(const std::shared_ptr<BasicChannel>&);
@ -389,6 +382,8 @@ namespace ts {
std::weak_ptr<MusicClient> subscribed_bot; std::weak_ptr<MusicClient> subscribed_bot;
std::weak_ptr<ts::music::Playlist> subscribed_playlist_{}; std::weak_ptr<ts::music::Playlist> subscribed_playlist_{};
multi_shot_task task_update_needed_permissions{};
bool loadDataForCurrentServer() override; bool loadDataForCurrentServer() override;
virtual void tick_server(const std::chrono::system_clock::time_point &time); virtual void tick_server(const std::chrono::system_clock::time_point &time);

View File

@ -601,34 +601,34 @@ bool ConnectedClient::handle_text_command(
return true; return true;
} else if (command == "dummy") { } else if (command == "dummy") {
if(TARG(0, "timerevent")) { if(TARG(0, "timerevent")) {
send_message(_this.lock(), "Sending command dummy_timerevent"); send_message(this->ref(), "Sending command dummy_timerevent");
this->sendCommand(Command("dummy_timerevent")); this->sendCommand(Command("dummy_timerevent"));
return true; return true;
} else if(TARG(0, "rd")) { } else if(TARG(0, "rd")) {
send_message(_this.lock(), "Sending command rd"); send_message(this->ref(), "Sending command rd");
Command cmd("rd"); Command cmd("rd");
cmd["msg"] = "Hello world"; cmd["msg"] = "Hello world";
this->sendCommand(cmd); this->sendCommand(cmd);
return true; return true;
} else if(TARG(0, "connectfailed")) { } else if(TARG(0, "connectfailed")) {
send_message(_this.lock(), "Sending command dummy_connectfailed"); send_message(this->ref(), "Sending command dummy_connectfailed");
Command cmd("dummy_connectfailed"); Command cmd("dummy_connectfailed");
cmd["status"] = 1797; cmd["status"] = 1797;
this->sendCommand(cmd); this->sendCommand(cmd);
return true; return true;
} }
send_message(_this.lock(), "Invalid dummy command!"); send_message(this->ref(), "Invalid dummy command!");
send_message(_this.lock(), "- timerevent"); send_message(this->ref(), "- timerevent");
send_message(_this.lock(), "- connectfailed"); send_message(this->ref(), "- connectfailed");
send_message(_this.lock(), "- rd"); send_message(this->ref(), "- rd");
return true; return true;
} else if(command == "protocol") { } else if(command == "protocol") {
if(TARG(0, "generation")) { if(TARG(0, "generation")) {
auto vc = dynamic_pointer_cast<VoiceClient>(_this.lock()); auto vc = dynamic_pointer_cast<VoiceClient>(this->ref());
if(!vc) return false; if(!vc) return false;
send_message(_this.lock(), "Packet generations:"); send_message(this->ref(), "Packet generations:");
/* /*
for(const auto& type : { for(const auto& type : {
protocol::PacketTypeInfo::Command, protocol::PacketTypeInfo::Command,
@ -644,20 +644,20 @@ bool ConnectedClient::handle_text_command(
//auto gen = vc->getConnection()->getPacketIdManager().generationId(type); //auto gen = vc->getConnection()->getPacketIdManager().generationId(type);
//auto& genestis = vc->getConnection()->get_incoming_generation_estimators(); //auto& genestis = vc->getConnection()->get_incoming_generation_estimators();
//send_message(_this.lock(), " OUT " + type.name() + " => generation: " + to_string(gen) + " id: " + to_string(id)); //send_message(this->ref(), " OUT " + type.name() + " => generation: " + to_string(gen) + " id: " + to_string(id));
//send_message(_this.lock(), " IN " + type.name() + " => generation: " + to_string(genestis[type.type()].generation()) + " id: " + to_string(genestis[type.type()].current_packet_id())); //send_message(this->ref(), " IN " + type.name() + " => generation: " + to_string(genestis[type.type()].generation()) + " id: " + to_string(genestis[type.type()].current_packet_id()));
} }
*/ */
return true; return true;
} else if(TARG(0, "rtt")) { } else if(TARG(0, "rtt")) {
auto vc = dynamic_pointer_cast<VoiceClient>(_this.lock()); auto vc = dynamic_pointer_cast<VoiceClient>(this->ref());
if(!vc) return false; if(!vc) return false;
auto& ack = vc->connection->packet_encoder().acknowledge_manager(); auto& ack = vc->connection->packet_encoder().acknowledge_manager();
send_message(_this.lock(), "Command retransmission values:"); send_message(this->ref(), "Command retransmission values:");
send_message(_this.lock(), " RTO : " + std::to_string(ack.current_rto())); send_message(this->ref(), " RTO : " + std::to_string(ack.current_rto()));
send_message(_this.lock(), " RTTVAR: " + std::to_string(ack.current_rttvar())); send_message(this->ref(), " RTTVAR: " + std::to_string(ack.current_rttvar()));
send_message(_this.lock(), " SRTT : " + std::to_string(ack.current_srtt())); send_message(this->ref(), " SRTT : " + std::to_string(ack.current_srtt()));
return true; return true;
} else if(TARG(0, "sgeneration")) { } else if(TARG(0, "sgeneration")) {
TLEN(4); TLEN(4);
@ -667,24 +667,24 @@ bool ConnectedClient::handle_text_command(
auto generation = stol(arguments[2]); auto generation = stol(arguments[2]);
auto pid = stol(arguments[3]); auto pid = stol(arguments[3]);
auto vc = dynamic_pointer_cast<VoiceClient>(_this.lock()); auto vc = dynamic_pointer_cast<VoiceClient>(this->ref());
if(!vc) return false; if(!vc) return false;
/* /*
auto& genestis = vc->getConnection()->get_incoming_generation_estimators(); auto& genestis = vc->getConnection()->get_incoming_generation_estimators();
if(type >= genestis.size()) { if(type >= genestis.size()) {
send_message(_this.lock(), "Invalid type"); send_message(this->ref(), "Invalid type");
return true; return true;
} }
genestis[type].set_last_state(pid, generation); genestis[type].set_last_state(pid, generation);
*/ */
} catch(std::exception& ex) { } catch(std::exception& ex) {
send_message(_this.lock(), "Failed to parse argument"); send_message(this->ref(), "Failed to parse argument");
return true; return true;
} }
return true; return true;
} else if(TARG(0, "ping")) { } else if(TARG(0, "ping")) {
auto vc = dynamic_pointer_cast<VoiceClient>(_this.lock()); auto vc = dynamic_pointer_cast<VoiceClient>(this->ref());
if(!vc) return false; if(!vc) return false;
auto ping_handler = vc->getConnection()->ping_handler(); auto ping_handler = vc->getConnection()->ping_handler();
@ -694,47 +694,47 @@ bool ConnectedClient::handle_text_command(
send_message(this->ref(), "Last ping response: " + std::to_string(last_response_ms)); send_message(this->ref(), "Last ping response: " + std::to_string(last_response_ms));
return true; return true;
} else if(TARG(0, "disconnect")) { } else if(TARG(0, "disconnect")) {
auto vc = dynamic_pointer_cast<VoiceClient>(_this.lock()); auto vc = dynamic_pointer_cast<VoiceClient>(this->ref());
if(!vc) return false; if(!vc) return false;
send_message(_this.lock(), "You'll timeout"); send_message(this->ref(), "You'll timeout");
Command cmd("notifyclientupdated"); Command cmd("notifyclientupdated");
vc->sendCommand(cmd); vc->sendCommand(cmd);
return true; return true;
} else if(TARG(0, "resetip")) { } else if(TARG(0, "resetip")) {
auto vc = dynamic_pointer_cast<VoiceClient>(_this.lock()); auto vc = dynamic_pointer_cast<VoiceClient>(this->ref());
if(!vc) return false; if(!vc) return false;
send_message(_this.lock(), "I lost your IP address. I'm so dump :)"); send_message(this->ref(), "I lost your IP address. I'm so dump :)");
vc->connection->reset_remote_address(); vc->connection->reset_remote_address();
memset(&vc->remote_address, 0, sizeof(vc->remote_address)); memset(&vc->remote_address, 0, sizeof(vc->remote_address));
send_message(_this.lock(), "Hey, we got the address back"); send_message(this->ref(), "Hey, we got the address back");
return true; return true;
} else if(TARG(0, "fb")) { } else if(TARG(0, "fb")) {
this->increaseFloodPoints(0xFF8F); this->increaseFloodPoints(0xFF8F);
send_message(_this.lock(), "Done :)"); send_message(this->ref(), "Done :)");
return true; return true;
} else if(TARG(0, "binary")) { } else if(TARG(0, "binary")) {
send_message(_this.lock(), "Send binary message"); send_message(this->ref(), "Send binary message");
this->sendCommand(Command{"\02\03\04 \22"}); this->sendCommand(Command{"\02\03\04 \22"});
return true; return true;
} }
send_message(_this.lock(), "Invalid protocol command!"); send_message(this->ref(), "Invalid protocol command!");
send_message(_this.lock(), "- generation"); send_message(this->ref(), "- generation");
send_message(_this.lock(), "- disconnect"); send_message(this->ref(), "- disconnect");
send_message(_this.lock(), "- resetip"); send_message(this->ref(), "- resetip");
send_message(_this.lock(), "- fb"); send_message(this->ref(), "- fb");
return true; return true;
} else if (command == "sleep") { } else if (command == "sleep") {
if(arguments.empty() || arguments[0].find_first_not_of("0123456789") != string::npos) { if(arguments.empty() || arguments[0].find_first_not_of("0123456789") != string::npos) {
send_message(_this.lock(), "Invalid argument! Requires a number in ms."); send_message(this->ref(), "Invalid argument! Requires a number in ms.");
return true; return true;
} }
send_message(_this.lock(), "Sleeping for " + to_string(stoll(arguments[0])) + "!"); send_message(this->ref(), "Sleeping for " + to_string(stoll(arguments[0])) + "!");
auto end = system_clock::now() + milliseconds(stoll(arguments[0])); auto end = system_clock::now() + milliseconds(stoll(arguments[0]));
threads::self::sleep_until(end); threads::self::sleep_until(end);
send_message(_this.lock(), "Done!"); send_message(this->ref(), "Done!");
return true; return true;
} else if(command == "conversation") { } else if(command == "conversation") {
if(TARG(0, "history")) { if(TARG(0, "history")) {
@ -761,12 +761,12 @@ bool ConnectedClient::handle_text_command(
os << std::put_time(std::localtime(&seconds_since_epoch), "%Y %b %d %H:%M:%S"); os << std::put_time(std::localtime(&seconds_since_epoch), "%Y %b %d %H:%M:%S");
return os.str(); return os.str();
}; };
send_message(_this.lock(), "Looking up history from " + time_str(timestamp_end) + " to " + time_str(timestamp_begin) + ". Max messages: " + to_string(message_count)); send_message(this->ref(), "Looking up history from " + time_str(timestamp_end) + " to " + time_str(timestamp_begin) + ". Max messages: " + to_string(message_count));
auto conversation = this->server->conversation_manager()->get_or_create(this->currentChannel->channelId()); auto conversation = this->server->conversation_manager()->get_or_create(this->currentChannel->channelId());
auto data = conversation->message_history(timestamp_begin, message_count, timestamp_end); auto data = conversation->message_history(timestamp_begin, message_count, timestamp_end);
send_message(_this.lock(), "Entries: " + to_string(data.size())); send_message(this->ref(), "Entries: " + to_string(data.size()));
for(auto& entry : data) { for(auto& entry : data) {
send_message(_this.lock(), "<" + time_str(entry->message_timestamp) + ">" + entry->sender_name + ": " + entry->message); send_message(this->ref(), "<" + time_str(entry->message_timestamp) + ">" + entry->sender_name + ": " + entry->message);
} }
return true; return true;
} }

View File

@ -29,7 +29,7 @@ bool InternalClient::close_connection(const std::chrono::system_clock::time_poin
logError(this->getServerId(), "Internal client is force to disconnect?"); logError(this->getServerId(), "Internal client is force to disconnect?");
if(this->server) if(this->server)
this->server->unregisterInternalClient(static_pointer_cast<InternalClient>(_this.lock())); this->server->unregisterInternalClient(static_pointer_cast<InternalClient>(this->ref()));
this->properties()[property::CLIENT_ID] = 0; this->properties()[property::CLIENT_ID] = 0;
return true; return true;
} }

View File

@ -9,9 +9,8 @@ namespace ts::server {
InternalClient(sql::SqlManager*, const std::shared_ptr<VirtualServer>&, std::string, bool); InternalClient(sql::SqlManager*, const std::shared_ptr<VirtualServer>&, std::string, bool);
~InternalClient(); ~InternalClient();
void setSharedLock(const std::shared_ptr<ConnectedClient>& _this){ void initialize_weak_reference(const std::shared_ptr<ConnectedClient> &client) override {
assert(_this.get() == this); ConnectedClient::initialize_weak_reference(client);
this->_this = _this;
} }
void sendCommand(const ts::Command &command, bool low) override; void sendCommand(const ts::Command &command, bool low) override;

View File

@ -117,7 +117,7 @@ command_result SpeakingClient::handleCommandClientInit(Command& cmd) {
} }
TIMING_STEP(timings, "join atmp c"); TIMING_STEP(timings, "join atmp c");
if(!DatabaseHelper::assignDatabaseId(this->server->getSql(), this->server->getServerId(), _this.lock())) { if(!DatabaseHelper::assignDatabaseId(this->server->getSql(), this->server->getServerId(), this->ref())) {
return command_result{error::vs_critical, "Could not assign database id!"}; return command_result{error::vs_critical, "Could not assign database id!"};
} }
@ -380,7 +380,7 @@ command_result SpeakingClient::handleCommandClientInit(Command& cmd) {
} }
this->postCommandHandler.emplace_back([&](){ this->postCommandHandler.emplace_back([&](){
auto self = dynamic_pointer_cast<SpeakingClient>(_this.lock()); auto self = dynamic_pointer_cast<SpeakingClient>(this->ref());
std::thread([self](){ std::thread([self](){
if(self->state != ConnectionState::INIT_HIGH) return; if(self->state != ConnectionState::INIT_HIGH) return;
try { try {
@ -411,7 +411,7 @@ void SpeakingClient::processJoin() {
} }
TIMING_STEP(timings, "setup "); TIMING_STEP(timings, "setup ");
ref_server->registerClient(_this.lock()); ref_server->registerClient(this->ref());
{ {
if(this->rtc_client_id) { if(this->rtc_client_id) {
/* in case of client reconnect */ /* in case of client reconnect */
@ -438,7 +438,7 @@ void SpeakingClient::processJoin() {
TIMING_STEP(timings, "server reg "); TIMING_STEP(timings, "server reg ");
ref_server->getGroupManager()->cleanupAssignments(this->getClientDatabaseId()); ref_server->getGroupManager()->cleanupAssignments(this->getClientDatabaseId());
TIMING_STEP(timings, "grp cleanup"); TIMING_STEP(timings, "grp cleanup");
ref_server->getGroupManager()->update_server_group_property(_this.lock(), true, nullptr); ref_server->getGroupManager()->update_server_group_property(this->ref(), true, nullptr);
TIMING_STEP(timings, "grp apply "); TIMING_STEP(timings, "grp apply ");
this->properties()[property::CLIENT_COUNTRY] = config::geo::countryFlag; this->properties()[property::CLIENT_COUNTRY] = config::geo::countryFlag;
@ -537,7 +537,7 @@ void SpeakingClient::processJoin() {
} }
void SpeakingClient::processLeave() { void SpeakingClient::processLeave() {
auto ownLock = _this.lock(); auto ownLock = this->ref();
auto server = this->getServer(); auto server = this->getServer();
auto channel = this->currentChannel; auto channel = this->currentChannel;

View File

@ -412,7 +412,7 @@ command_result ConnectedClient::handleCommandChannelGroupDel(Command &cmd) {
if (this->server) { if (this->server) {
this->server->forEachClient([&](shared_ptr<ConnectedClient> cl) { this->server->forEachClient([&](shared_ptr<ConnectedClient> cl) {
if (this->server->notifyClientPropertyUpdates(cl, this->server->groups->update_server_group_property(cl, true, cl->getChannel()))) { if (this->server->notifyClientPropertyUpdates(cl, this->server->groups->update_server_group_property(cl, true, cl->getChannel()))) {
if (cl->update_cached_permissions()) /* update cached calculated permissions */ if (cl->update_client_needed_permissions()) /* update cached calculated permissions */
cl->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ cl->sendNeededPermissions(false); /* cached permissions had changed, notify the client */
} }
cl->notifyChannelGroupList(); cl->notifyChannelGroupList();
@ -559,7 +559,7 @@ command_result ConnectedClient::handleCommandChannelGroupAddPerm(Command &cmd) {
this->server->forEachClient([channelGroup](shared_ptr<ConnectedClient> cl) { this->server->forEachClient([channelGroup](shared_ptr<ConnectedClient> cl) {
unique_lock client_channel_lock(cl->channel_lock); /* while we're updating groups we dont want to change anything! */ unique_lock client_channel_lock(cl->channel_lock); /* while we're updating groups we dont want to change anything! */
if (cl->channelGroupAssigned(channelGroup, cl->getChannel())) { if (cl->channelGroupAssigned(channelGroup, cl->getChannel())) {
if (cl->update_cached_permissions()) { if (cl->update_client_needed_permissions()) {
cl->sendNeededPermissions(false); /* update the needed permissions */ cl->sendNeededPermissions(false); /* update the needed permissions */
} }
cl->join_state_id++; /* join permission may changed, all channels need to be recalculate dif needed */ cl->join_state_id++; /* join permission may changed, all channels need to be recalculate dif needed */
@ -609,7 +609,7 @@ command_result ConnectedClient::handleCommandChannelGroupDelPerm(Command &cmd) {
this->server->forEachClient([channelGroup](shared_ptr<ConnectedClient> cl) { this->server->forEachClient([channelGroup](shared_ptr<ConnectedClient> cl) {
unique_lock client_channel_lock(cl->channel_lock); /* while we're updating groups we dont want to change anything! */ unique_lock client_channel_lock(cl->channel_lock); /* while we're updating groups we dont want to change anything! */
if (cl->channelGroupAssigned(channelGroup, cl->getChannel())) { if (cl->channelGroupAssigned(channelGroup, cl->getChannel())) {
if (cl->update_cached_permissions()) /* update cached calculated permissions */ if (cl->update_client_needed_permissions()) /* update cached calculated permissions */
cl->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ cl->sendNeededPermissions(false); /* cached permissions had changed, notify the client */
cl->join_state_id++; /* join permission may changed, all channels need to be recalculate dif needed */ cl->join_state_id++; /* join permission may changed, all channels need to be recalculate dif needed */
} }
@ -955,7 +955,7 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) {
} }
if (this->server) { if (this->server) {
const auto self_lock = _this.lock(); const auto self_lock = this->ref();
GroupId adminGroup = this->server->properties()[property::VIRTUALSERVER_DEFAULT_CHANNEL_ADMIN_GROUP]; GroupId adminGroup = this->server->properties()[property::VIRTUALSERVER_DEFAULT_CHANNEL_ADMIN_GROUP];
auto channel_admin_group = this->server->groups->findGroup(adminGroup); auto channel_admin_group = this->server->groups->findGroup(adminGroup);
@ -2057,7 +2057,7 @@ command_result ConnectedClient::handleCommandChannelMove(Command &cmd) {
deletions.push_back(action.second->channelId()); deletions.push_back(action.second->channelId());
break; break;
case ClientChannelView::MOVE: case ClientChannelView::MOVE:
client->notifyChannelMoved(action.second->channel(), action.second->previous_channel, _this.lock()); client->notifyChannelMoved(action.second->channel(), action.second->previous_channel, this->ref());
break; break;
case ClientChannelView::REORDER: case ClientChannelView::REORDER:
client->notifyChannelEdited(action.second->channel(), {property::CHANNEL_ORDER}, self_rev, false); client->notifyChannelEdited(action.second->channel(), {property::CHANNEL_ORDER}, self_rev, false);
@ -2354,7 +2354,7 @@ command_result ConnectedClient::handleCommandChannelClientDelPerm(Command &cmd)
auto onlineClients = this->server->findClientsByCldbId(cldbid); auto onlineClients = this->server->findClientsByCldbId(cldbid);
if (!onlineClients.empty()) { if (!onlineClients.empty()) {
for (const auto &elm : onlineClients) { for (const auto &elm : onlineClients) {
if (elm->update_cached_permissions()) /* update cached calculated permissions */ if (elm->update_client_needed_permissions()) /* update cached calculated permissions */
elm->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ elm->sendNeededPermissions(false); /* cached permissions had changed, notify the client */
if (elm->currentChannel == channel) { if (elm->currentChannel == channel) {
@ -2423,7 +2423,7 @@ command_result ConnectedClient::handleCommandChannelClientAddPerm(Command &cmd)
auto onlineClients = this->server->findClientsByCldbId(cldbid); auto onlineClients = this->server->findClientsByCldbId(cldbid);
if (!onlineClients.empty()) if (!onlineClients.empty())
for (const auto &elm : onlineClients) { for (const auto &elm : onlineClients) {
if (elm->update_cached_permissions()) /* update cached calculated permissions */ if (elm->update_client_needed_permissions()) /* update cached calculated permissions */
elm->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ elm->sendNeededPermissions(false); /* cached permissions had changed, notify the client */
if (elm->currentChannel == channel) { if (elm->currentChannel == channel) {

View File

@ -258,7 +258,7 @@ command_result ConnectedClient::handleCommandClientMove(Command &cmd) {
this->server->client_move( this->server->client_move(
client.client, client.client,
channel, channel,
client.client == this ? nullptr : _this.lock(), client.client == this ? nullptr : this->ref(),
"", "",
client.client == this ? ViewReasonId::VREASON_USER_ACTION : ViewReasonId::VREASON_MOVED, client.client == this ? ViewReasonId::VREASON_USER_ACTION : ViewReasonId::VREASON_MOVED,
true, true,
@ -334,7 +334,7 @@ command_result ConnectedClient::handleCommandClientPoke(Command &cmd) {
return command_result{error::parameter_invalid_size, "msg"}; return command_result{error::parameter_invalid_size, "msg"};
for(auto& client : clients) for(auto& client : clients)
client->notifyClientPoke(_this.lock(), message); client->notifyClientPoke(this->ref(), message);
return command_result{std::forward<command_result_bulk>(result)}; return command_result{std::forward<command_result_bulk>(result)};
} }
@ -347,7 +347,7 @@ command_result ConnectedClient::handleCommandClientChatComposing(Command &cmd) {
ConnectedLockedClient client{this->server->find_client_by_id(cmd["clid"].as<ClientId>())}; ConnectedLockedClient client{this->server->find_client_by_id(cmd["clid"].as<ClientId>())};
if (!client) return command_result{error::client_invalid_id}; if (!client) return command_result{error::client_invalid_id};
client->notifyClientChatComposing(_this.lock()); client->notifyClientChatComposing(this->ref());
return command_result{error::ok}; return command_result{error::ok};
} }
@ -369,7 +369,7 @@ command_result ConnectedClient::handleCommandClientChatClosed(Command &cmd) {
return weak.lock().get() == this; return weak.lock().get() == this;
}), client->open_private_conversations.end()); }), client->open_private_conversations.end());
} }
client->notifyClientChatClosed(_this.lock()); client->notifyClientChatClosed(this->ref());
return command_result{error::ok}; return command_result{error::ok};
} }
@ -719,7 +719,7 @@ command_result ConnectedClient::handleCommandClientEdit(Command &cmd, const std:
} }
command_result ConnectedClient::handleCommandClientUpdate(Command &cmd) { command_result ConnectedClient::handleCommandClientUpdate(Command &cmd) {
return this->handleCommandClientEdit(cmd, _this.lock()); return this->handleCommandClientEdit(cmd, this->ref());
} }
command_result ConnectedClient::handleCommandClientMute(Command &cmd) { command_result ConnectedClient::handleCommandClientMute(Command &cmd) {
@ -737,7 +737,7 @@ command_result ConnectedClient::handleCommandClientMute(Command &cmd) {
} }
if (config::voice::notifyMuted) if (config::voice::notifyMuted)
client->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, _this.lock(), client->getClientId(), 0, system_clock::now(), config::messages::mute_notify_message); client->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, this->ref(), client->getClientId(), 0, system_clock::now(), config::messages::mute_notify_message);
return command_result{error::ok}; return command_result{error::ok};
} }
@ -758,7 +758,7 @@ command_result ConnectedClient::handleCommandClientUnmute(Command &cmd) {
} }
if (config::voice::notifyMuted) if (config::voice::notifyMuted)
client->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, _this.lock(), client->getClientId(), 0, system_clock::now(), config::messages::unmute_notify_message); client->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, this->ref(), client->getClientId(), 0, system_clock::now(), config::messages::unmute_notify_message);
return command_result{error::ok}; return command_result{error::ok};
} }
@ -976,7 +976,7 @@ command_result ConnectedClient::handleCommandClientAddPerm(Command &cmd) {
auto onlineClients = this->server->findClientsByCldbId(cldbid); auto onlineClients = this->server->findClientsByCldbId(cldbid);
if (!onlineClients.empty()) if (!onlineClients.empty())
for (const auto &elm : onlineClients) { for (const auto &elm : onlineClients) {
if(elm->update_cached_permissions()) /* update cached calculated permissions */ if(elm->update_client_needed_permissions()) /* update cached calculated permissions */
elm->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ elm->sendNeededPermissions(false); /* cached permissions had changed, notify the client */
if(update_channels) if(update_channels)
elm->updateChannelClientProperties(true, true); elm->updateChannelClientProperties(true, true);
@ -1019,7 +1019,7 @@ command_result ConnectedClient::handleCommandClientDelPerm(Command &cmd) {
auto onlineClients = this->server->findClientsByCldbId(cldbid); auto onlineClients = this->server->findClientsByCldbId(cldbid);
if (!onlineClients.empty()) if (!onlineClients.empty())
for (const auto &elm : onlineClients) { for (const auto &elm : onlineClients) {
if(elm->update_cached_permissions()) /* update cached calculated permissions */ if(elm->update_client_needed_permissions()) /* update cached calculated permissions */
elm->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ elm->sendNeededPermissions(false); /* cached permissions had changed, notify the client */
if(update_channels) if(update_channels)
elm->updateChannelClientProperties(true, true); elm->updateChannelClientProperties(true, true);

View File

@ -328,7 +328,7 @@ command_result ConnectedClient::handleCommandFTDeleteFile(Command &cmd) {
file_log_info.emplace_back(0, "/avatar_" + avId); file_log_info.emplace_back(0, "/avatar_" + avId);
} else { } else {
this->properties()[property::CLIENT_FLAG_AVATAR] = ""; this->properties()[property::CLIENT_FLAG_AVATAR] = "";
this->server->notifyClientPropertyUpdates(_this.lock(), deque<property::ClientProperties>{property::CLIENT_FLAG_AVATAR}); this->server->notifyClientPropertyUpdates(this->ref(), deque<property::ClientProperties>{property::CLIENT_FLAG_AVATAR});
delete_files.push_back("/avatar_" + this->getAvatarId()); delete_files.push_back("/avatar_" + this->getAvatarId());
file_log_info.emplace_back(0, "/avatar_" + this->getAvatarId()); file_log_info.emplace_back(0, "/avatar_" + this->getAvatarId());
} }

View File

@ -293,7 +293,7 @@ command_result ConnectedClient::handleCommandGetConnectionInfo(Command &cmd) {
if (!client) return command_result{error::client_invalid_id}; if (!client) return command_result{error::client_invalid_id};
bool send_temp{false}; bool send_temp{false};
auto info = client->request_connection_info(_this.lock(), send_temp); auto info = client->request_connection_info(this->ref(), send_temp);
if (info || send_temp) { if (info || send_temp) {
this->notifyConnectionInfo(client.client, info); this->notifyConnectionInfo(client.client, info);
} else if(this->getType() != ClientType::CLIENT_TEAMSPEAK) } else if(this->getType() != ClientType::CLIENT_TEAMSPEAK)
@ -329,7 +329,7 @@ command_result ConnectedClient::handleCommandSetConnectionInfo(Command &cmd) {
this->connection_info.data_age = system_clock::now(); this->connection_info.data_age = system_clock::now();
} }
for(const auto& receiver : receivers) for(const auto& receiver : receivers)
receiver->notifyConnectionInfo(_this.lock(), info); receiver->notifyConnectionInfo(this->ref(), info);
return command_result{error::ok}; return command_result{error::ok};
} }
@ -506,7 +506,7 @@ command_result ConnectedClient::handleCommandSetClientChannelGroup(Command &cmd)
shared_lock client_channel_lock_r(targetClient->channel_lock); shared_lock client_channel_lock_r(targetClient->channel_lock);
auto result = this->server->notifyClientPropertyUpdates(targetClient, updates); auto result = this->server->notifyClientPropertyUpdates(targetClient, updates);
if (result) { if (result) {
if(targetClient->update_cached_permissions()) /* update cached calculated permissions */ if(targetClient->update_client_needed_permissions()) /* update cached calculated permissions */
targetClient->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ targetClient->sendNeededPermissions(false); /* cached permissions had changed, notify the client */
if(targetClient->properties()[property::CLIENT_CHANNEL_GROUP_INHERITED_CHANNEL_ID] == channel->channelId()) { //Only if group assigned over the channel if(targetClient->properties()[property::CLIENT_CHANNEL_GROUP_INHERITED_CHANNEL_ID] == channel->channelId()) { //Only if group assigned over the channel
@ -515,7 +515,7 @@ command_result ConnectedClient::handleCommandSetClientChannelGroup(Command &cmd)
shared_lock viewer_channel_lock(viewer->channel_lock, defer_lock); shared_lock viewer_channel_lock(viewer->channel_lock, defer_lock);
if(viewer != targetClient) if(viewer != targetClient)
viewer_channel_lock.lock(); viewer_channel_lock.lock();
viewer->notifyClientChannelGroupChanged(_this.lock(), targetClient, targetClient->getChannel(), channel, serverGroup, false); viewer->notifyClientChannelGroupChanged(this->ref(), targetClient, targetClient->getChannel(), channel, serverGroup, false);
} }
} }
} }
@ -592,8 +592,8 @@ command_result ConnectedClient::handleCommandSendTextMessage(Command &cmd) {
return command_result{error::ok}; return command_result{error::ok};
} }
target->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, _this.lock(), target->getClientId(), 0, timestamp, cmd["msg"].string()); target->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, this->ref(), target->getClientId(), 0, timestamp, cmd["msg"].string());
this->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, _this.lock(), target->getClientId(), 0, timestamp, cmd["msg"].string()); this->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, this->ref(), target->getClientId(), 0, timestamp, cmd["msg"].string());
} else if (cmd["targetmode"] == ChatMessageMode::TEXTMODE_CHANNEL) { } else if (cmd["targetmode"] == ChatMessageMode::TEXTMODE_CHANNEL) {
if(cmd[0].has("cid")) { if(cmd[0].has("cid")) {
cmd["target"] = cmd["cid"].string(); cmd["target"] = cmd["cid"].string();
@ -648,7 +648,7 @@ command_result ConnectedClient::handleCommandSendTextMessage(Command &cmd) {
if (type == ClientType::CLIENT_INTERNAL || type == ClientType::CLIENT_MUSIC) if (type == ClientType::CLIENT_INTERNAL || type == ClientType::CLIENT_MUSIC)
continue; continue;
client->notifyTextMessage(ChatMessageMode::TEXTMODE_SERVER, _this.lock(), this->getClientId(), 0, timestamp, cmd["msg"].string()); client->notifyTextMessage(ChatMessageMode::TEXTMODE_SERVER, this->ref(), this->getClientId(), 0, timestamp, cmd["msg"].string());
} }
{ {
@ -773,7 +773,7 @@ command_result ConnectedClient::handleCommandBanAdd(Command &cmd) {
} }
for(auto server : (this->server ? std::deque<shared_ptr<VirtualServer>>{this->server} : serverInstance->getVoiceServerManager()->serverInstances())) for(auto server : (this->server ? std::deque<shared_ptr<VirtualServer>>{this->server} : serverInstance->getVoiceServerManager()->serverInstances()))
server->testBanStateChange(_this.lock()); server->testBanStateChange(this->ref());
return command_result{error::ok}; return command_result{error::ok};
} }
@ -930,7 +930,7 @@ command_result ConnectedClient::handleCommandBanClient(Command &cmd) {
ban_ids.push_back(id); ban_ids.push_back(id);
} }
} }
this->server->testBanStateChange(_this.lock()); this->server->testBanStateChange(this->ref());
if (this->getType() == CLIENT_QUERY) { if (this->getType() == CLIENT_QUERY) {
Command notify(""); Command notify("");
@ -1102,17 +1102,17 @@ command_result ConnectedClient::handleCommandTokenUse(Command &cmd) {
} }
} }
if (this->server->notifyClientPropertyUpdates(_this.lock(), this->server->groups->update_server_group_property(_this.lock(), true, this->getChannel()))) { if (this->server->notifyClientPropertyUpdates(this->ref(), this->server->groups->update_server_group_property(this->ref(), true, this->getChannel()))) {
if(this->update_cached_permissions()) /* update cached calculated permissions */ if(this->update_client_needed_permissions()) /* update cached calculated permissions */
this->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ this->sendNeededPermissions(false); /* cached permissions had changed, notify the client */
{ {
for (auto &viewer : this->server->getClients()) { for (auto &viewer : this->server->getClients()) {
if(viewer->isClientVisible(_this.lock(), true)) if(viewer->isClientVisible(this->ref(), true))
viewer->notifyServerGroupClientAdd(this->server->serverRoot, _this.lock(), serverGroup); viewer->notifyServerGroupClientAdd(this->server->serverRoot, this->ref(), serverGroup);
} }
} }
this->notifyServerGroupClientAdd(this->server->serverRoot, _this.lock(), serverGroup); this->notifyServerGroupClientAdd(this->server->serverRoot, this->ref(), serverGroup);
} }
return command_result{error::ok}; return command_result{error::ok};
@ -1149,26 +1149,26 @@ command_result ConnectedClient::handleCommandPluginCmd(Command &cmd) {
if (mode == PluginTargetMode::PLUGINCMD_CURRENT_CHANNEL) { if (mode == PluginTargetMode::PLUGINCMD_CURRENT_CHANNEL) {
CMD_REQ_CHANNEL; CMD_REQ_CHANNEL;
for (auto &cl : this->server->getClientsByChannel(this->currentChannel)) for (auto &cl : this->server->getClientsByChannel(this->currentChannel))
cl->notifyPluginCmd(cmd["name"], cmd["data"], _this.lock()); cl->notifyPluginCmd(cmd["name"], cmd["data"], this->ref());
} else if (mode == PluginTargetMode::PLUGINCMD_SUBSCRIBED_CLIENTS) { } else if (mode == PluginTargetMode::PLUGINCMD_SUBSCRIBED_CLIENTS) {
for (auto &cl : this->server->getClients()) for (auto &cl : this->server->getClients())
if (cl->isClientVisible(_this.lock(), true)) if (cl->isClientVisible(this->ref(), true))
cl->notifyPluginCmd(cmd["name"], cmd["data"], _this.lock()); cl->notifyPluginCmd(cmd["name"], cmd["data"], this->ref());
} else if (mode == PluginTargetMode::PLUGINCMD_SERVER) { } else if (mode == PluginTargetMode::PLUGINCMD_SERVER) {
for (auto &cl : this->server->getClients()) for (auto &cl : this->server->getClients())
cl->notifyPluginCmd(cmd["name"], cmd["data"], _this.lock()); cl->notifyPluginCmd(cmd["name"], cmd["data"], this->ref());
} else if (mode == PluginTargetMode::PLUGINCMD_CLIENT) { } else if (mode == PluginTargetMode::PLUGINCMD_CLIENT) {
for (int index = 0; index < cmd.bulkCount(); index++) { for (int index = 0; index < cmd.bulkCount(); index++) {
auto target = cmd[index]["target"].as<ClientId>(); auto target = cmd[index]["target"].as<ClientId>();
ConnectedLockedClient cl{this->server->find_client_by_id(target)}; ConnectedLockedClient cl{this->server->find_client_by_id(target)};
if (!cl) return command_result{error::client_invalid_id}; if (!cl) return command_result{error::client_invalid_id};
cl->notifyPluginCmd(cmd["name"], cmd["data"], _this.lock()); cl->notifyPluginCmd(cmd["name"], cmd["data"], this->ref());
} }
} }
/* /*
else if(mode == PluginTargetMode::PLUGINCMD_SEND_COMMAND) { else if(mode == PluginTargetMode::PLUGINCMD_SEND_COMMAND) {
auto target = _this.lock(); auto target = this->ref();
if(cmd[0].has("target")) if(cmd[0].has("target"))
target = this->server->findClient(cmd["target"].as<ClientId>()); target = this->server->findClient(cmd["target"].as<ClientId>());
if(!target) return command_result{error::client_invalid_id, "invalid target id"}; if(!target) return command_result{error::client_invalid_id, "invalid target id"};
@ -2547,7 +2547,7 @@ command_result ConnectedClient::handleCommandDummy_IpChange(ts::Command &cmd) {
if(loc) { if(loc) {
logMessage(this->getServerId(), "[{}] Received new ip location. IP {} traced to {} ({}).", CLIENT_STR_LOG_PREFIX, this->getLoggingPeerIp(), loc->name, loc->identifier); logMessage(this->getServerId(), "[{}] Received new ip location. IP {} traced to {} ({}).", CLIENT_STR_LOG_PREFIX, this->getLoggingPeerIp(), loc->name, loc->identifier);
this->properties()[property::CLIENT_COUNTRY] = loc->identifier; this->properties()[property::CLIENT_COUNTRY] = loc->identifier;
server->notifyClientPropertyUpdates(_this.lock(), deque<property::ClientProperties>{property::CLIENT_COUNTRY}); server->notifyClientPropertyUpdates(this->ref(), deque<property::ClientProperties>{property::CLIENT_COUNTRY});
new_country = loc->identifier; new_country = loc->identifier;
} else { } else {
logError(this->getServerId(), "[{}] Failed to resolve ip location for IP {}.", CLIENT_STR_LOG_PREFIX, this->getLoggingPeerIp()); logError(this->getServerId(), "[{}] Failed to resolve ip location for IP {}.", CLIENT_STR_LOG_PREFIX, this->getLoggingPeerIp());

View File

@ -189,11 +189,11 @@ command_result ConnectedClient::handleCommandMusicBotSetSubscription(ts::Command
{ {
auto old_bot = this->subscribed_bot.lock(); auto old_bot = this->subscribed_bot.lock();
if(old_bot) if(old_bot)
old_bot->remove_subscriber(_this.lock()); old_bot->remove_subscriber(this->ref());
} }
if(bot) { if(bot) {
bot->add_subscriber(_this.lock()); bot->add_subscriber(this->ref());
this->subscribed_bot = bot; this->subscribed_bot = bot;
} }
@ -912,7 +912,7 @@ command_result ConnectedClient::handleCommandPlaylistSongAdd(ts::Command &cmd) {
loader_string = "ChannelProvider"; loader_string = "ChannelProvider";
} }
auto song = playlist->add_song(_this.lock(), cmd["url"], loader_string, cmd["previous"]); auto song = playlist->add_song(this->ref(), cmd["url"], loader_string, cmd["previous"]);
if(!song) return command_result{error::vs_critical}; if(!song) return command_result{error::vs_critical};
return command_result{error::ok}; return command_result{error::ok};
@ -1069,11 +1069,11 @@ command_result ConnectedClient::handleCommandMusicBotQueueAdd(Command& cmd) {
} }
if(!loader) return command_result{error::music_invalid_action}; if(!loader) return command_result{error::music_invalid_action};
auto entry = bot->queue()->insertEntry(cmd["url"], _this.lock(), loader); auto entry = bot->queue()->insertEntry(cmd["url"], this->ref(), loader);
if(!entry) return command_result{error::vs_critical}; if(!entry) return command_result{error::vs_critical};
this->server->forEachClient([&](shared_ptr<ConnectedClient> client) { this->server->forEachClient([&](shared_ptr<ConnectedClient> client) {
client->notifyMusicQueueAdd(bot, entry, bot->queue()->queueEntries().size() - 1, _this.lock()); client->notifyMusicQueueAdd(bot, entry, bot->queue()->queueEntries().size() - 1, this->ref());
}); });
return command_result{error::ok}; return command_result{error::ok};
@ -1106,7 +1106,7 @@ command_result ConnectedClient::handleCommandMusicBotQueueRemove(Command& cmd) {
for(const auto& entry : songs) for(const auto& entry : songs)
bot->queue()->deleteEntry(dynamic_pointer_cast<music::PlayableSong>(entry)); bot->queue()->deleteEntry(dynamic_pointer_cast<music::PlayableSong>(entry));
this->server->forEachClient([&](shared_ptr<ConnectedClient> client) { this->server->forEachClient([&](shared_ptr<ConnectedClient> client) {
client->notifyMusicQueueRemove(bot, songs, _this.lock()); client->notifyMusicQueueRemove(bot, songs, this->ref());
}); });
return command_result{error::ok}; return command_result{error::ok};
*/ */
@ -1130,7 +1130,7 @@ command_result ConnectedClient::handleCommandMusicBotQueueReorder(Command& cmd)
auto order = bot->queue()->changeOrder(entry, cmd["index"]); auto order = bot->queue()->changeOrder(entry, cmd["index"]);
if(order < 0) return command_result{error::vs_critical}; if(order < 0) return command_result{error::vs_critical};
this->server->forEachClient([&](shared_ptr<ConnectedClient> client) { this->server->forEachClient([&](shared_ptr<ConnectedClient> client) {
client->notifyMusicQueueOrderChange(bot, entry, order, _this.lock()); client->notifyMusicQueueOrderChange(bot, entry, order, this->ref());
}); });
return command_result{error::ok}; return command_result{error::ok};
*/ */
@ -1177,7 +1177,7 @@ command_result ConnectedClient::handleCommandPlaylistSetSubscription(ts::Command
{ {
auto old_playlist = this->subscribed_playlist_.lock(); auto old_playlist = this->subscribed_playlist_.lock();
if(old_playlist) { if(old_playlist) {
old_playlist->remove_subscriber(_this.lock()); old_playlist->remove_subscriber(this->ref());
} }
} }
@ -1186,7 +1186,7 @@ command_result ConnectedClient::handleCommandPlaylistSetSubscription(ts::Command
return command_result{perr}; return command_result{perr};
} }
playlist->add_subscriber(_this.lock()); playlist->add_subscriber(this->ref());
this->subscribed_playlist_ = playlist; this->subscribed_playlist_ = playlist;
} }

View File

@ -41,7 +41,7 @@ using namespace ts::token;
command_result ConnectedClient::handleCommandServerGetVariables(Command &cmd) { command_result ConnectedClient::handleCommandServerGetVariables(Command &cmd) {
CMD_REQ_SERVER; CMD_REQ_SERVER;
this->notifyServerUpdated(_this.lock()); this->notifyServerUpdated(this->ref());
return command_result{error::ok}; return command_result{error::ok};
} }
@ -238,13 +238,13 @@ command_result ConnectedClient::handleCommandServerEdit(Command &cmd) {
if (group_update) if (group_update)
target_server->forEachClient([&](const shared_ptr<ConnectedClient>& client) { target_server->forEachClient([&](const shared_ptr<ConnectedClient>& client) {
if(target_server->notifyClientPropertyUpdates(client, target_server->groups->update_server_group_property(client, true, client->getChannel()))) { if(target_server->notifyClientPropertyUpdates(client, target_server->groups->update_server_group_property(client, true, client->getChannel()))) {
if(client->update_cached_permissions()) /* update cached calculated permissions */ if(client->update_client_needed_permissions()) /* update cached calculated permissions */
client->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ client->sendNeededPermissions(false); /* cached permissions had changed, notify the client */
} }
}); });
if (!keys.empty()) if (!keys.empty())
target_server->notifyServerEdited(_this.lock(), keys); target_server->notifyServerEdited(this->ref(), keys);
} }
return command_result{error::ok}; return command_result{error::ok};
} }
@ -579,7 +579,7 @@ command_result ConnectedClient::handleCommandServerGroupDel(Command &cmd) {
if(this->server) if(this->server)
this->server->forEachClient([&](shared_ptr<ConnectedClient> cl) { this->server->forEachClient([&](shared_ptr<ConnectedClient> cl) {
if(this->server->notifyClientPropertyUpdates(cl, this->server->groups->update_server_group_property(cl, true, cl->getChannel()))) { if(this->server->notifyClientPropertyUpdates(cl, this->server->groups->update_server_group_property(cl, true, cl->getChannel()))) {
if(cl->update_cached_permissions()) /* update cached calculated permissions */ if(cl->update_client_needed_permissions()) /* update cached calculated permissions */
cl->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ cl->sendNeededPermissions(false); /* cached permissions had changed, notify the client */
} }
cl->notifyServerGroupList(); cl->notifyServerGroupList();
@ -727,9 +727,9 @@ command_result ConnectedClient::handleCommandServerGroupAddClient(Command &cmd)
for (const auto &client : _server->getClients()) { for (const auto &client : _server->getClients()) {
if(client->isClientVisible(targetClient, true) || client == targetClient) if(client->isClientVisible(targetClient, true) || client == targetClient)
for(const auto& group : applied_groups) for(const auto& group : applied_groups)
client->notifyServerGroupClientAdd(_this.lock(), targetClient, group); client->notifyServerGroupClientAdd(this->ref(), targetClient, group);
} }
if(targetClient->update_cached_permissions()) /* update cached calculated permissions */ if(targetClient->update_client_needed_permissions()) /* update cached calculated permissions */
targetClient->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ targetClient->sendNeededPermissions(false); /* cached permissions had changed, notify the client */
targetClient->updateChannelClientProperties(true, true); targetClient->updateChannelClientProperties(true, true);
} }
@ -866,9 +866,9 @@ command_result ConnectedClient::handleCommandServerGroupDelClient(Command &cmd)
for (const auto &client : _server->getClients()) { for (const auto &client : _server->getClients()) {
if(client->isClientVisible(targetClient, true) || client == targetClient) if(client->isClientVisible(targetClient, true) || client == targetClient)
for(const auto& group : applied_groups) for(const auto& group : applied_groups)
client->notifyServerGroupClientRemove(_this.lock(), targetClient, group); client->notifyServerGroupClientRemove(this->ref(), targetClient, group);
} }
if(targetClient->update_cached_permissions()) /* update cached calculated permissions */ if(targetClient->update_client_needed_permissions()) /* update cached calculated permissions */
targetClient->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ targetClient->sendNeededPermissions(false); /* cached permissions had changed, notify the client */
targetClient->updateChannelClientProperties(true, true); targetClient->updateChannelClientProperties(true, true);
} }
@ -945,7 +945,7 @@ command_result ConnectedClient::handleCommandServerGroupAddPerm(Command &cmd) {
//TODO may update for every server? //TODO may update for every server?
if(this->server) { if(this->server) {
auto lock = this->_this.lock(); auto lock = this->ref();
auto server = this->server; auto server = this->server;
threads::Thread([update_talk_power, update_server_group_list, serverGroup, lock, server]() { threads::Thread([update_talk_power, update_server_group_list, serverGroup, lock, server]() {
if(update_server_group_list) if(update_server_group_list)
@ -954,7 +954,7 @@ command_result ConnectedClient::handleCommandServerGroupAddPerm(Command &cmd) {
}); });
server->forEachClient([serverGroup, update_talk_power](shared_ptr<ConnectedClient> cl) { server->forEachClient([serverGroup, update_talk_power](shared_ptr<ConnectedClient> cl) {
if (cl->serverGroupAssigned(serverGroup)) { if (cl->serverGroupAssigned(serverGroup)) {
if(cl->update_cached_permissions()) /* update cached calculated permissions */ if(cl->update_client_needed_permissions()) /* update cached calculated permissions */
cl->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ cl->sendNeededPermissions(false); /* cached permissions had changed, notify the client */
if (update_talk_power) if (update_talk_power)
cl->updateChannelClientProperties(true, true); cl->updateChannelClientProperties(true, true);
@ -1009,7 +1009,7 @@ command_result ConnectedClient::handleCommandServerGroupDelPerm(Command &cmd) {
serverGroup->apply_properties_from_permissions(); serverGroup->apply_properties_from_permissions();
if(this->server) { if(this->server) {
auto lock = this->_this.lock(); auto lock = this->ref();
auto server = this->server; auto server = this->server;
threads::Thread([update_talk_power, update_server_group_list, serverGroup, lock, server]() { threads::Thread([update_talk_power, update_server_group_list, serverGroup, lock, server]() {
if(update_server_group_list) if(update_server_group_list)
@ -1019,7 +1019,7 @@ command_result ConnectedClient::handleCommandServerGroupDelPerm(Command &cmd) {
server->forEachClient([serverGroup, update_talk_power](shared_ptr<ConnectedClient> cl) { server->forEachClient([serverGroup, update_talk_power](shared_ptr<ConnectedClient> cl) {
if (cl->serverGroupAssigned(serverGroup)) { if (cl->serverGroupAssigned(serverGroup)) {
if(cl->update_cached_permissions()) /* update cached calculated permissions */ if(cl->update_client_needed_permissions()) /* update cached calculated permissions */
cl->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ cl->sendNeededPermissions(false); /* cached permissions had changed, notify the client */
if (update_talk_power) if (update_talk_power)
cl->updateChannelClientProperties(true, true); cl->updateChannelClientProperties(true, true);
@ -1085,7 +1085,7 @@ command_result ConnectedClient::handleCommandServerGroupAutoAddPerm(ts::Command&
for(auto& group : groups) for(auto& group : groups)
group->apply_properties_from_permissions(); group->apply_properties_from_permissions();
auto lock = this->_this.lock(); auto lock = this->ref();
if(ref_server) { if(ref_server) {
threads::Thread([update_clients, update_server_group_list, groups, lock, ref_server]() { threads::Thread([update_clients, update_server_group_list, groups, lock, ref_server]() {
if(update_server_group_list) if(update_server_group_list)
@ -1095,7 +1095,7 @@ command_result ConnectedClient::handleCommandServerGroupAutoAddPerm(ts::Command&
ref_server->forEachClient([groups, update_clients](shared_ptr<ConnectedClient> cl) { ref_server->forEachClient([groups, update_clients](shared_ptr<ConnectedClient> cl) {
for(const auto& serverGroup : groups) { for(const auto& serverGroup : groups) {
if (cl->serverGroupAssigned(serverGroup)) { if (cl->serverGroupAssigned(serverGroup)) {
if(cl->update_cached_permissions()) {/* update cached calculated permissions */ if(cl->update_client_needed_permissions()) {/* update cached calculated permissions */
cl->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ cl->sendNeededPermissions(false); /* cached permissions had changed, notify the client */
} }
if (update_clients) { if (update_clients) {
@ -1166,7 +1166,7 @@ command_result ConnectedClient::handleCommandServerGroupAutoDelPerm(ts::Command&
} }
if(ref_server) { if(ref_server) {
auto lock = this->_this.lock(); auto lock = this->ref();
threads::Thread([update_clients, update_server_group_list, groups, lock, ref_server]() { threads::Thread([update_clients, update_server_group_list, groups, lock, ref_server]() {
if(update_server_group_list) if(update_server_group_list)
ref_server->forEachClient([](shared_ptr<ConnectedClient> cl) { ref_server->forEachClient([](shared_ptr<ConnectedClient> cl) {
@ -1175,7 +1175,7 @@ command_result ConnectedClient::handleCommandServerGroupAutoDelPerm(ts::Command&
ref_server->forEachClient([groups, update_clients](shared_ptr<ConnectedClient> cl) { ref_server->forEachClient([groups, update_clients](shared_ptr<ConnectedClient> cl) {
for(const auto& serverGroup : groups) { for(const auto& serverGroup : groups) {
if (cl->serverGroupAssigned(serverGroup)) { if (cl->serverGroupAssigned(serverGroup)) {
if(cl->update_cached_permissions()) /* update cached calculated permissions */ if(cl->update_client_needed_permissions()) /* update cached calculated permissions */
cl->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ cl->sendNeededPermissions(false); /* cached permissions had changed, notify the client */
if (update_clients) if (update_clients)
cl->updateChannelClientProperties(true, true); cl->updateChannelClientProperties(true, true);

View File

@ -87,7 +87,7 @@ bool MusicClient::close_connection(const std::chrono::system_clock::time_point&)
/* /*
if(this->server) if(this->server)
this->server->unregisterInternalClient(static_pointer_cast<InternalClient>(_this.lock())); this->server->unregisterInternalClient(static_pointer_cast<InternalClient>(this->ref()));
*/ */
//TODO! //TODO!
this->properties()[property::CLIENT_ID] = 0; this->properties()[property::CLIENT_ID] = 0;
@ -133,8 +133,8 @@ void MusicClient::initialize_bot() {
auto channel = this->server->getChannelTree()->findChannel(last); auto channel = this->server->getChannelTree()->findChannel(last);
if(!channel) channel = this->server->getChannelTree()->getDefaultChannel(); if(!channel) channel = this->server->getChannelTree()->getDefaultChannel();
if(this->getClientId() == 0 || this->server->find_client_by_id(this->getClientId()) != _this.lock()) { if(this->getClientId() == 0 || this->server->find_client_by_id(this->getClientId()) != this->ref()) {
this->server->registerClient(_this.lock()); this->server->registerClient(this->ref());
} }
{ {
unique_lock server_channel_lock(this->server->channel_tree_lock); unique_lock server_channel_lock(this->server->channel_tree_lock);
@ -190,12 +190,12 @@ void MusicClient::changePlayerState(ReplayState state) {
this->_player_state = state; this->_player_state = state;
this->properties()[property::CLIENT_PLAYER_STATE] = state; this->properties()[property::CLIENT_PLAYER_STATE] = state;
this->properties()[property::CLIENT_FLAG_TALKING] = state == ReplayState::PLAYING; this->properties()[property::CLIENT_FLAG_TALKING] = state == ReplayState::PLAYING;
this->server->notifyClientPropertyUpdates(_this.lock(), deque<property::ClientProperties>{property::CLIENT_PLAYER_STATE}); this->server->notifyClientPropertyUpdates(this->ref(), deque<property::ClientProperties>{property::CLIENT_PLAYER_STATE});
} }
void MusicClient::notifySongChange(const std::shared_ptr<music::SongInfo>& song) { void MusicClient::notifySongChange(const std::shared_ptr<music::SongInfo>& song) {
this->server->forEachClient([&](shared_ptr<ConnectedClient> client) { this->server->forEachClient([&](shared_ptr<ConnectedClient> client) {
client->notifyMusicPlayerSongChange(dynamic_pointer_cast<MusicClient>(_this.lock()), song); client->notifyMusicPlayerSongChange(dynamic_pointer_cast<MusicClient>(this->ref()), song);
}); });
} }

View File

@ -42,11 +42,6 @@ namespace ts::server {
MusicClient(const std::shared_ptr<VirtualServer>&,const std::string&); MusicClient(const std::shared_ptr<VirtualServer>&,const std::string&);
virtual ~MusicClient() override; virtual ~MusicClient() override;
void setSharedLock(const std::shared_ptr<ConnectedClient> &_this){
assert(_this.get() == this);
this->_this = _this;
}
//Basic TeaSpeak stuff //Basic TeaSpeak stuff
void sendCommand(const ts::Command &command, bool low) override; void sendCommand(const ts::Command &command, bool low) override;
void sendCommand(const ts::command_builder &command, bool low) override; void sendCommand(const ts::command_builder &command, bool low) override;

View File

@ -182,7 +182,7 @@ std::shared_ptr<::music::MusicPlayer> MusicClient::current_player() {
} }
void MusicClient::playMusic() { void MusicClient::playMusic() {
auto self = dynamic_pointer_cast<MusicClient>(_this.lock()); auto self = dynamic_pointer_cast<MusicClient>(this->ref());
ts::music::MusicBotManager::tick_music.execute([self]{ ts::music::MusicBotManager::tick_music.execute([self]{
auto playlist = self->playlist(); auto playlist = self->playlist();
if(playlist->properties()[property::PLAYLIST_FLAG_FINISHED].as<bool>()) { if(playlist->properties()[property::PLAYLIST_FLAG_FINISHED].as<bool>()) {
@ -199,7 +199,7 @@ void MusicClient::playMusic() {
} }
void MusicClient::stopMusic() { void MusicClient::stopMusic() {
auto self = dynamic_pointer_cast<MusicClient>(_this.lock()); auto self = dynamic_pointer_cast<MusicClient>(this->ref());
ts::music::MusicBotManager::tick_music.execute([self]{ ts::music::MusicBotManager::tick_music.execute([self]{
auto player = self->current_player(); auto player = self->current_player();
if(player) if(player)
@ -210,7 +210,7 @@ void MusicClient::stopMusic() {
} }
void MusicClient::player_pause() { void MusicClient::player_pause() {
auto self = dynamic_pointer_cast<MusicClient>(_this.lock()); auto self = dynamic_pointer_cast<MusicClient>(this->ref());
ts::music::MusicBotManager::tick_music.execute([self]{ ts::music::MusicBotManager::tick_music.execute([self]{
auto player = self->current_player(); auto player = self->current_player();
if(player) if(player)
@ -311,7 +311,7 @@ void MusicClient::musicEventHandler(const std::weak_ptr<ts::music::PlayableSong>
void MusicClient::volume_modifier(float vol) { void MusicClient::volume_modifier(float vol) {
this->playback.volume_modifier = vol; this->playback.volume_modifier = vol;
this->properties()[property::CLIENT_PLAYER_VOLUME] = this->playback.volume_modifier; this->properties()[property::CLIENT_PLAYER_VOLUME] = this->playback.volume_modifier;
this->server->notifyClientPropertyUpdates(_this.lock(), std::deque<property::ClientProperties>{property::CLIENT_PLAYER_VOLUME}); this->server->notifyClientPropertyUpdates(this->ref(), std::deque<property::ClientProperties>{property::CLIENT_PLAYER_VOLUME});
} }
void MusicClient::schedule_music_tick(const unique_lock<recursive_timed_mutex>& song_lock, const std::shared_ptr<ts::music::PlayableSong> &song, const std::chrono::system_clock::time_point& timepoint, bool ignore_lock) { void MusicClient::schedule_music_tick(const unique_lock<recursive_timed_mutex>& song_lock, const std::shared_ptr<ts::music::PlayableSong> &song, const std::chrono::system_clock::time_point& timepoint, bool ignore_lock) {
@ -384,7 +384,7 @@ void MusicClient::broadcast_music_stop() {
SpeakingClient::VoicePacketFlags flags{}; SpeakingClient::VoicePacketFlags flags{};
for(const auto& cl : this->server->getClientsByChannel<SpeakingClient>(this->currentChannel)) { for(const auto& cl : this->server->getClientsByChannel<SpeakingClient>(this->currentChannel)) {
if(cl->shouldReceiveVoice(_this.lock())) { if(cl->shouldReceiveVoice(this->ref())) {
cl->send_voice_packet(pipes::buffer_view{voice_buffer, voice_header_length}, flags); cl->send_voice_packet(pipes::buffer_view{voice_buffer, voice_header_length}, flags);
} }
} }
@ -445,7 +445,7 @@ void MusicClient::execute_music_tick(const shared_ptr<ts::music::PlayableSong>&
auto buffer = pipes::buffer_view{voice_buffer, voice_header_length + length}; auto buffer = pipes::buffer_view{voice_buffer, voice_header_length + length};
for(const auto& cl : this->server->getClientsByChannel<SpeakingClient>(this->currentChannel)) for(const auto& cl : this->server->getClientsByChannel<SpeakingClient>(this->currentChannel))
if(cl->shouldReceiveVoice(_this.lock())) if(cl->shouldReceiveVoice(this->ref()))
cl->send_voice_packet(buffer, flags); cl->send_voice_packet(buffer, flags);
} }
} else { } else {

View File

@ -57,12 +57,12 @@ QueryClient::QueryClient(QueryServer* handle, int sockfd) : ConnectedClient(hand
this->resetEventMask(); this->resetEventMask();
} }
void QueryClient::initialize_self_reference(const std::shared_ptr<QueryClient> &reference) { void QueryClient::initialize_weak_reference(const std::shared_ptr<ConnectedClient> &self) {
this->_this = reference; ConnectedClient::initialize_weak_reference(self);
this->command_queue = std::make_unique<ServerCommandQueue>( this->command_queue = std::make_unique<ServerCommandQueue>(
serverInstance->server_command_executor(), serverInstance->server_command_executor(),
std::make_unique<QueryClientCommandHandler>(reference) std::make_unique<QueryClientCommandHandler>(dynamic_pointer_cast<QueryClient>(self))
); );
this->event_read = event_new(this->handle->event_io_loop, this->client_file_descriptor, EV_READ | EV_PERSIST, [](int a, short b, void* c){ this->event_read = event_new(this->handle->event_io_loop, this->client_file_descriptor, EV_READ | EV_PERSIST, [](int a, short b, void* c){
@ -94,7 +94,7 @@ void QueryClient::preInitialize() {
this->properties()[property::CLIENT_UNIQUE_IDENTIFIER] = "UnknownQuery"; this->properties()[property::CLIENT_UNIQUE_IDENTIFIER] = "UnknownQuery";
this->properties()[property::CLIENT_NICKNAME] = string() + "ServerQuery#" + this->getLoggingPeerIp() + "/" + to_string(this->getPeerPort()); this->properties()[property::CLIENT_NICKNAME] = string() + "ServerQuery#" + this->getLoggingPeerIp() + "/" + to_string(this->getPeerPort());
DatabaseHelper::assignDatabaseId(this->sql, this->getServerId(), _this.lock()); DatabaseHelper::assignDatabaseId(this->sql, this->getServerId(), this->ref());
if(ts::config::query::sslMode == 0) { if(ts::config::query::sslMode == 0) {
this->connectionType = ConnectionType::PLAIN; this->connectionType = ConnectionType::PLAIN;
@ -154,7 +154,7 @@ void QueryClient::postInitialize() {
} }
} }
this->update_cached_permissions(); this->update_client_needed_permissions();
} }
void QueryClient::send_message(const std::string_view& message) { void QueryClient::send_message(const std::string_view& message) {
@ -622,7 +622,7 @@ void QueryClient::disconnect_from_virtual_server(const std::string& reason) {
old_server->client_move(this->ref(), nullptr, nullptr, "", ViewReasonId::VREASON_USER_ACTION, false, tree_lock); old_server->client_move(this->ref(), nullptr, nullptr, "", ViewReasonId::VREASON_USER_ACTION, false, tree_lock);
} }
old_server->unregisterClient(_this.lock(), reason, tree_lock); old_server->unregisterClient(this->ref(), reason, tree_lock);
} }
{ {

View File

@ -60,7 +60,7 @@ namespace ts::server {
inline std::shared_ptr<QueryAccount> getQueryAccount() { return this->query_account; } inline std::shared_ptr<QueryAccount> getQueryAccount() { return this->query_account; }
protected: protected:
void initialize_self_reference(const std::shared_ptr<QueryClient> &reference); void initialize_weak_reference(const std::shared_ptr<ConnectedClient> &) override;
void preInitialize(); void preInitialize();
void initializeSSL(); void initializeSSL();

View File

@ -245,7 +245,7 @@ command_result QueryClient::handleCommandLogin(Command& cmd) {
unique_lock tree_lock(this->server->channel_tree_lock); unique_lock tree_lock(this->server->channel_tree_lock);
if(joined_channel) if(joined_channel)
this->server->client_move(this->ref(), nullptr, nullptr, "", ViewReasonId::VREASON_USER_ACTION, false, tree_lock); this->server->client_move(this->ref(), nullptr, nullptr, "", ViewReasonId::VREASON_USER_ACTION, false, tree_lock);
this->server->unregisterClient(_this.lock(), "login", tree_lock); this->server->unregisterClient(this->ref(), "login", tree_lock);
} }
this->server->groups->disableCache(this->getClientDatabaseId()); this->server->groups->disableCache(this->getClientDatabaseId());
} else serverInstance->getGroupManager()->disableCache(this->getClientDatabaseId()); } else serverInstance->getGroupManager()->disableCache(this->getClientDatabaseId());
@ -266,15 +266,15 @@ command_result QueryClient::handleCommandLogin(Command& cmd) {
} }
this->server = target_server; this->server = target_server;
DatabaseHelper::assignDatabaseId(this->sql, static_cast<ServerId>(target_server ? target_server->getServerId() : 0), _this.lock()); DatabaseHelper::assignDatabaseId(this->sql, static_cast<ServerId>(target_server ? target_server->getServerId() : 0), this->ref());
if(target_server) { if(target_server) {
target_server->groups->enableCache(this->getClientDatabaseId()); target_server->groups->enableCache(this->getClientDatabaseId());
target_server->registerClient(_this.lock()); target_server->registerClient(this->ref());
{ {
shared_lock server_tree_lock(target_server->channel_tree_lock); shared_lock server_tree_lock(target_server->channel_tree_lock);
if(joined_channel) /* needs only notify if we were already on that server within a channel */ if(joined_channel) /* needs only notify if we were already on that server within a channel */
target_server->notifyClientPropertyUpdates(_this.lock(), deque<property::ClientProperties>{property::CLIENT_NICKNAME, property::CLIENT_UNIQUE_IDENTIFIER}); target_server->notifyClientPropertyUpdates(this->ref(), deque<property::ClientProperties>{property::CLIENT_NICKNAME, property::CLIENT_UNIQUE_IDENTIFIER});
unique_lock client_tree_lock(this->channel_lock); unique_lock client_tree_lock(this->channel_lock);
this->channels->reset(); this->channels->reset();
@ -289,10 +289,10 @@ command_result QueryClient::handleCommandLogin(Command& cmd) {
} else if(!permission::v2::permission_granted(1, this->calculate_permission(permission::b_virtualserver_select_godmode, 1))) } else if(!permission::v2::permission_granted(1, this->calculate_permission(permission::b_virtualserver_select_godmode, 1)))
this->server->assignDefaultChannel(this->ref(), true); this->server->assignDefaultChannel(this->ref(), true);
else else
this->update_cached_permissions(); this->update_client_needed_permissions();
} else { } else {
serverInstance->getGroupManager()->enableCache(this->getClientDatabaseId()); serverInstance->getGroupManager()->enableCache(this->getClientDatabaseId());
this->update_cached_permissions(); this->update_client_needed_permissions();
} }
this->properties()[property::CLIENT_TOTALCONNECTIONS]++; this->properties()[property::CLIENT_TOTALCONNECTIONS]++;
@ -314,14 +314,14 @@ command_result QueryClient::handleCommandLogout(Command &) {
unique_lock tree_lock(this->server->channel_tree_lock); unique_lock tree_lock(this->server->channel_tree_lock);
if(joined) if(joined)
this->server->client_move(this->ref(), nullptr, nullptr, "", ViewReasonId::VREASON_USER_ACTION, false, tree_lock); this->server->client_move(this->ref(), nullptr, nullptr, "", ViewReasonId::VREASON_USER_ACTION, false, tree_lock);
this->server->unregisterClient(_this.lock(), "logout", tree_lock); this->server->unregisterClient(this->ref(), "logout", tree_lock);
} }
this->server->groups->disableCache(this->getClientDatabaseId()); this->server->groups->disableCache(this->getClientDatabaseId());
} else serverInstance->getGroupManager()->disableCache(this->getClientDatabaseId()); } else serverInstance->getGroupManager()->disableCache(this->getClientDatabaseId());
this->properties()[property::CLIENT_UNIQUE_IDENTIFIER] = "UnknownQuery"; //TODO load from table this->properties()[property::CLIENT_UNIQUE_IDENTIFIER] = "UnknownQuery"; //TODO load from table
this->properties()[property::CLIENT_NICKNAME] = string() + "ServerQuery#" + this->getLoggingPeerIp() + "/" + to_string(ntohs(this->getPeerPort())); this->properties()[property::CLIENT_NICKNAME] = string() + "ServerQuery#" + this->getLoggingPeerIp() + "/" + to_string(ntohs(this->getPeerPort()));
DatabaseHelper::assignDatabaseId(this->sql, static_cast<ServerId>(this->server ? this->server->getServerId() : 0), _this.lock()); DatabaseHelper::assignDatabaseId(this->sql, static_cast<ServerId>(this->server ? this->server->getServerId() : 0), this->ref());
if(this->server){ if(this->server){
this->server->groups->enableCache(this->getClientDatabaseId()); this->server->groups->enableCache(this->getClientDatabaseId());
@ -342,11 +342,11 @@ command_result QueryClient::handleCommandLogout(Command &) {
} else if(!permission::v2::permission_granted(1, this->calculate_permission(permission::b_virtualserver_select_godmode, 1))) { } else if(!permission::v2::permission_granted(1, this->calculate_permission(permission::b_virtualserver_select_godmode, 1))) {
this->server->assignDefaultChannel(this->ref(), true); this->server->assignDefaultChannel(this->ref(), true);
} else { } else {
this->update_cached_permissions(); this->update_client_needed_permissions();
} }
} else { } else {
serverInstance->getGroupManager()->enableCache(this->getClientDatabaseId()); serverInstance->getGroupManager()->enableCache(this->getClientDatabaseId());
this->update_cached_permissions(); this->update_client_needed_permissions();
} }
this->updateChannelClientProperties(true, true); this->updateChannelClientProperties(true, true);
@ -397,10 +397,10 @@ command_result QueryClient::handleCommandServerSelect(Command &cmd) {
if(cmd[0].has("client_nickname")) if(cmd[0].has("client_nickname"))
this->properties()[property::CLIENT_NICKNAME] = cmd["client_nickname"].string(); this->properties()[property::CLIENT_NICKNAME] = cmd["client_nickname"].string();
DatabaseHelper::assignDatabaseId(this->sql, static_cast<ServerId>(this->server ? this->server->getServerId() : 0), _this.lock()); DatabaseHelper::assignDatabaseId(this->sql, static_cast<ServerId>(this->server ? this->server->getServerId() : 0), this->ref());
if(this->server) { if(this->server) {
this->server->groups->enableCache(this->getClientDatabaseId()); this->server->groups->enableCache(this->getClientDatabaseId());
this->server->registerClient(_this.lock()); this->server->registerClient(this->ref());
{ {
shared_lock server_channel_lock(target->channel_tree_lock); shared_lock server_channel_lock(target->channel_tree_lock);
@ -415,10 +415,10 @@ command_result QueryClient::handleCommandServerSelect(Command &cmd) {
if(!negated_enforce_join) if(!negated_enforce_join)
this->server->assignDefaultChannel(this->ref(), true); this->server->assignDefaultChannel(this->ref(), true);
else else
this->update_cached_permissions(); this->update_client_needed_permissions();
} else { } else {
serverInstance->getGroupManager()->enableCache(this->getClientDatabaseId()); serverInstance->getGroupManager()->enableCache(this->getClientDatabaseId());
this->update_cached_permissions(); this->update_client_needed_permissions();
} }
this->updateChannelClientProperties(true, true); this->updateChannelClientProperties(true, true);
serverInstance->action_logger()->query_logger.log_query_switch(std::dynamic_pointer_cast<QueryClient>(this->ref()), this->properties()[property::CLIENT_LOGIN_NAME].value(), old_server_id, this->getServerId()); serverInstance->action_logger()->query_logger.log_query_switch(std::dynamic_pointer_cast<QueryClient>(this->ref()), this->properties()[property::CLIENT_LOGIN_NAME].value(), old_server_id, this->getServerId());

View File

@ -142,11 +142,11 @@ bool VoiceClient::disconnect(ts::ViewReasonId reason_id, const std::string &reas
threads::MutexLock lock(this->command_lock); threads::MutexLock lock(this->command_lock);
auto server_channel = dynamic_pointer_cast<ServerChannel>(this->currentChannel); auto server_channel = dynamic_pointer_cast<ServerChannel>(this->currentChannel);
if(server_channel) if(server_channel)
server_channel->unregister_client(_this.lock()); server_channel->unregister_client(this->ref());
this->currentChannel = nullptr; this->currentChannel = nullptr;
} }
auto weak_self = this->_this; auto weak_self = this->weak_ref();
this->sendCommand0(cmd.build(), false, std::make_unique<std::function<void(bool)>>([weak_self](bool success) { this->sendCommand0(cmd.build(), false, std::make_unique<std::function<void(bool)>>([weak_self](bool success) {
auto self = weak_self.lock(); auto self = weak_self.lock();
if(!self) { if(!self) {
@ -170,7 +170,7 @@ bool VoiceClient::disconnect(ts::ViewReasonId reason_id, const std::string &reas
} }
bool VoiceClient::close_connection(const system_clock::time_point &timeout) { bool VoiceClient::close_connection(const system_clock::time_point &timeout) {
auto self_lock = dynamic_pointer_cast<VoiceClient>(_this.lock()); auto self_lock = dynamic_pointer_cast<VoiceClient>(this->ref());
assert(self_lock); //Should never happen! assert(self_lock); //Should never happen!
bool flush = timeout.time_since_epoch().count() > 0; bool flush = timeout.time_since_epoch().count() > 0;
@ -240,7 +240,7 @@ bool VoiceClient::close_connection(const system_clock::time_point &timeout) {
} }
void VoiceClient::finalDisconnect() { void VoiceClient::finalDisconnect() {
auto ownLock = dynamic_pointer_cast<VoiceClient>(_this.lock()); auto ownLock = dynamic_pointer_cast<VoiceClient>(this->ref());
assert(ownLock); assert(ownLock);
lock_guard disconnect_lock_final(this->finalDisconnectLock); lock_guard disconnect_lock_final(this->finalDisconnectLock);

View File

@ -72,7 +72,7 @@ std::string VoiceClientConnection::log_prefix() {
void VoiceClientConnection::triggerWrite() { void VoiceClientConnection::triggerWrite() {
if(this->current_client->voice_server) { if(this->current_client->voice_server) {
this->current_client->voice_server->triggerWrite(dynamic_pointer_cast<VoiceClient>(this->current_client->_this.lock())); this->current_client->voice_server->triggerWrite(dynamic_pointer_cast<VoiceClient>(this->current_client->ref()));
} }
} }

View File

@ -11,7 +11,7 @@ using namespace ts::server;
using namespace ts::protocol; using namespace ts::protocol;
void WebClient::handleMessageWrite(int fd, short, void *) { void WebClient::handleMessageWrite(int fd, short, void *) {
auto self_lock = _this.lock(); auto self_lock = this->ref();
unique_lock buffer_lock(this->queue_mutex); unique_lock buffer_lock(this->queue_mutex);
if(this->queue_write.empty()) return; if(this->queue_write.empty()) return;
@ -62,7 +62,7 @@ void WebClient::handleMessageWrite(int fd, short, void *) {
} }
void WebClient::handleMessageRead(int fd, short, void *) { void WebClient::handleMessageRead(int fd, short, void *) {
auto self_lock = _this.lock(); auto self_lock = this->ref();
size_t buffer_length = 1024 * 4; size_t buffer_length = 1024 * 4;
uint8_t buffer[buffer_length]; uint8_t buffer[buffer_length];

View File

@ -207,7 +207,7 @@ void WebClient::sendCommand(const ts::command_builder &command, bool low) {
bool WebClient::close_connection(const std::chrono::system_clock::time_point& timeout) { bool WebClient::close_connection(const std::chrono::system_clock::time_point& timeout) {
bool flushing = timeout.time_since_epoch().count() > 0; bool flushing = timeout.time_since_epoch().count() > 0;
auto self_lock = dynamic_pointer_cast<WebClient>(_this.lock()); auto self_lock = dynamic_pointer_cast<WebClient>(this->ref());
auto server_lock = this->server; auto server_lock = this->server;
assert(self_lock); assert(self_lock);
@ -225,7 +225,7 @@ bool WebClient::close_connection(const std::chrono::system_clock::time_point& ti
if(this->server){ if(this->server){
{ {
unique_lock server_channel_lock(this->server->channel_tree_lock); unique_lock server_channel_lock(this->server->channel_tree_lock);
this->server->unregisterClient(_this.lock(), "disconnected", server_channel_lock); this->server->unregisterClient(this->ref(), "disconnected", server_channel_lock);
} }
this->server->groups->disableCache(this->getClientDatabaseId()); this->server->groups->disableCache(this->getClientDatabaseId());
//this->server = nullptr; //this->server = nullptr;
@ -395,7 +395,7 @@ void WebClient::onWSMessage(const pipes::WSMessage &message) {
/* called while helding close_lock*/ /* called while helding close_lock*/
void WebClient::disconnectFinal() { void WebClient::disconnectFinal() {
auto self_lock = this->_this.lock(); auto self_lock = this->ref();
{ {
/* waiting to finish all executes */ /* waiting to finish all executes */
lock_guard lock(this->execute_mutex); lock_guard lock(this->execute_mutex);
@ -546,7 +546,7 @@ bool WebClient::disconnect(const std::string &reason) {
this->notifyClientLeftViewKicked(this->ref(), nullptr, reason, this->server->serverRoot, false); this->notifyClientLeftViewKicked(this->ref(), nullptr, reason, this->server->serverRoot, false);
} }
this->server->client_move(this->ref(), nullptr, this->server->serverRoot, reason, ViewReasonId::VREASON_SERVER_KICK, false, server_channel_lock); this->server->client_move(this->ref(), nullptr, this->server->serverRoot, reason, ViewReasonId::VREASON_SERVER_KICK, false, server_channel_lock);
this->server->unregisterClient(_this.lock(), "disconnected", server_channel_lock); this->server->unregisterClient(this->ref(), "disconnected", server_channel_lock);
} }
return this->close_connection(system_clock::now() + seconds(1)); return this->close_connection(system_clock::now() + seconds(1));
} }

View File

@ -38,8 +38,6 @@ namespace ts::server {
protected: protected:
void tick_server(const std::chrono::system_clock::time_point&) override; /* Every 500ms */ void tick_server(const std::chrono::system_clock::time_point&) override; /* Every 500ms */
void applySelfLock(const std::shared_ptr<WebClient> &cl){ _this = cl; }
private: private:
WebControlServer* handle; WebControlServer* handle;

View File

@ -77,7 +77,7 @@ std::shared_ptr<server::MusicClient> MusicBotManager::createBot(ClientDbId owner
auto uid = base64::encode(digest::sha1("music#" + rnd_string(15))); auto uid = base64::encode(digest::sha1("music#" + rnd_string(15)));
auto musicBot = make_shared<MusicClient>(this->handle.lock(), uid); auto musicBot = make_shared<MusicClient>(this->handle.lock(), uid);
musicBot->_this = musicBot; musicBot->initialize_weak_reference(musicBot);
musicBot->manager = this; musicBot->manager = this;
musicBot->server = handle; musicBot->server = handle;
DatabaseHelper::assignDatabaseId(handle->getSql(), handle->getServerId(), musicBot); DatabaseHelper::assignDatabaseId(handle->getSql(), handle->getServerId(), musicBot);
@ -233,7 +233,7 @@ int MusicBotManager::sqlCreateMusicBot(int length, std::string* values, std::str
if(botId == 0 || uid.empty()) return 0; if(botId == 0 || uid.empty()) return 0;
auto musicBot = make_shared<MusicClient>(handle, uid); auto musicBot = make_shared<MusicClient>(handle, uid);
musicBot->_this = musicBot; musicBot->initialize_weak_reference(musicBot);
musicBot->manager = this; musicBot->manager = this;
DatabaseHelper::assignDatabaseId(handle->getSql(), handle->getServerId(), musicBot); DatabaseHelper::assignDatabaseId(handle->getSql(), handle->getServerId(), musicBot);
musicBot->properties()[property::CLIENT_OWNER] = owner; musicBot->properties()[property::CLIENT_OWNER] = owner;

View File

@ -295,7 +295,7 @@ shared_ptr<VoiceClient> POWHandler::register_verified_client(const std::shared_p
if(!voice_client) { if(!voice_client) {
voice_client = std::make_shared<VoiceClient>(this->server->get_server()->getVoiceServer(), &client->address); voice_client = std::make_shared<VoiceClient>(this->server->get_server()->getVoiceServer(), &client->address);
voice_client->_this = voice_client; voice_client->initialize_weak_reference(voice_client);
voice_client->initialize(); voice_client->initialize();
voice_client->connection->socket_id_ = client->socket; voice_client->connection->socket_id_ = client->socket;

View File

@ -435,7 +435,7 @@ void QueryServer::on_client_receive(int server_file_descriptor, short, void *) {
auto client = std::make_shared<QueryClient>(this, client_file_descriptor); auto client = std::make_shared<QueryClient>(this, client_file_descriptor);
memcpy(&client->remote_address, &remote_address, sizeof(remote_address)); memcpy(&client->remote_address, &remote_address, sizeof(remote_address));
client->initialize_self_reference(client); client->initialize_weak_reference(client);
{ {
lock_guard lock(this->connected_clients_mutex); lock_guard lock(this->connected_clients_mutex);

View File

@ -172,7 +172,7 @@ void WebControlServer::on_client_receive(int _server_file_descriptor, short ev,
shared_ptr<WebClient> client = std::make_shared<WebClient>(this, file_descriptor); shared_ptr<WebClient> client = std::make_shared<WebClient>(this, file_descriptor);
memcpy(&client->remote_address, &remote_address, sizeof(remote_address)); memcpy(&client->remote_address, &remote_address, sizeof(remote_address));
client->applySelfLock(client); client->initialize_weak_reference(client);
client->initialize(); client->initialize();
this->clientLock.lock(); this->clientLock.lock();