Using new command error system

This commit is contained in:
WolverinDEV
2020-01-25 23:42:37 +01:00
parent 10092cfab0
commit bb2e7699dc
18 changed files with 1223 additions and 1190 deletions
+15 -11
View File
@@ -7,7 +7,6 @@
#include <misc/memtracker.h>
#include "src/InstanceHandler.h"
#include <pipes/errors.h>
#include <query/command2.h>
#include <misc/std_unique_ptr.h>
using namespace std;
@@ -76,7 +75,9 @@ void QueryClient::postInitialize() {
this->properties()[property::CLIENT_LASTCONNECTED] = duration_cast<seconds>(this->connectTimestamp.time_since_epoch()).count();
if(ts::config::query::sslMode == 1 && this->connectionType != ConnectionType::SSL_ENCRIPTED) {
this->notifyError({findError("failed_connection_initialisation"), "Please use a SSL encryption!"});
command_result error{error::failed_connection_initialisation, "Please use a SSL encryption!"};
this->notifyError(error);
error.release_details();
this->disconnect("Please us a SSL encryption for more security.\nThe server denies also all other connections!");
return;
}
@@ -495,28 +496,31 @@ bool QueryClient::handleMessage(const pipes::buffer_view& message) {
}
unique_ptr<Command> cmd;
command_result error{};
try {
cmd = make_unique<Command>(Command::parse(pipes::buffer_view{(void*) command.data(), command.length()}, true, !ts::config::server::strict_ut8_mode));
} catch(std::invalid_argument& ex) {
logTrace(LOG_QUERY, "[{}:{}] Failed to parse command (invalid argument): {}", this->getLoggingPeerIp(), this->getPeerPort(), command);
this->notifyError(CommandResult{findError("parameter_convert"), ex.what()});
return false;
} catch(command_malformed_exception& ex) {
logTrace(LOG_QUERY, "[{}:{}] Failed to parse command (malformed command at {}): {}", this->getLoggingPeerIp(), this->getPeerPort(), ex.index(), command);
this->notifyError(CommandResult{findError("parameter_convert"), "invalid character @" + to_string(ex.index())});
return false;
error = command_result{error::parameter_convert};
goto handle_error;
} catch(std::exception& ex) {
logTrace(LOG_QUERY, "[{}:{}] Failed to parse command (exception: {}): {}", this->getLoggingPeerIp(), this->getPeerPort(), ex.what(), command);
this->notifyError(CommandResult{ErrorType::VSError, ex.what()});
return false;
error = command_result{error::vs_critical, std::string{ex.what()}};
goto handle_error;
}
try {
this->handleCommandFull(*cmd);
} catch(std::exception& ex) {
this->notifyError(CommandResult{ErrorType::VSError, ex.what()});
error = command_result{error::vs_critical, std::string{ex.what()}};
goto handle_error;
}
return true;
handle_error:
this->notifyError(error);
error.release_details();
return false;
}
void QueryClient::sendCommand(const ts::Command &command, bool) {
+27 -27
View File
@@ -86,7 +86,7 @@ namespace ts {
std::shared_ptr<QueryAccount> query_account;
protected:
CommandResult handleCommand(Command &command) override;
command_result handleCommand(Command &command) override;
public:
//Silent events
@@ -144,41 +144,41 @@ namespace ts {
bool notifyClientLeftViewBanned(const std::shared_ptr<ConnectedClient> &client, const std::string &message, std::shared_ptr<ConnectedClient> invoker, size_t length, bool lock_channel_tree) override;
private:
CommandResult handleCommandExit(Command&);
CommandResult handleCommandLogin(Command&);
CommandResult handleCommandLogout(Command&);
CommandResult handleCommandServerSelect(Command &);
CommandResult handleCommandServerInfo(Command&);
CommandResult handleCommandChannelList(Command&);
CommandResult handleCommandJoin(Command&);
CommandResult handleCommandLeft(Command&);
command_result handleCommandExit(Command&);
command_result handleCommandLogin(Command&);
command_result handleCommandLogout(Command&);
command_result handleCommandServerSelect(Command &);
command_result handleCommandServerInfo(Command&);
command_result handleCommandChannelList(Command&);
command_result handleCommandJoin(Command&);
command_result handleCommandLeft(Command&);
CommandResult handleCommandServerList(Command&);
CommandResult handleCommandServerCreate(Command&);
CommandResult handleCommandServerDelete(Command&);
CommandResult handleCommandServerStart(Command&);
CommandResult handleCommandServerStop(Command&);
command_result handleCommandServerList(Command&);
command_result handleCommandServerCreate(Command&);
command_result handleCommandServerDelete(Command&);
command_result handleCommandServerStart(Command&);
command_result handleCommandServerStop(Command&);
CommandResult handleCommandInstanceInfo(Command&);
CommandResult handleCommandInstanceEdit(Command&);
command_result handleCommandInstanceInfo(Command&);
command_result handleCommandInstanceEdit(Command&);
CommandResult handleCommandBindingList(Command&);
command_result handleCommandBindingList(Command&);
CommandResult handleCommandHostInfo(Command&);
command_result handleCommandHostInfo(Command&);
CommandResult handleCommandGlobalMessage(Command&);
command_result handleCommandGlobalMessage(Command&);
CommandResult handleCommandServerIdGetByPort(Command&);
command_result handleCommandServerIdGetByPort(Command&);
CommandResult handleCommandServerSnapshotDeploy(Command&);
CommandResult handleCommandServerSnapshotCreate(Command&);
CommandResult handleCommandServerProcessStop(Command&);
command_result handleCommandServerSnapshotDeploy(Command&);
command_result handleCommandServerSnapshotCreate(Command&);
command_result handleCommandServerProcessStop(Command&);
CommandResult handleCommandServerNotifyRegister(Command&);
CommandResult handleCommandServerNotifyList(Command&);
CommandResult handleCommandServerNotifyUnregister(Command&);
command_result handleCommandServerNotifyRegister(Command&);
command_result handleCommandServerNotifyList(Command&);
command_result handleCommandServerNotifyUnregister(Command&);
CommandResult handleCommandSetCompressionMode(Command&);
command_result handleCommandSetCompressionMode(Command&);
};
}
}
+100 -95
View File
@@ -20,7 +20,7 @@ constexpr unsigned int string_hash(const char* str, int h = 0) {
return !str[h] ? 5381 : (string_hash(str, h + 1U) * 33U) ^ str[h];
}
CommandResult QueryClient::handleCommand(Command& cmd) {
command_result QueryClient::handleCommand(Command& cmd) {
/*
if (cmd.command() == "exit" || cmd.command() == "quit") return this->handleCommandExit(cmd);
else if (cmd.command() == "use" || cmd.command() == "serverselect") return this->handleCommandServerSelect(cmd);
@@ -117,14 +117,14 @@ CommandResult QueryClient::handleCommand(Command& cmd) {
return ConnectedClient::handleCommand(cmd);
}
CommandResult QueryClient::handleCommandExit(Command &) {
command_result QueryClient::handleCommandExit(Command &) {
logMessage(LOG_QUERY, "[Query] {}:{} disconnected. (Requested by client)", this->getLoggingPeerIp(), this->getPeerPort());
this->closeConnection(system_clock::now() + seconds(1));
return CommandResult::Success;
return command_result{error::ok};
}
//login client_login_name=andreas client_login_password=meinPW
CommandResult QueryClient::handleCommandLogin(Command& cmd) {
command_result QueryClient::handleCommandLogin(Command& cmd) {
CMD_RESET_IDLE;
std::string username, password;
@@ -144,7 +144,7 @@ CommandResult QueryClient::handleCommandLogin(Command& cmd) {
threads::MutexLock lock(this->handle->loginLock);
if(!account)
return {findError("client_invalid_password"), "username or password dose not match"};
return command_result{error::client_invalid_password, "username or password dose not match"};
if (account->password != password) {
if(!this->whitelisted) {
@@ -154,15 +154,20 @@ CommandResult QueryClient::handleCommandLogin(Command& cmd) {
this->postCommandHandler.emplace_back([&](){
this->closeConnection(system_clock::now() + seconds(1));
});
return {findError("ban_flooding"), ""};
return command_result{error::ban_flooding};
}
}
return {findError("client_invalid_password"), "username or password dose not match"};
return command_result{error::client_invalid_password, "username or password dose not match"};
}
}
if(!this->properties()[property::CLIENT_LOGIN_NAME].as<string>().empty()) {
Command log("logout");
if(!this->handleCommandLogout(log)) return {ErrorType::VSError, "Failed to logout!"};
auto result = this->handleCommandLogout(log);
if(result.error_code()) {
result.release_details();
logError(this->getServerId(), "Query client failed to login from old login.");
return command_result{error::vs_critical};
}
}
this->query_account = account;
@@ -190,7 +195,7 @@ CommandResult QueryClient::handleCommandLogin(Command& cmd) {
if(target_server != this->server)
joined_channel = nullptr;
if(!target_server)
return {findError("server_invalid_id"), "server does not exists anymore"};
return command_result{error::server_invalid_id, "server does not exists anymore"};
}
this->server = target_server;
@@ -226,12 +231,12 @@ CommandResult QueryClient::handleCommandLogin(Command& cmd) {
this->properties()[property::CLIENT_TOTALCONNECTIONS]++;
this->updateChannelClientProperties(true, true);
return CommandResult::Success;
return command_result{error::ok};
}
CommandResult QueryClient::handleCommandLogout(Command &) {
command_result QueryClient::handleCommandLogout(Command &) {
CMD_RESET_IDLE;
if(this->properties()[property::CLIENT_LOGIN_NAME].as<string>().empty()) return {findError("client_not_logged_in"), "not logged in"};
if(this->properties()[property::CLIENT_LOGIN_NAME].as<string>().empty()) return command_result{error::client_not_logged_in, "not logged in"};
this->properties()[property::CLIENT_LOGIN_NAME] = "";
this->query_account = nullptr;
@@ -278,10 +283,10 @@ CommandResult QueryClient::handleCommandLogout(Command &) {
this->updateChannelClientProperties(true, true);
return CommandResult::Success;
return command_result{error::ok};
}
CommandResult QueryClient::handleCommandServerSelect(Command &cmd) {
command_result QueryClient::handleCommandServerSelect(Command &cmd) {
CMD_RESET_IDLE;
shared_ptr<TSServer> target;
@@ -295,18 +300,18 @@ CommandResult QueryClient::handleCommandServerSelect(Command &cmd) {
if(parm.find_first_not_of("0123456789") == string::npos)
target = serverInstance->getVoiceServerManager()->findServerById(static_cast<ServerId>(stol(parm)));
if(!target && (!cmd[0].has("0") && (!cmd[0].has("sid") || !cmd["sid"] == 0))) return {findError("server_invalid_id"), "Invalid server id"};
if(!target && (!cmd[0].has("0") && (!cmd[0].has("sid") || !cmd["sid"] == 0))) return command_result{error::server_invalid_id, "Invalid server id"};
if(target == this->server) return CommandResult::Success;
if(target == this->server) return command_result{error::ok};
if(target) {
if(this->query_account && this->query_account->bound_server > 0) {
if(target->getServerId() != this->query_account->bound_server)
return {findError("server_invalid_id"), "You're a server bound query, and the target server isn't your origin."};
return command_result{error::server_invalid_id, "You're a server bound query, and the target server isn't your origin."};
} else {
auto allowed = target->calculatePermission(permission::PERMTEST_ORDERED, this->getClientDatabaseId(), permission::b_virtualserver_select, this->getType(), nullptr);
if(allowed != -1 && allowed <= 0) return CommandResultPermissionError{permission::b_virtualserver_select};
if(allowed != -1 && allowed <= 0) return command_result{permission::b_virtualserver_select};
}
}
@@ -362,23 +367,23 @@ CommandResult QueryClient::handleCommandServerSelect(Command &cmd) {
}
this->updateChannelClientProperties(true, true);
return CommandResult::Success;
return command_result{error::ok};
}
CommandResult QueryClient::handleCommandJoin(Command &) {
command_result QueryClient::handleCommandJoin(Command &) {
CMD_REQ_SERVER;
CMD_RESET_IDLE;
if(!this->server->running())
return {findError("server_is_not_running"), "server isnt started yet"};
return command_result{error::server_is_not_running, "server isnt started yet"};
if(this->currentChannel)
return {findError("server_already_joined"), "already joined!"};
return command_result{error::server_already_joined, "already joined!"};
this->server->assignDefaultChannel(this->ref(), true);
return CommandResult::Success;
return command_result{error::ok};
}
CommandResult QueryClient::handleCommandLeft(Command&) {
command_result QueryClient::handleCommandLeft(Command&) {
CMD_REQ_SERVER;
CMD_REQ_CHANNEL;
CMD_RESET_IDLE;
@@ -386,10 +391,10 @@ CommandResult QueryClient::handleCommandLeft(Command&) {
PERM_CHECK_CHANNELR(permission::b_virtualserver_select_godmode, 1, nullptr, 1);
unique_lock server_channel_lock(this->server->channel_tree_lock);
this->server->client_move(this->ref(), nullptr, nullptr, "leaving", ViewReasonId::VREASON_SERVER_LEFT, true, server_channel_lock);
return CommandResult::Success;
return command_result{error::ok};
}
CommandResult QueryClient::handleCommandServerInfo(Command &) {
command_result QueryClient::handleCommandServerInfo(Command &) {
CMD_RESET_IDLE;
PERM_CHECKR(permission::b_virtualserver_info_view, 1, true);
@@ -469,10 +474,10 @@ CommandResult QueryClient::handleCommandServerInfo(Command &) {
}
this->sendCommand(cmd);
return CommandResult::Success;
return command_result{error::ok};
}
CommandResult QueryClient::handleCommandChannelList(Command& cmd) {
command_result QueryClient::handleCommandChannelList(Command& cmd) {
PERM_CHECKR(permission::b_virtualserver_channel_list, 1, true);
CMD_RESET_IDLE;
@@ -530,10 +535,10 @@ CommandResult QueryClient::handleCommandChannelList(Command& cmd) {
}
this->sendCommand(result);
return CommandResult::Success;
return command_result{error::ok};
}
CommandResult QueryClient::handleCommandServerList(Command& cmd) {
command_result QueryClient::handleCommandServerList(Command& cmd) {
CMD_RESET_IDLE;
PERM_CHECKR(permission::b_serverinstance_virtualserver_list, 1, true);
Command res("");
@@ -563,15 +568,15 @@ CommandResult QueryClient::handleCommandServerList(Command& cmd) {
}
this->sendCommand(res);
return CommandResult::Success;
return command_result{error::ok};
}
CommandResult QueryClient::handleCommandServerCreate(Command& cmd) {
command_result QueryClient::handleCommandServerCreate(Command& cmd) {
CMD_RESET_IDLE;
PERM_CHECKR(permission::b_virtualserver_create, 1, true);
if(serverInstance->getVoiceServerManager()->getState() != ServerManager::STARTED) {
return {findError("vs_critical"), "Server manager isn't started yet or not finished starting"};
return command_result{error::vs_critical, "Server manager isn't started yet or not finished starting"};
}
string startError;
@@ -583,9 +588,9 @@ CommandResult QueryClient::handleCommandServerCreate(Command& cmd) {
threads::MutexLock lock(serverInstance->getVoiceServerManager()->server_create_lock);
auto instances = serverInstance->getVoiceServerManager()->serverInstances();
if(config::server::max_virtual_server != -1 && instances.size() > config::server::max_virtual_server)
return {findError("server_max_vs_reached"), "You reached the via config.yml enabled virtual server limit."};
return command_result{error::server_max_vs_reached, "You reached the via config.yml enabled virtual server limit."};
if(instances.size() >= 65535)
return {findError("server_max_vs_reached"), "You cant create anymore virtual servers. (Software limit reached)"};
return command_result{error::server_max_vs_reached, "You cant create anymore virtual servers. (Software limit reached)"};
{
auto end = system_clock::now();
time_wait = duration_cast<milliseconds>(end - start);
@@ -601,7 +606,7 @@ CommandResult QueryClient::handleCommandServerCreate(Command& cmd) {
auto _end = system_clock::now();
time_create = duration_cast<milliseconds>(_end - _start);
}
if(!server) return {findError("vs_critical"), "could not create new server"};
if(!server) return command_result{error::vs_critical, "could not create new server"};
for(const auto& key : cmd[0].keys()){
if(key == "virtualserver_port") continue;
@@ -640,64 +645,64 @@ CommandResult QueryClient::handleCommandServerCreate(Command& cmd) {
res["time_global"] = time_global.count();
res["time_wait"] = time_wait.count();
this->sendCommand(res);
return CommandResult::Success;
return command_result{error::ok};
}
CommandResult QueryClient::handleCommandServerDelete(Command& cmd) {
command_result QueryClient::handleCommandServerDelete(Command& cmd) {
CMD_RESET_IDLE;
PERM_CHECKR(permission::b_virtualserver_delete, 1, true);
if(serverInstance->getVoiceServerManager()->getState() != ServerManager::STARTED)
return {findError("vs_critical"), "Server manager isn't started yet or not finished starting"};
return command_result{error::vs_critical, "Server manager isn't started yet or not finished starting"};
auto server = serverInstance->getVoiceServerManager()->findServerById(cmd["sid"]);
if(!server) return {findError("server_invalid_id"), "invalid bounded server"};
if(!serverInstance->getVoiceServerManager()->deleteServer(server)) return {ErrorType::VSError};
return CommandResult::Success;
if(!server) return command_result{error::server_invalid_id, "invalid bounded server"};
if(!serverInstance->getVoiceServerManager()->deleteServer(server)) return command_result{error::vs_critical};
return command_result{error::ok};
}
CommandResult QueryClient::handleCommandServerStart(Command& cmd) {
command_result QueryClient::handleCommandServerStart(Command& cmd) {
CMD_RESET_IDLE;
PERM_CHECKR(permission::b_virtualserver_start_any, 1, true);
if(serverInstance->getVoiceServerManager()->getState() != ServerManager::STARTED)
return {findError("vs_critical"), "Server manager isn't started yet or not finished starting"};
return command_result{error::vs_critical, "Server manager isn't started yet or not finished starting"};
auto server = serverInstance->getVoiceServerManager()->findServerById(cmd["sid"]);
if(!server) return {findError("server_invalid_id"), "invalid bounded server"};
if(server->running()) return {findError("server_running"), "server already running"};
if(!server) return command_result{error::server_invalid_id, "invalid bounded server"};
if(server->running()) return command_result{error::server_running, "server already running"};
if(server->calculatePermission(permission::PERMTEST_ORDERED, this->getClientDatabaseId(), permission::b_virtualserver_start, ClientType::CLIENT_QUERY, nullptr) != 1) {
if(!this->permissionGranted(permission::PERMTEST_HIGHEST, permission::b_virtualserver_start_any, 1))
return CommandResultPermissionError{permission::b_virtualserver_start};
return command_result{permission::b_virtualserver_start};
}
string err;
if(!server->start(err)) return {findError("vs_critical"), err};
return CommandResult::Success;
if(!server->start(err)) return command_result{error::vs_critical, err};
return command_result{error::ok};
}
CommandResult QueryClient::handleCommandServerStop(Command& cmd) {
command_result QueryClient::handleCommandServerStop(Command& cmd) {
CMD_RESET_IDLE;
PERM_CHECKR(permission::b_virtualserver_stop, 1, true);
if(serverInstance->getVoiceServerManager()->getState() != ServerManager::STARTED)
return {findError("vs_critical"), "Server manager isn't started yet or not finished starting"};
return command_result{error::vs_critical, "Server manager isn't started yet or not finished starting"};
auto server = serverInstance->getVoiceServerManager()->findServerById(cmd["sid"]);
if(!server) return {findError("server_invalid_id"), "invalid bounded server"};
if(!server->running()) return {findError("server_is_not_running"), "server is not running"};
if(!server) return command_result{error::server_invalid_id, "invalid bounded server"};
if(!server->running()) return command_result{error::server_is_not_running, "server is not running"};
if(server->calculatePermission(permission::PERMTEST_ORDERED, this->getClientDatabaseId(), permission::b_virtualserver_stop, ClientType::CLIENT_QUERY, nullptr) != 1) {
if(!this->permissionGranted(permission::PERMTEST_HIGHEST, permission::b_virtualserver_stop_any, 1))
return CommandResultPermissionError{permission::b_virtualserver_stop};
return command_result{permission::b_virtualserver_stop};
}
server->stop("server stopped");
return CommandResult::Success;
return command_result{error::ok};
}
CommandResult QueryClient::handleCommandInstanceInfo(Command& cmd) {
command_result QueryClient::handleCommandInstanceInfo(Command& cmd) {
PERM_CHECKR(permission::b_serverinstance_info_view, 1, true);
Command res("");
@@ -707,10 +712,10 @@ CommandResult QueryClient::handleCommandInstanceInfo(Command& cmd) {
res["serverinstance_teaspeak"] = true;
this->sendCommand(res);
return CommandResult::Success;
return command_result{error::ok};
}
CommandResult QueryClient::handleCommandInstanceEdit(Command& cmd) {
command_result QueryClient::handleCommandInstanceEdit(Command& cmd) {
PERM_CHECKR(permission::b_serverinstance_modify_settings, 1, true);
for(const auto &key : cmd[0].keys()){
@@ -730,10 +735,10 @@ CommandResult QueryClient::handleCommandInstanceEdit(Command& cmd) {
}
serverInstance->properties()[info] = cmd[key].string();
}
return CommandResult::Success;
return command_result{error::ok};
}
CommandResult QueryClient::handleCommandHostInfo(Command &) {
command_result QueryClient::handleCommandHostInfo(Command &) {
PERM_CHECKR(permission::b_serverinstance_info_view, 1, true);
Command res("");
@@ -765,37 +770,37 @@ CommandResult QueryClient::handleCommandHostInfo(Command &) {
res["connection_filetransfer_bytes_received_total"] = (*stats)[property::CONNECTION_FILETRANSFER_BYTES_RECEIVED_TOTAL].as<string>();
this->sendCommand(res);
return CommandResult::Success;
return command_result{error::ok};
}
CommandResult QueryClient::handleCommandGlobalMessage(Command& cmd) {
command_result QueryClient::handleCommandGlobalMessage(Command& cmd) {
PERM_CHECKR(permission::b_serverinstance_textmessage_send, 1, true);
for(const auto &server : serverInstance->getVoiceServerManager()->serverInstances())
if(server->running()) server->broadcastMessage(server->getServerRoot(), cmd["msg"]);
return CommandResult::Success;
return command_result{error::ok};
}
CommandResult QueryClient::handleCommandServerIdGetByPort(Command& cmd) {
command_result QueryClient::handleCommandServerIdGetByPort(Command& cmd) {
uint16_t port = cmd["virtualserver_port"];
auto server = serverInstance->getVoiceServerManager()->findServerByPort(port);
if(!server) return {findError("databse_empty_result"), "Invalid port"};
if(!server) return command_result{error::server_invalid_id};
Command res("");
res["server_id"] = server->getServerId();
this->sendCommand(res);
return CommandResult::Success;
return command_result{error::ok};
}
CommandResult QueryClient::handleCommandBindingList(Command& cmd) {
command_result QueryClient::handleCommandBindingList(Command& cmd) {
Command res("");
res["ip"] = "0.0.0.0 ";
this->sendCommand(res); //TODO maybe list here all bindings from voice & file and query server?
return CommandResult::Success;
return command_result{error::ok};
}
//TODO with mapping!
CommandResult QueryClient::handleCommandServerSnapshotDeploy(Command& cmd) {
command_result QueryClient::handleCommandServerSnapshotDeploy(Command& cmd) {
PERM_CHECKR(permission::b_virtualserver_snapshot_deploy, 1, true);
CMD_RESET_IDLE;
@@ -809,7 +814,7 @@ CommandResult QueryClient::handleCommandServerSnapshotDeploy(Command& cmd) {
}
auto hash = cmd["hash"].string();
if(hash.empty()) return {findError("parameter_invalid"), "Invalid hash (not present)"};
if(hash.empty()) return command_result{error::parameter_invalid, "Invalid hash (not present)"};
debugMessage(this->getServerId(), "Serversnapshot calculated hash: {}", hash);
bool mapping = cmd.hasParm("mapping");
cmd.disableParm("mapping");
@@ -821,7 +826,7 @@ CommandResult QueryClient::handleCommandServerSnapshotDeploy(Command& cmd) {
auto str = cmd.build().substr(strlen("serversnapshotdeploy "));
if(!ignore_hash) {
auto buildHash = base64::encode(digest::sha1(str));
if(buildHash != hash) return {findError("parameter_invalid"), "Invalid hash (Expected: \"" + hash + "\", Got: \"" + buildHash + "\")"};
if(buildHash != hash) return command_result{error::parameter_invalid, "Invalid hash (Expected: \"" + hash + "\", Got: \"" + buildHash + "\")"};
}
unique_lock server_create_lock(serverInstance->getVoiceServerManager()->server_create_lock);
@@ -853,10 +858,10 @@ CommandResult QueryClient::handleCommandServerSnapshotDeploy(Command& cmd) {
res["time"] = duration_cast<milliseconds>(end - start).count();
this->sendCommand(res);
return CommandResult::Success;
return command_result{error::ok};
}
CommandResult QueryClient::handleCommandServerSnapshotCreate(Command& cmd) {
command_result QueryClient::handleCommandServerSnapshotCreate(Command& cmd) {
PERM_CHECKR(permission::b_virtualserver_snapshot_create, 1, true);
CMD_RESET_IDLE;
CMD_REQ_SERVER;
@@ -868,7 +873,7 @@ CommandResult QueryClient::handleCommandServerSnapshotCreate(Command& cmd) {
if(version == -1 && (cmd.hasParm("lagacy") || cmd.hasParm("legacy")))
version = 0;
if(!serverInstance->getVoiceServerManager()->createServerSnapshot(result, this->server, version, error))
return {ErrorType::VSError, error};
return command_result{error::vs_critical, error};
string data = result.build();
auto buildHash = base64::encode(digest::sha1(data));
@@ -877,23 +882,23 @@ CommandResult QueryClient::handleCommandServerSnapshotCreate(Command& cmd) {
result[0]["hash"] = buildHash;
this->sendCommand(result);
return CommandResult::Success;
return command_result{error::ok};
}
extern bool mainThreadActive;
CommandResult QueryClient::handleCommandServerProcessStop(Command& cmd) {
command_result QueryClient::handleCommandServerProcessStop(Command& cmd) {
PERM_CHECKR(permission::b_serverinstance_stop, 1, true);
if(cmd[0].has("type")) {
if(cmd["type"] == "cancel") {
auto task = ts::server::scheduledShutdown();
if(!task) return {findError("server_is_not_shutting_down"), "There isn't a shutdown scheduled"};
if(!task) return command_result{error::server_is_not_shutting_down, "There isn't a shutdown scheduled"};
ts::server::cancelShutdown(true);
return CommandResult::Success;
return command_result{error::ok};
} else if(cmd["type"] == "schedule") {
if(!cmd[0].has("time")) return {findError("parameter_missing"), "Missing time"};
if(!cmd[0].has("time")) return command_result{error::parameter_missing, "Missing time"};
ts::server::scheduleShutdown(system_clock::now() + seconds(cmd["time"].as<uint64_t>()), cmd[0].has("msg") ? cmd["msg"].string() : ts::config::messages::applicationStopped);
return CommandResult::Success;
return command_result{error::ok};
}
}
@@ -904,18 +909,18 @@ CommandResult QueryClient::handleCommandServerProcessStop(Command& cmd) {
reason = cmd["reasonmsg"].string();
serverInstance->getVoiceServerManager()->shutdownAll(reason);
mainThreadActive = false;
return CommandResult::Success;
return command_result{error::ok};
}
#define XMACRO_EV(evName0, evSpec0, evName1, evSpec1) \
if(cmd["event"].value() == "all" || (cmd["event"].value() == (evName0) && (cmd["specifier"].value() == "all" || cmd["specifier"].value() == (evSpec0)))) \
events.push_back({QueryEventGroup::evName1, QueryEventSpecifier::evSpec1});
inline CommandResult parseEvent(ParameterBulk& cmd, vector<pair<QueryEventGroup, QueryEventSpecifier>>& events){
inline bool parseEvent(ParameterBulk& cmd, vector<pair<QueryEventGroup, QueryEventSpecifier>>& events){
auto start = events.size();
#include "XMacroEventTypes.h"
if(start == events.size()) return {findError("parameter_invalid"), "invalid group/specifier"};
return CommandResult::Success;
if(start == events.size()) return false;
return true;
}
#undef XMACRO_EV
@@ -923,7 +928,7 @@ inline CommandResult parseEvent(ParameterBulk& cmd, vector<pair<QueryEventGroup,
#define XMACRO_LAGACY_EV(lagacyName, gr, spec) \
if(event == lagacyName) this->toggleEvent(QueryEventGroup::gr, QueryEventSpecifier::spec, true);
CommandResult QueryClient::handleCommandServerNotifyRegister(Command &cmd) {
command_result QueryClient::handleCommandServerNotifyRegister(Command &cmd) {
CMD_REQ_SERVER;
CMD_REQ_PARM("event");
CMD_RESET_IDLE;
@@ -932,17 +937,17 @@ CommandResult QueryClient::handleCommandServerNotifyRegister(Command &cmd) {
string event = cmd["event"];
std::transform(event.begin(), event.end(), event.begin(), ::tolower);
#include "XMacroEventTypes.h"
return CommandResult::Success;
return command_result{error::ok};
}
//TODO implement bulk
vector<pair<QueryEventGroup, QueryEventSpecifier>> events;
//parameter_invalid
auto result = parseEvent(cmd[0], events);
if(!result) return result;
if(!result) return command_result{error::parameter_invalid};
for(const auto& ev : events)
this->toggleEvent(ev.first, ev.second, true);
return CommandResult::Success;
return command_result{error::ok};
}
#undef XMACRO_LAGACY_EV
@@ -953,7 +958,7 @@ else if((evName1) == group && (evSpec1) == spec){ \
index++; \
}
CommandResult QueryClient::handleCommandServerNotifyList(Command& cmd) {
command_result QueryClient::handleCommandServerNotifyList(Command& cmd) {
CMD_REQ_SERVER;
CMD_RESET_IDLE;
@@ -970,16 +975,16 @@ CommandResult QueryClient::handleCommandServerNotifyList(Command& cmd) {
}
}
if(index == 0) return {findError("database_empty_result"), ""};
if(index == 0) return command_result{error::database_empty_result};
this->sendCommand(res);
return CommandResult::Success;
return command_result{error::ok};
}
#undef XMACRO_EV
#define XMACRO_LAGACY_EV(lagacyName, gr, spec) \
if(event == lagacyName) this->toggleEvent(QueryEventGroup::gr, QueryEventSpecifier::spec, false);
CommandResult QueryClient::handleCommandServerNotifyUnregister(Command &cmd) {
command_result QueryClient::handleCommandServerNotifyUnregister(Command &cmd) {
CMD_REQ_SERVER;
CMD_REQ_PARM("event");
CMD_RESET_IDLE;
@@ -988,15 +993,15 @@ CommandResult QueryClient::handleCommandServerNotifyUnregister(Command &cmd) {
string event = cmd["event"];
std::transform(event.begin(), event.end(), event.begin(), ::tolower);
#include "XMacroEventTypes.h"
return CommandResult::Success;
return command_result{error::ok};
}
//TODO implemt bulk
vector<pair<QueryEventGroup, QueryEventSpecifier>> events;
auto result = parseEvent(cmd[0], events);
if(!result) return result;
if(!result) return command_result{error::parameter_invalid};
for(const auto& ev : events)
this->toggleEvent(ev.first, ev.second, false);
return CommandResult::Success;
return command_result{error::ok};
}
#undef XMACRO_LAGACY_EV
+2 -2
View File
@@ -1,6 +1,6 @@
#ifndef XMACRO_EV
#define XMACRO_EV_UNDEF
#define XMACRO_EV(a, b, c, d)
#ifndef XMACRO_EV
#define XMACRO_EV(a, b, c, d)
#endif
#ifndef XMACRO_LAGACY_EV
#define XMACRO_LAGACY_EV_UNDEF