Start working on BungeeAuth support

This commit is contained in:
games647
2016-03-20 12:49:24 +01:00
parent 5608821fe3
commit 10bfd279d6
12 changed files with 128 additions and 14 deletions

View File

@ -34,6 +34,7 @@ So they don't need to enter passwords. This is also called auto login (auto-logi
* Java 7+
* Run Spigot and/or BungeeCord in offline mode (see server.properties or config.yml)
* An auth plugin. Supported Plugins:
* Bukkit:
* [AuthMe](http://dev.bukkit.org/bukkit-plugins/authme-reloaded/)
* [xAuth](http://dev.bukkit.org/bukkit-plugins/xauth/)
* [CrazyLogin](http://dev.bukkit.org/bukkit-plugins/crazylogin/)
@ -41,6 +42,9 @@ So they don't need to enter passwords. This is also called auto login (auto-logi
* [RoyalAuth](http://dev.bukkit.org/bukkit-plugins/royalauth/)
* [UltraAuth](http://dev.bukkit.org/bukkit-plugins/ultraauth-aa/)
* BungeeCord:
* [BungeeAuth](https://www.spigotmc.org/resources/bungeeauth.493/)
###Downloads
https://www.spigotmc.org/resources/fastlogin.14153/history

View File

@ -6,7 +6,6 @@ import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.utility.SafeCacheBuilder;
import com.github.games647.fastlogin.bukkit.commands.CrackedCommand;
import com.github.games647.fastlogin.bukkit.commands.PremiumCommand;
import com.github.games647.fastlogin.bukkit.hooks.AuthPlugin;
import com.github.games647.fastlogin.bukkit.listener.BukkitJoinListener;
import com.github.games647.fastlogin.bukkit.listener.BungeeCordListener;
import com.github.games647.fastlogin.bukkit.listener.EncryptionPacketListener;
@ -28,6 +27,7 @@ import java.util.logging.Level;
import org.apache.commons.lang.RandomStringUtils;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin;
/**
* This plugin checks if a player has a paid account and if so tries to skip offline mode authentication.
@ -58,7 +58,7 @@ public class FastLoginBukkit extends JavaPlugin {
}
});
private AuthPlugin authPlugin;
private BukkitAuthPlugin authPlugin;
private final MojangApiConnector mojangApiConnector = new MojangApiConnector(this);
@Override
@ -157,7 +157,7 @@ public class FastLoginBukkit extends JavaPlugin {
*
* @return interface to any supported auth plugin
*/
public AuthPlugin getAuthPlugin() {
public BukkitAuthPlugin getAuthPlugin() {
return authPlugin;
}
@ -172,7 +172,7 @@ public class FastLoginBukkit extends JavaPlugin {
}
private boolean registerHooks() {
AuthPlugin authPluginHook = null;
BukkitAuthPlugin authPluginHook = null;
try {
String hooksPackage = this.getClass().getPackage().getName() + ".hooks";
//Look through all classes in the hooks package and look for supporting plugins on the server
@ -181,10 +181,10 @@ public class FastLoginBukkit extends JavaPlugin {
String pluginName = clazzInfo.getSimpleName().replace("Hook", "");
Class<?> clazz = clazzInfo.load();
//uses only member classes which uses AuthPlugin interface (skip interfaces)
if (AuthPlugin.class.isAssignableFrom(clazz)
if (BukkitAuthPlugin.class.isAssignableFrom(clazz)
//check only for enabled plugins. A single plugin could be disabled by plugin managers
&& getServer().getPluginManager().isPluginEnabled(pluginName)) {
authPluginHook = (AuthPlugin) clazz.newInstance();
authPluginHook = (BukkitAuthPlugin) clazz.newInstance();
getLogger().log(Level.INFO, "Hooking into auth plugin: {0}", pluginName);
break;
}

View File

@ -11,7 +11,7 @@ import org.bukkit.entity.Player;
* Bukkit: http://dev.bukkit.org/bukkit-plugins/authme-reloaded/
* Spigot: https://www.spigotmc.org/resources/authme-reloaded.6269/
*/
public class AuthMeHook implements AuthPlugin {
public class AuthMeHook implements BukkitAuthPlugin {
@Override
public void forceLogin(Player player) {

View File

@ -3,9 +3,9 @@ package com.github.games647.fastlogin.bukkit.hooks;
import org.bukkit.entity.Player;
/**
* Represents a supporting authentication plugin
* Represents a supporting authentication plugin in Bukkit/Spigot/... servers
*/
public interface AuthPlugin {
public interface BukkitAuthPlugin {
/**
* Login the premium (paid account) player after

View File

@ -20,7 +20,7 @@ import org.bukkit.entity.Player;
*
* Bukkit: http://dev.bukkit.org/server-mods/crazylogin/
*/
public class CrazyLoginHook implements AuthPlugin {
public class CrazyLoginHook implements BukkitAuthPlugin {
private final PlayerListener playerListener = getListener();

View File

@ -21,7 +21,7 @@ import org.bukkit.entity.Player;
* on join:
* https://github.com/lenis0012/LoginSecurity-2/blob/master/src/main/java/com/lenis0012/bukkit/ls/LoginSecurity.java#L282
*/
public class LoginSecurityHook implements AuthPlugin {
public class LoginSecurityHook implements BukkitAuthPlugin {
@Override
public void forceLogin(Player player) {

View File

@ -11,7 +11,7 @@ import org.royaldev.royalauth.Config;
*
* Bukkit: http://dev.bukkit.org/bukkit-plugins/royalauth/
*/
public class RoyalAuthHook implements AuthPlugin {
public class RoyalAuthHook implements BukkitAuthPlugin {
@Override
public void forceLogin(Player player) {

View File

@ -61,7 +61,7 @@ import ultraauth.api.UltraAuthAPI;
* Bukkit: http://dev.bukkit.org/bukkit-plugins/ultraauth-aa/
* Spigot: https://www.spigotmc.org/resources/ultraauth.17044/
*/
public class UltraAuthHook implements AuthPlugin {
public class UltraAuthHook implements BukkitAuthPlugin {
@Override
public void forceLogin(Player player) {

View File

@ -12,7 +12,7 @@ import org.bukkit.entity.Player;
*
* Bukkit: http://dev.bukkit.org/bukkit-plugins/xauth/
*/
public class xAuthHook implements AuthPlugin {
public class xAuthHook implements BukkitAuthPlugin {
@Override
public void forceLogin(Player player) {

View File

@ -22,6 +22,12 @@
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<!--Github automatic maven builds-->
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
@ -32,5 +38,11 @@
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.MatteCarra</groupId>
<artifactId>BungeeAuth</artifactId>
<version>-1.2.1-gc367d92-8</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,70 @@
package com.github.games647.fastlogin.bungee.hooks;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import me.vik1395.BungeeAuth.ListenerClass;
import me.vik1395.BungeeAuth.Main;
import me.vik1395.BungeeAuth.Password.PasswordHandler;
import me.vik1395.BungeeAuth.Tables;
import net.md_5.bungee.api.connection.ProxiedPlayer;
/**
* Github: https://github.com/MatteCarra/BungeeAuth
*
* Project page:
*
* Spigot: https://www.spigotmc.org/resources/bungeeauth.493/
*/
public class BungeeAuthHook implements BungeeAuthPlugin {
//https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Login.java#L32
private final Tables databaseConnection = new Tables();
@Override
public void forceLogin(ProxiedPlayer player) {
//https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Login.java#L92-95
Main.plonline.add(player.getName());
//renamed from ct to databaseConnection
// databaseConnection.setStatus(player.getName(), "online");
ListenerClass.movePlayer(player, false);
ListenerClass.prelogin.get(player.getName()).cancel();
}
@Override
public boolean isRegistered(String playerName) {
//https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Register.java#L46
//renamed t to databaseConnection
return databaseConnection.checkPlayerEntry(playerName);
}
@Override
public void forceRegister(ProxiedPlayer player, String password) {
//https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Register.java#L102
PasswordHandler ph = new PasswordHandler();
Random rand = new Random();
int maxp = 7; //Total Password Hashing methods.
Date dNow = new Date();
SimpleDateFormat ft = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
String Pw = password;
String pType = "" + rand.nextInt(maxp + 1);
String regdate = ft.format(dNow);
//https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Register.java#L60
String lastip = player.getAddress().getAddress().getHostAddress();
String lastseen = regdate;
String hash = ph.newHash(Pw, pType);
//creates a new SQL entry with the player's details.
// try {
//renamed t to databaseConnection
// databaseConnection.newPlayerEntry(player.getName(), hash, pType, "", lastip, regdate, lastip, lastseen);
ListenerClass.prelogin.get(player.getName()).cancel();
// } catch (SQLException e) {
// Main.plugin.getLogger().severe("[BungeeAuth] Error when creating a new player in the MySQL Database");
// e.printStackTrace();
// }
}
}

View File

@ -0,0 +1,28 @@
package com.github.games647.fastlogin.bungee.hooks;
import net.md_5.bungee.api.connection.ProxiedPlayer;
//do not use yet -
public interface BungeeAuthPlugin {
/**
*
* @param player the player that needs to be logged in
*/
void forceLogin(ProxiedPlayer player);
/**
*
* @param playerName player name
* @return if the player has an account
*/
boolean isRegistered(String playerName);
/**
*
* @param player the premium account
* @param password a strong random generated password
*/
void forceRegister(ProxiedPlayer player, String password);
}