Skip to content

Commit

Permalink
Added more popup menu commands.
Browse files Browse the repository at this point in the history
Removed support for partial messages with no line ending.
  • Loading branch information
StevenLawson committed Aug 18, 2014
1 parent 9dd733a commit 9fd37e5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map;
Expand All @@ -20,7 +19,6 @@ public class BTC_ConnectionManager
private int port;
private boolean canDoDisconnect = false;
private String loginName;
final ByteArrayOutputStream consoleBuffer = new ByteArrayOutputStream();

public BTC_ConnectionManager()
{
Expand All @@ -35,7 +33,7 @@ public void triggerConnect(final String hostname, final int port)
btc.getTxtServer().setEnabled(false);
btc.getBtnDisconnect().setEnabled(true);

btc.writeToConsole("Connecting to " + hostname + ":" + port + "...\n");
btc.writeToConsole("Connecting to " + hostname + ":" + port + "...");

this.hostname = hostname;
this.port = port;
Expand Down Expand Up @@ -100,7 +98,7 @@ public void finishDisconnect()

updateTitle(false);

btc.writeToConsole("\nDisconnected.\n");
btc.writeToConsole("Disconnected.");
}

public void sendCommand(final String text)
Expand All @@ -114,15 +112,10 @@ public void sendCommand(final String text, final boolean verbose)
{
if (verbose)
{
final BTC_MainPanel btc = BukkitTelnetClient.mainPanel;

String buffer = consoleBuffer.toString();
consoleBuffer.reset();

btc.writeToConsole(buffer + text);
BukkitTelnetClient.mainPanel.writeToConsole(":" + text);
}

this.telnetClient.getOutputStream().write((text + "\n").getBytes());
this.telnetClient.getOutputStream().write((text + "\r\n").getBytes());
this.telnetClient.getOutputStream().flush();
}
catch (IOException ex)
Expand Down Expand Up @@ -171,63 +164,33 @@ public void run()

try (final BufferedReader reader = new BufferedReader(new InputStreamReader(telnetClient.getInputStream())))
{
int read = 0;
while (read != -1)
String line;
while ((line = reader.readLine()) != null)
{
boolean block = true;

while (block || reader.ready())
String _loginName = null;
if (BTC_ConnectionManager.this.loginName == null)
{
block = false;

read = reader.read();
if (read != -1)
_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)
{
consoleBuffer.write(read);
btc.updatePlayerList(playerList);
}

if (read == '\n')
else
{
final String line = consoleBuffer.toString();

String _loginName = null;
if (BTC_ConnectionManager.this.loginName == null)
if (!BTC_FormatHandler.skipLine(line))
{
_loginName = BTC_PlayerListDecoder.checkForLoginMessage(line);
btc.writeToConsole(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 (consoleBuffer.size() > 0)
{
final String line = consoleBuffer.toString();
if (line.endsWith("Username: ") || line.endsWith("Password: "))
{
btc.writeToConsole(line);
consoleBuffer.reset();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.io.IOException;
import java.io.PrintStream;
import java.net.URL;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
Expand Down Expand Up @@ -146,7 +145,7 @@ public final void updateConsole()
final String data = CONSOLE.toString();
CONSOLE.reset();

final String[] lines = data.split("\\n");
final String[] lines = data.split("\\r?\\n");
for (String line : lines)
{
if (!line.isEmpty())
Expand All @@ -158,7 +157,7 @@ public final void updateConsole()

public final void writeToConsole(String line)
{
CONSOLE_STREAM.append(line);
CONSOLE_STREAM.append(line + '\n');
updateConsole();
}

Expand Down Expand Up @@ -273,7 +272,13 @@ public static enum ServerCommand
SMITE("Smite", "smite %s"),
OP("Op", "op %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 commandFormat;
Expand Down Expand Up @@ -471,7 +476,7 @@ public final void saveServersAndTriggerConnect()

if (selectedServer == null || selectedServer.isEmpty())
{
writeToConsole("Invalid server address.\n");
writeToConsole("Invalid server address.");
return;
}

Expand Down

0 comments on commit 9fd37e5

Please sign in to comment.