Server user limit configuration option

master
Perttu Ahola 2011-09-26 11:57:51 +03:00
parent 0ccc0ac927
commit b9e680d06c
2 changed files with 20 additions and 9 deletions

View File

@ -77,6 +77,7 @@ void set_default_settings()
// Server stuff // Server stuff
g_settings.setDefault("motd", ""); g_settings.setDefault("motd", "");
g_settings.setDefault("max_users", "20");
g_settings.setDefault("enable_experimental", "false"); g_settings.setDefault("enable_experimental", "false");
g_settings.setDefault("creative_mode", "false"); g_settings.setDefault("creative_mode", "false");
g_settings.setDefault("enable_damage", "true"); g_settings.setDefault("enable_damage", "true");

View File

@ -2097,10 +2097,20 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
m_authmanager.save(); m_authmanager.save();
} }
// Enforce user limit.
// Don't enforce for users that have some admin right
if(m_clients.size() >= g_settings.getU16("max_users") &&
(m_authmanager.getPrivs(playername)
& (PRIV_SERVER|PRIV_BAN|PRIV_PRIVS)) == 0 &&
playername != g_settings.get("name"))
{
SendAccessDenied(m_con, peer_id, L"Too many users.");
return;
}
// Get player // Get player
Player *player = emergePlayer(playername, password, peer_id); Player *player = emergePlayer(playername, password, peer_id);
/*{ /*{
// DEBUG: Test serialization // DEBUG: Test serialization
std::ostringstream test_os; std::ostringstream test_os;
@ -4426,17 +4436,17 @@ void Server::handlePeerChange(PeerChange &c)
// Collect information about leaving in chat // Collect information about leaving in chat
std::wstring message; std::wstring message;
{ {
std::wstring name = L"unknown";
Player *player = m_env.getPlayer(c.peer_id); Player *player = m_env.getPlayer(c.peer_id);
if(player != NULL) if(player != NULL)
name = narrow_to_wide(player->getName()); {
std::wstring name = narrow_to_wide(player->getName());
message += L"*** "; message += L"*** ";
message += name; message += name;
message += L" left game"; message += L" left game";
if(c.timeout) if(c.timeout)
message += L" (timed out)"; message += L" (timed out)";
} }
}
/*// Delete player /*// Delete player
{ {