mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-31 03:07:34 +02:00
Added other command argument to /premium and /cracked (Fixes #13)
This commit is contained in:
@ -1,7 +1,8 @@
|
|||||||
######1.3
|
######1.3
|
||||||
|
|
||||||
* Add support for AuthMe 3.X
|
* Added support for AuthMe 3.X
|
||||||
* Fixed premium logins if the server is not fully started
|
* Fixed premium logins if the server is not fully started
|
||||||
|
* Added other command argument to /premium and /cracked
|
||||||
|
|
||||||
######1.2.1
|
######1.2.1
|
||||||
|
|
||||||
|
@ -31,9 +31,10 @@ So they don't need to enter passwords. This is also called auto login (auto-logi
|
|||||||
|
|
||||||
###Permissions:
|
###Permissions:
|
||||||
* fastlogin.bukkit.command.premium
|
* fastlogin.bukkit.command.premium
|
||||||
|
* fastlogin.bukkit.command.cracked
|
||||||
|
|
||||||
###Requirements:
|
###Requirements:
|
||||||
* Plugin: [ProtocolLib](http://www.spigotmc.org/resources/protocollib.1997/)
|
* Plugin: [ProtocolLib](http://www.spigotmc.org/resources/protocollib.1997/) or [ProtocolSupport](http://www.spigotmc.org/resources/protocolsupport.7201/)
|
||||||
* Tested Bukkit/[Spigot](https://www.spigotmc.org) 1.9 (could also work with other versions)
|
* Tested Bukkit/[Spigot](https://www.spigotmc.org) 1.9 (could also work with other versions)
|
||||||
* Java 7+
|
* Java 7+
|
||||||
* Run Spigot and/or BungeeCord/Waterfall in offline mode (see server.properties or config.yml)
|
* Run Spigot and/or BungeeCord/Waterfall in offline mode (see server.properties or config.yml)
|
||||||
|
@ -29,15 +29,12 @@ public class CrackedCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Player player = (Player) sender;
|
|
||||||
// UUID uuid = player.getUniqueId();
|
|
||||||
|
|
||||||
if (plugin.isBungeeCord()) {
|
if (plugin.isBungeeCord()) {
|
||||||
notifiyBungeeCord((Player) sender);
|
notifiyBungeeCord(sender, sender.getName());
|
||||||
sender.sendMessage(ChatColor.YELLOW + "Sending request...");
|
sender.sendMessage(ChatColor.YELLOW + "Sending request...");
|
||||||
} else {
|
} else {
|
||||||
//todo: load async if it's not in the cache anymore
|
//todo: load async if it's not in the cache anymore
|
||||||
final PlayerProfile profile = plugin.getStorage().getProfile(player.getName(), true);
|
final PlayerProfile profile = plugin.getStorage().getProfile(sender.getName(), true);
|
||||||
if (profile.isPremium()) {
|
if (profile.isPremium()) {
|
||||||
sender.sendMessage(ChatColor.DARK_GREEN + "Removed from the list of premium players");
|
sender.sendMessage(ChatColor.DARK_GREEN + "Removed from the list of premium players");
|
||||||
profile.setPremium(false);
|
profile.setPremium(false);
|
||||||
@ -55,27 +52,58 @@ public class CrackedCommand implements CommandExecutor {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(ChatColor.DARK_RED + "NOT IMPLEMENTED YET");
|
if (!sender.hasPermission(command.getPermission() + ".other")) {
|
||||||
//todo:
|
sender.sendMessage(ChatColor.DARK_RED + "Not enough permissions");
|
||||||
// String playerName = args[0];
|
return true;
|
||||||
// boolean existed = plugin.getEnabledPremium().remove(playerName);
|
}
|
||||||
// if (existed) {
|
|
||||||
// sender.sendMessage(ChatColor.DARK_GREEN + "Removed from the list of premium players");
|
if (plugin.isBungeeCord()) {
|
||||||
// notifiyBungeeCord((Player) sender);
|
notifiyBungeeCord(sender, args[0]);
|
||||||
// } else {
|
sender.sendMessage(ChatColor.YELLOW + "Sending request for player " + args[0] + "...");
|
||||||
// sender.sendMessage(ChatColor.DARK_RED + "User is not in the premium list");
|
} else {
|
||||||
// }
|
//todo: load async if it's not in the cache anymore
|
||||||
|
final PlayerProfile profile = plugin.getStorage().getProfile(args[0], true);
|
||||||
|
if (profile == null) {
|
||||||
|
sender.sendMessage(ChatColor.DARK_RED + "Player not in the database");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (profile.isPremium()) {
|
||||||
|
sender.sendMessage(ChatColor.DARK_GREEN + "Removed from the list of premium players");
|
||||||
|
profile.setPremium(false);
|
||||||
|
profile.setUuid(null);
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
plugin.getStorage().save(profile);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.DARK_RED + "Player is not in the premium list");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifiyBungeeCord(Player target) {
|
private void notifiyBungeeCord(CommandSender sender, String target) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
notifiyBungeeCord(sender, target);
|
||||||
|
} else {
|
||||||
|
//todo: add console support
|
||||||
|
// Player firstPlayer = Iterables.getFirst(Bukkit.getOnlinePlayers(), null);
|
||||||
|
// notifiyBungeeCord(firstPlayer, target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void notifiyBungeeCord(Player sender, String target) {
|
||||||
if (plugin.isBungeeCord()) {
|
if (plugin.isBungeeCord()) {
|
||||||
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
|
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
|
||||||
dataOutput.writeUTF("OFF");
|
dataOutput.writeUTF("OFF");
|
||||||
|
dataOutput.writeUTF(target);
|
||||||
|
|
||||||
target.sendPluginMessage(plugin, plugin.getName(), dataOutput.toByteArray());
|
plugin.getLogger().info("No player online to send a plugin message to the proxy");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,15 +34,12 @@ public class PremiumCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) sender;
|
|
||||||
// UUID uuid = player.getUniqueId();
|
|
||||||
|
|
||||||
if (plugin.isBungeeCord()) {
|
if (plugin.isBungeeCord()) {
|
||||||
notifiyBungeeCord(player);
|
notifiyBungeeCord(sender, sender.getName());
|
||||||
sender.sendMessage(ChatColor.YELLOW + "Sending request...");
|
sender.sendMessage(ChatColor.YELLOW + "Sending request...");
|
||||||
} else {
|
} else {
|
||||||
// //todo: load async if it's not in the cache anymore
|
// //todo: load async if it's not in the cache anymore
|
||||||
final PlayerProfile profile = plugin.getStorage().getProfile(player.getName(), true);
|
final PlayerProfile profile = plugin.getStorage().getProfile(sender.getName(), true);
|
||||||
if (profile.isPremium()) {
|
if (profile.isPremium()) {
|
||||||
sender.sendMessage(ChatColor.DARK_RED + "You are already on the premium list");
|
sender.sendMessage(ChatColor.DARK_RED + "You are already on the premium list");
|
||||||
} else {
|
} else {
|
||||||
@ -61,27 +58,59 @@ public class PremiumCommand implements CommandExecutor {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(ChatColor.DARK_RED + "NOT IMPLEMENTED YET");
|
if (!sender.hasPermission(command.getPermission() + ".other")) {
|
||||||
//todo: async load
|
sender.sendMessage(ChatColor.DARK_RED + "Not enough permissions");
|
||||||
// String playerName = args[0];
|
return true;
|
||||||
// boolean didntexist = plugin.getEnabledPremium().add(playerName);
|
}
|
||||||
// if (!didntexist) {
|
|
||||||
// sender.sendMessage(ChatColor.DARK_RED + "You are already on the premium list");
|
if (plugin.isBungeeCord()) {
|
||||||
// } else {
|
notifiyBungeeCord(sender, args[0]);
|
||||||
// sender.sendMessage(ChatColor.DARK_GREEN + "Added to the list of premium players");
|
sender.sendMessage(ChatColor.YELLOW + "Sending request...");
|
||||||
// }
|
} else {
|
||||||
// notifiyBungeeCord();
|
//todo: load async if it's not in the cache anymore
|
||||||
|
final PlayerProfile profile = plugin.getStorage().getProfile(args[0], true);
|
||||||
|
if (profile == null) {
|
||||||
|
sender.sendMessage(ChatColor.DARK_RED + "Player not in the database");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (profile.isPremium()) {
|
||||||
|
sender.sendMessage(ChatColor.DARK_RED + "Player is already on the premium list");
|
||||||
|
} else {
|
||||||
|
//todo: resolve uuid
|
||||||
|
profile.setPremium(true);
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
plugin.getStorage().save(profile);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
sender.sendMessage(ChatColor.DARK_GREEN + "Added to the list of premium players");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifiyBungeeCord(Player target) {
|
private void notifiyBungeeCord(CommandSender sender, String target) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
notifiyBungeeCord(sender, target);
|
||||||
|
} else {
|
||||||
|
//todo: add console support
|
||||||
|
// Player firstPlayer = Iterables.getFirst(Bukkit.getOnlinePlayers(), null);
|
||||||
|
// notifiyBungeeCord(firstPlayer, target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void notifiyBungeeCord(Player sender, String target) {
|
||||||
if (plugin.isBungeeCord()) {
|
if (plugin.isBungeeCord()) {
|
||||||
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
|
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
|
||||||
dataOutput.writeUTF("ON");
|
dataOutput.writeUTF("ON");
|
||||||
|
dataOutput.writeUTF(target);
|
||||||
|
|
||||||
target.sendPluginMessage(plugin, plugin.getName(), dataOutput.toByteArray());
|
sender.sendPluginMessage(plugin, plugin.getName(), dataOutput.toByteArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,12 +72,12 @@ public class LoginSecurityHook implements BukkitAuthPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean forceRegister(final Player player, final String password) {
|
public boolean forceRegister(final Player player, final String password) {
|
||||||
final DataManager dataManager = securityPlugin.data;
|
DataManager dataManager = securityPlugin.data;
|
||||||
|
|
||||||
UUID playerUUID = player.getUniqueId();
|
UUID playerUUID = player.getUniqueId();
|
||||||
final String uuidString = playerUUID.toString().replace("-", "");
|
String uuidString = playerUUID.toString().replace("-", "");
|
||||||
final InetAddress ipAddress = player.getAddress().getAddress();
|
InetAddress ipAddress = player.getAddress().getAddress();
|
||||||
final String passwordHash = securityPlugin.hasher.hash(password);
|
String passwordHash = securityPlugin.hasher.hash(password);
|
||||||
|
|
||||||
//this executes a sql query without interacting with other parts so we can run it async.
|
//this executes a sql query without interacting with other parts so we can run it async.
|
||||||
dataManager.register(uuidString, passwordHash, securityPlugin.hasher.getTypeId(), ipAddress.toString());
|
dataManager.register(uuidString, passwordHash, securityPlugin.hasher.getTypeId(), ipAddress.toString());
|
||||||
|
@ -47,11 +47,11 @@ permissions:
|
|||||||
children:
|
children:
|
||||||
${project.artifactId}.command.premium: true
|
${project.artifactId}.command.premium: true
|
||||||
|
|
||||||
${project.artifactId}.command.unpremium:
|
${project.artifactId}.command.cracked:
|
||||||
description: 'Label themselves as cracked'
|
description: 'Label themselves as cracked'
|
||||||
default: true
|
default: true
|
||||||
|
|
||||||
${project.artifactId}.command..unpremium.other:
|
${project.artifactId}.command..cracked.other:
|
||||||
description: 'Label others as cracked'
|
description: 'Label others as cracked'
|
||||||
children:
|
children:
|
||||||
${project.artifactId}.command.unpremium: true
|
${project.artifactId}.command.cracked: true
|
@ -1,7 +1,9 @@
|
|||||||
package com.github.games647.fastlogin.bungee;
|
package com.github.games647.fastlogin.bungee;
|
||||||
|
|
||||||
|
import com.github.games647.fastlogin.bungee.listener.PlayerConnectionListener;
|
||||||
import com.github.games647.fastlogin.bungee.hooks.BungeeAuthHook;
|
import com.github.games647.fastlogin.bungee.hooks.BungeeAuthHook;
|
||||||
import com.github.games647.fastlogin.bungee.hooks.BungeeAuthPlugin;
|
import com.github.games647.fastlogin.bungee.hooks.BungeeAuthPlugin;
|
||||||
|
import com.github.games647.fastlogin.bungee.listener.PluginMessageListener;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -85,6 +87,7 @@ public class FastLoginBungee extends Plugin {
|
|||||||
|
|
||||||
//events
|
//events
|
||||||
getProxy().getPluginManager().registerListener(this, new PlayerConnectionListener(this));
|
getProxy().getPluginManager().registerListener(this, new PlayerConnectionListener(this));
|
||||||
|
getProxy().getPluginManager().registerListener(this, new PluginMessageListener(this));
|
||||||
|
|
||||||
//this is required to listen to messages from the server
|
//this is required to listen to messages from the server
|
||||||
getProxy().registerChannel(getDescription().getName());
|
getProxy().registerChannel(getDescription().getName());
|
||||||
|
@ -25,14 +25,14 @@ public class BungeeAuthHook implements BungeeAuthPlugin {
|
|||||||
private final Tables databaseConnection = new Tables();
|
private final Tables databaseConnection = new Tables();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean forceLogin(final ProxiedPlayer player) {
|
public boolean forceLogin(ProxiedPlayer player) {
|
||||||
//https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Login.java#L92-95
|
//https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Login.java#L92-95
|
||||||
Main.plonline.add(player.getName());
|
Main.plonline.add(player.getName());
|
||||||
|
|
||||||
//renamed from ct to databaseConnection
|
//renamed from ct to databaseConnection
|
||||||
// databaseConnection.setStatus(player.getName(), "online");
|
// databaseConnection.setStatus(player.getName(), "online");
|
||||||
final Class<?>[] parameterTypes = new Class<?>[]{String.class, String.class};
|
Class<?>[] parameterTypes = new Class<?>[]{String.class, String.class};
|
||||||
final Object[] arguments = new Object[]{player.getName(), "online"};
|
Object[] arguments = new Object[]{player.getName(), "online"};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
callProtected("setStatus", parameterTypes, arguments);
|
callProtected("setStatus", parameterTypes, arguments);
|
||||||
@ -56,7 +56,7 @@ public class BungeeAuthHook implements BungeeAuthPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean forceRegister(final ProxiedPlayer player, String password) {
|
public boolean forceRegister(ProxiedPlayer player, String password) {
|
||||||
//https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Register.java#L102
|
//https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Register.java#L102
|
||||||
PasswordHandler ph = new PasswordHandler();
|
PasswordHandler ph = new PasswordHandler();
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
@ -77,9 +77,9 @@ public class BungeeAuthHook implements BungeeAuthPlugin {
|
|||||||
//renamed t to databaseConnection
|
//renamed t to databaseConnection
|
||||||
// databaseConnection.newPlayerEntry(player.getName(), hash, pType, "", lastip, regdate, lastip, lastseen);
|
// databaseConnection.newPlayerEntry(player.getName(), hash, pType, "", lastip, regdate, lastip, lastseen);
|
||||||
|
|
||||||
final Class<?>[] parameterTypes = new Class<?>[] {String.class, String.class, String.class, String.class
|
Class<?>[] parameterTypes = new Class<?>[] {String.class, String.class, String.class, String.class
|
||||||
, String.class, String.class, String.class, String.class};
|
, String.class, String.class, String.class, String.class};
|
||||||
final Object[] arguments = new Object[] {player.getName(), hash, pType, "", lastip, regdate, lastip, lastseen};
|
Object[] arguments = new Object[] {player.getName(), hash, pType, "", lastip, regdate, lastip, lastseen};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
callProtected("newPlayerEntry", parameterTypes, arguments);
|
callProtected("newPlayerEntry", parameterTypes, arguments);
|
||||||
|
@ -1,21 +1,18 @@
|
|||||||
package com.github.games647.fastlogin.bungee;
|
package com.github.games647.fastlogin.bungee.listener;
|
||||||
|
|
||||||
|
import com.github.games647.fastlogin.bungee.FastLoginBungee;
|
||||||
|
import com.github.games647.fastlogin.bungee.ForceLoginTask;
|
||||||
|
import com.github.games647.fastlogin.bungee.PlayerProfile;
|
||||||
import com.github.games647.fastlogin.bungee.hooks.BungeeAuthPlugin;
|
import com.github.games647.fastlogin.bungee.hooks.BungeeAuthPlugin;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
|
||||||
import com.google.common.io.ByteStreams;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.connection.PendingConnection;
|
import net.md_5.bungee.api.connection.PendingConnection;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.connection.Server;
|
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
|
||||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||||
import net.md_5.bungee.api.event.PreLoginEvent;
|
import net.md_5.bungee.api.event.PreLoginEvent;
|
||||||
import net.md_5.bungee.api.event.ServerConnectedEvent;
|
import net.md_5.bungee.api.event.ServerConnectedEvent;
|
||||||
@ -122,82 +119,4 @@ public class PlayerConnectionListener implements Listener {
|
|||||||
ForceLoginTask loginTask = new ForceLoginTask(plugin, player, serverConnectedEvent.getServer());
|
ForceLoginTask loginTask = new ForceLoginTask(plugin, player, serverConnectedEvent.getServer());
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(plugin, loginTask);
|
ProxyServer.getInstance().getScheduler().runAsync(plugin, loginTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPluginMessage(PluginMessageEvent pluginMessageEvent) {
|
|
||||||
String channel = pluginMessageEvent.getTag();
|
|
||||||
if (pluginMessageEvent.isCancelled() || !plugin.getDescription().getName().equals(channel)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//the client shouldn't be able to read the messages in order to know something about server internal states
|
|
||||||
//moreover the client shouldn't be able fake a running premium check by sending the result message
|
|
||||||
pluginMessageEvent.setCancelled(true);
|
|
||||||
|
|
||||||
//check if the message is sent from the server
|
|
||||||
if (Server.class.isAssignableFrom(pluginMessageEvent.getSender().getClass())) {
|
|
||||||
byte[] data = pluginMessageEvent.getData();
|
|
||||||
ByteArrayDataInput dataInput = ByteStreams.newDataInput(data);
|
|
||||||
String subchannel = dataInput.readUTF();
|
|
||||||
|
|
||||||
final ProxiedPlayer forPlayer = (ProxiedPlayer) pluginMessageEvent.getReceiver();
|
|
||||||
if ("ON".equals(subchannel)) {
|
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(plugin, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
PlayerProfile playerProfile = plugin.getStorage().getProfile(forPlayer.getName(), true);
|
|
||||||
if (playerProfile.isPremium()) {
|
|
||||||
if (forPlayer.isConnected()) {
|
|
||||||
TextComponent textComponent = new TextComponent("You are already on the premium list");
|
|
||||||
textComponent.setColor(ChatColor.DARK_RED);
|
|
||||||
forPlayer.sendMessage(textComponent);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
playerProfile.setPremium(true);
|
|
||||||
//todo: set uuid
|
|
||||||
plugin.getStorage().save(playerProfile);
|
|
||||||
TextComponent textComponent = new TextComponent("Added to the list of premium players");
|
|
||||||
textComponent.setColor(ChatColor.DARK_GREEN);
|
|
||||||
forPlayer.sendMessage(textComponent);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if ("OFF".equals(subchannel)) {
|
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(plugin, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
PlayerProfile playerProfile = plugin.getStorage().getProfile(forPlayer.getName(), true);
|
|
||||||
if (!playerProfile.isPremium()) {
|
|
||||||
if (forPlayer.isConnected()) {
|
|
||||||
TextComponent textComponent = new TextComponent("You are not in the premium list");
|
|
||||||
textComponent.setColor(ChatColor.DARK_RED);
|
|
||||||
forPlayer.sendMessage(textComponent);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
playerProfile.setPremium(false);
|
|
||||||
playerProfile.setUuid(null);
|
|
||||||
plugin.getStorage().save(playerProfile);
|
|
||||||
TextComponent textComponent = new TextComponent("Removed to the list of premium players");
|
|
||||||
textComponent.setColor(ChatColor.DARK_GREEN);
|
|
||||||
forPlayer.sendMessage(textComponent);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if ("SUCCESS".equals(subchannel)) {
|
|
||||||
if (forPlayer.getPendingConnection().isOnlineMode()) {
|
|
||||||
//bukkit module successfully received and force logged in the user
|
|
||||||
//update only on success to prevent corrupt data
|
|
||||||
PlayerProfile playerProfile = plugin.getStorage().getProfile(forPlayer.getName(), false);
|
|
||||||
playerProfile.setPremium(true);
|
|
||||||
//we override this in the loginevent
|
|
||||||
// playerProfile.setUuid(forPlayer.getUniqueId());
|
|
||||||
plugin.getStorage().save(playerProfile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -0,0 +1,110 @@
|
|||||||
|
package com.github.games647.fastlogin.bungee.listener;
|
||||||
|
|
||||||
|
import com.github.games647.fastlogin.bungee.FastLoginBungee;
|
||||||
|
import com.github.games647.fastlogin.bungee.PlayerProfile;
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.connection.Server;
|
||||||
|
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||||
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
|
public class PluginMessageListener implements Listener {
|
||||||
|
|
||||||
|
protected final FastLoginBungee plugin;
|
||||||
|
|
||||||
|
public PluginMessageListener(FastLoginBungee plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPluginMessage(PluginMessageEvent pluginMessageEvent) {
|
||||||
|
String channel = pluginMessageEvent.getTag();
|
||||||
|
if (pluginMessageEvent.isCancelled() || !plugin.getDescription().getName().equals(channel)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//the client shouldn't be able to read the messages in order to know something about server internal states
|
||||||
|
//moreover the client shouldn't be able fake a running premium check by sending the result message
|
||||||
|
pluginMessageEvent.setCancelled(true);
|
||||||
|
|
||||||
|
//check if the message is sent from the server
|
||||||
|
if (Server.class.isAssignableFrom(pluginMessageEvent.getSender().getClass())) {
|
||||||
|
readMessage(pluginMessageEvent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void readMessage(PluginMessageEvent pluginMessageEvent) {
|
||||||
|
byte[] data = pluginMessageEvent.getData();
|
||||||
|
ByteArrayDataInput dataInput = ByteStreams.newDataInput(data);
|
||||||
|
String subchannel = dataInput.readUTF();
|
||||||
|
|
||||||
|
final ProxiedPlayer forPlayer = (ProxiedPlayer) pluginMessageEvent.getReceiver();
|
||||||
|
if ("ON".equals(subchannel)) {
|
||||||
|
final String playerName = dataInput.readUTF();
|
||||||
|
|
||||||
|
ProxyServer.getInstance().getScheduler().runAsync(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
PlayerProfile playerProfile = plugin.getStorage().getProfile(playerName, true);
|
||||||
|
if (playerProfile.isPremium()) {
|
||||||
|
if (forPlayer.isConnected()) {
|
||||||
|
TextComponent textComponent = new TextComponent("You are already on the premium list");
|
||||||
|
textComponent.setColor(ChatColor.DARK_RED);
|
||||||
|
forPlayer.sendMessage(textComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
playerProfile.setPremium(true);
|
||||||
|
//todo: set uuid
|
||||||
|
plugin.getStorage().save(playerProfile);
|
||||||
|
TextComponent textComponent = new TextComponent("Added to the list of premium players");
|
||||||
|
textComponent.setColor(ChatColor.DARK_GREEN);
|
||||||
|
forPlayer.sendMessage(textComponent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if ("OFF".equals(subchannel)) {
|
||||||
|
final String playerName = dataInput.readUTF();
|
||||||
|
|
||||||
|
ProxyServer.getInstance().getScheduler().runAsync(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
PlayerProfile playerProfile = plugin.getStorage().getProfile(playerName, true);
|
||||||
|
if (!playerProfile.isPremium()) {
|
||||||
|
if (forPlayer.isConnected()) {
|
||||||
|
TextComponent textComponent = new TextComponent("You are not in the premium list");
|
||||||
|
textComponent.setColor(ChatColor.DARK_RED);
|
||||||
|
forPlayer.sendMessage(textComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
playerProfile.setPremium(false);
|
||||||
|
playerProfile.setUuid(null);
|
||||||
|
plugin.getStorage().save(playerProfile);
|
||||||
|
TextComponent textComponent = new TextComponent("Removed to the list of premium players");
|
||||||
|
textComponent.setColor(ChatColor.DARK_GREEN);
|
||||||
|
forPlayer.sendMessage(textComponent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if ("SUCCESS".equals(subchannel)) {
|
||||||
|
if (forPlayer.getPendingConnection().isOnlineMode()) {
|
||||||
|
//bukkit module successfully received and force logged in the user
|
||||||
|
//update only on success to prevent corrupt data
|
||||||
|
PlayerProfile playerProfile = plugin.getStorage().getProfile(forPlayer.getName(), false);
|
||||||
|
playerProfile.setPremium(true);
|
||||||
|
//we override this in the loginevent
|
||||||
|
// playerProfile.setUuid(forPlayer.getUniqueId());
|
||||||
|
plugin.getStorage().save(playerProfile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user