diff --git a/server/server.cpp b/server/server.cpp index a6e765a..2207515 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -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()); + } } } diff --git a/server/serverinfoupdater.cpp b/server/serverinfoupdater.cpp index 10ef1c7..af0b358 100644 --- a/server/serverinfoupdater.cpp +++ b/server/serverinfoupdater.cpp @@ -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 diff --git a/server/serverinfoupdater.h b/server/serverinfoupdater.h index 6f5d802..babe37a 100644 --- a/server/serverinfoupdater.h +++ b/server/serverinfoupdater.h @@ -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; }