Revert to old login logic. Ban messages weren't working right.

This commit is contained in:
Steven Lawson 2013-07-11 18:21:23 -04:00
parent 22bf0c2f62
commit aaf96d00a9

View File

@ -121,6 +121,8 @@ public class TFM_ServerInterface
public static void handlePlayerLogin(PlayerLoginEvent event) public static void handlePlayerLogin(PlayerLoginEvent event)
{ {
// this should supersede all other onPlayerLogin authentication on the TFM server.
// when using the TFM CraftBukkit, CraftBukkit itself should not do any of its own authentication.
final Server server = TotalFreedomMod.plugin.getServer(); final Server server = TotalFreedomMod.plugin.getServer();
@ -135,8 +137,7 @@ public class TFM_ServerInterface
if (player_name.trim().length() <= 2) if (player_name.trim().length() <= 2)
{ {
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username is too short (must be at least 3 characters long).");
"Your username is too short (must be at least 3 characters long).");
return; return;
} }
else if (Pattern.compile("[^a-zA-Z0-9\\-\\.\\_]").matcher(player_name).find()) else if (Pattern.compile("[^a-zA-Z0-9\\-\\.\\_]").matcher(player_name).find())
@ -145,8 +146,7 @@ public class TFM_ServerInterface
return; return;
} }
// not safe to use TFM_Util.isUserSuperadmin for player logging in because p.getAddress() // not safe to use TFM_Util.isUserSuperadmin for player logging in because p.getAddress() will return a null until after player login.
// will return a null until after player login.
boolean is_superadmin; boolean is_superadmin;
if (server.getOnlineMode()) if (server.getOnlineMode())
{ {
@ -271,21 +271,8 @@ public class TFM_ServerInterface
} }
} }
} }
else // if user is superadmin else
{ {
// force-allow superadmins to log in
event.allow();
if (isIPBanned(player_ip))
{
unbanIP(player_ip);
}
if (isNameBanned(player_name))
{
unbanUsername(player_name);
}
for (Player test_player : server.getOnlinePlayers()) for (Player test_player : server.getOnlinePlayers())
{ {
if (test_player.getName().equalsIgnoreCase(player_name)) if (test_player.getName().equalsIgnoreCase(player_name))
@ -294,22 +281,19 @@ public class TFM_ServerInterface
} }
} }
if (server.getOnlinePlayers().length >= server.getMaxPlayers()) boolean can_kick = true; // if the server is full of superadmins, however unlikely that might be, this will prevent an infinite loop.
while (server.getOnlinePlayers().length >= server.getMaxPlayers() && can_kick)
{ {
for (Player op : server.getOnlinePlayers()) can_kick = false;
for (Player test_player : server.getOnlinePlayers())
{ {
if (!TFM_SuperadminList.isUserSuperadmin(op)) if (!TFM_SuperadminList.isUserSuperadmin(test_player))
{ {
op.kickPlayer("You have been kicked to free up space for an admin"); can_kick = true;
return; test_player.kickPlayer("You have been kicked to free up room for an admin.");
break;
} }
} }
// if the server is full of superadmins, however unlikely that might be, this will prevent an infinite loop.
if (server.getOnlinePlayers().length >= server.getMaxPlayers())
{
event.disallow(PlayerLoginEvent.Result.KICK_FULL, "Sorry, this server is full");
}
} }
} }
} }