don't queue disconnects on shut down

add a 'help' command
This commit is contained in:
Gunter Labes 2008-01-05 17:49:57 +00:00
parent 80c7037486
commit d1b2c4890a

View File

@ -354,11 +354,11 @@ void server::run() {
WRN_CONFIG << "Warning: error in received data: " << e.message << "\n";
} catch(network::error& e) {
if (e.message == "shut down") {
LOG_SERVER << "Kicking everyone...\n";
LOG_SERVER << "Try to disconnect all users...\n";
for (player_map::const_iterator pl = players_.begin();
pl != players_.end(); ++pl)
{
network::queue_disconnect(pl->first);
network::disconnect(pl->first);
}
std::cout << "Shutting server down.\n";
break;
@ -591,34 +591,35 @@ void server::process_query(const network::connection sock, const config& query)
DBG_SERVER << "ERROR: Could not find player with socket: " << sock << "\n";
return;
}
std::string command(query["type"]);
const std::string& command(query["type"]);
std::ostringstream response;
if (command == "status" && admins_.count(sock) == 0) {
command += " " + pl->second.name();
}
if (command.empty()) {
// commands a player may issue
} else if (command == "metrics" || command == "motd"
|| command == "status " + pl->second.name()) {
response << process_command(command);
} else if (admin_passwd_.empty() == false && command == admin_passwd_) {
admins_.insert(sock);
response << "You are now recognized as an administrator";
LOG_SERVER << "New Admin recognized:" << "\tIP: "
<< network::ip_address(sock) << "\tnick: "
<< pl->second.name() << std::endl;
} else if (admins_.count(sock) != 0) {
response << process_command(command);
const std::string& help_msg = "Available commands are: help, metrics,"
" motd, status.";
if (admins_.count(sock) != 0) {
LOG_SERVER << "Admin Command:" << "\ttype: " << command
<< "\tIP: "<< network::ip_address(sock)
<< "\tnick: "<< pl->second.name() << std::endl;
response << process_command(command);
// Commands a player may issue.
} else if (command == "help") {
response << help_msg;
} else if (command == "status") {
response << process_command(command + " " + pl->second.name());
} else if (command == "metrics" || command == "motd") {
response << process_command(command);
} else if (command == admin_passwd_) {
LOG_SERVER << "New Admin recognized:" << "\tIP: "
<< network::ip_address(sock) << "\tnick: "
<< pl->second.name() << std::endl;
admins_.insert(sock);
response << "You are now recognized as an administrator.";
} else if (admin_passwd_.empty() == false) {
WRN_SERVER << "FAILED Admin attempt:" << "\tIP: "
<< network::ip_address(sock) << "\tnick: "
<< pl->second.name() << std::endl;
response << "Error: unrecognized query";
response << "Error: unrecognized query.\n" << help_msg;
} else {
response << "Error: unrecognized query";
response << "Error: unrecognized query.\n" << help_msg;
}
network::send_data(lobby_.construct_server_message(response.str()), sock, send_gzipped_);
}
@ -629,10 +630,18 @@ std::string server::process_command(const std::string& query) {
const std::string command(query.begin(),i);
std::string parameters = (i == query.end() ? "" : std::string(i+1,query.end()));
utils::strip(parameters);
const std::string& help_msg = "Available commands are: (k)ban(s) [<mask>],"
"kick <mask>, help, metrics, (lobby)msg <message>, motd [<message>],"
"status [<mask>], unban <ipmask>";
if (command == "shut_down") {
throw network::error("shut down");
}
if (command == "msg" || command == "lobbymsg") {
} else if (command == "help") {
out << help_msg;
} else if (command == "metrics") {
out << metrics_ << "Current number of games = " << games_.size() << "\n"
"Total number of users = " << players_.size() << "\n"
"Number of users in the lobby = " << lobby_.nobservers() << "\n";
} else if (command == "msg" || command == "lobbymsg") {
if (parameters == "") {
return "You must type a message.";
}
@ -660,10 +669,6 @@ std::string server::process_command(const std::string& query) {
<< stats.bytes_received << " bytes\n";
}
}
} else if (command == "metrics") {
out << metrics_ << "Current number of games = " << games_.size() << "\n"
"Total number of users = " << players_.size() << "\n"
"Number of users in the lobby = " << lobby_.nobservers() << "\n";
} else if (command == "ban" || command == "bans" || command == "kban") {
if (parameters == "") {
if (bans_.empty()) return "No bans set.";
@ -765,10 +770,7 @@ std::string server::process_command(const std::string& query) {
motd_ = parameters;
out << "Message of the day set to: " << motd_;
} else {
out << "Command '" << command << "' is not recognized.\n";
out << "Available commands are: (lobby)msg <message>, motd [<message>]"
", status [<mask>], metrics, (k)ban(s) [<mask>], unban <ipmask>"
", kick <mask>";
out << "Command '" << command << "' is not recognized.\n" << help_msg;
}
return out.str();