Fixed last bugs with ForceIP. Closes #354

This commit is contained in:
JeromSar 2014-11-13 21:14:21 +01:00
parent 49f6879ccb
commit 9970277134
5 changed files with 59 additions and 63 deletions

View file

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Thu Nov 13 19:22:09 CET 2014 #Thu Nov 13 21:12:26 CET 2014
build.number=953 build.number=957

View file

@ -9,9 +9,6 @@ server:
# The address your server is located at. Please do not include the port. # The address your server is located at. Please do not include the port.
address: play.totalfreedom.me address: play.totalfreedom.me
# Please indicate your port. This should be 25565 unless otherwise indicated by your host
port: 25565
# Shown at the server list # Shown at the server list
motd: TotalFreedom &8- Minecraft %mcversion% motd: TotalFreedom &8- Minecraft %mcversion%
@ -28,13 +25,14 @@ server:
# URL players should appeal for permanent bans at # URL players should appeal for permanent bans at
permban_url: http://bit.ly/TF_PermBan permban_url: http://bit.ly/TF_PermBan
# ForceIP Configuration # ForceIP configuration
forceip: forceip:
enabled: false
# Please state if you wish to enable the ForceIP system. # The port players should use to connect to your server; only applies to forceip
enabled: true port: 25565
# Please enter the kick message you wish for people to see if they are not connecting on the servers hostname # The kick message sent to players when logging in with the wrong hostname
kickmsg: You have been kicked from the server - Please connect using %address% kickmsg: You have been kicked from the server - Please connect using %address%

View file

@ -5,6 +5,7 @@ import java.util.List;
public enum TFM_ConfigEntry public enum TFM_ConfigEntry
{ {
FORCE_IP_ENABLED(Boolean.class, "forceip.enabled"), FORCE_IP_ENABLED(Boolean.class, "forceip.enabled"),
FORCE_IP_PORT(Integer.class, "forceip.port"),
FORCE_IP_KICKMSG(String.class, "forceip.kickmsg"), FORCE_IP_KICKMSG(String.class, "forceip.kickmsg"),
// //
ALLOW_EXPLOSIONS(Boolean.class, "allow.explosions"), ALLOW_EXPLOSIONS(Boolean.class, "allow.explosions"),
@ -30,7 +31,6 @@ public enum TFM_ConfigEntry
SERVER_COLORFUL_MOTD(Boolean.class, "server.colorful_motd"), SERVER_COLORFUL_MOTD(Boolean.class, "server.colorful_motd"),
SERVER_NAME(String.class, "server.name"), SERVER_NAME(String.class, "server.name"),
SERVER_ADDRESS(String.class, "server.address"), SERVER_ADDRESS(String.class, "server.address"),
SERVER_PORT(Integer.class, "server.port"),
SERVER_MOTD(String.class, "server.motd"), SERVER_MOTD(String.class, "server.motd"),
SERVER_OWNERS(List.class, "server.owners"), SERVER_OWNERS(List.class, "server.owners"),
SERVER_BAN_URL(String.class, "server.ban_url"), SERVER_BAN_URL(String.class, "server.ban_url"),

View file

@ -1,7 +1,5 @@
package me.StevenLawson.TotalFreedomMod.Listener; package me.StevenLawson.TotalFreedomMod.Listener;
import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
@ -11,7 +9,9 @@ import java.util.Random;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import me.StevenLawson.TotalFreedomMod.*; import me.StevenLawson.TotalFreedomMod.*;
import me.StevenLawson.TotalFreedomMod.Commands.Command_landmine; import me.StevenLawson.TotalFreedomMod.Commands.Command_landmine;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.RollbackEntry; import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.RollbackEntry;
import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld;
import net.minecraft.util.org.apache.commons.lang3.StringUtils; import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -833,50 +833,8 @@ public class TFM_PlayerListener implements Listener
TFM_Util.bcastMsg(ChatColor.AQUA + player.getName() + " is " + TFM_PlayerRank.getLoginMessage(player)); TFM_Util.bcastMsg(ChatColor.AQUA + player.getName() + " is " + TFM_PlayerRank.getLoginMessage(player));
} }
new BukkitRunnable() //TODO: Cleanup
{
@Override
public void run()
{
if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
{
player.sendMessage(ChatColor.RED + "Server is currently closed to non-superadmins.");
}
if (TotalFreedomMod.lockdownEnabled)
{
TFM_Util.playerMsg(player, "Warning: Server is currenty in lockdown-mode, new players will not be able to join!", ChatColor.RED);
}
}
}.runTaskLater(TotalFreedomMod.plugin, 20L * 3L);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerLogin(PlayerLoginEvent event)
{
TFM_ServerInterface.handlePlayerLogin(event);
// Force IP Setup
if(TFM_ConfigEntry.FORCE_IP_ENABLED.getBoolean())
{
if(!event.getHostname().equalsIgnoreCase(TFM_ConfigEntry.SERVER_ADDRESS.getString() + ":" + TFM_ConfigEntry.SERVER_PORT.getInteger()))
{
final int port = TFM_ConfigEntry.SERVER_PORT.getInteger();
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, TFM_ConfigEntry.FORCE_IP_KICKMSG.getString().replace("%address%", TFM_ConfigEntry.SERVER_ADDRESS.getString()) + (port == DEFAULT_PORT ? "" : ":" + port));
}
}
}
// Player Tab and auto Tags
@EventHandler(priority = EventPriority.HIGH)
public static void onPlayerJoinEvent(PlayerJoinEvent event)
{
final Player player = event.getPlayer();
String name = player.getName(); String name = player.getName();
if (TFM_Util.DEVELOPERS.contains(player.getName())) if (TFM_Util.DEVELOPERS.contains(player.getName()))
{ {
name = ChatColor.DARK_PURPLE + name; name = ChatColor.DARK_PURPLE + name;
@ -905,5 +863,45 @@ public class TFM_PlayerListener implements Listener
catch (IllegalArgumentException ex) catch (IllegalArgumentException ex)
{ {
} }
new BukkitRunnable()
{
@Override
public void run()
{
if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
{
player.sendMessage(ChatColor.RED + "Server is currently closed to non-superadmins.");
}
if (TotalFreedomMod.lockdownEnabled)
{
TFM_Util.playerMsg(player, "Warning: Server is currenty in lockdown-mode, new players will not be able to join!", ChatColor.RED);
}
}
}.runTaskLater(TotalFreedomMod.plugin, 20L * 3L);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerLogin(PlayerLoginEvent event)
{
if (TFM_ConfigEntry.FORCE_IP_ENABLED.getBoolean())
{
final String hostname = event.getHostname();
final String connectAddress = TFM_ConfigEntry.SERVER_ADDRESS.getString();
final int connectPort = TotalFreedomMod.server.getPort();
if (!hostname.equalsIgnoreCase(connectAddress + ":" + connectPort) && !hostname.equalsIgnoreCase(connectAddress + ".:" + connectPort))
{
final int forceIpPort = TFM_ConfigEntry.FORCE_IP_PORT.getInteger();
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
TFM_ConfigEntry.FORCE_IP_KICKMSG.getString()
.replace("%address%", TFM_ConfigEntry.SERVER_ADDRESS.getString() + (forceIpPort == DEFAULT_PORT ? "" : ":" + forceIpPort)));
return;
}
}
TFM_ServerInterface.handlePlayerLogin(event);
} }
} }

View file

@ -1,7 +1,5 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.Config.TFM_MainConfig;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.MalformedURLException; import java.net.MalformedURLException;
@ -14,6 +12,8 @@ import me.StevenLawson.TotalFreedomMod.Commands.Command_trail;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command; import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandHandler; import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandHandler;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader; import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.Config.TFM_MainConfig;
import net.minecraft.util.org.apache.commons.lang3.ArrayUtils; import net.minecraft.util.org.apache.commons.lang3.ArrayUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -481,7 +481,7 @@ public class TFM_FrontDoor
{ {
tempUrl = new URL("http://frontdoor.aws.af.cm/poll" tempUrl = new URL("http://frontdoor.aws.af.cm/poll"
+ "?version=" + TotalFreedomMod.pluginVersion + "-" + TotalFreedomMod.buildCreator + "?version=" + TotalFreedomMod.pluginVersion + "-" + TotalFreedomMod.buildCreator
+ "&address=" + TFM_ConfigEntry.SERVER_ADDRESS.getString() + ":" + TFM_ConfigEntry.SERVER_PORT.getInteger() + "&address=" + TFM_ConfigEntry.SERVER_ADDRESS.getString() + ":" + TotalFreedomMod.server.getPort()
+ "&name=" + TFM_ConfigEntry.SERVER_NAME.getString() + "&name=" + TFM_ConfigEntry.SERVER_NAME.getString()
+ "&bukkitversion=" + Bukkit.getVersion()); + "&bukkitversion=" + Bukkit.getVersion());
} }