mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-22 00:27:36 +01:00
Moved VeryGames IP check into AsyncJoin process.
- Updated VeryGames IP check method. - Remove player's IP from realIp map on quit.
This commit is contained in:
parent
4ea6cc9d69
commit
052e414ff3
@ -1,35 +1,9 @@
|
|||||||
package fr.xephi.authme;
|
package fr.xephi.authme;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.PluginManager;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
import org.mcstats.Metrics;
|
|
||||||
import org.mcstats.Metrics.Graph;
|
|
||||||
|
|
||||||
import com.earth2me.essentials.Essentials;
|
import com.earth2me.essentials.Essentials;
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
|
import com.google.common.io.Resources;
|
||||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||||
|
|
||||||
import fr.xephi.authme.api.API;
|
import fr.xephi.authme.api.API;
|
||||||
import fr.xephi.authme.api.NewAPI;
|
import fr.xephi.authme.api.NewAPI;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
@ -80,6 +54,29 @@ import fr.xephi.authme.util.StringUtils;
|
|||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.Utils;
|
||||||
import fr.xephi.authme.util.Wrapper;
|
import fr.xephi.authme.util.Wrapper;
|
||||||
import net.minelink.ctplus.CombatTagPlus;
|
import net.minelink.ctplus.CombatTagPlus;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
import org.mcstats.Metrics;
|
||||||
|
import org.mcstats.Metrics.Graph;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The AuthMe main class.
|
* The AuthMe main class.
|
||||||
@ -135,6 +132,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the plugin's instance.
|
* Get the plugin's instance.
|
||||||
|
*
|
||||||
* @return AuthMe
|
* @return AuthMe
|
||||||
*/
|
*/
|
||||||
public static AuthMe getInstance() {
|
public static AuthMe getInstance() {
|
||||||
@ -143,6 +141,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the plugin's name.
|
* Get the plugin's name.
|
||||||
|
*
|
||||||
* @return The plugin's name.
|
* @return The plugin's name.
|
||||||
*/
|
*/
|
||||||
public static String getPluginName() {
|
public static String getPluginName() {
|
||||||
@ -151,6 +150,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the plugin's version.
|
* Get the plugin's version.
|
||||||
|
*
|
||||||
* @return The plugin's version.
|
* @return The plugin's version.
|
||||||
*/
|
*/
|
||||||
public static String getPluginVersion() {
|
public static String getPluginVersion() {
|
||||||
@ -159,6 +159,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the plugin's build number.
|
* Get the plugin's build number.
|
||||||
|
*
|
||||||
* @return The plugin's build number.
|
* @return The plugin's build number.
|
||||||
*/
|
*/
|
||||||
public static String getPluginBuildNumber() {
|
public static String getPluginBuildNumber() {
|
||||||
@ -167,6 +168,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the plugin's Settings.
|
* Get the plugin's Settings.
|
||||||
|
*
|
||||||
* @return Plugin's settings.
|
* @return Plugin's settings.
|
||||||
*/
|
*/
|
||||||
public Settings getSettings() {
|
public Settings getSettings() {
|
||||||
@ -175,6 +177,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Messages instance.
|
* Get the Messages instance.
|
||||||
|
*
|
||||||
* @return Plugin's messages.
|
* @return Plugin's messages.
|
||||||
*/
|
*/
|
||||||
public Messages getMessages() {
|
public Messages getMessages() {
|
||||||
@ -274,7 +277,6 @@ public class AuthMe extends JavaPlugin {
|
|||||||
new PerformBackup(plugin).doBackup(PerformBackup.BackupCause.START);
|
new PerformBackup(plugin).doBackup(PerformBackup.BackupCause.START);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Setup the inventory backup
|
// Setup the inventory backup
|
||||||
playerBackup = new JsonCache();
|
playerBackup = new JsonCache();
|
||||||
|
|
||||||
@ -308,7 +310,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
// Register a server shutdown hook
|
// Register a server shutdown hook
|
||||||
try {
|
try {
|
||||||
Runtime.getRuntime().addShutdownHook(new AuthMeServerStop(this));
|
Runtime.getRuntime().addShutdownHook(new AuthMeServerStop(this));
|
||||||
} catch (Exception e){
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -717,8 +719,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
inventoryProtector = null;
|
inventoryProtector = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tabComplete == null)
|
if (tabComplete == null) {
|
||||||
{
|
|
||||||
tabComplete = new AuthMeTabCompletePacketAdapter(this);
|
tabComplete = new AuthMeTabCompletePacketAdapter(this);
|
||||||
tabComplete.register();
|
tabComplete.register();
|
||||||
}
|
}
|
||||||
@ -891,50 +892,34 @@ public class AuthMe extends JavaPlugin {
|
|||||||
* Gets a player's real IP through VeryGames method.
|
* Gets a player's real IP through VeryGames method.
|
||||||
*
|
*
|
||||||
* @param player The player to process.
|
* @param player The player to process.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void getVerygamesIp(final Player player) {
|
public void getVerygamesIp(final Player player) {
|
||||||
final String name = player.getName().toLowerCase();
|
final String name = player.getName().toLowerCase();
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable(){
|
String currentIp = player.getAddress().getAddress().getHostAddress();
|
||||||
@Override
|
if (realIp.containsKey(name)) {
|
||||||
public void run() {
|
currentIp = realIp.get(name);
|
||||||
String realIP = player.getAddress().getAddress().getHostAddress();
|
}
|
||||||
if (realIp.containsKey(name))
|
|
||||||
realIP = realIp.get(name);
|
|
||||||
String sUrl = "http://monitor-1.verygames.net/api/?action=ipclean-real-ip&out=raw&ip=%IP%&port=%PORT%";
|
String sUrl = "http://monitor-1.verygames.net/api/?action=ipclean-real-ip&out=raw&ip=%IP%&port=%PORT%";
|
||||||
sUrl = sUrl.replace("%IP%", realIP)
|
sUrl = sUrl.replace("%IP%", currentIp).replace("%PORT%", "" + player.getAddress().getPort());
|
||||||
.replace("%PORT%", "" + player.getAddress().getPort());
|
|
||||||
try {
|
try {
|
||||||
URL url = new URL(sUrl);
|
String result = Resources.toString(new URL(sUrl), Charsets.UTF_8);
|
||||||
URLConnection urlCon = url.openConnection();
|
if (!StringUtils.isEmpty(result) && !result.equalsIgnoreCase("error") && !result.contains("error")) {
|
||||||
urlCon.setConnectTimeout(5000);
|
currentIp = result;
|
||||||
urlCon.setReadTimeout(5000);
|
realIp.put(name, currentIp);
|
||||||
try (BufferedReader in = new BufferedReader(new InputStreamReader(urlCon.getInputStream()))) {
|
|
||||||
String inputLine = in.readLine();
|
|
||||||
if (!StringUtils.isEmpty(inputLine) && !inputLine.equalsIgnoreCase("error")
|
|
||||||
&& !inputLine.contains("error")) {
|
|
||||||
realIP = inputLine;
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
ConsoleLogger.showError("Could not read from Very Games API - " + StringUtils.formatException(e));
|
ConsoleLogger.showError("Could not fetch Very Games API with URL '" +
|
||||||
|
sUrl + "' - " + StringUtils.formatException(e));
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
ConsoleLogger.showError("Could not fetch Very Games API with URL '" + sUrl + "' - "
|
|
||||||
+ StringUtils.formatException(e));
|
|
||||||
}
|
|
||||||
if (realIp.containsKey(name))
|
|
||||||
realIp.remove(name);
|
|
||||||
realIp.putIfAbsent(name, realIP);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIP(final Player player) {
|
public String getIP(final Player player) {
|
||||||
final String name = player.getName().toLowerCase();
|
final String name = player.getName().toLowerCase();
|
||||||
String ip = player.getAddress().getAddress().getHostAddress();
|
String ip = player.getAddress().getAddress().getHostAddress();
|
||||||
if (realIp.containsKey(name))
|
if (realIp.containsKey(name)) {
|
||||||
ip = realIp.get(name);
|
ip = realIp.get(name);
|
||||||
|
}
|
||||||
return ip;
|
return ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +49,10 @@ public class AsynchronousJoin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void process() {
|
public void process() {
|
||||||
|
if (Settings.checkVeryGames) {
|
||||||
|
plugin.getVerygamesIp(player);
|
||||||
|
}
|
||||||
|
|
||||||
if (Utils.isUnrestricted(player)) {
|
if (Utils.isUnrestricted(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,7 @@ public class AsynchronousQuit {
|
|||||||
database.setUnlogged(name);
|
database.setUnlogged(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugin.realIp.remove(name);
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, player, isOp, needToChange));
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, player, isOp, needToChange));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user