Add command to change server info keys on live servers

- Ability to modify some existing keys (sort, status, name, location,
and type).
- Ability to add, modify, and remove extra keys.
This commit is contained in:
Nathan Fulton 2016-04-03 15:34:35 -04:00
parent 3032e898fb
commit 99f659f6fe
3 changed files with 44 additions and 0 deletions

View File

@ -289,6 +289,22 @@ void Server::OnCommand(const std::string command, const json::JsonMap *map) {
json::JsonString *name = (json::JsonString *)objN;
json::JsonString *message = (json::JsonString *)objM;
lobby_.SendAdminChat(name->GetString(), message->GetString());
} else if (command == "setinfo") {
const json::JsonObject *objK = map->GetObject("key");
if (objK == NULL || objK->type() != json::JSONTYPE_STRING) {
return;
}
const json::JsonObject *objV = map->GetObject("value");
if (objV == NULL || objV->type() != json::JSONTYPE_STRING) {
return;
}
json::JsonString *key = (json::JsonString *)objK;
json::JsonString *value = (json::JsonString *)objV;
if (updater_ != NULL) {
updater_->SetInfo(key->GetString(), value->GetString());
}
}
}

View File

@ -185,4 +185,31 @@ void ServerInfoUpdater::ParseExtra(const std::string& extra_json) {
delete map;
}
void ServerInfoUpdater::SetInfo(const std::string key, const std::string value) {
if (key == "sort") {
int n = 0;
base::Format::ToInteger(value.c_str(), 10, &n);
sort_key_ = n;
} else if (key == "status") {
if (value == "drain") {
drain_ = true;
}
if (value == "undrain" || value == "ok") {
drain_ = false;
}
} else if (key == "name") {
server_name_ = value;
} else if (key == "location") {
server_location_ = value;
} else if (key == "type") {
server_type_ = value;
} else {
if (value.empty()) {
extra_.erase(key);
} else {
extra_[key] = value;
}
}
}
} // namespace wi

View File

@ -33,6 +33,7 @@ public:
~ServerInfoUpdater();
void Start();
void SetInfo(const std::string key, const std::string value);
void set_drain() { drain_ = true; }
void clear_drain() { drain_ = false; }