Small api improvements

This commit is contained in:
unknown 2014-03-21 11:34:01 +01:00
parent 0316e52260
commit 0de2dcae69
6 changed files with 59 additions and 45 deletions

View file

@ -24,8 +24,8 @@ public class TelnetConfig
configEntries.setAddress(config.getString("address"));
configEntries.setPort(config.getInt("port"));
configEntries.setPassword(config.getString("password"));
configEntries.clearAdmins();
configEntries.clearAdmins();
if (config.isConfigurationSection("admins"))
{
for (String admin : config.getConfigurationSection("admins").getKeys(false))
@ -113,10 +113,10 @@ public class TelnetConfig
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();
}

View file

@ -2,33 +2,20 @@ package me.StevenLawson.BukkitTelnet.api;
import org.bukkit.command.CommandSender;
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 = false;
//
private boolean cancelled;
private CommandSender sender;
private String command;
public TelnetCommandEvent(CommandSender sender, String command)
{
this.cancelled = false;
this.sender = sender;
this.command = command;
}
@Override
public HandlerList getHandlers()
{
return handlers;
}
//public static HandlerList getHandlerList()
//{
// return handlers;
//}
@Override
public boolean isCancelled()
{

View 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;
}
}

View file

@ -1,15 +1,12 @@
package me.StevenLawson.BukkitTelnet.api;
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 String name = null;
private String name;
private final String ip;
private boolean bypassPassword;
@ -20,17 +17,6 @@ public class TelnetPreLoginEvent extends Event implements Cancellable
this.bypassPassword = bypassPassword;
}
@Override
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
@Override
public boolean isCancelled()
{

View file

@ -235,7 +235,7 @@ public final class ClientSession extends Thread
return false;
}
boolean authenticated = false;
boolean passAuth = false;
// Pre-authenticate IP addresses
if (clientAddress != null)
@ -251,7 +251,7 @@ public final class ClientSession extends Thread
{
if (Util.fuzzyIpMatch(ip, clientAddress, 3))
{
authenticated = true;
passAuth = true;
this.username = name;
break;
}
@ -259,8 +259,8 @@ public final class ClientSession extends Thread
}
}
// Send TelnetPreLoginEvent
final TelnetPreLoginEvent event = new TelnetPreLoginEvent(clientAddress, username, authenticated);
// TelnetPreLoginEvent authentication
final TelnetPreLoginEvent event = new TelnetPreLoginEvent(clientAddress, username, passAuth);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled())
@ -269,12 +269,17 @@ public final class ClientSession extends Thread
}
if (event.canBypassPassword())
{
if (!event.getName().isEmpty()) // If the name hasn't been set, we'll ask for it.
{
this.username = event.getName();
return true;
}
// Username / password authentication
passAuth = true;
}
// Username
boolean validUsername = false;
int tries = 0;
@ -317,6 +322,14 @@ public final class ClientSession extends Thread
return false;
}
// If the TelnetPreLoginEvent authenticates the password,
// don't ask for it.
if (passAuth)
{
return true;
}
// Password
tries = 0;
while (tries++ < 3)
{
@ -373,6 +386,7 @@ public final class ClientSession extends Thread
// Start feeding data to the client.
getLogger().addAppender(logAppender);
// Process commands
while (syncIsConnected())
{
// Read a command
@ -449,14 +463,18 @@ public final class ClientSession extends Thread
{
filterMode = FilterMode.FULL;
println("Showing all logs.");
return;
}
return;
}
if (command.equalsIgnoreCase("telnet.exit"))
{
println("Goodbye <3");
syncTerminateSession();
}
println("Invalid telnet command, use \"telnet.help\" to view help.");
}
}

View file

@ -38,7 +38,10 @@ public class SessionLogAppender extends AbstractAppender
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;
}