Fixed some subscribe issues
This commit is contained in:
@@ -13,12 +13,9 @@ using namespace ts;
|
||||
using namespace ts::server;
|
||||
using namespace ts::permission;
|
||||
|
||||
extern ts::server::InstanceHandler* serverInstance;
|
||||
|
||||
DataClient::DataClient(sql::SqlManager* database, const std::shared_ptr<TSServer>& server) : server(server), sql(database) {
|
||||
assert(database);
|
||||
this->_properties = std::make_shared<Properties>();
|
||||
DatabaseHelper::assign_default_properties_client(this->_properties.get(), ClientType::CLIENT_INTERNAL);
|
||||
this->_properties = DatabaseHelper::default_properties_client(nullptr, ClientType::CLIENT_INTERNAL);
|
||||
}
|
||||
|
||||
DataClient::~DataClient() {
|
||||
@@ -28,26 +25,48 @@ DataClient::~DataClient() {
|
||||
|
||||
bool DataClient::loadDataForCurrentServer() { //TODO for query
|
||||
if(this->getUid().empty()) return false;
|
||||
auto ref_server = this->server;
|
||||
auto server_id = ref_server ? ref_server->getServerId() : 0;
|
||||
|
||||
properties()[property::CLIENT_DATABASE_ID] = 0;
|
||||
properties()[property::CLIENT_CREATED] = 0;
|
||||
properties()[property::CLIENT_TOTALCONNECTIONS] = 0;
|
||||
|
||||
|
||||
sql::command(this->sql, "SELECT `cldbid`,`firstConnect`,`connections` FROM `clients` WHERE `serverId` = :sid AND `clientUid`=:uid LIMIT 1", variable{":sid", this->server ? this->server->getServerId() : 0}, variable{":uid", this->getUid()}).query([&](DataClient* cl, int length, string* values, string* names){
|
||||
for (int index = 0; index < length; index++) {
|
||||
logTrace(this->server ? this->server->getServerId() : 0, "Reading client (" + this->getUid() + ") property from client database table. (Key: " + names[index] + ", Value: " + values[index] + ")");
|
||||
if (names[index] == "cldbid") {
|
||||
cl->properties()[property::CLIENT_DATABASE_ID] = string(values[index]);
|
||||
} else if (names[index] == "firstConnect") {
|
||||
cl->properties()[property::CLIENT_CREATED] = values[index];
|
||||
} else if (names[index] == "connections") {
|
||||
cl->properties()[property::CLIENT_TOTALCONNECTIONS] = values[index];
|
||||
} else {
|
||||
debugMessage(lstream << "Unknown row name '" << names[index] << "'" << endl);
|
||||
}
|
||||
}
|
||||
ClientDbId client_db_id = 0;
|
||||
sql::command(this->sql, "SELECT `cldbid`,`firstConnect`,`connections` FROM `clients` WHERE `serverId` = :sid AND `clientUid` = :uid LIMIT 1",
|
||||
variable{":sid", server_id},
|
||||
variable{":uid", this->getUid()}
|
||||
).query([&](DataClient* cl, int length, string* values, string* names){
|
||||
for (int index = 0; index < length; index++) {
|
||||
try {
|
||||
if (names[index] == "cldbid") {
|
||||
client_db_id = stoull(values[index]);
|
||||
} else if (names[index] == "firstConnect") {
|
||||
cl->properties()[property::CLIENT_CREATED] = values[index];
|
||||
} else if (names[index] == "connections") {
|
||||
cl->properties()[property::CLIENT_TOTALCONNECTIONS] = values[index];
|
||||
} else {
|
||||
logWarning(LOG_INSTANCE, "Received unknown column with name {} within client list", names[index]);
|
||||
}
|
||||
} catch(const std::exception& ex) {
|
||||
logError(server_id, "Failed to load client {} base properties from database. Colum parsing for column {} failed. Value: {}. Message: {}",
|
||||
this->getUid(),
|
||||
names[index],
|
||||
values[index],
|
||||
ex.what()
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}, this);
|
||||
|
||||
if(client_db_id == 0)
|
||||
return false;
|
||||
|
||||
this->properties()[property::CLIENT_DATABASE_ID] = client_db_id; /* do this before the property saving (it saved the cldbid as well!)*/
|
||||
|
||||
//Load general properties
|
||||
deque<ts::PropertyWrapper> copied;
|
||||
for(const auto& prop : this->_properties->list_properties()){
|
||||
@@ -56,20 +75,19 @@ bool DataClient::loadDataForCurrentServer() { //TODO for query
|
||||
copied.push_back(prop);
|
||||
}
|
||||
|
||||
if(this->getClientDatabaseId() == 0) return false;
|
||||
if(!this->server) {
|
||||
if(!ref_server) {
|
||||
if(this->getType() == ClientType::CLIENT_WEB || this->getType() == ClientType::CLIENT_TEAMSPEAK)
|
||||
logCritical("Got a voice or web manager, which is unbound to any server!");
|
||||
logCritical(LOG_INSTANCE, "Got a voice or web client, which is unbound to any server!");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto clType = this->getType();
|
||||
if(this->getType() == CLIENT_TEAMSPEAK || this->server) {
|
||||
this->_properties = serverInstance->databaseHelper()->loadClientProperties(this->server, this->getClientDatabaseId(), clType);
|
||||
auto client_type = this->getType();
|
||||
if(client_type == CLIENT_TEAMSPEAK || ref_server) {
|
||||
this->_properties = serverInstance->databaseHelper()->loadClientProperties(ref_server, this->getClientDatabaseId(), client_type);
|
||||
} else {
|
||||
this->_properties = std::make_shared<Properties>();
|
||||
DatabaseHelper::assign_default_properties_client(this->_properties.get(), clType);
|
||||
this->_properties->registerNotifyHandler([&](Property& prop){
|
||||
this->_properties = DatabaseHelper::default_properties_client(nullptr, client_type);
|
||||
|
||||
this->_properties->registerNotifyHandler([&, server_id, client_db_id](Property& prop){
|
||||
std::string query;
|
||||
if(prop.type() == property::CLIENT_TOTALCONNECTIONS)
|
||||
query = "UPDATE `clients` SET `connections` = :value WHERE `serverId` = :sid AND `cldbid` = :cldbid";
|
||||
@@ -77,9 +95,12 @@ bool DataClient::loadDataForCurrentServer() { //TODO for query
|
||||
query = "UPDATE `clients` SET `lastName` = :value WHERE `serverId` = :sid AND `cldbid` = :cldbid";
|
||||
else if(prop.type() == property::CLIENT_LASTCONNECTED)
|
||||
query = "UPDATE `clients` SET `lastConnect` = :value WHERE `serverId` = :sid AND `cldbid` = :cldbid";
|
||||
if(query.empty()) return;
|
||||
debugMessage("[SQL] " + query + " - " + to_string(0) + " - " + prop.value() + " - " + to_string(this->getClientDatabaseId()));
|
||||
sql::command(this->sql, query, variable{":sid", 0}, variable{":cldbid", this->getClientDatabaseId()}, variable{":value", prop.value()}).executeLater().waitAndGetLater(LOG_SQL_CMD, {1, "future failed"});
|
||||
else
|
||||
return;
|
||||
|
||||
debugMessage(server_id, "[Property] Updating general client table property for client {}. Key: {} Value: {}", client_db_id, prop.type().name, prop.value());
|
||||
sql::command(this->sql, query, variable{":sid", 0}, variable{":cldbid", client_db_id}, variable{":value", prop.value()}).executeLater()
|
||||
.waitAndGetLater(LOG_SQL_CMD, {1, "failed to update general client properties"});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -91,35 +112,21 @@ bool DataClient::loadDataForCurrentServer() { //TODO for query
|
||||
}
|
||||
this->_properties->toggleSave(true);
|
||||
|
||||
/*
|
||||
* //TODO What did this?
|
||||
vector<string> updatedProps;
|
||||
if(this->server) {
|
||||
auto cclient = dynamic_cast<ConnectedClient*>(this);
|
||||
if(cclient){
|
||||
if(cclient->state == CONNECTED)
|
||||
this->server->notifyClientPropertyUpdates(dynamic_cast<ConnectedClient*>(this)->_this.lock(), updatedProps);
|
||||
}
|
||||
}
|
||||
*/
|
||||
this->clientPermissions = serverInstance->databaseHelper()->loadClientPermissionManager(this->server, this->getClientDatabaseId());
|
||||
this->clientPermissions = serverInstance->databaseHelper()->loadClientPermissionManager(ref_server, this->getClientDatabaseId());
|
||||
|
||||
//Setup / fix stuff
|
||||
if(!this->properties()[property::CLIENT_FLAG_AVATAR].as<string>().empty()){
|
||||
if(
|
||||
!this->server ||
|
||||
!serverInstance->getFileServer()->findFile("/avatar_" + this->getAvatarId(),serverInstance->getFileServer()->avatarDirectory(this->server))) {
|
||||
!ref_server ||
|
||||
!serverInstance->getFileServer()->findFile("/avatar_" + this->getAvatarId(),serverInstance->getFileServer()->avatarDirectory(ref_server))) {
|
||||
if(config::server::delete_missing_icon_permissions)
|
||||
this->properties()[property::CLIENT_FLAG_AVATAR] = "";
|
||||
}
|
||||
}
|
||||
|
||||
if(this->server){
|
||||
int ureadMessages = 0;
|
||||
for(const auto &elm : this->server->letters->avariableLetters(this->getUid()))
|
||||
if(!elm->read) ureadMessages++;
|
||||
this->properties()[property::CLIENT_UNREAD_MESSAGES] = ureadMessages;
|
||||
}
|
||||
if(ref_server)
|
||||
this->properties()[property::CLIENT_UNREAD_MESSAGES] = ref_server->letters->unread_letter_count(this->getUid());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user