Prevent players from logging into the wrong clans server

This commit is contained in:
Shaun Bennett 2015-08-28 17:31:09 -07:00
parent c51a449df3
commit 676817601a
2 changed files with 71 additions and 0 deletions

View File

@ -56,6 +56,7 @@ import mineplex.game.clans.clans.commands.ClanManagementCommand;
import mineplex.game.clans.clans.commands.ClansAllyChatCommand;
import mineplex.game.clans.clans.commands.ClansChatCommand;
import mineplex.game.clans.clans.commands.ClansCommand;
import mineplex.game.clans.clans.commands.ClansLoginManager;
import mineplex.game.clans.clans.commands.MapCommand;
import mineplex.game.clans.clans.commands.RegionsCommand;
import mineplex.game.clans.clans.commands.ServerTimeCommand;
@ -183,6 +184,8 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
_explosion = new Explosion(plugin, blockRestore);
new ClansLoginManager(getPlugin(), clientManager, _serverName);
Energy energy = new Energy(plugin);
// TODO: Re-enable customtagfix with NCP update?
//new CustomTagFix(plugin, packetHandler);

View File

@ -0,0 +1,68 @@
package mineplex.game.clans.clans.commands;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.ILoginProcessor;
import mineplex.core.common.util.UtilPlayer;
import mineplex.database.Tables;
import org.jooq.impl.DSL;
public class ClansLoginManager extends MiniPlugin implements ILoginProcessor
{
private String _serverName;
public ClansLoginManager(JavaPlugin plugin, CoreClientManager clientManager, String serverName)
{
super("Clans Login Manager", plugin);
_serverName = serverName;
clientManager.addStoredProcedureLoginProcessor(this);
}
private void kickPlayer(Player player, String homeServer)
{
player.kickPlayer("This is not your home server. To play clans, connect to " + homeServer);
}
@Override
public void processLoginResultSet(final String playerName, int accountId, ResultSet resultSet) throws SQLException
{
while (resultSet.next())
{
final String serverName = resultSet.getString(1);
if (serverName != null)
{
System.out.println("Player " + playerName + " is from server: " + serverName);
if (!serverName.equals(_serverName))
{
runSyncLater(new Runnable()
{
@Override
public void run()
{
final Player player = UtilPlayer.searchExact(playerName);
if (player != null)
kickPlayer(player, serverName);
}
}, 20);
}
}
}
}
@Override
public String getQuery(int accountId, String uuid, String name)
{
return "SELECT `clanServer`.`serverName` FROM `accountClan` JOIN `clans` ON `clans`.`id` = `accountClan`.`clanId` JOIN `clanServer` ON `clanServer`.`id` = `clans`.`serverId` WHERE `accountClan`.`accountId` = " + accountId + ";";
}
}