AuthMe 3.0

//Changes 3.0://
* Repackaging from uk.org.whoami.authme to fr.xephi.authme, please
developpers, update!
* Rewrite some of parts of the plugin
* Some code was already perfect , also did not change it :p
* Full support for phpbb3
* Add full support for WordPress + passwordHash: WORDPRESS
* Completely rewrite Management system for inventories and tp issues,
Thanks to : [[http://dev.bukkit.org/profiles/Possible/|Possible]]
* Rework on /passpartu command
* Completely rewrite the password encryption method
* Add a way for developers to add their own Password Encryption Method
on AuthMe via event way (please see
fr.xephi.authme.events.PasswordEncryptionEvent)
* Add an auto purge with players.dat removing method and essentials
files removing ( if you want authme to hook with an another plugin let
me know )
* Complete Hook with BungeeCord by removing the /server command before
login
* message_lang.yml will never be overwritten with English Strings , but
correctly update the message_lang.yml when needed to
* Fix a lot of issues mentioned in tickets , commants , or by mp, Thanks
for all your reports!
This commit is contained in:
Xephi
2013-10-17 05:14:46 +02:00
parent e6467eccf2
commit 10b4eaeca7
112 changed files with 3142 additions and 2640 deletions
+216
View File
@@ -0,0 +1,216 @@
package fr.xephi.authme.cache.auth;
import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.settings.Settings;
public class PlayerAuth {
private String nickname;
private String hash;
private String ip = "198.18.0.1";
private long lastLogin;
private int x = 0;
private int y = 0;
private int z = 0;
private String world = "world";
private String salt = "";
private String vBhash = null;
private int groupId;
private String email = "your@email.com";
public PlayerAuth(String nickname, String hash, String ip, long lastLogin) {
this.nickname = nickname;
this.hash = hash;
this.ip = ip;
this.lastLogin = lastLogin;
}
public PlayerAuth(String nickname, String hash, String ip, long lastLogin, String email) {
this.nickname = nickname;
this.hash = hash;
this.ip = ip;
this.lastLogin = lastLogin;
this.email = email;
}
public PlayerAuth(String nickname, int x, int y, int z, String world) {
this.nickname = nickname;
this.x = x;
this.y = y;
this.z = z;
this.world = world;
}
public PlayerAuth(String nickname, String hash, String ip, long lastLogin, int x, int y, int z, String world, String email) {
this.nickname = nickname;
this.hash = hash;
this.ip = ip;
this.lastLogin = lastLogin;
this.x = x;
this.y = y;
this.z = z;
this.world = world;
this.email = email;
}
public PlayerAuth(String nickname, String hash, String salt, int groupId, String ip, long lastLogin, int x, int y, int z, String world, String email) {
this.nickname = nickname;
this.hash = hash;
this.ip = ip;
this.lastLogin = lastLogin;
this.x = x;
this.y = y;
this.z = z;
this.world = world;
this.salt = salt;
this.groupId = groupId;
this.email = email;
}
public PlayerAuth(String nickname, String hash, String salt, int groupId , String ip, long lastLogin) {
this.nickname = nickname;
this.hash = hash;
this.ip = ip;
this.lastLogin = lastLogin;
this.salt = salt;
this.groupId = groupId;
}
public PlayerAuth(String nickname, String hash, String salt, String ip, long lastLogin) {
this.nickname = nickname;
this.hash = hash;
this.ip = ip;
this.lastLogin = lastLogin;
this.salt = salt;
}
public PlayerAuth(String nickname, String hash, String salt, String ip, long lastLogin, int x, int y, int z, String world, String email) {
this.nickname = nickname;
this.hash = hash;
this.ip = ip;
this.lastLogin = lastLogin;
this.x = x;
this.y = y;
this.z = z;
this.world = world;
this.salt = salt;
this.email = email;
}
public PlayerAuth(String nickname, String hash, String ip, long lastLogin, int x, int y, int z, String world) {
this.nickname = nickname;
this.hash = hash;
this.ip = ip;
this.lastLogin = lastLogin;
this.x = x;
this.y = y;
this.z = z;
this.world = world;
this.email = "your@email.com";
}
public String getIp() {
return ip;
}
public String getNickname() {
return nickname;
}
public String getHash() {
if(!salt.isEmpty() && Settings.getPasswordHash == HashAlgorithm.MD5VB) {
vBhash = "$MD5vb$"+salt+"$"+hash;
return vBhash;
}
else {
return hash;
}
}
public String getSalt() {
return this.salt;
}
public int getGroupId() {
return groupId;
}
public int getQuitLocX() {
return x;
}
public int getQuitLocY() {
return y;
}
public int getQuitLocZ() {
return z;
}
public String getEmail() {
return email;
}
public void setQuitLocX(int x) {
this.x = x;
}
public void setQuitLocY(int y) {
this.y = y;
}
public void setQuitLocZ(int z) {
this.z = z;
}
public long getLastLogin() {
return lastLogin;
}
public void setHash(String hash) {
this.hash = hash;
}
public void setIp(String ip) {
this.ip = ip;
}
public void setLastLogin(long lastLogin) {
this.lastLogin = lastLogin;
}
public void setEmail(String email) {
this.email = email;
}
public void setSalt(String salt) {
this.salt = salt;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof PlayerAuth)) {
return false;
}
PlayerAuth other = (PlayerAuth) obj;
return other.getIp().equals(this.ip) && other.getNickname().equals(this.nickname);
}
@Override
public int hashCode() {
int hashCode = 7;
hashCode = 71 * hashCode + (this.nickname != null ? this.nickname.hashCode() : 0);
hashCode = 71 * hashCode + (this.ip != null ? this.ip.hashCode() : 0);
return hashCode;
}
public void setWorld(String world) {
this.world = world;
}
public String getWorld() {
return world;
}
@Override
public String toString() {
String s = "Player : " + nickname + " ! IP : " + ip + " ! LastLogin : " + lastLogin + " ! LastPosition : " + x + "," + y + "," + z + "," + world
+ " ! Email : " + email + " ! Hash : " + hash + " ! Salt : " + salt;
return s;
}
}
@@ -0,0 +1,42 @@
package fr.xephi.authme.cache.auth;
import java.util.HashMap;
public class PlayerCache {
private static PlayerCache singleton = null;
private HashMap<String, PlayerAuth> cache;
private PlayerCache() {
cache = new HashMap<String, PlayerAuth>();
}
public void addPlayer(PlayerAuth auth) {
cache.put(auth.getNickname().toLowerCase(), auth);
}
public void updatePlayer(PlayerAuth auth) {
cache.remove(auth.getNickname().toLowerCase());
cache.put(auth.getNickname().toLowerCase(), auth);
}
public void removePlayer(String user) {
cache.remove(user.toLowerCase());
}
public boolean isAuthenticated(String user) {
return cache.containsKey(user.toLowerCase());
}
public PlayerAuth getAuth(String user) {
return cache.get(user.toLowerCase());
}
public static PlayerCache getInstance() {
if (singleton == null) {
singleton = new PlayerCache();
}
return singleton;
}
}
@@ -0,0 +1,45 @@
package fr.xephi.authme.cache.backup;
import org.bukkit.inventory.ItemStack;
public class DataFileCache {
private ItemStack[] inventory;
private ItemStack[] armor;
private String group;
private boolean operator;
private boolean flying;
public DataFileCache(ItemStack[] inventory, ItemStack[] armor){
this.inventory = inventory;
this.armor = armor;
}
public DataFileCache(ItemStack[] inventory, ItemStack[] armor, String group, boolean operator, boolean flying){
this.inventory = inventory;
this.armor = armor;
this.group = group;
this.operator = operator;
this.flying = flying;
}
public ItemStack[] getInventory(){
return inventory;
}
public ItemStack[] getArmour(){
return armor;
}
public String getGroup(){
return group;
}
public boolean getOperator(){
return operator;
}
public boolean isFlying(){
return flying;
}
}
@@ -0,0 +1,187 @@
package fr.xephi.authme.cache.backup;
import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import fr.xephi.authme.api.API;
public class FileCache {
public FileCache() {
final File folder = new File("cache");
if (!folder.exists()) {
folder.mkdirs();
}
}
public void createCache(String playername, DataFileCache playerData, String group, boolean operator, boolean flying) {
final File file = new File("cache/" + playername
+ ".cache");
if (file.exists()) {
return;
}
FileWriter writer = null;
try {
file.createNewFile();
writer = new FileWriter(file);
String s = group+";";
if (operator)
s = s + "1";
else s = s + "0";
// line format Group|OperatorStatus|isFlying
if(flying)
writer.write(s+";1" + API.newline);
else writer.write(s+";0" + API.newline);
writer.flush();
ItemStack[] invstack = playerData.getInventory();
for (int i = 0; i < invstack.length; i++) {
int itemid = 0;
int amount = 0;
int durability = 0;
String enchList = "";
if (invstack[i] != null) {
itemid = invstack[i].getTypeId();
amount = invstack[i].getAmount();
durability = invstack[i].getDurability();
for(Enchantment e : invstack[i].getEnchantments().keySet()) {
enchList = enchList.concat(e.getName()+":"+invstack[i].getEnchantmentLevel(e)+":");
}
}
writer.write("i" + ":" + itemid + ":" + amount + ":"
+ durability + ":"+ enchList + "\r\n");
writer.flush();
}
ItemStack[] armorstack = playerData.getArmour();
for (int i = 0; i < armorstack.length; i++) {
int itemid = 0;
int amount = 0;
int durability = 0;
String enchList = "";
if (armorstack[i] != null) {
itemid = armorstack[i].getTypeId();
amount = armorstack[i].getAmount();
durability = armorstack[i].getDurability();
for(Enchantment e : armorstack[i].getEnchantments().keySet()) {
enchList = enchList.concat(e.getName()+":"+armorstack[i].getEnchantmentLevel(e)+":");
}
}
writer.write("w" + ":" + itemid + ":" + amount + ":"
+ durability + ":"+ enchList + "\r\n");
writer.flush();
}
writer.close();
} catch (final Exception e) {
e.printStackTrace();
}
}
public DataFileCache readCache(String playername) {
final File file = new File("cache/" + playername
+ ".cache");
ItemStack[] stacki = new ItemStack[36];
ItemStack[] stacka = new ItemStack[4];
String group = null;
boolean op = false;
boolean flying = false;
if (!file.exists()) {
return new DataFileCache(stacki, stacka);
}
Scanner reader = null;
try {
reader = new Scanner(file);
int i = 0;
int a = 0;
while (reader.hasNextLine()) {
final String line = reader.nextLine();
if (!line.contains(":")) {
// the fist line represent the player group, operator status and flying status
final String[] playerInfo = line.split(";");
group = playerInfo[0];
if (Integer.parseInt(playerInfo[1]) == 1) {
op = true;
} else op = false;
if (playerInfo.length > 2) {
if (Integer.parseInt(playerInfo[2]) == 1)
flying = true;
else flying = false;
}
continue;
}
final String[] in = line.split(":");
if (!in[0].equals("i") && !in[0].equals("w")) {
continue;
}
// can enchant item? size ofstring in file - 4 all / 2 = number of enchant
if (in[0].equals("i")) {
stacki[i] = new ItemStack(Integer.parseInt(in[1]),
Integer.parseInt(in[2]), Short.parseShort((in[3])));
if(in.length > 4 && !in[4].isEmpty()) {
for(int k=4;k<in.length-1;k++) {
stacki[i].addUnsafeEnchantment(Enchantment.getByName(in[k]) ,Integer.parseInt(in[k+1]));
k++;
}
}
i++;
} else {
stacka[a] = new ItemStack(Integer.parseInt(in[1]),
Integer.parseInt(in[2]), Short.parseShort((in[3])));
if(in.length > 4 && !in[4].isEmpty()) {
for(int k=4;k<in.length-1;k++) {
stacka[a].addUnsafeEnchantment(Enchantment.getByName(in[k]) ,Integer.parseInt(in[k+1]));
k++;
}
}
a++;
}
}
} catch (final Exception e) {
e.printStackTrace();
} finally {
if (reader != null) {
reader.close();
}
}
return new DataFileCache(stacki, stacka, group, op, flying);
}
public void removeCache(String playername) {
final File file = new File("cache/" + playername
+ ".cache");
if (file.exists()) {
file.delete();
}
}
public boolean doesCacheExist(String playername) {
final File file = new File("cache/" + playername
+ ".cache");
if (file.exists()) {
return true;
}
return false;
}
}
@@ -0,0 +1,125 @@
package fr.xephi.authme.cache.limbo;
import java.util.HashMap;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.api.API;
import fr.xephi.authme.cache.backup.FileCache;
import fr.xephi.authme.events.ResetInventoryEvent;
import fr.xephi.authme.events.StoreInventoryEvent;
import fr.xephi.authme.settings.Settings;
public class LimboCache {
private static LimboCache singleton = null;
public HashMap<String, LimboPlayer> cache;
private FileCache playerData = new FileCache();
public AuthMe plugin;
private LimboCache(AuthMe plugin) {
this.plugin = plugin;
this.cache = new HashMap<String, LimboPlayer>();
}
public void addLimboPlayer(Player player) {
String name = player.getName().toLowerCase();
Location loc = player.getLocation();
int gameMode = player.getGameMode().getValue();
ItemStack[] arm;
ItemStack[] inv;
boolean operator;
String playerGroup = "";
boolean flying;
if (playerData.doesCacheExist(name)) {
StoreInventoryEvent event = new StoreInventoryEvent(player, playerData);
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled() && event.getInventory() != null && event.getArmor() != null) {
inv = event.getInventory();
arm = event.getArmor();
} else {
inv = null;
arm = null;
}
playerGroup = playerData.readCache(name).getGroup();
operator = playerData.readCache(name).getOperator();
flying = playerData.readCache(name).isFlying();
} else {
StoreInventoryEvent event = new StoreInventoryEvent(player);
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled() && event.getInventory() != null && event.getArmor() != null) {
inv = event.getInventory();
arm = event.getArmor();
} else {
inv = null;
arm = null;
}
if(player.isOp())
operator = true;
else operator = false;
if(player.isFlying())
flying = true;
else flying = false;
}
if(Settings.isForceSurvivalModeEnabled) {
if(Settings.isResetInventoryIfCreative && gameMode != 0 ) {
ResetInventoryEvent event = new ResetInventoryEvent(player);
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
API.setPlayerInventory(player, new ItemStack[36], new ItemStack[4]);
player.sendMessage("Your inventory has been cleaned!");
}
}
gameMode = 0;
}
if(player.isDead()) {
loc = plugin.getSpawnLocation(player.getWorld());
}
try {
if(cache.containsKey(name) && playerGroup.isEmpty()) {
LimboPlayer groupLimbo = cache.get(name);
playerGroup = groupLimbo.getGroup();
}
} catch (NullPointerException ex) {
}
cache.put(player.getName().toLowerCase(), new LimboPlayer(name, loc, inv, arm, gameMode, operator, playerGroup, flying));
}
public void addLimboPlayer(Player player, String group) {
cache.put(player.getName().toLowerCase(), new LimboPlayer(player.getName().toLowerCase(), group));
}
public void deleteLimboPlayer(String name) {
cache.remove(name);
}
public LimboPlayer getLimboPlayer(String name) {
return cache.get(name);
}
public boolean hasLimboPlayer(String name) {
return cache.containsKey(name);
}
public static LimboCache getInstance() {
if (singleton == null) {
singleton = new LimboCache(AuthMe.getInstance());
}
return singleton;
}
public void updateLimboPlayer(Player player) {
if (this.hasLimboPlayer(player.getName().toLowerCase())) {
this.deleteLimboPlayer(player.getName().toLowerCase());
}
this.addLimboPlayer(player);
}
}
@@ -0,0 +1,100 @@
package fr.xephi.authme.cache.limbo;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;
public class LimboPlayer {
private String name;
private ItemStack[] inventory;
private ItemStack[] armour;
private Location loc = null;
private int timeoutTaskId = -1;
private int messageTaskId = -1;
private int gameMode = 0;
private boolean operator = false;
private String group = null;
private boolean flying = false;
public LimboPlayer(String name, Location loc, ItemStack[] inventory, ItemStack[] armour, int gameMode, boolean operator, String group, boolean flying) {
this.name = name;
this.loc = loc;
this.inventory = inventory;
this.armour = armour;
this.gameMode = gameMode;
this.operator = operator;
this.group = group;
this.flying = flying;
}
public LimboPlayer(String name, Location loc, int gameMode, boolean operator, String group, boolean flying) {
this.name = name;
this.loc = loc;
this.gameMode = gameMode;
this.operator = operator;
this.group = group;
this.flying = flying;
}
public LimboPlayer(String name, String group) {
this.name = name;
this.group = group;
}
public String getName() {
return name;
}
public Location getLoc() {
return loc;
}
public ItemStack[] getArmour() {
return armour;
}
public ItemStack[] getInventory() {
return inventory;
}
public void setArmour(ItemStack[] armour) {
this.armour = armour;
}
public void setInventory(ItemStack[] inventory) {
this.inventory = inventory;
}
public int getGameMode() {
return gameMode;
}
public boolean getOperator() {
return operator;
}
public String getGroup() {
return group;
}
public void setTimeoutTaskId(int i) {
this.timeoutTaskId = i;
}
public int getTimeoutTaskId() {
return timeoutTaskId;
}
public void setMessageTaskId(int messageTaskId) {
this.messageTaskId = messageTaskId;
}
public int getMessageTaskId() {
return messageTaskId;
}
public boolean isFlying() {
return flying;
}
}