Using this->ref()
and this->weak_ref()
instead of direct member access
This commit is contained in:
parent
e9445d6568
commit
71b2d734bd
@ -13,12 +13,10 @@
|
||||
#include <ThreadPool/Timer.h>
|
||||
#include "ShutdownHelper.h"
|
||||
#include <sys/utsname.h>
|
||||
#include "build.h"
|
||||
#include <misc/digest.h>
|
||||
#include <misc/base64.h>
|
||||
#include <misc/hex.h>
|
||||
#include <misc/rnd.h>
|
||||
#include <misc/strobf.h>
|
||||
#include <protocol/buffers.h>
|
||||
|
||||
#ifndef _POSIX_SOURCE
|
||||
@ -40,6 +38,21 @@ using namespace ts::server;
|
||||
extern bool mainThreadActive;
|
||||
InstanceHandler::InstanceHandler(SqlDataManager *sql) : sql(sql) {
|
||||
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->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);
|
||||
static_pointer_cast<ts::server::InternalClient>(globalServerAdmin)->setSharedLock(globalServerAdmin);
|
||||
globalServerAdmin->initialize_weak_reference(this->globalServerAdmin);
|
||||
ts::server::DatabaseHelper::assignDatabaseId(this->getSql(), 0, globalServerAdmin);
|
||||
|
||||
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());
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "manager/SqlDataManager.h"
|
||||
#include "lincense/TeamSpeakLicense.h"
|
||||
#include "server/WebIoManager.h"
|
||||
#include <misc/task_executor.h>
|
||||
|
||||
namespace ts {
|
||||
namespace weblist {
|
||||
@ -75,6 +76,8 @@ namespace ts {
|
||||
|
||||
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<threads::Scheduler> scheduler(){ return this->tick_manager; }
|
||||
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<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::PermissionType,
|
||||
@ -151,6 +154,8 @@ namespace ts {
|
||||
std::shared_ptr<stats::ConnectionStatistics> statistics = 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<TeamSpeakLicense> teamspeak_license = nullptr;
|
||||
|
||||
|
@ -532,7 +532,7 @@ void VirtualServer::client_move(
|
||||
}
|
||||
|
||||
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);
|
||||
TIMING_STEP(timings, "perm gr upd");
|
||||
|
||||
|
@ -249,14 +249,15 @@ bool VirtualServer::initialize(bool test_properties) {
|
||||
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);
|
||||
static_pointer_cast<InternalClient>(this->serverRoot)->setSharedLock(this->serverRoot);
|
||||
this->serverRoot->initialize_weak_reference(this->serverRoot);
|
||||
|
||||
this->properties().registerNotifyHandler([&](Property& property) {
|
||||
if(property.type() == property::VIRTUALSERVER_NAME) static_pointer_cast<InternalClient>(this->serverRoot)->properties()[property::CLIENT_NICKNAME] = property.as<string>();
|
||||
});
|
||||
this->serverRoot->server = nullptr;
|
||||
|
||||
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);
|
||||
this->serverAdmin->server = nullptr;
|
||||
this->registerInternalClient(this->serverAdmin); /* lets assign server id 0 */
|
||||
@ -1212,7 +1213,7 @@ bool VirtualServer::resetPermissions(std::string& token) {
|
||||
client->notifyChannelGroupList();
|
||||
}
|
||||
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->updateChannelClientProperties(true, true);
|
||||
|
@ -36,6 +36,19 @@ ConnectedClient::~ConnectedClient() {
|
||||
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() {
|
||||
auto result = DataClient::loadDataForCurrentServer();
|
||||
if(!result) {
|
||||
@ -177,7 +190,7 @@ void ConnectedClient::updateChannelClientProperties(bool lock_channel_tree, bool
|
||||
|
||||
block_flood = !permission::v2::permission_granted(1, permission_ignore_antiflood);
|
||||
if(server_ref)
|
||||
server_ref->notifyClientPropertyUpdates(_this.lock(), notifyList, notify_self);
|
||||
server_ref->notifyClientPropertyUpdates(this->ref(), notifyList, notify_self);
|
||||
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) {
|
||||
@ -570,8 +583,8 @@ bool ConnectedClient::notifyClientNeededPermissions() {
|
||||
Command cmd("notifyclientneededpermissions");
|
||||
int index = 0;
|
||||
|
||||
unique_lock cache_lock(this->cached_permissions_lock);
|
||||
auto permissions = this->cached_permissions;
|
||||
unique_lock cache_lock(this->client_needed_permissions_lock);
|
||||
auto permissions = this->client_needed_permissions;
|
||||
cache_lock.unlock();
|
||||
|
||||
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!");
|
||||
|
||||
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);
|
||||
//this->notifyClientEnterView(_this.lock(), nullptr, "", this->currentChannel, ViewReasonId::VREASON_SYSTEM, nullptr, false); //Notify self after path is send
|
||||
this->sendCommand(Command("channellistfinished"));
|
||||
@ -923,22 +936,22 @@ std::shared_ptr<BanRecord> ConnectedClient::resolveActiveBan(const std::string&
|
||||
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 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};
|
||||
this->cached_permissions = values;
|
||||
std::sort(this->cached_permissions.begin(), this->cached_permissions.end(), [](const auto& a, const auto& b) { return a.first < b.first; });
|
||||
auto old_cached_permissions{this->client_needed_permissions};
|
||||
this->client_needed_permissions = values;
|
||||
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;
|
||||
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) {
|
||||
updated = true;
|
||||
break;
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <misc/net.h>
|
||||
#include <cstdint>
|
||||
#include <src/music/PlayablePlaylist.h>
|
||||
#include <misc/task_executor.h>
|
||||
#include "music/Song.h"
|
||||
#include "../channel/ClientChannelView.h"
|
||||
#include "DataClient.h"
|
||||
@ -273,7 +274,8 @@ namespace ts {
|
||||
|
||||
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; }
|
||||
|
||||
@ -284,19 +286,7 @@ namespace ts {
|
||||
/*
|
||||
* permission stuff
|
||||
*/
|
||||
/*
|
||||
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();
|
||||
bool update_client_needed_permissions();
|
||||
|
||||
std::shared_lock<std::shared_mutex> require_connected_state(bool blocking = false) {
|
||||
//try_to_lock_t
|
||||
@ -373,14 +363,17 @@ namespace ts {
|
||||
std::shared_ptr<ClientChannelView> channels;
|
||||
std::shared_mutex channel_lock;
|
||||
|
||||
std::mutex cached_permissions_lock;
|
||||
std::vector<std::pair<permission::PermissionType, permission::v2::PermissionFlaggedValue>> cached_permissions; /* contains all needed permissions which are set */
|
||||
/* The permission overview which the client itself has (for basic client actions ) */
|
||||
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_ignore_view{0, false};
|
||||
permission::v2::PermissionFlaggedValue cpmerission_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;
|
||||
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>&);
|
||||
@ -389,6 +382,8 @@ namespace ts {
|
||||
std::weak_ptr<MusicClient> subscribed_bot;
|
||||
std::weak_ptr<ts::music::Playlist> subscribed_playlist_{};
|
||||
|
||||
multi_shot_task task_update_needed_permissions{};
|
||||
|
||||
bool loadDataForCurrentServer() override;
|
||||
|
||||
virtual void tick_server(const std::chrono::system_clock::time_point &time);
|
||||
|
@ -601,34 +601,34 @@ bool ConnectedClient::handle_text_command(
|
||||
return true;
|
||||
} else if (command == "dummy") {
|
||||
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"));
|
||||
return true;
|
||||
} else if(TARG(0, "rd")) {
|
||||
send_message(_this.lock(), "Sending command rd");
|
||||
send_message(this->ref(), "Sending command rd");
|
||||
Command cmd("rd");
|
||||
cmd["msg"] = "Hello world";
|
||||
this->sendCommand(cmd);
|
||||
return true;
|
||||
} 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");
|
||||
cmd["status"] = 1797;
|
||||
this->sendCommand(cmd);
|
||||
return true;
|
||||
}
|
||||
|
||||
send_message(_this.lock(), "Invalid dummy command!");
|
||||
send_message(_this.lock(), "- timerevent");
|
||||
send_message(_this.lock(), "- connectfailed");
|
||||
send_message(_this.lock(), "- rd");
|
||||
send_message(this->ref(), "Invalid dummy command!");
|
||||
send_message(this->ref(), "- timerevent");
|
||||
send_message(this->ref(), "- connectfailed");
|
||||
send_message(this->ref(), "- rd");
|
||||
return true;
|
||||
} else if(command == "protocol") {
|
||||
if(TARG(0, "generation")) {
|
||||
auto vc = dynamic_pointer_cast<VoiceClient>(_this.lock());
|
||||
auto vc = dynamic_pointer_cast<VoiceClient>(this->ref());
|
||||
if(!vc) return false;
|
||||
|
||||
send_message(_this.lock(), "Packet generations:");
|
||||
send_message(this->ref(), "Packet generations:");
|
||||
/*
|
||||
for(const auto& type : {
|
||||
protocol::PacketTypeInfo::Command,
|
||||
@ -644,20 +644,20 @@ bool ConnectedClient::handle_text_command(
|
||||
//auto gen = vc->getConnection()->getPacketIdManager().generationId(type);
|
||||
//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.lock(), " IN " + type.name() + " => generation: " + to_string(genestis[type.type()].generation()) + " id: " + to_string(genestis[type.type()].current_packet_id()));
|
||||
//send_message(this->ref(), " OUT " + type.name() + " => generation: " + to_string(gen) + " id: " + to_string(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;
|
||||
} 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;
|
||||
|
||||
auto& ack = vc->connection->packet_encoder().acknowledge_manager();
|
||||
send_message(_this.lock(), "Command retransmission values:");
|
||||
send_message(_this.lock(), " RTO : " + std::to_string(ack.current_rto()));
|
||||
send_message(_this.lock(), " RTTVAR: " + std::to_string(ack.current_rttvar()));
|
||||
send_message(_this.lock(), " SRTT : " + std::to_string(ack.current_srtt()));
|
||||
send_message(this->ref(), "Command retransmission values:");
|
||||
send_message(this->ref(), " RTO : " + std::to_string(ack.current_rto()));
|
||||
send_message(this->ref(), " RTTVAR: " + std::to_string(ack.current_rttvar()));
|
||||
send_message(this->ref(), " SRTT : " + std::to_string(ack.current_srtt()));
|
||||
return true;
|
||||
} else if(TARG(0, "sgeneration")) {
|
||||
TLEN(4);
|
||||
@ -667,24 +667,24 @@ bool ConnectedClient::handle_text_command(
|
||||
auto generation = stol(arguments[2]);
|
||||
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;
|
||||
|
||||
/*
|
||||
auto& genestis = vc->getConnection()->get_incoming_generation_estimators();
|
||||
if(type >= genestis.size()) {
|
||||
send_message(_this.lock(), "Invalid type");
|
||||
send_message(this->ref(), "Invalid type");
|
||||
return true;
|
||||
}
|
||||
genestis[type].set_last_state(pid, generation);
|
||||
*/
|
||||
} catch(std::exception& ex) {
|
||||
send_message(_this.lock(), "Failed to parse argument");
|
||||
send_message(this->ref(), "Failed to parse argument");
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
} 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;
|
||||
|
||||
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));
|
||||
return true;
|
||||
} 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;
|
||||
|
||||
send_message(_this.lock(), "You'll timeout");
|
||||
send_message(this->ref(), "You'll timeout");
|
||||
Command cmd("notifyclientupdated");
|
||||
vc->sendCommand(cmd);
|
||||
return true;
|
||||
} 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;
|
||||
|
||||
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();
|
||||
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;
|
||||
} else if(TARG(0, "fb")) {
|
||||
this->increaseFloodPoints(0xFF8F);
|
||||
send_message(_this.lock(), "Done :)");
|
||||
send_message(this->ref(), "Done :)");
|
||||
return true;
|
||||
} 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"});
|
||||
return true;
|
||||
}
|
||||
send_message(_this.lock(), "Invalid protocol command!");
|
||||
send_message(_this.lock(), "- generation");
|
||||
send_message(_this.lock(), "- disconnect");
|
||||
send_message(_this.lock(), "- resetip");
|
||||
send_message(_this.lock(), "- fb");
|
||||
send_message(this->ref(), "Invalid protocol command!");
|
||||
send_message(this->ref(), "- generation");
|
||||
send_message(this->ref(), "- disconnect");
|
||||
send_message(this->ref(), "- resetip");
|
||||
send_message(this->ref(), "- fb");
|
||||
return true;
|
||||
} else if (command == "sleep") {
|
||||
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;
|
||||
}
|
||||
|
||||
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]));
|
||||
threads::self::sleep_until(end);
|
||||
send_message(_this.lock(), "Done!");
|
||||
send_message(this->ref(), "Done!");
|
||||
return true;
|
||||
} else if(command == "conversation") {
|
||||
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");
|
||||
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 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) {
|
||||
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;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ bool InternalClient::close_connection(const std::chrono::system_clock::time_poin
|
||||
logError(this->getServerId(), "Internal client is force to disconnect?");
|
||||
|
||||
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;
|
||||
return true;
|
||||
}
|
||||
|
@ -9,9 +9,8 @@ namespace ts::server {
|
||||
InternalClient(sql::SqlManager*, const std::shared_ptr<VirtualServer>&, std::string, bool);
|
||||
~InternalClient();
|
||||
|
||||
void setSharedLock(const std::shared_ptr<ConnectedClient>& _this){
|
||||
assert(_this.get() == this);
|
||||
this->_this = _this;
|
||||
void initialize_weak_reference(const std::shared_ptr<ConnectedClient> &client) override {
|
||||
ConnectedClient::initialize_weak_reference(client);
|
||||
}
|
||||
|
||||
void sendCommand(const ts::Command &command, bool low) override;
|
||||
|
@ -117,7 +117,7 @@ command_result SpeakingClient::handleCommandClientInit(Command& cmd) {
|
||||
}
|
||||
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!"};
|
||||
}
|
||||
|
||||
@ -380,7 +380,7 @@ command_result SpeakingClient::handleCommandClientInit(Command& cmd) {
|
||||
}
|
||||
|
||||
this->postCommandHandler.emplace_back([&](){
|
||||
auto self = dynamic_pointer_cast<SpeakingClient>(_this.lock());
|
||||
auto self = dynamic_pointer_cast<SpeakingClient>(this->ref());
|
||||
std::thread([self](){
|
||||
if(self->state != ConnectionState::INIT_HIGH) return;
|
||||
try {
|
||||
@ -411,7 +411,7 @@ void SpeakingClient::processJoin() {
|
||||
}
|
||||
|
||||
TIMING_STEP(timings, "setup ");
|
||||
ref_server->registerClient(_this.lock());
|
||||
ref_server->registerClient(this->ref());
|
||||
{
|
||||
if(this->rtc_client_id) {
|
||||
/* in case of client reconnect */
|
||||
@ -438,7 +438,7 @@ void SpeakingClient::processJoin() {
|
||||
TIMING_STEP(timings, "server reg ");
|
||||
ref_server->getGroupManager()->cleanupAssignments(this->getClientDatabaseId());
|
||||
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 ");
|
||||
|
||||
this->properties()[property::CLIENT_COUNTRY] = config::geo::countryFlag;
|
||||
@ -537,7 +537,7 @@ void SpeakingClient::processJoin() {
|
||||
}
|
||||
|
||||
void SpeakingClient::processLeave() {
|
||||
auto ownLock = _this.lock();
|
||||
auto ownLock = this->ref();
|
||||
auto server = this->getServer();
|
||||
|
||||
auto channel = this->currentChannel;
|
||||
|
@ -412,7 +412,7 @@ command_result ConnectedClient::handleCommandChannelGroupDel(Command &cmd) {
|
||||
if (this->server) {
|
||||
this->server->forEachClient([&](shared_ptr<ConnectedClient> cl) {
|
||||
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->notifyChannelGroupList();
|
||||
@ -559,7 +559,7 @@ command_result ConnectedClient::handleCommandChannelGroupAddPerm(Command &cmd) {
|
||||
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! */
|
||||
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->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) {
|
||||
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->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->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) {
|
||||
const auto self_lock = _this.lock();
|
||||
const auto self_lock = this->ref();
|
||||
|
||||
GroupId adminGroup = this->server->properties()[property::VIRTUALSERVER_DEFAULT_CHANNEL_ADMIN_GROUP];
|
||||
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());
|
||||
break;
|
||||
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;
|
||||
case ClientChannelView::REORDER:
|
||||
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);
|
||||
if (!onlineClients.empty()) {
|
||||
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 */
|
||||
|
||||
if (elm->currentChannel == channel) {
|
||||
@ -2423,7 +2423,7 @@ command_result ConnectedClient::handleCommandChannelClientAddPerm(Command &cmd)
|
||||
auto onlineClients = this->server->findClientsByCldbId(cldbid);
|
||||
if (!onlineClients.empty())
|
||||
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 */
|
||||
|
||||
if (elm->currentChannel == channel) {
|
||||
|
@ -258,7 +258,7 @@ command_result ConnectedClient::handleCommandClientMove(Command &cmd) {
|
||||
this->server->client_move(
|
||||
client.client,
|
||||
channel,
|
||||
client.client == this ? nullptr : _this.lock(),
|
||||
client.client == this ? nullptr : this->ref(),
|
||||
"",
|
||||
client.client == this ? ViewReasonId::VREASON_USER_ACTION : ViewReasonId::VREASON_MOVED,
|
||||
true,
|
||||
@ -334,7 +334,7 @@ command_result ConnectedClient::handleCommandClientPoke(Command &cmd) {
|
||||
return command_result{error::parameter_invalid_size, "msg"};
|
||||
|
||||
for(auto& client : clients)
|
||||
client->notifyClientPoke(_this.lock(), message);
|
||||
client->notifyClientPoke(this->ref(), message);
|
||||
|
||||
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>())};
|
||||
if (!client) return command_result{error::client_invalid_id};
|
||||
|
||||
client->notifyClientChatComposing(_this.lock());
|
||||
client->notifyClientChatComposing(this->ref());
|
||||
return command_result{error::ok};
|
||||
}
|
||||
|
||||
@ -369,7 +369,7 @@ command_result ConnectedClient::handleCommandClientChatClosed(Command &cmd) {
|
||||
return weak.lock().get() == this;
|
||||
}), client->open_private_conversations.end());
|
||||
}
|
||||
client->notifyClientChatClosed(_this.lock());
|
||||
client->notifyClientChatClosed(this->ref());
|
||||
return command_result{error::ok};
|
||||
}
|
||||
|
||||
@ -719,7 +719,7 @@ command_result ConnectedClient::handleCommandClientEdit(Command &cmd, const std:
|
||||
}
|
||||
|
||||
command_result ConnectedClient::handleCommandClientUpdate(Command &cmd) {
|
||||
return this->handleCommandClientEdit(cmd, _this.lock());
|
||||
return this->handleCommandClientEdit(cmd, this->ref());
|
||||
}
|
||||
|
||||
command_result ConnectedClient::handleCommandClientMute(Command &cmd) {
|
||||
@ -737,7 +737,7 @@ command_result ConnectedClient::handleCommandClientMute(Command &cmd) {
|
||||
}
|
||||
|
||||
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};
|
||||
}
|
||||
@ -758,7 +758,7 @@ command_result ConnectedClient::handleCommandClientUnmute(Command &cmd) {
|
||||
}
|
||||
|
||||
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};
|
||||
}
|
||||
@ -976,7 +976,7 @@ command_result ConnectedClient::handleCommandClientAddPerm(Command &cmd) {
|
||||
auto onlineClients = this->server->findClientsByCldbId(cldbid);
|
||||
if (!onlineClients.empty())
|
||||
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 */
|
||||
if(update_channels)
|
||||
elm->updateChannelClientProperties(true, true);
|
||||
@ -1019,7 +1019,7 @@ command_result ConnectedClient::handleCommandClientDelPerm(Command &cmd) {
|
||||
auto onlineClients = this->server->findClientsByCldbId(cldbid);
|
||||
if (!onlineClients.empty())
|
||||
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 */
|
||||
if(update_channels)
|
||||
elm->updateChannelClientProperties(true, true);
|
||||
|
@ -328,7 +328,7 @@ command_result ConnectedClient::handleCommandFTDeleteFile(Command &cmd) {
|
||||
file_log_info.emplace_back(0, "/avatar_" + avId);
|
||||
} else {
|
||||
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());
|
||||
file_log_info.emplace_back(0, "/avatar_" + this->getAvatarId());
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ command_result ConnectedClient::handleCommandGetConnectionInfo(Command &cmd) {
|
||||
if (!client) return command_result{error::client_invalid_id};
|
||||
|
||||
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) {
|
||||
this->notifyConnectionInfo(client.client, info);
|
||||
} 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();
|
||||
}
|
||||
for(const auto& receiver : receivers)
|
||||
receiver->notifyConnectionInfo(_this.lock(), info);
|
||||
receiver->notifyConnectionInfo(this->ref(), info);
|
||||
return command_result{error::ok};
|
||||
}
|
||||
|
||||
@ -506,7 +506,7 @@ command_result ConnectedClient::handleCommandSetClientChannelGroup(Command &cmd)
|
||||
shared_lock client_channel_lock_r(targetClient->channel_lock);
|
||||
auto result = this->server->notifyClientPropertyUpdates(targetClient, updates);
|
||||
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 */
|
||||
|
||||
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);
|
||||
if(viewer != targetClient)
|
||||
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};
|
||||
}
|
||||
|
||||
target->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, _this.lock(), target->getClientId(), 0, timestamp, cmd["msg"].string());
|
||||
this->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->ref(), target->getClientId(), 0, timestamp, cmd["msg"].string());
|
||||
} else if (cmd["targetmode"] == ChatMessageMode::TEXTMODE_CHANNEL) {
|
||||
if(cmd[0].has("cid")) {
|
||||
cmd["target"] = cmd["cid"].string();
|
||||
@ -648,7 +648,7 @@ command_result ConnectedClient::handleCommandSendTextMessage(Command &cmd) {
|
||||
if (type == ClientType::CLIENT_INTERNAL || type == ClientType::CLIENT_MUSIC)
|
||||
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()))
|
||||
server->testBanStateChange(_this.lock());
|
||||
server->testBanStateChange(this->ref());
|
||||
return command_result{error::ok};
|
||||
}
|
||||
|
||||
@ -930,7 +930,7 @@ command_result ConnectedClient::handleCommandBanClient(Command &cmd) {
|
||||
ban_ids.push_back(id);
|
||||
}
|
||||
}
|
||||
this->server->testBanStateChange(_this.lock());
|
||||
this->server->testBanStateChange(this->ref());
|
||||
|
||||
if (this->getType() == CLIENT_QUERY) {
|
||||
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->update_cached_permissions()) /* update cached calculated permissions */
|
||||
if (this->server->notifyClientPropertyUpdates(this->ref(), this->server->groups->update_server_group_property(this->ref(), true, this->getChannel()))) {
|
||||
if(this->update_client_needed_permissions()) /* update cached calculated permissions */
|
||||
this->sendNeededPermissions(false); /* cached permissions had changed, notify the client */
|
||||
|
||||
{
|
||||
for (auto &viewer : this->server->getClients()) {
|
||||
if(viewer->isClientVisible(_this.lock(), true))
|
||||
viewer->notifyServerGroupClientAdd(this->server->serverRoot, _this.lock(), serverGroup);
|
||||
if(viewer->isClientVisible(this->ref(), true))
|
||||
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};
|
||||
@ -1149,26 +1149,26 @@ command_result ConnectedClient::handleCommandPluginCmd(Command &cmd) {
|
||||
if (mode == PluginTargetMode::PLUGINCMD_CURRENT_CHANNEL) {
|
||||
CMD_REQ_CHANNEL;
|
||||
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) {
|
||||
for (auto &cl : this->server->getClients())
|
||||
if (cl->isClientVisible(_this.lock(), true))
|
||||
cl->notifyPluginCmd(cmd["name"], cmd["data"], _this.lock());
|
||||
if (cl->isClientVisible(this->ref(), true))
|
||||
cl->notifyPluginCmd(cmd["name"], cmd["data"], this->ref());
|
||||
} else if (mode == PluginTargetMode::PLUGINCMD_SERVER) {
|
||||
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) {
|
||||
for (int index = 0; index < cmd.bulkCount(); index++) {
|
||||
auto target = cmd[index]["target"].as<ClientId>();
|
||||
ConnectedLockedClient cl{this->server->find_client_by_id(target)};
|
||||
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) {
|
||||
auto target = _this.lock();
|
||||
auto target = this->ref();
|
||||
if(cmd[0].has("target"))
|
||||
target = this->server->findClient(cmd["target"].as<ClientId>());
|
||||
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) {
|
||||
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;
|
||||
server->notifyClientPropertyUpdates(_this.lock(), deque<property::ClientProperties>{property::CLIENT_COUNTRY});
|
||||
server->notifyClientPropertyUpdates(this->ref(), deque<property::ClientProperties>{property::CLIENT_COUNTRY});
|
||||
new_country = loc->identifier;
|
||||
} else {
|
||||
logError(this->getServerId(), "[{}] Failed to resolve ip location for IP {}.", CLIENT_STR_LOG_PREFIX, this->getLoggingPeerIp());
|
||||
|
@ -189,11 +189,11 @@ command_result ConnectedClient::handleCommandMusicBotSetSubscription(ts::Command
|
||||
{
|
||||
auto old_bot = this->subscribed_bot.lock();
|
||||
if(old_bot)
|
||||
old_bot->remove_subscriber(_this.lock());
|
||||
old_bot->remove_subscriber(this->ref());
|
||||
}
|
||||
|
||||
if(bot) {
|
||||
bot->add_subscriber(_this.lock());
|
||||
bot->add_subscriber(this->ref());
|
||||
this->subscribed_bot = bot;
|
||||
}
|
||||
|
||||
@ -912,7 +912,7 @@ command_result ConnectedClient::handleCommandPlaylistSongAdd(ts::Command &cmd) {
|
||||
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};
|
||||
|
||||
return command_result{error::ok};
|
||||
@ -1069,11 +1069,11 @@ command_result ConnectedClient::handleCommandMusicBotQueueAdd(Command& cmd) {
|
||||
}
|
||||
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};
|
||||
|
||||
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};
|
||||
@ -1106,7 +1106,7 @@ command_result ConnectedClient::handleCommandMusicBotQueueRemove(Command& cmd) {
|
||||
for(const auto& entry : songs)
|
||||
bot->queue()->deleteEntry(dynamic_pointer_cast<music::PlayableSong>(entry));
|
||||
this->server->forEachClient([&](shared_ptr<ConnectedClient> client) {
|
||||
client->notifyMusicQueueRemove(bot, songs, _this.lock());
|
||||
client->notifyMusicQueueRemove(bot, songs, this->ref());
|
||||
});
|
||||
return command_result{error::ok};
|
||||
*/
|
||||
@ -1130,7 +1130,7 @@ command_result ConnectedClient::handleCommandMusicBotQueueReorder(Command& cmd)
|
||||
auto order = bot->queue()->changeOrder(entry, cmd["index"]);
|
||||
if(order < 0) return command_result{error::vs_critical};
|
||||
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};
|
||||
*/
|
||||
@ -1177,7 +1177,7 @@ command_result ConnectedClient::handleCommandPlaylistSetSubscription(ts::Command
|
||||
{
|
||||
auto old_playlist = this->subscribed_playlist_.lock();
|
||||
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};
|
||||
}
|
||||
|
||||
playlist->add_subscriber(_this.lock());
|
||||
playlist->add_subscriber(this->ref());
|
||||
this->subscribed_playlist_ = playlist;
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ using namespace ts::token;
|
||||
|
||||
command_result ConnectedClient::handleCommandServerGetVariables(Command &cmd) {
|
||||
CMD_REQ_SERVER;
|
||||
this->notifyServerUpdated(_this.lock());
|
||||
this->notifyServerUpdated(this->ref());
|
||||
return command_result{error::ok};
|
||||
}
|
||||
|
||||
@ -238,13 +238,13 @@ command_result ConnectedClient::handleCommandServerEdit(Command &cmd) {
|
||||
if (group_update)
|
||||
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(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 */
|
||||
}
|
||||
});
|
||||
|
||||
if (!keys.empty())
|
||||
target_server->notifyServerEdited(_this.lock(), keys);
|
||||
target_server->notifyServerEdited(this->ref(), keys);
|
||||
}
|
||||
return command_result{error::ok};
|
||||
}
|
||||
@ -579,7 +579,7 @@ command_result ConnectedClient::handleCommandServerGroupDel(Command &cmd) {
|
||||
if(this->server)
|
||||
this->server->forEachClient([&](shared_ptr<ConnectedClient> cl) {
|
||||
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->notifyServerGroupList();
|
||||
@ -727,9 +727,9 @@ command_result ConnectedClient::handleCommandServerGroupAddClient(Command &cmd)
|
||||
for (const auto &client : _server->getClients()) {
|
||||
if(client->isClientVisible(targetClient, true) || client == targetClient)
|
||||
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->updateChannelClientProperties(true, true);
|
||||
}
|
||||
@ -866,9 +866,9 @@ command_result ConnectedClient::handleCommandServerGroupDelClient(Command &cmd)
|
||||
for (const auto &client : _server->getClients()) {
|
||||
if(client->isClientVisible(targetClient, true) || client == targetClient)
|
||||
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->updateChannelClientProperties(true, true);
|
||||
}
|
||||
@ -945,7 +945,7 @@ command_result ConnectedClient::handleCommandServerGroupAddPerm(Command &cmd) {
|
||||
|
||||
//TODO may update for every server?
|
||||
if(this->server) {
|
||||
auto lock = this->_this.lock();
|
||||
auto lock = this->ref();
|
||||
auto server = this->server;
|
||||
threads::Thread([update_talk_power, update_server_group_list, serverGroup, lock, server]() {
|
||||
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) {
|
||||
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 */
|
||||
if (update_talk_power)
|
||||
cl->updateChannelClientProperties(true, true);
|
||||
@ -1009,7 +1009,7 @@ command_result ConnectedClient::handleCommandServerGroupDelPerm(Command &cmd) {
|
||||
serverGroup->apply_properties_from_permissions();
|
||||
|
||||
if(this->server) {
|
||||
auto lock = this->_this.lock();
|
||||
auto lock = this->ref();
|
||||
auto server = this->server;
|
||||
threads::Thread([update_talk_power, update_server_group_list, serverGroup, lock, server]() {
|
||||
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) {
|
||||
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 */
|
||||
if (update_talk_power)
|
||||
cl->updateChannelClientProperties(true, true);
|
||||
@ -1085,7 +1085,7 @@ command_result ConnectedClient::handleCommandServerGroupAutoAddPerm(ts::Command&
|
||||
for(auto& group : groups)
|
||||
group->apply_properties_from_permissions();
|
||||
|
||||
auto lock = this->_this.lock();
|
||||
auto lock = this->ref();
|
||||
if(ref_server) {
|
||||
threads::Thread([update_clients, update_server_group_list, groups, lock, ref_server]() {
|
||||
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) {
|
||||
for(const auto& serverGroup : groups) {
|
||||
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 */
|
||||
}
|
||||
if (update_clients) {
|
||||
@ -1166,7 +1166,7 @@ command_result ConnectedClient::handleCommandServerGroupAutoDelPerm(ts::Command&
|
||||
}
|
||||
|
||||
if(ref_server) {
|
||||
auto lock = this->_this.lock();
|
||||
auto lock = this->ref();
|
||||
threads::Thread([update_clients, update_server_group_list, groups, lock, ref_server]() {
|
||||
if(update_server_group_list)
|
||||
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) {
|
||||
for(const auto& serverGroup : groups) {
|
||||
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 */
|
||||
if (update_clients)
|
||||
cl->updateChannelClientProperties(true, true);
|
||||
|
@ -87,7 +87,7 @@ bool MusicClient::close_connection(const std::chrono::system_clock::time_point&)
|
||||
|
||||
/*
|
||||
if(this->server)
|
||||
this->server->unregisterInternalClient(static_pointer_cast<InternalClient>(_this.lock()));
|
||||
this->server->unregisterInternalClient(static_pointer_cast<InternalClient>(this->ref()));
|
||||
*/
|
||||
//TODO!
|
||||
this->properties()[property::CLIENT_ID] = 0;
|
||||
@ -133,8 +133,8 @@ void MusicClient::initialize_bot() {
|
||||
auto channel = this->server->getChannelTree()->findChannel(last);
|
||||
if(!channel) channel = this->server->getChannelTree()->getDefaultChannel();
|
||||
|
||||
if(this->getClientId() == 0 || this->server->find_client_by_id(this->getClientId()) != _this.lock()) {
|
||||
this->server->registerClient(_this.lock());
|
||||
if(this->getClientId() == 0 || this->server->find_client_by_id(this->getClientId()) != this->ref()) {
|
||||
this->server->registerClient(this->ref());
|
||||
}
|
||||
{
|
||||
unique_lock server_channel_lock(this->server->channel_tree_lock);
|
||||
@ -190,12 +190,12 @@ void MusicClient::changePlayerState(ReplayState state) {
|
||||
this->_player_state = state;
|
||||
this->properties()[property::CLIENT_PLAYER_STATE] = state;
|
||||
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) {
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -42,11 +42,6 @@ namespace ts::server {
|
||||
MusicClient(const std::shared_ptr<VirtualServer>&,const std::string&);
|
||||
virtual ~MusicClient() override;
|
||||
|
||||
void setSharedLock(const std::shared_ptr<ConnectedClient> &_this){
|
||||
assert(_this.get() == this);
|
||||
this->_this = _this;
|
||||
}
|
||||
|
||||
//Basic TeaSpeak stuff
|
||||
void sendCommand(const ts::Command &command, bool low) override;
|
||||
void sendCommand(const ts::command_builder &command, bool low) override;
|
||||
|
@ -182,7 +182,7 @@ std::shared_ptr<::music::MusicPlayer> MusicClient::current_player() {
|
||||
}
|
||||
|
||||
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]{
|
||||
auto playlist = self->playlist();
|
||||
if(playlist->properties()[property::PLAYLIST_FLAG_FINISHED].as<bool>()) {
|
||||
@ -199,7 +199,7 @@ void MusicClient::playMusic() {
|
||||
}
|
||||
|
||||
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]{
|
||||
auto player = self->current_player();
|
||||
if(player)
|
||||
@ -210,7 +210,7 @@ void MusicClient::stopMusic() {
|
||||
}
|
||||
|
||||
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]{
|
||||
auto player = self->current_player();
|
||||
if(player)
|
||||
@ -311,7 +311,7 @@ void MusicClient::musicEventHandler(const std::weak_ptr<ts::music::PlayableSong>
|
||||
void MusicClient::volume_modifier(float vol) {
|
||||
this->playback.volume_modifier = vol;
|
||||
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) {
|
||||
@ -384,7 +384,7 @@ void MusicClient::broadcast_music_stop() {
|
||||
|
||||
SpeakingClient::VoicePacketFlags flags{};
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -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};
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
|
@ -57,12 +57,12 @@ QueryClient::QueryClient(QueryServer* handle, int sockfd) : ConnectedClient(hand
|
||||
this->resetEventMask();
|
||||
}
|
||||
|
||||
void QueryClient::initialize_self_reference(const std::shared_ptr<QueryClient> &reference) {
|
||||
this->_this = reference;
|
||||
void QueryClient::initialize_weak_reference(const std::shared_ptr<ConnectedClient> &self) {
|
||||
ConnectedClient::initialize_weak_reference(self);
|
||||
|
||||
this->command_queue = std::make_unique<ServerCommandQueue>(
|
||||
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){
|
||||
@ -94,7 +94,7 @@ void QueryClient::preInitialize() {
|
||||
this->properties()[property::CLIENT_UNIQUE_IDENTIFIER] = "UnknownQuery";
|
||||
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) {
|
||||
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) {
|
||||
@ -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->unregisterClient(_this.lock(), reason, tree_lock);
|
||||
old_server->unregisterClient(this->ref(), reason, tree_lock);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -60,7 +60,7 @@ namespace ts::server {
|
||||
|
||||
inline std::shared_ptr<QueryAccount> getQueryAccount() { return this->query_account; }
|
||||
protected:
|
||||
void initialize_self_reference(const std::shared_ptr<QueryClient> &reference);
|
||||
void initialize_weak_reference(const std::shared_ptr<ConnectedClient> &) override;
|
||||
|
||||
void preInitialize();
|
||||
void initializeSSL();
|
||||
|
@ -245,7 +245,7 @@ command_result QueryClient::handleCommandLogin(Command& cmd) {
|
||||
unique_lock tree_lock(this->server->channel_tree_lock);
|
||||
if(joined_channel)
|
||||
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());
|
||||
} else serverInstance->getGroupManager()->disableCache(this->getClientDatabaseId());
|
||||
@ -266,15 +266,15 @@ command_result QueryClient::handleCommandLogin(Command& cmd) {
|
||||
}
|
||||
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) {
|
||||
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);
|
||||
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);
|
||||
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)))
|
||||
this->server->assignDefaultChannel(this->ref(), true);
|
||||
else
|
||||
this->update_cached_permissions();
|
||||
this->update_client_needed_permissions();
|
||||
} else {
|
||||
serverInstance->getGroupManager()->enableCache(this->getClientDatabaseId());
|
||||
this->update_cached_permissions();
|
||||
this->update_client_needed_permissions();
|
||||
}
|
||||
|
||||
this->properties()[property::CLIENT_TOTALCONNECTIONS]++;
|
||||
@ -314,14 +314,14 @@ command_result QueryClient::handleCommandLogout(Command &) {
|
||||
unique_lock tree_lock(this->server->channel_tree_lock);
|
||||
if(joined)
|
||||
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());
|
||||
} else serverInstance->getGroupManager()->disableCache(this->getClientDatabaseId());
|
||||
|
||||
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()));
|
||||
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){
|
||||
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))) {
|
||||
this->server->assignDefaultChannel(this->ref(), true);
|
||||
} else {
|
||||
this->update_cached_permissions();
|
||||
this->update_client_needed_permissions();
|
||||
}
|
||||
} else {
|
||||
serverInstance->getGroupManager()->enableCache(this->getClientDatabaseId());
|
||||
this->update_cached_permissions();
|
||||
this->update_client_needed_permissions();
|
||||
}
|
||||
|
||||
this->updateChannelClientProperties(true, true);
|
||||
@ -397,10 +397,10 @@ command_result QueryClient::handleCommandServerSelect(Command &cmd) {
|
||||
if(cmd[0].has("client_nickname"))
|
||||
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) {
|
||||
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);
|
||||
@ -415,10 +415,10 @@ command_result QueryClient::handleCommandServerSelect(Command &cmd) {
|
||||
if(!negated_enforce_join)
|
||||
this->server->assignDefaultChannel(this->ref(), true);
|
||||
else
|
||||
this->update_cached_permissions();
|
||||
this->update_client_needed_permissions();
|
||||
} else {
|
||||
serverInstance->getGroupManager()->enableCache(this->getClientDatabaseId());
|
||||
this->update_cached_permissions();
|
||||
this->update_client_needed_permissions();
|
||||
}
|
||||
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());
|
||||
|
@ -142,11 +142,11 @@ bool VoiceClient::disconnect(ts::ViewReasonId reason_id, const std::string &reas
|
||||
threads::MutexLock lock(this->command_lock);
|
||||
auto server_channel = dynamic_pointer_cast<ServerChannel>(this->currentChannel);
|
||||
if(server_channel)
|
||||
server_channel->unregister_client(_this.lock());
|
||||
server_channel->unregister_client(this->ref());
|
||||
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) {
|
||||
auto self = weak_self.lock();
|
||||
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) {
|
||||
auto self_lock = dynamic_pointer_cast<VoiceClient>(_this.lock());
|
||||
auto self_lock = dynamic_pointer_cast<VoiceClient>(this->ref());
|
||||
assert(self_lock); //Should never happen!
|
||||
|
||||
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() {
|
||||
auto ownLock = dynamic_pointer_cast<VoiceClient>(_this.lock());
|
||||
auto ownLock = dynamic_pointer_cast<VoiceClient>(this->ref());
|
||||
assert(ownLock);
|
||||
|
||||
lock_guard disconnect_lock_final(this->finalDisconnectLock);
|
||||
|
@ -72,7 +72,7 @@ std::string VoiceClientConnection::log_prefix() {
|
||||
|
||||
void VoiceClientConnection::triggerWrite() {
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ using namespace ts::server;
|
||||
using namespace ts::protocol;
|
||||
|
||||
void WebClient::handleMessageWrite(int fd, short, void *) {
|
||||
auto self_lock = _this.lock();
|
||||
auto self_lock = this->ref();
|
||||
|
||||
unique_lock buffer_lock(this->queue_mutex);
|
||||
if(this->queue_write.empty()) return;
|
||||
@ -62,7 +62,7 @@ void WebClient::handleMessageWrite(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;
|
||||
uint8_t buffer[buffer_length];
|
||||
|
@ -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 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;
|
||||
assert(self_lock);
|
||||
|
||||
@ -225,7 +225,7 @@ bool WebClient::close_connection(const std::chrono::system_clock::time_point& ti
|
||||
if(this->server){
|
||||
{
|
||||
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 = nullptr;
|
||||
@ -395,7 +395,7 @@ void WebClient::onWSMessage(const pipes::WSMessage &message) {
|
||||
|
||||
/* called while helding close_lock*/
|
||||
void WebClient::disconnectFinal() {
|
||||
auto self_lock = this->_this.lock();
|
||||
auto self_lock = this->ref();
|
||||
{
|
||||
/* waiting to finish all executes */
|
||||
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->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));
|
||||
}
|
||||
|
@ -38,8 +38,6 @@ namespace ts::server {
|
||||
|
||||
protected:
|
||||
void tick_server(const std::chrono::system_clock::time_point&) override; /* Every 500ms */
|
||||
|
||||
void applySelfLock(const std::shared_ptr<WebClient> &cl){ _this = cl; }
|
||||
private:
|
||||
WebControlServer* handle;
|
||||
|
||||
|
@ -77,7 +77,7 @@ std::shared_ptr<server::MusicClient> MusicBotManager::createBot(ClientDbId owner
|
||||
|
||||
auto uid = base64::encode(digest::sha1("music#" + rnd_string(15)));
|
||||
auto musicBot = make_shared<MusicClient>(this->handle.lock(), uid);
|
||||
musicBot->_this = musicBot;
|
||||
musicBot->initialize_weak_reference(musicBot);
|
||||
musicBot->manager = this;
|
||||
musicBot->server = handle;
|
||||
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;
|
||||
|
||||
auto musicBot = make_shared<MusicClient>(handle, uid);
|
||||
musicBot->_this = musicBot;
|
||||
musicBot->initialize_weak_reference(musicBot);
|
||||
musicBot->manager = this;
|
||||
DatabaseHelper::assignDatabaseId(handle->getSql(), handle->getServerId(), musicBot);
|
||||
musicBot->properties()[property::CLIENT_OWNER] = owner;
|
||||
|
@ -295,7 +295,7 @@ shared_ptr<VoiceClient> POWHandler::register_verified_client(const std::shared_p
|
||||
|
||||
if(!voice_client) {
|
||||
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->connection->socket_id_ = client->socket;
|
||||
|
@ -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);
|
||||
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);
|
||||
|
@ -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);
|
||||
memcpy(&client->remote_address, &remote_address, sizeof(remote_address));
|
||||
client->applySelfLock(client);
|
||||
client->initialize_weak_reference(client);
|
||||
client->initialize();
|
||||
|
||||
this->clientLock.lock();
|
||||
|
Loading…
Reference in New Issue
Block a user