Fix BungeeCord player real IP - 2.7.12b1

This commit is contained in:
Xephi 2013-03-21 00:03:34 +01:00
parent cedafe52a8
commit def5821e5c
12 changed files with 141 additions and 40 deletions

BIN
lib/BungeeCord.jar Normal file

Binary file not shown.

Binary file not shown.

View File

@ -28,12 +28,12 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<version>2.7.11b3</version> <version>2.7.12b1</version>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> <artifactId>bukkit</artifactId>
<version>1.4.7-R1.0</version> <version>1.5-R0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.milkbowl.vault</groupId> <groupId>net.milkbowl.vault</groupId>
@ -122,9 +122,9 @@
<dependency> <dependency>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId> <artifactId>bungeecord-api</artifactId>
<version>1.4.7-SNAPSHOT</version> <version>1.5-SNAPSHOT</version>
<scope>system</scope> <scope>system</scope>
<systemPath>${project.basedir}/lib/bungeecord-api-1.4.7-20130228.060400-44.jar</systemPath> <systemPath>${project.basedir}/lib/BungeeCord.jar</systemPath>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sun.mail</groupId> <groupId>com.sun.mail</groupId>

View File

@ -95,6 +95,7 @@ public class AuthMe extends JavaPlugin {
public API api; public API api;
public HashMap<String, Integer> captcha = new HashMap<String, Integer>(); public HashMap<String, Integer> captcha = new HashMap<String, Integer>();
public HashMap<String, String> cap = new HashMap<String, String>(); public HashMap<String, String> cap = new HashMap<String, String>();
public HashMap<String, String> bungeesIp = new HashMap<String, String>();
public MultiverseCore mv = null; public MultiverseCore mv = null;
@Override @Override
@ -233,7 +234,11 @@ public class AuthMe extends JavaPlugin {
api = new API(this, database); api = new API(this, database);
management = new Management(database, this); management = new Management(database, this);
if (Settings.bungee) {
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeCord(this));
}
PluginManager pm = getServer().getPluginManager(); PluginManager pm = getServer().getPluginManager();
if (pm.isPluginEnabled("Spout")) { if (pm.isPluginEnabled("Spout")) {
pm.registerEvents(new AuthMeSpoutListener(database), this); pm.registerEvents(new AuthMeSpoutListener(database), this);

View File

@ -0,0 +1,52 @@
package uk.org.whoami.authme;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import uk.org.whoami.authme.settings.Settings;
public class BungeeCord implements PluginMessageListener {
public AuthMe plugin;
public BungeeCord(AuthMe plugin) {
this.plugin = plugin;
}
@Override
public void onPluginMessageReceived(String channel, Player player,
byte[] message) {
if (channel.equals("BungeeCord")) {
DataInputStream in = new DataInputStream(new ByteArrayInputStream(
message));
try {
String packetType = in.readUTF();
if (packetType.equals("IP")) {
if (player.isOnline()) {
String ip = in.readUTF();
if (!Settings.noConsoleSpam)
ConsoleLogger.info(
"Got data from bungeecord: Player "
+ player.getName()
+ " Logged in with IP :" + ip);
String name = player.getName();
plugin.bungeesIp.put(name, ip);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

View File

@ -5,8 +5,6 @@ import java.util.Date;
import java.util.List; import java.util.List;
import me.muizers.Notifications.Notification; import me.muizers.Notifications.Notification;
import net.md_5.bungee.api.connection.ConnectedPlayer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -62,12 +60,14 @@ public class Management {
String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
String ip = player.getAddress().getAddress().getHostAddress(); String ip = player.getAddress().getAddress().getHostAddress();
if (Settings.bungee && player instanceof ProxiedPlayer) { String playerName = player.getName();
ProxiedPlayer pPlayer = (ProxiedPlayer) player; if (Settings.bungee) {
ip = pPlayer.getAddress().getAddress().getHostAddress(); try {
} else if (Settings.bungee && player instanceof ConnectedPlayer) { if (plugin.bungeesIp.containsKey(playerName))
ConnectedPlayer cPlayer = (ConnectedPlayer) player; ip = plugin.bungeesIp.get(playerName);
ip = cPlayer.getAddress().getAddress().getHostAddress(); } catch (NoClassDefFoundError ncdfe) {
ConsoleLogger.showError("Your BungeeCord version is outdated");
}
} }
World world = player.getWorld(); World world = player.getWorld();
Location spawnLoc = world.getSpawnLocation(); Location spawnLoc = world.getSpawnLocation();

View File

@ -20,8 +20,6 @@ import java.security.NoSuchAlgorithmException;
import java.util.Date; import java.util.Date;
import me.muizers.Notifications.Notification; import me.muizers.Notifications.Notification;
import net.md_5.bungee.api.connection.ConnectedPlayer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -78,14 +76,16 @@ public class RegisterCommand implements CommandExecutor {
final Player player = (Player) sender; final Player player = (Player) sender;
final String name = player.getName().toLowerCase(); final String name = player.getName().toLowerCase();
final String playerName = player.getName();
String ipA = player.getAddress().getAddress().getHostAddress(); String ipA = player.getAddress().getAddress().getHostAddress();
if (Settings.bungee && player instanceof ProxiedPlayer) { if (Settings.bungee) {
ProxiedPlayer pPlayer = (ProxiedPlayer) player; try {
ipA = pPlayer.getAddress().getAddress().getHostAddress(); if (plugin.bungeesIp.containsKey(playerName))
} else if (Settings.bungee && player instanceof ConnectedPlayer) { ipA = plugin.bungeesIp.get(playerName);
ConnectedPlayer cPlayer = (ConnectedPlayer) player; } catch (NoClassDefFoundError ncdfe) {
ipA = cPlayer.getAddress().getAddress().getHostAddress(); ConsoleLogger.showError("Your BungeeCord version is outdated");
}
} }
final String ip = ipA; final String ip = ipA;

View File

@ -110,7 +110,13 @@ public class MySQLDataSource implements DataSource {
+ lastlocZ + " smallint(6) DEFAULT '0'," + lastlocZ + " smallint(6) DEFAULT '0',"
+ columnEmail + " VARCHAR(255) DEFAULT 'your@email.com'," + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com',"
+ "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));"); + "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));");
rs = con.getMetaData().getColumns(null, null, tableName, columnPassword);
if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
+ columnPassword + " VARCHAR(255) NOT NULL;");
}
rs.close();
rs = con.getMetaData().getColumns(null, null, tableName, columnIp); rs = con.getMetaData().getColumns(null, null, tableName, columnIp);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "

View File

@ -93,7 +93,13 @@ public class SqliteDataSource implements DataSource {
+ lastlocZ + " smallint(6) DEFAULT '0'," + lastlocZ + " smallint(6) DEFAULT '0',"
+ columnEmail + " VARCHAR(255) DEFAULT 'your@email.com'," + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com',"
+ "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));"); + "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));");
rs = con.getMetaData().getColumns(null, null, tableName, columnPassword);
if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
+ columnPassword + " VARCHAR(255) NOT NULL;");
}
rs.close();
rs = con.getMetaData().getColumns(null, null, tableName, columnIp); rs = con.getMetaData().getColumns(null, null, tableName, columnIp);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "

View File

@ -16,12 +16,12 @@
package uk.org.whoami.authme.listener; package uk.org.whoami.authme.listener;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import net.md_5.bungee.api.connection.ConnectedPlayer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
@ -664,9 +664,36 @@ public class AuthMePlayerListener implements Listener {
Location spawnLoc = world.getSpawnLocation(); Location spawnLoc = world.getSpawnLocation();
gm = player.getGameMode().getValue(); gm = player.getGameMode().getValue();
final String name = player.getName().toLowerCase(); final String name = player.getName().toLowerCase();
final String playerName = player.getName();
gameMode.put(name, gm); gameMode.put(name, gm);
BukkitScheduler sched = plugin.getServer().getScheduler(); BukkitScheduler sched = plugin.getServer().getScheduler();
final PlayerJoinEvent e = event; final PlayerJoinEvent e = event;
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
try {
ByteArrayOutputStream b = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(b);
try {
out.writeUTF("IP");
} catch (IOException e) {
// Can never happen
}
plugin.getServer()
.getPlayerExact(playerName)
.sendPluginMessage(plugin, "BungeeCord",
b.toByteArray());
} catch (Exception exception) {
exception.printStackTrace();
}
}
}, 21L);
if (plugin.getCitizensCommunicator().isNPC(player, plugin) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { if (plugin.getCitizensCommunicator().isNPC(player, plugin) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) {
@ -674,12 +701,13 @@ public class AuthMePlayerListener implements Listener {
} }
String ip = player.getAddress().getAddress().getHostAddress(); String ip = player.getAddress().getAddress().getHostAddress();
if (Settings.bungee && player instanceof ProxiedPlayer) { if (Settings.bungee) {
ProxiedPlayer pPlayer = (ProxiedPlayer) player; try {
ip = pPlayer.getAddress().getAddress().getHostAddress(); if (plugin.bungeesIp.containsKey(playerName))
} else if (Settings.bungee && player instanceof ConnectedPlayer) { ip = plugin.bungeesIp.get(playerName);
ConnectedPlayer cPlayer = (ConnectedPlayer) player; } catch (NoClassDefFoundError ncdfe) {
ip = cPlayer.getAddress().getAddress().getHostAddress(); ConsoleLogger.showError("Your BungeeCord version is outdated");
}
} }
if(Settings.isAllowRestrictedIp && !Settings.getRestrictedIp(name, ip)) { if(Settings.isAllowRestrictedIp && !Settings.getRestrictedIp(name, ip)) {
int gM = gameMode.get(name); int gM = gameMode.get(name);
@ -961,10 +989,9 @@ public class AuthMePlayerListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
if (event.isCancelled() || event.getPlayer() == null) { if (event.isCancelled() || event.getPlayer() == null) return;
return; if (event.getClickedBlock() == null) return;
}
Player player = event.getPlayer(); Player player = event.getPlayer();
String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
@ -982,11 +1009,16 @@ public class AuthMePlayerListener implements Listener {
} }
} }
final int sign = event.getClickedBlock().getTypeId(); try {
if (sign == Material.SIGN_POST.getId() || sign == Material.WALL_SIGN.getId()) { final int sign = event.getClickedBlock().getTypeId();
event.setUseInteractedBlock(org.bukkit.event.Event.Result.DENY); if (sign == Material.SIGN_POST.getId() || sign == Material.WALL_SIGN.getId()) {
event.setUseInteractedBlock(org.bukkit.event.Event.Result.DENY);
}
} catch (NullPointerException npe) {
} }
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -3,7 +3,7 @@ author: darkwarriros,Xephi
website: http://www.multiplayer-italia.com/ website: http://www.multiplayer-italia.com/
description: AuthMe prevents people, which aren't logged in, from doing stuff like placing blocks, moving, typing commands or seeing the inventory of the current player. description: AuthMe prevents people, which aren't logged in, from doing stuff like placing blocks, moving, typing commands or seeing the inventory of the current player.
main: uk.org.whoami.authme.AuthMe main: uk.org.whoami.authme.AuthMe
version: 2.7.11b3 version: 2.7.12b1
softdepend: [Vault, ChestShop, Spout, Multiverse-Core, Notifications, Citizens, CombatTag] softdepend: [Vault, ChestShop, Spout, Multiverse-Core, Notifications, Citizens, CombatTag]
commands: commands:
register: register: