mirror of
https://github.com/TotalFreedomMC/BukkitTelnet.git
synced 2024-12-28 11:04:22 +00:00
Small api improvements
This commit is contained in:
parent
0316e52260
commit
0de2dcae69
6 changed files with 59 additions and 45 deletions
|
@ -24,8 +24,8 @@ public class TelnetConfig
|
||||||
configEntries.setAddress(config.getString("address"));
|
configEntries.setAddress(config.getString("address"));
|
||||||
configEntries.setPort(config.getInt("port"));
|
configEntries.setPort(config.getInt("port"));
|
||||||
configEntries.setPassword(config.getString("password"));
|
configEntries.setPassword(config.getString("password"));
|
||||||
configEntries.clearAdmins();
|
|
||||||
|
|
||||||
|
configEntries.clearAdmins();
|
||||||
if (config.isConfigurationSection("admins"))
|
if (config.isConfigurationSection("admins"))
|
||||||
{
|
{
|
||||||
for (String admin : config.getConfigurationSection("admins").getKeys(false))
|
for (String admin : config.getConfigurationSection("admins").getKeys(false))
|
||||||
|
@ -113,10 +113,10 @@ public class TelnetConfig
|
||||||
|
|
||||||
public static TelnetConfig getInstance()
|
public static TelnetConfig getInstance()
|
||||||
{
|
{
|
||||||
return BT_ConfigHolder.INSTANCE;
|
return TelnetConfigHolder.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class BT_ConfigHolder
|
private static class TelnetConfigHolder
|
||||||
{
|
{
|
||||||
private static final TelnetConfig INSTANCE = new TelnetConfig();
|
private static final TelnetConfig INSTANCE = new TelnetConfig();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,33 +2,20 @@ package me.StevenLawson.BukkitTelnet.api;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
public class TelnetCommandEvent extends Event implements Cancellable
|
public class TelnetCommandEvent extends TelnetEvent implements Cancellable
|
||||||
{
|
{
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private boolean cancelled;
|
||||||
private boolean cancelled = false;
|
|
||||||
//
|
|
||||||
private CommandSender sender;
|
private CommandSender sender;
|
||||||
private String command;
|
private String command;
|
||||||
|
|
||||||
public TelnetCommandEvent(CommandSender sender, String command)
|
public TelnetCommandEvent(CommandSender sender, String command)
|
||||||
{
|
{
|
||||||
|
this.cancelled = false;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.command = command;
|
this.command = command;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public HandlerList getHandlers()
|
|
||||||
{
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
//public static HandlerList getHandlerList()
|
|
||||||
//{
|
|
||||||
// return handlers;
|
|
||||||
//}
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled()
|
public boolean isCancelled()
|
||||||
{
|
{
|
||||||
|
|
20
src/me/StevenLawson/BukkitTelnet/api/TelnetEvent.java
Normal file
20
src/me/StevenLawson/BukkitTelnet/api/TelnetEvent.java
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package me.StevenLawson.BukkitTelnet.api;
|
||||||
|
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.event.server.ServerEvent;
|
||||||
|
|
||||||
|
public abstract class TelnetEvent extends ServerEvent
|
||||||
|
{
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers()
|
||||||
|
{
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList()
|
||||||
|
{
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,15 +1,12 @@
|
||||||
package me.StevenLawson.BukkitTelnet.api;
|
package me.StevenLawson.BukkitTelnet.api;
|
||||||
|
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
public class TelnetPreLoginEvent extends Event implements Cancellable
|
public class TelnetPreLoginEvent extends TelnetEvent implements Cancellable
|
||||||
{
|
{
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
private boolean cancelled = false;
|
private boolean cancelled = false;
|
||||||
//
|
//
|
||||||
private String name = null;
|
private String name;
|
||||||
private final String ip;
|
private final String ip;
|
||||||
private boolean bypassPassword;
|
private boolean bypassPassword;
|
||||||
|
|
||||||
|
@ -20,17 +17,6 @@ public class TelnetPreLoginEvent extends Event implements Cancellable
|
||||||
this.bypassPassword = bypassPassword;
|
this.bypassPassword = bypassPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public HandlerList getHandlers()
|
|
||||||
{
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList()
|
|
||||||
{
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled()
|
public boolean isCancelled()
|
||||||
{
|
{
|
||||||
|
|
|
@ -106,7 +106,7 @@ public final class ClientSession extends Thread
|
||||||
|
|
||||||
hasTerminated = true;
|
hasTerminated = true;
|
||||||
|
|
||||||
TelnetLogger.info("Closing connection: " + clientAddress + (username.isEmpty() ? "" : "(" + username + ")"));
|
TelnetLogger.info("Closing connection: " + clientAddress + (username.isEmpty() ? "" : " (" + username + ")"));
|
||||||
getLogger().removeAppender(logAppender);
|
getLogger().removeAppender(logAppender);
|
||||||
|
|
||||||
synchronized (clientSocket)
|
synchronized (clientSocket)
|
||||||
|
@ -235,7 +235,7 @@ public final class ClientSession extends Thread
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean authenticated = false;
|
boolean passAuth = false;
|
||||||
|
|
||||||
// Pre-authenticate IP addresses
|
// Pre-authenticate IP addresses
|
||||||
if (clientAddress != null)
|
if (clientAddress != null)
|
||||||
|
@ -251,7 +251,7 @@ public final class ClientSession extends Thread
|
||||||
{
|
{
|
||||||
if (Util.fuzzyIpMatch(ip, clientAddress, 3))
|
if (Util.fuzzyIpMatch(ip, clientAddress, 3))
|
||||||
{
|
{
|
||||||
authenticated = true;
|
passAuth = true;
|
||||||
this.username = name;
|
this.username = name;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -259,8 +259,8 @@ public final class ClientSession extends Thread
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send TelnetPreLoginEvent
|
// TelnetPreLoginEvent authentication
|
||||||
final TelnetPreLoginEvent event = new TelnetPreLoginEvent(clientAddress, username, authenticated);
|
final TelnetPreLoginEvent event = new TelnetPreLoginEvent(clientAddress, username, passAuth);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
|
@ -270,11 +270,16 @@ public final class ClientSession extends Thread
|
||||||
|
|
||||||
if (event.canBypassPassword())
|
if (event.canBypassPassword())
|
||||||
{
|
{
|
||||||
this.username = event.getName();
|
if (!event.getName().isEmpty()) // If the name hasn't been set, we'll ask for it.
|
||||||
return true;
|
{
|
||||||
|
this.username = event.getName();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
passAuth = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Username / password authentication
|
// Username
|
||||||
boolean validUsername = false;
|
boolean validUsername = false;
|
||||||
|
|
||||||
int tries = 0;
|
int tries = 0;
|
||||||
|
@ -317,6 +322,14 @@ public final class ClientSession extends Thread
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the TelnetPreLoginEvent authenticates the password,
|
||||||
|
// don't ask for it.
|
||||||
|
if (passAuth)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Password
|
||||||
tries = 0;
|
tries = 0;
|
||||||
while (tries++ < 3)
|
while (tries++ < 3)
|
||||||
{
|
{
|
||||||
|
@ -373,6 +386,7 @@ public final class ClientSession extends Thread
|
||||||
// Start feeding data to the client.
|
// Start feeding data to the client.
|
||||||
getLogger().addAppender(logAppender);
|
getLogger().addAppender(logAppender);
|
||||||
|
|
||||||
|
// Process commands
|
||||||
while (syncIsConnected())
|
while (syncIsConnected())
|
||||||
{
|
{
|
||||||
// Read a command
|
// Read a command
|
||||||
|
@ -449,14 +463,18 @@ public final class ClientSession extends Thread
|
||||||
{
|
{
|
||||||
filterMode = FilterMode.FULL;
|
filterMode = FilterMode.FULL;
|
||||||
println("Showing all logs.");
|
println("Showing all logs.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.equalsIgnoreCase("telnet.exit"))
|
if (command.equalsIgnoreCase("telnet.exit"))
|
||||||
{
|
{
|
||||||
|
println("Goodbye <3");
|
||||||
syncTerminateSession();
|
syncTerminateSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
println("Invalid telnet command, use \"telnet.help\" to view help.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,10 @@ public class SessionLogAppender extends AbstractAppender
|
||||||
|
|
||||||
if (session.getFilterMode() == FilterMode.NONCHAT_ONLY)
|
if (session.getFilterMode() == FilterMode.NONCHAT_ONLY)
|
||||||
{
|
{
|
||||||
if (message.startsWith("<") || message.startsWith("[Server") || message.startsWith("[CONSOLE") || message.startsWith("[TotalFreedomMod] [ADMIN]"))
|
if (message.startsWith("<")
|
||||||
|
|| message.startsWith("[Server")
|
||||||
|
|| message.startsWith("[CONSOLE")
|
||||||
|
|| message.startsWith("[TotalFreedomMod] [ADMIN]"))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue