/reg command can block anon logins server wide

Admins can issue "/reg server" to prevent anonymous logins on the game server.
This commit is contained in:
Nathan Fulton 2016-03-15 13:47:52 -04:00
parent 896e5a59a3
commit f6dd61415f
5 changed files with 40 additions and 4 deletions

View File

@ -209,6 +209,11 @@ bool LoginForm::AttemptLogin() {
"The player authentication server is not responding. Please try to login as an anonymous player.");
return false;
case knLoginResultNoAnons:
HtMessageBox(kfMbWhiteBorder, "Login Failure",
"This server does not allow anonymous logins. Please login with an account.");
return false;
case knLoginResultFail:
default:
if (!handler_.anonymous()) {

View File

@ -78,6 +78,7 @@ const dword knLoginResultFail = 2;
const dword knLoginResultStaleToken = 3;
const dword knLoginResultAuthDown = 4;
const dword knLoginResultNoPassword = 5;
const dword knLoginResultNoAnons = 6;
STARTLABEL(LoginResults)
LABEL(knLoginResultSuccess)
@ -86,6 +87,7 @@ STARTLABEL(LoginResults)
LABEL(knLoginResultStaleToken)
LABEL(knLoginResultAuthDown)
LABEL(knLoginResultNoPassword)
LABEL(knLoginResultNoAnons)
ENDLABEL(LoginResults)
const dword knSignOutResultSuccess = 0;

View File

@ -117,8 +117,13 @@ void Endpoint::OnLogin(const char *username, const char *token, const char *did)
return;
}
// Anonymous login always works, if that's what the user wants
// Try anonymous login if that's what the user wants
if (TokenAuth::IsAnonymous(username, token)) {
if (!server_.AnonsAllowed() && !admin_) {
LOG() << "FAILED LOGIN: Server doesn't allow anon logins: " << username << ", " << token << ", " << did;
xpump_.Send(XMsgLoginResult::ToBuffer(knLoginResultNoAnons));
return;
}
RememberName(name_);
delete name_;
name_ = AllocString(base::Format::ToString("anon%d", id_));
@ -1044,6 +1049,19 @@ bool Endpoint::ProcessCommand(const char *chat, std::string *response) {
*response = "Room id not found.";
return true;
}
if (roomid_str == "server" && IsAdmin()) {
bool anonsAllowed = server().AnonsAllowed();
if (anonsAllowed) {
server().SetAnonsAllowed(false);
*response = "The server is now closed to anons.";
} else {
server().SetAnonsAllowed(true);
*response = "The server is now open to everyone.";
}
return true;
}
dword roomid = 0;
base::Format::ToDword(roomid_str.c_str(), 10, &roomid);
room = server_.lobby().FindRoom(roomid);
@ -1340,9 +1358,9 @@ bool Endpoint::ProcessCommand(const char *chat, std::string *response) {
case kModeratorCommandHelp:
if (IsAdmin()) {
if (state_ == ES_GAME) {
*response = "/ids [all] [lobby] [roomid] [gameid], /mute <id> [minutes], /unmute <id>, /ban <id> [minutes], /rooms, /kill <roomid>, /games <roomid>, /names <id>, /w <id>, /m, /title <roomid>, /clear, /filter, /sig, /see, /perm <roomid>, /reg <roomid>, /swap, /anon, /rules, /flag [msg], /ann [msg], /help.";
*response = "/ids [all] [lobby] [roomid] [gameid], /mute <id> [minutes], /unmute <id>, /ban <id> [minutes], /rooms, /kill <roomid>, /games <roomid>, /names <id>, /w <id>, /m, /title <roomid>, /clear, /filter, /sig, /see, /perm <roomid>, /reg [server] [roomid], /swap, /anon, /rules, /flag [msg], /ann [msg], /help.";
} else {
*response = "/ids [all] [lobby] [roomid] [gameid], /mute <id> [minutes], /unmute <id>, /kick <id> [minutes], /ban <id> [minutes], /rooms, /kill <roomid>, /games <roomid>, /names <id>, /w <id>, /m, /title <roomid>, /clear, /filter, /sig, /see, /perm <roomid>, /reg <roomid>, /rules, /flag [msg], /ann [msg], /help.";
*response = "/ids [all] [lobby] [roomid] [gameid], /mute <id> [minutes], /unmute <id>, /kick <id> [minutes], /ban <id> [minutes], /rooms, /kill <roomid>, /games <roomid>, /names <id>, /w <id>, /m, /title <roomid>, /clear, /filter, /sig, /see, /perm <roomid>, /reg [server] [roomid], /rules, /flag [msg], /ann [msg], /help.";
}
} else {
if (state_ == ES_GAME) {

View File

@ -30,7 +30,7 @@ Server::Server(StatsPoster& poster, XMsgLog *log, LevelInfoCache& cache,
modlist_watcher_(modlist_path), badwords_(badwords_path),
listener_(NULL), gameidCounter_(1), endpointidCounter_(1),
endpoint_count_thread_safe_(0), updater_(NULL),
logger_("log", id) {
logger_("log", id), anons_allowed_(true) {
start_time_ = base::GetSecondsUnixEpocUTC();
@ -364,4 +364,12 @@ bool Server::IsAdmin(const char *name) {
return false;
}
bool Server::AnonsAllowed() {
return anons_allowed_;
}
void Server::SetAnonsAllowed(bool anons_allowed) {
anons_allowed_ = anons_allowed;
}
} // namespace wi

View File

@ -44,6 +44,8 @@ public:
Endpoint *GetEndpoint(dword id);
bool IsModerator(const char *name);
bool IsAdmin(const char *name);
bool AnonsAllowed();
void SetAnonsAllowed(bool anons_allowed);
dword GetChatterId(Endpoint *endpointAsker, Endpoint *endpoint);
Endpoint *GetEndpointFromChatterId(dword id);
const char *GetChatRules();
@ -86,6 +88,7 @@ private:
base::Socket *listener_;
LevelInfoCache& cache_;
bool checksync_;
bool anons_allowed_;
dword gameidCounter_;
dword endpointidCounter_;
dword start_time_;