mirror of
https://github.com/TotalFreedomMC/ZeroTelnetClient.git
synced 2024-12-23 00:35:22 +00:00
Added more popup menu commands.
Removed support for partial messages with no line ending.
This commit is contained in:
parent
9dd733ad83
commit
9fd37e5e03
2 changed files with 36 additions and 68 deletions
|
@ -3,7 +3,6 @@ package me.StevenLawson.BukkitTelnetClient;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -20,7 +19,6 @@ public class BTC_ConnectionManager
|
||||||
private int port;
|
private int port;
|
||||||
private boolean canDoDisconnect = false;
|
private boolean canDoDisconnect = false;
|
||||||
private String loginName;
|
private String loginName;
|
||||||
final ByteArrayOutputStream consoleBuffer = new ByteArrayOutputStream();
|
|
||||||
|
|
||||||
public BTC_ConnectionManager()
|
public BTC_ConnectionManager()
|
||||||
{
|
{
|
||||||
|
@ -35,7 +33,7 @@ public class BTC_ConnectionManager
|
||||||
btc.getTxtServer().setEnabled(false);
|
btc.getTxtServer().setEnabled(false);
|
||||||
btc.getBtnDisconnect().setEnabled(true);
|
btc.getBtnDisconnect().setEnabled(true);
|
||||||
|
|
||||||
btc.writeToConsole("Connecting to " + hostname + ":" + port + "...\n");
|
btc.writeToConsole("Connecting to " + hostname + ":" + port + "...");
|
||||||
|
|
||||||
this.hostname = hostname;
|
this.hostname = hostname;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
|
@ -100,7 +98,7 @@ public class BTC_ConnectionManager
|
||||||
|
|
||||||
updateTitle(false);
|
updateTitle(false);
|
||||||
|
|
||||||
btc.writeToConsole("\nDisconnected.\n");
|
btc.writeToConsole("Disconnected.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendCommand(final String text)
|
public void sendCommand(final String text)
|
||||||
|
@ -114,15 +112,10 @@ public class BTC_ConnectionManager
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
final BTC_MainPanel btc = BukkitTelnetClient.mainPanel;
|
BukkitTelnetClient.mainPanel.writeToConsole(":" + text);
|
||||||
|
|
||||||
String buffer = consoleBuffer.toString();
|
|
||||||
consoleBuffer.reset();
|
|
||||||
|
|
||||||
btc.writeToConsole(buffer + text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.telnetClient.getOutputStream().write((text + "\n").getBytes());
|
this.telnetClient.getOutputStream().write((text + "\r\n").getBytes());
|
||||||
this.telnetClient.getOutputStream().flush();
|
this.telnetClient.getOutputStream().flush();
|
||||||
}
|
}
|
||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
|
@ -171,63 +164,33 @@ public class BTC_ConnectionManager
|
||||||
|
|
||||||
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(telnetClient.getInputStream())))
|
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(telnetClient.getInputStream())))
|
||||||
{
|
{
|
||||||
int read = 0;
|
String line;
|
||||||
while (read != -1)
|
while ((line = reader.readLine()) != null)
|
||||||
{
|
{
|
||||||
boolean block = true;
|
String _loginName = null;
|
||||||
|
if (BTC_ConnectionManager.this.loginName == null)
|
||||||
while (block || reader.ready())
|
|
||||||
{
|
{
|
||||||
block = false;
|
_loginName = BTC_PlayerListDecoder.checkForLoginMessage(line);
|
||||||
|
|
||||||
read = reader.read();
|
|
||||||
if (read != -1)
|
|
||||||
{
|
|
||||||
consoleBuffer.write(read);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (read == '\n')
|
|
||||||
{
|
|
||||||
final String line = consoleBuffer.toString();
|
|
||||||
|
|
||||||
String _loginName = null;
|
|
||||||
if (BTC_ConnectionManager.this.loginName == null)
|
|
||||||
{
|
|
||||||
_loginName = BTC_PlayerListDecoder.checkForLoginMessage(line);
|
|
||||||
}
|
|
||||||
if (_loginName != null)
|
|
||||||
{
|
|
||||||
BTC_ConnectionManager.this.loginName = _loginName;
|
|
||||||
updateTitle(true);
|
|
||||||
sendDelayedCommand("telnet.enhanced", false, 100);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
final Map<String, PlayerInfo> playerList = BTC_PlayerListDecoder.checkForPlayerListMessage(line);
|
|
||||||
if (playerList != null)
|
|
||||||
{
|
|
||||||
btc.updatePlayerList(playerList);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!BTC_FormatHandler.skipLine(line))
|
|
||||||
{
|
|
||||||
btc.writeToConsole(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
consoleBuffer.reset();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (_loginName != null)
|
||||||
if (consoleBuffer.size() > 0)
|
|
||||||
{
|
{
|
||||||
final String line = consoleBuffer.toString();
|
BTC_ConnectionManager.this.loginName = _loginName;
|
||||||
if (line.endsWith("Username: ") || line.endsWith("Password: "))
|
updateTitle(true);
|
||||||
|
sendDelayedCommand("telnet.enhanced", false, 100);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
final Map<String, PlayerInfo> playerList = BTC_PlayerListDecoder.checkForPlayerListMessage(line);
|
||||||
|
if (playerList != null)
|
||||||
{
|
{
|
||||||
btc.writeToConsole(line);
|
btc.updatePlayerList(playerList);
|
||||||
consoleBuffer.reset();
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!BTC_FormatHandler.skipLine(line))
|
||||||
|
{
|
||||||
|
btc.writeToConsole(line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -146,7 +145,7 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
final String data = CONSOLE.toString();
|
final String data = CONSOLE.toString();
|
||||||
CONSOLE.reset();
|
CONSOLE.reset();
|
||||||
|
|
||||||
final String[] lines = data.split("\\n");
|
final String[] lines = data.split("\\r?\\n");
|
||||||
for (String line : lines)
|
for (String line : lines)
|
||||||
{
|
{
|
||||||
if (!line.isEmpty())
|
if (!line.isEmpty())
|
||||||
|
@ -158,7 +157,7 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
|
|
||||||
public final void writeToConsole(String line)
|
public final void writeToConsole(String line)
|
||||||
{
|
{
|
||||||
CONSOLE_STREAM.append(line);
|
CONSOLE_STREAM.append(line + '\n');
|
||||||
updateConsole();
|
updateConsole();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,7 +272,13 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
SMITE("Smite", "smite %s"),
|
SMITE("Smite", "smite %s"),
|
||||||
OP("Op", "op %s"),
|
OP("Op", "op %s"),
|
||||||
DEOP("Deop", "deop %s"),
|
DEOP("Deop", "deop %s"),
|
||||||
GTFO("GTFO", "gtfo %s");
|
GTFO("GTFO", "gtfo %s"),
|
||||||
|
FREEZE("Toggle Freeze", "fr %s"),
|
||||||
|
CAGE("Cage", "cage %s"),
|
||||||
|
UNCAGE("Uncage", "cage %s off"),
|
||||||
|
DOOM("Doom", "doom %s"),
|
||||||
|
CREATIVE("Creative", "creative %s"),
|
||||||
|
SURVIVAL("Survival", "survival %s");
|
||||||
|
|
||||||
private final String commandName;
|
private final String commandName;
|
||||||
private final String commandFormat;
|
private final String commandFormat;
|
||||||
|
@ -471,7 +476,7 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
|
|
||||||
if (selectedServer == null || selectedServer.isEmpty())
|
if (selectedServer == null || selectedServer.isEmpty())
|
||||||
{
|
{
|
||||||
writeToConsole("Invalid server address.\n");
|
writeToConsole("Invalid server address.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue