diff --git a/game/loginform.cpp b/game/loginform.cpp index e04d738..adcfe41 100644 --- a/game/loginform.cpp +++ b/game/loginform.cpp @@ -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()) { diff --git a/mpshared/messages.h b/mpshared/messages.h index d7cde1b..f5bdedf 100644 --- a/mpshared/messages.h +++ b/mpshared/messages.h @@ -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; diff --git a/server/endpoint.cpp b/server/endpoint.cpp index b6b8434..b65e745 100644 --- a/server/endpoint.cpp +++ b/server/endpoint.cpp @@ -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 [minutes], /unmute , /ban [minutes], /rooms, /kill , /games , /names , /w , /m, /title , /clear, /filter, /sig, /see, /perm , /reg , /swap, /anon, /rules, /flag [msg], /ann [msg], /help."; + *response = "/ids [all] [lobby] [roomid] [gameid], /mute [minutes], /unmute , /ban [minutes], /rooms, /kill , /games , /names , /w , /m, /title , /clear, /filter, /sig, /see, /perm , /reg [server] [roomid], /swap, /anon, /rules, /flag [msg], /ann [msg], /help."; } else { - *response = "/ids [all] [lobby] [roomid] [gameid], /mute [minutes], /unmute , /kick [minutes], /ban [minutes], /rooms, /kill , /games , /names , /w , /m, /title , /clear, /filter, /sig, /see, /perm , /reg , /rules, /flag [msg], /ann [msg], /help."; + *response = "/ids [all] [lobby] [roomid] [gameid], /mute [minutes], /unmute , /kick [minutes], /ban [minutes], /rooms, /kill , /games , /names , /w , /m, /title , /clear, /filter, /sig, /see, /perm , /reg [server] [roomid], /rules, /flag [msg], /ann [msg], /help."; } } else { if (state_ == ES_GAME) { diff --git a/server/server.cpp b/server/server.cpp index e756460..51b9ba6 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -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 diff --git a/server/server.h b/server/server.h index cecd4df..caffcd1 100644 --- a/server/server.h +++ b/server/server.h @@ -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_;