some more server command tweaks
merged the samples command back into metrics actually allowed advertised commands for ordinary users
This commit is contained in:
parent
5a4c0e925c
commit
f396861bd3
4 changed files with 56 additions and 45 deletions
|
@ -629,7 +629,7 @@ namespace wesnothd {
|
||||||
}
|
}
|
||||||
ban_help_ += "ban 127.0.0.1 2h20m flooded lobby\n"
|
ban_help_ += "ban 127.0.0.1 2h20m flooded lobby\n"
|
||||||
"kban suokko 5D flooded again\n"
|
"kban suokko 5D flooded again\n"
|
||||||
"kban suokko Y One year ban for constant flooding\n";
|
"kban suokko Y One year ban for constant flooding";
|
||||||
}
|
}
|
||||||
|
|
||||||
void ban_manager::load_config(const config& cfg)
|
void ban_manager::load_config(const config& cfg)
|
||||||
|
|
|
@ -111,36 +111,15 @@ void metrics::game_terminated(const std::string& reason)
|
||||||
|
|
||||||
std::ostream& metrics::games(std::ostream& out)
|
std::ostream& metrics::games(std::ostream& out)
|
||||||
{
|
{
|
||||||
if (terminations_.empty()) return out;
|
if (terminations_.empty()) return out << "No game ended so far.";
|
||||||
|
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
out << "Games have been terminated in the following ways: \n";
|
out << "Games have been terminated in the following ways:\n";
|
||||||
for(std::map<std::string,int>::const_iterator i = terminations_.begin(); i != terminations_.end(); ++i) {
|
for(std::map<std::string,int>::const_iterator i = terminations_.begin(); i != terminations_.end(); ++i) {
|
||||||
out << i->first << ": " << i->second << "\n";
|
out << i->first << ": " << i->second << "\n";
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
out << "Total number of games = " << n;
|
out << "Total number of finished games = " << n;
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ostream& metrics::samples(std::ostream& out)
|
|
||||||
{
|
|
||||||
if (samples_.empty()) return out;
|
|
||||||
|
|
||||||
std::vector<metrics::sample> ordered_samples = samples_;
|
|
||||||
std::sort(ordered_samples.begin(), ordered_samples.end(), compare_samples_by_time());
|
|
||||||
|
|
||||||
out << "Request types:\n";
|
|
||||||
|
|
||||||
size_t n = 0;
|
|
||||||
for(std::vector<metrics::sample>::const_iterator s = ordered_samples.begin(); s != ordered_samples.end(); ++s) {
|
|
||||||
out << "'" << s->name << "' called " << s->nsamples << " times "
|
|
||||||
<< s->parsing_time << "("<< s->max_parsing_time <<") parsing time, "
|
|
||||||
<< s->processing_time << "("<<s->max_processing_time<<") processing time\n";
|
|
||||||
++n;
|
|
||||||
}
|
|
||||||
out << "Total number of games = " << n;
|
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -158,8 +137,30 @@ std::ostream& operator<<(std::ostream& out, metrics& met)
|
||||||
<< minutes << " minutes, " << seconds << " seconds\n"
|
<< minutes << " minutes, " << seconds << " seconds\n"
|
||||||
<< met.nrequests_ << " requests serviced. " << requests_immediate
|
<< met.nrequests_ << " requests serviced. " << requests_immediate
|
||||||
<< " (" << percent_immediate << "%) "
|
<< " (" << percent_immediate << "%) "
|
||||||
<< " requests were serviced immediately\n"
|
<< "requests were serviced immediately.\n"
|
||||||
<< "longest burst of requests was " << met.most_consecutive_requests_;
|
<< "longest burst of requests was: " << met.most_consecutive_requests_;
|
||||||
|
|
||||||
|
if (met.samples_.empty()) return out;
|
||||||
|
|
||||||
|
std::vector<metrics::sample> ordered_samples = met.samples_;
|
||||||
|
std::sort(ordered_samples.begin(), ordered_samples.end(), compare_samples_by_time());
|
||||||
|
|
||||||
|
out << "\nSampled request types:\n";
|
||||||
|
|
||||||
|
size_t n = 0;
|
||||||
|
size_t pa = 0;
|
||||||
|
size_t pr = 0;
|
||||||
|
for(std::vector<metrics::sample>::const_iterator s = ordered_samples.begin(); s != ordered_samples.end(); ++s) {
|
||||||
|
out << "'" << s->name << "' called " << s->nsamples << " times "
|
||||||
|
<< s->parsing_time << "("<< s->max_parsing_time <<") parsing time, "
|
||||||
|
<< s->processing_time << "("<<s->max_processing_time<<") processing time\n";
|
||||||
|
n += s->nsamples;
|
||||||
|
pa += s->parsing_time;
|
||||||
|
pr += s->processing_time;
|
||||||
|
}
|
||||||
|
out << "Total number of request samples = " << n << "\n"
|
||||||
|
<< "Total parsing time = " << pa << "\n"
|
||||||
|
<< "Total processing time = " << pr;
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,6 @@ public:
|
||||||
void game_terminated(const std::string& reason);
|
void game_terminated(const std::string& reason);
|
||||||
|
|
||||||
std::ostream& games(std::ostream& out);
|
std::ostream& games(std::ostream& out);
|
||||||
std::ostream& samples(std::ostream& out);
|
|
||||||
friend std::ostream& operator<<(std::ostream& out, metrics& met);
|
friend std::ostream& operator<<(std::ostream& out, metrics& met);
|
||||||
|
|
||||||
struct sample {
|
struct sample {
|
||||||
|
|
|
@ -1125,7 +1125,7 @@ void server::process_query(const network::connection sock,
|
||||||
const simple_wml::string_span& command(query["type"]);
|
const simple_wml::string_span& command(query["type"]);
|
||||||
std::ostringstream response;
|
std::ostringstream response;
|
||||||
const std::string& help_msg = "Available commands are: help, games, metrics,"
|
const std::string& help_msg = "Available commands are: help, games, metrics,"
|
||||||
" motd, netstats [all], samples, stats, status, wml.";
|
" motd, netstats [all], stats, status, wml.";
|
||||||
if (admins_.count(sock) != 0) {
|
if (admins_.count(sock) != 0) {
|
||||||
LOG_SERVER << "Admin Command:" << "\ttype: " << command
|
LOG_SERVER << "Admin Command:" << "\ttype: " << command
|
||||||
<< "\tIP: "<< network::ip_address(sock)
|
<< "\tIP: "<< network::ip_address(sock)
|
||||||
|
@ -1136,8 +1136,16 @@ void server::process_query(const network::connection sock,
|
||||||
response << help_msg;
|
response << help_msg;
|
||||||
} else if (command == "status") {
|
} else if (command == "status") {
|
||||||
response << process_command(command.to_string() + " " + pl->second.name(), pl->second.name());
|
response << process_command(command.to_string() + " " + pl->second.name(), pl->second.name());
|
||||||
} else if (command == "status " + pl->second.name() || command == "metrics"
|
} else if (command == "games"
|
||||||
|| command == "motd" || command == "wml" || command == "netstats" || command == "netstats all") {
|
|| command == "metrics"
|
||||||
|
|| command == "motd"
|
||||||
|
|| command == "netstats"
|
||||||
|
|| command == "netstats all"
|
||||||
|
|| command == "sample"
|
||||||
|
|| command == "stats"
|
||||||
|
|| command == "status " + pl->second.name()
|
||||||
|
|| command == "wml")
|
||||||
|
{
|
||||||
response << process_command(command.to_string(), pl->second.name());
|
response << process_command(command.to_string(), pl->second.name());
|
||||||
} else if (command == admin_passwd_) {
|
} else if (command == admin_passwd_) {
|
||||||
LOG_SERVER << "New Admin recognized:" << "\tIP: "
|
LOG_SERVER << "New Admin recognized:" << "\tIP: "
|
||||||
|
@ -1175,11 +1183,12 @@ std::string server::process_command(const std::string& query, const std::string&
|
||||||
std::string parameters = (i == query.end() ? "" : std::string(i+1,query.end()));
|
std::string parameters = (i == query.end() ? "" : std::string(i+1,query.end()));
|
||||||
utils::strip(parameters);
|
utils::strip(parameters);
|
||||||
const std::string& help_msg = "Available commands are: ban <mask> [<time>] <reason>,"
|
const std::string& help_msg = "Available commands are: ban <mask> [<time>] <reason>,"
|
||||||
" bans [deleted], kick <mask>, k(ick)ban <mask> [<time>] <reason>,"
|
" bans [deleted], kick <mask>, k[ick]ban <mask> [<time>] <reason>,"
|
||||||
" help, games, metrics, netstats, (lobby)msg <message>, motd [<message>],"
|
" help, games, metrics, netstats [all], [lobby]msg <message>, motd [<message>],"
|
||||||
" samples, stats, status [<mask>], searchlog [<mask>], unban <ipmask>";
|
" requestes, stats, status [<mask>], searchlog [<mask>], unban <ipmask>";
|
||||||
// Shutdown and restart commands can only be issued via the socket.
|
// Shutdown, restart and sample commands can only be issued via the socket.
|
||||||
if (command == "shut_down" && issuer_name == "*socket*") {
|
if (command == "shut_down") {
|
||||||
|
if (issuer_name != "*socket*") return "";
|
||||||
if (parameters == "now") {
|
if (parameters == "now") {
|
||||||
throw network::error("shut down");
|
throw network::error("shut down");
|
||||||
} else {
|
} else {
|
||||||
|
@ -1193,7 +1202,8 @@ std::string server::process_command(const std::string& query, const std::string&
|
||||||
|
|
||||||
#ifndef _WIN32 // Not sure if this works on windows
|
#ifndef _WIN32 // Not sure if this works on windows
|
||||||
// TODO: check if this works in windows.
|
// TODO: check if this works in windows.
|
||||||
} else if (command == "restart" && issuer_name == "*socket*") {
|
} else if (command == "restart") {
|
||||||
|
if (issuer_name != "*socket*") return "";
|
||||||
if (restart_command.empty()) {
|
if (restart_command.empty()) {
|
||||||
out << "No restart_command configured! Not restarting.";
|
out << "No restart_command configured! Not restarting.";
|
||||||
} else {
|
} else {
|
||||||
|
@ -1208,10 +1218,12 @@ std::string server::process_command(const std::string& query, const std::string&
|
||||||
out << "New server started.";
|
out << "New server started.";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if (command == "sample" && issuer_name == "*socket*") {
|
} else if (command == "sample") {
|
||||||
if (parameters.empty()) {
|
if (parameters.empty()) {
|
||||||
out << "Current sample frequency: " << request_sample_frequency;
|
out << "Current sample frequency: " << request_sample_frequency;
|
||||||
return out.str();
|
return out.str();
|
||||||
|
} else if (issuer_name != "*socket*") {
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
request_sample_frequency = atoi(parameters.c_str());
|
request_sample_frequency = atoi(parameters.c_str());
|
||||||
if (request_sample_frequency <= 0) {
|
if (request_sample_frequency <= 0) {
|
||||||
|
@ -1220,16 +1232,15 @@ std::string server::process_command(const std::string& query, const std::string&
|
||||||
out << "Sampling every " << request_sample_frequency << " requests.";
|
out << "Sampling every " << request_sample_frequency << " requests.";
|
||||||
}
|
}
|
||||||
} else if (command == "help") {
|
} else if (command == "help") {
|
||||||
out << help_msg;
|
return help_msg;
|
||||||
} else if (command == "stats") {
|
} else if (command == "stats") {
|
||||||
out << "Number of games = " << games_.size()
|
out << "Number of games = " << games_.size()
|
||||||
<< "\nTotal number of users = " << players_.size()
|
<< "\nTotal number of users = " << players_.size()
|
||||||
<< "\nNumber of ghost users = " << ghost_players_.size()
|
<< "\nNumber of ghost users = " << ghost_players_.size()
|
||||||
<< "\nNumber of users in the lobby = " << lobby_.nobservers();
|
<< "\nNumber of users in the lobby = " << lobby_.nobservers();
|
||||||
|
return out.str();
|
||||||
} else if (command == "metrics") {
|
} else if (command == "metrics") {
|
||||||
out << metrics_;
|
out << metrics_;
|
||||||
} else if (command == "samples") {
|
|
||||||
metrics_.samples(out);
|
|
||||||
} else if (command == "games") {
|
} else if (command == "games") {
|
||||||
metrics_.games(out);
|
metrics_.games(out);
|
||||||
} else if (command == "wml") {
|
} else if (command == "wml") {
|
||||||
|
@ -1254,7 +1265,7 @@ std::string server::process_command(const std::string& query, const std::string&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG_SERVER << "<server> " + parameters + "\n";
|
LOG_SERVER << "<server> " + parameters + "\n";
|
||||||
out << "message '" << parameters << "' relayed to players\n";
|
out << "message '" << parameters << "' relayed to players";
|
||||||
} else if (command == "status") {
|
} else if (command == "status") {
|
||||||
out << "STATUS REPORT";
|
out << "STATUS REPORT";
|
||||||
// If a simple username is given we'll check for its IP instead.
|
// If a simple username is given we'll check for its IP instead.
|
||||||
|
@ -1267,7 +1278,7 @@ std::string server::process_command(const std::string& query, const std::string&
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) return "";
|
if (!found) return out.str();
|
||||||
}
|
}
|
||||||
for (wesnothd::player_map::const_iterator pl = players_.begin(); pl != players_.end(); ++pl) {
|
for (wesnothd::player_map::const_iterator pl = players_.begin(); pl != players_.end(); ++pl) {
|
||||||
if (parameters == ""
|
if (parameters == ""
|
||||||
|
@ -1446,7 +1457,7 @@ std::string server::process_command(const std::string& query, const std::string&
|
||||||
i != ip_log_.end(); i++) {
|
i != ip_log_.end(); i++) {
|
||||||
if (utils::wildcard_string_match(i->second, parameters)) {
|
if (utils::wildcard_string_match(i->second, parameters)) {
|
||||||
found_something = true;
|
found_something = true;
|
||||||
out << "\n" << i->first << "@" << i->second;
|
out << "\n'" << i->first << "' @ " << i->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1458,7 +1469,7 @@ std::string server::process_command(const std::string& query, const std::string&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found_something) out << "No results found for '" << parameters << "'.";
|
if (!found_something) out << "\nNo results found for '" << parameters << "'.";
|
||||||
} else {
|
} else {
|
||||||
out << "Command '" << command << "' is not recognized.\n" << help_msg;
|
out << "Command '" << command << "' is not recognized.\n" << help_msg;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue