Using property wrapper for all property accesses

This commit is contained in:
WolverinDEV
2021-03-01 14:37:03 +01:00
parent 1bdb178a3f
commit db71461646
14 changed files with 47 additions and 76 deletions
+2 -2
View File
@@ -677,7 +677,7 @@ inline void send_channels(ConnectedClient* client, ChannelIT begin, const Channe
continue;
}
for (const auto &elm : channel->properties().list_properties(property::FLAG_CHANNEL_VIEW, client->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0)) {
for (const auto &elm : channel->properties()->list_properties(property::FLAG_CHANNEL_VIEW, client->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0)) {
if(elm.type() == property::CHANNEL_ORDER)
builder.put_unchecked(index, elm.type().name, override_orderid ? 0 : (*begin)->previous_channel);
else
@@ -799,7 +799,7 @@ void ConnectedClient::tick_server(const std::chrono::system_clock::time_point &t
void ConnectedClient::sendServerInit() {
Command command("initserver");
for(const auto& prop : this->server->properties().list_properties(property::FLAG_SERVER_VIEW, this->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0)) {
for(const auto& prop : this->server->properties()->list_properties(property::FLAG_SERVER_VIEW, this->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0)) {
command[std::string{prop.type().name}] = prop.value();
}
command["virtualserver_maxclients"] = 32;
@@ -471,7 +471,7 @@ bool ConnectedClient::notifyChannelMoved(const std::shared_ptr<BasicChannel> &ch
bool ConnectedClient::notifyChannelCreate(const std::shared_ptr<BasicChannel> &channel, ChannelId orderId, const std::shared_ptr<ConnectedClient> &invoker) {
Command notify("notifychannelcreated");
for (auto &prop : channel->properties().list_properties(property::FLAG_CHANNEL_VARIABLE | property::FLAG_CHANNEL_VIEW, this->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0)) {
for (auto &prop : channel->properties()->list_properties(property::FLAG_CHANNEL_VARIABLE | property::FLAG_CHANNEL_VIEW, this->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0)) {
if(prop.type() == property::CHANNEL_ORDER)
notify[prop.type().name] = orderId;
else if(prop.type() == property::CHANNEL_DESCRIPTION)
@@ -536,7 +536,7 @@ bool ConnectedClient::notifyChannelShow(const std::shared_ptr<ts::BasicChannel>
result = this->notifyChannelCreate(channel, orderId, this->server->serverRoot);
} else {
Command notify("notifychannelshow");
for (auto &prop : channel->properties().list_properties(property::FLAG_CHANNEL_VARIABLE | property::FLAG_CHANNEL_VIEW, this->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0)) {
for (auto &prop : channel->properties()->list_properties(property::FLAG_CHANNEL_VARIABLE | property::FLAG_CHANNEL_VIEW, this->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0)) {
if(prop.type() == property::CHANNEL_ORDER) {
notify[prop.type().name] = orderId;
} else if(prop.type() == property::CHANNEL_DESCRIPTION) {
@@ -730,7 +730,7 @@ bool ConnectedClient::notifyChannelDeleted(const deque<ChannelId>& channel_ids,
bool ConnectedClient::notifyServerUpdated(std::shared_ptr<ConnectedClient> invoker) {
Command response("notifyserverupdated");
for (const auto& elm : this->server->properties().list_properties(property::FLAG_SERVER_VARIABLE, this->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0)) {
for (const auto& elm : this->server->properties()->list_properties(property::FLAG_SERVER_VARIABLE, this->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0)) {
if(elm.type() == property::VIRTUALSERVER_MIN_WINPHONE_VERSION)
continue;
+2 -36
View File
@@ -24,45 +24,11 @@ namespace ts {
friend class QueryServer;
friend class music::MusicBotManager;
public:
struct PropertyWrapper {
std::shared_ptr<PropertyManager> handle;
PropertyManager* operator->() {
return handle.get();
}
const PropertyManager* operator->() const {
return handle.get();
}
template<class F>
std::result_of_t<F(PropertyManager &)> operator->*(F &&f) {
return std::forward<F>(f)(*handle);
}
template<class F>
std::result_of_t<F(PropertyManager const &)> operator->*(F &&f) const {
return std::forward<F>(f)(*handle);
}
/*
template <typename T>
ts::PropertyWrapper operator[](T type) {
return (*handle)[type];
}
*/
template <typename T>
ts::Property operator[](const T& type) {
return (*handle)[type];
}
};
DataClient(sql::SqlManager*, const std::shared_ptr<VirtualServer>&);
virtual ~DataClient();
PropertyWrapper properties(){ return { this->_properties }; }
inline PropertyWrapper properties() { return PropertyWrapper{this->_properties}; }
inline const PropertyWrapper properties() const { return PropertyWrapper{this->_properties}; }
/* main permission calculate function */
/**
@@ -32,9 +32,10 @@ using namespace std;
using namespace ts;
using namespace ts::server;
//{findError("parameter_invalid"), "could not resolve permission " + (cmd[index].has("permid") ? cmd[index]["permid"].as<string>() : cmd[index]["permsid"].as<string>())}; \
//TODO: Log missing permissions?
/*
TODO: Log missing permissions?
{findError("parameter_invalid"), "could not resolve permission " + (cmd[index].has("permid") ? cmd[index]["permid"].as<string>() : cmd[index]["permsid"].as<string>())};
*/
command_result ConnectedClient::handleCommandChannelGetDescription(Command &cmd) {
CMD_CHK_AND_INC_FLOOD_POINTS(0);
RESOLVE_CHANNEL_R(cmd["cid"], true);
@@ -1182,7 +1183,6 @@ ts::command_result ConnectedClient::execute_channel_edit(ChannelId& channel_id,
bool updating_max_family_clients{false};
bool updating_talk_power{false};
bool updating_type{false};
bool updating_conversation{false};
bool updating_sort_order{false};
/* Step 1: Parse all values which are possible and validate them without any context. */
@@ -1411,7 +1411,7 @@ ts::command_result ConnectedClient::execute_channel_edit(ChannelId& channel_id,
}
/* Step 2: Remove all not changed properties and test the updates */
auto& channel_properties = channel->properties();
auto channel_properties = channel->properties();
std::map<property::ChannelProperties, std::string> changed_values{};
for(auto& [ key, value ] : values) {
@@ -1478,7 +1478,6 @@ ts::command_result ConnectedClient::execute_channel_edit(ChannelId& channel_id,
case property::CHANNEL_CONVERSATION_HISTORY_LENGTH:
case property::CHANNEL_CONVERSATION_MODE:
updating_conversation = true;
break;
/* non updatable properties */
@@ -1553,7 +1552,7 @@ ts::command_result ConnectedClient::execute_channel_edit(ChannelId& channel_id,
}
ChannelType::ChannelType target_channel_type;
{
if(updating_type) {
auto flag_permanent = converter<bool>::from_string_view(target_channel_property_value(property::CHANNEL_FLAG_PERMANENT));
auto flag_semi_permanent = converter<bool>::from_string_view(target_channel_property_value(property::CHANNEL_FLAG_SEMI_PERMANENT));
@@ -2477,7 +2476,7 @@ command_result ConnectedClient::handleCommandChannelInfo(Command &cmd) {
Command res("");
for (const auto &prop : channel->properties().list_properties(property::FLAG_CHANNEL_VIEW | property::FLAG_CHANNEL_VARIABLE, this->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0))
for (const auto &prop : channel->properties()->list_properties(property::FLAG_CHANNEL_VIEW | property::FLAG_CHANNEL_VARIABLE, this->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0))
res[prop.type().name] = prop.value();
res["seconds_empty"] = channel->emptySince();
+1 -1
View File
@@ -212,7 +212,7 @@ command_result ConnectedClient::handleCommandServerEdit(Command &cmd) {
continue;
}
auto property = target_server ? target_server->properties()[info] : (*serverInstance->getDefaultServerProperties())[info];
auto property = target_server ? target_server->properties()[info] : serverInstance->getDefaultServerProperties()[info];
if(property.value() == elm.second)
continue;
auto old_value = property.value();
@@ -459,7 +459,8 @@ command_result QueryClient::handleCommandServerInfo(Command &) {
Command cmd("");
for(const auto &prop : (this->server ? this->server->properties() : *serverInstance->getDefaultServerProperties()).list_properties(property::FLAG_SERVER_VIEW | property::FLAG_SERVER_VARIABLE, this->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0)) {
auto properties = this->server ? this->server->properties() : serverInstance->getDefaultServerProperties();
for(const auto &prop : properties->list_properties(property::FLAG_SERVER_VIEW | property::FLAG_SERVER_VARIABLE, this->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0)) {
cmd[prop.type().name] = prop.as_unchecked<string>();
if(prop.type() == property::VIRTUALSERVER_HOST)
cmd["virtualserver_ip"] = prop.as_unchecked<string>();
@@ -813,8 +814,8 @@ command_result QueryClient::handleCommandInstanceInfo(Command& cmd) {
ACTION_REQUIRES_INSTANCE_PERMISSION(permission::b_serverinstance_info_view, 1);
Command res("");
for(const auto& e : serverInstance->properties().list_properties(property::FLAG_INSTANCE_VARIABLE, this->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0))
res[e.type().name] = e.as_unchecked<string>();
for(const auto& e : serverInstance->properties()->list_properties(property::FLAG_INSTANCE_VARIABLE, this->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0))
res[e.type().name] = e.value();
if(!this->properties()[property::CLIENT_LOGIN_NAME].value().empty())
res["serverinstance_teaspeak"] = true;
res["serverinstance_serverquery_max_connections_per_ip"] = res["serverinstance_query_max_connections_per_ip"].as<std::string>();