mirror of
https://github.com/TotalFreedomMC/ZeroTelnetClient.git
synced 2024-12-23 00:35:22 +00:00
Added automatic enabling of telnet.enhanced.
Better title display.
This commit is contained in:
parent
2077e4ba33
commit
ba202365c7
5 changed files with 127 additions and 34 deletions
|
@ -1,5 +1,7 @@
|
||||||
package me.StevenLawson.BukkitTelnetClient;
|
package me.StevenLawson.BukkitTelnetClient;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -7,6 +9,7 @@ import java.io.InputStreamReader;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import javax.swing.Timer;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.net.telnet.TelnetClient;
|
import org.apache.commons.net.telnet.TelnetClient;
|
||||||
|
|
||||||
|
@ -17,6 +20,7 @@ public class BTC_ConnectionManager
|
||||||
private String hostname;
|
private String hostname;
|
||||||
private int port;
|
private int port;
|
||||||
private boolean canDoDisconnect = false;
|
private boolean canDoDisconnect = false;
|
||||||
|
private String loginName;
|
||||||
|
|
||||||
public BTC_ConnectionManager()
|
public BTC_ConnectionManager()
|
||||||
{
|
{
|
||||||
|
@ -31,12 +35,12 @@ public class BTC_ConnectionManager
|
||||||
btc.getTxtServer().setEnabled(false);
|
btc.getTxtServer().setEnabled(false);
|
||||||
btc.getBtnDisconnect().setEnabled(true);
|
btc.getBtnDisconnect().setEnabled(true);
|
||||||
|
|
||||||
btc.setTitle("BukkitTelnetClient - " + BukkitTelnetClient.VERSION_STRING + " - " + hostname + ":" + port);
|
|
||||||
|
|
||||||
System.out.println("Connecting to " + hostname + ":" + port + "...");
|
System.out.println("Connecting to " + hostname + ":" + port + "...");
|
||||||
|
|
||||||
this.hostname = hostname;
|
this.hostname = hostname;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
|
this.loginName = null;
|
||||||
|
updateTitle(true);
|
||||||
|
|
||||||
startConnectThread();
|
startConnectThread();
|
||||||
}
|
}
|
||||||
|
@ -92,7 +96,9 @@ public class BTC_ConnectionManager
|
||||||
btc.getBtnSend().setEnabled(false);
|
btc.getBtnSend().setEnabled(false);
|
||||||
btc.getTxtCommand().setEnabled(false);
|
btc.getTxtCommand().setEnabled(false);
|
||||||
|
|
||||||
btc.setTitle("BukkitTelnetClient - " + BukkitTelnetClient.VERSION_STRING + " - Disconnected");
|
loginName = null;
|
||||||
|
|
||||||
|
updateTitle(false);
|
||||||
|
|
||||||
System.out.println("\nDisconnected.");
|
System.out.println("\nDisconnected.");
|
||||||
}
|
}
|
||||||
|
@ -101,10 +107,18 @@ public class BTC_ConnectionManager
|
||||||
private final PrintStream consoleStream = new PrintStream(consoleBuffer);
|
private final PrintStream consoleStream = new PrintStream(consoleBuffer);
|
||||||
|
|
||||||
public void sendCommand(String text)
|
public void sendCommand(String text)
|
||||||
|
{
|
||||||
|
sendCommand(text, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendCommand(String text, boolean verbose)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
if (verbose)
|
||||||
{
|
{
|
||||||
consoleStream.format("%s\r\n", text);
|
consoleStream.format("%s\r\n", text);
|
||||||
|
}
|
||||||
|
|
||||||
this.telnetClient.getOutputStream().write((text + "\n").getBytes());
|
this.telnetClient.getOutputStream().write((text + "\n").getBytes());
|
||||||
this.telnetClient.getOutputStream().flush();
|
this.telnetClient.getOutputStream().flush();
|
||||||
|
@ -115,6 +129,21 @@ public class BTC_ConnectionManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendDelayedCommand(final String text, final boolean verbose, final int delay)
|
||||||
|
{
|
||||||
|
final Timer timer = new Timer(delay, new ActionListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent ae)
|
||||||
|
{
|
||||||
|
sendCommand(text, verbose);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
timer.setRepeats(false);
|
||||||
|
timer.start();
|
||||||
|
}
|
||||||
|
|
||||||
private void startConnectThread()
|
private void startConnectThread()
|
||||||
{
|
{
|
||||||
if (this.connectThread != null)
|
if (this.connectThread != null)
|
||||||
|
@ -160,8 +189,20 @@ public class BTC_ConnectionManager
|
||||||
{
|
{
|
||||||
final String line = consoleBuffer.toString();
|
final String line = consoleBuffer.toString();
|
||||||
|
|
||||||
final Map<String, BTC_PlayerListDecoder.PlayerInfo> playerList = BTC_PlayerListDecoder.decodePlayerListMessage(line);
|
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, 500);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
final Map<String, BTC_PlayerListDecoder.PlayerInfo> playerList = BTC_PlayerListDecoder.checkForPlayerListMessage(line);
|
||||||
if (playerList != null)
|
if (playerList != null)
|
||||||
{
|
{
|
||||||
btc.updatePlayerList(playerList);
|
btc.updatePlayerList(playerList);
|
||||||
|
@ -173,6 +214,7 @@ public class BTC_ConnectionManager
|
||||||
System.out.print(line);
|
System.out.print(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
consoleBuffer.reset();
|
consoleBuffer.reset();
|
||||||
}
|
}
|
||||||
|
@ -204,4 +246,33 @@ public class BTC_ConnectionManager
|
||||||
});
|
});
|
||||||
this.connectThread.start();
|
this.connectThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final void updateTitle(boolean isConnected)
|
||||||
|
{
|
||||||
|
final BTC_MainPanel mainPanel = BukkitTelnetClient.mainPanel;
|
||||||
|
if (mainPanel == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String title;
|
||||||
|
|
||||||
|
if (isConnected)
|
||||||
|
{
|
||||||
|
if (loginName == null)
|
||||||
|
{
|
||||||
|
title = String.format("BukkitTelnetClient - %s - %s:%d", BukkitTelnetClient.VERSION_STRING, hostname, port);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
title = String.format("BukkitTelnetClient - %s - %s@%s:%d", BukkitTelnetClient.VERSION_STRING, loginName, hostname, port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
title = String.format("BukkitTelnetClient - %s - Disconnected", BukkitTelnetClient.VERSION_STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
mainPanel.setTitle(title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
|
||||||
<Form version="1.5" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
<Form version="1.6" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||||
<Property name="title" type="java.lang.String" value="BukkitTelnetClient"/>
|
<Property name="title" type="java.lang.String" value="BukkitTelnetClient"/>
|
||||||
|
@ -269,7 +269,10 @@
|
||||||
</Column>
|
</Column>
|
||||||
</TableColumnModel>
|
</TableColumnModel>
|
||||||
</Property>
|
</Property>
|
||||||
<Property name="columnSelectionAllowed" type="boolean" value="true"/>
|
<Property name="rowSelectionAllowed" type="boolean" value="true"/>
|
||||||
|
<Property name="selectionModel" type="javax.swing.ListSelectionModel" editor="org.netbeans.modules.form.editors2.JTableSelectionModelEditor">
|
||||||
|
<JTableSelectionModel selectionMode="0"/>
|
||||||
|
</Property>
|
||||||
<Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
|
<Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
|
||||||
<TableHeader reorderingAllowed="true" resizingAllowed="true"/>
|
<TableHeader reorderingAllowed="true" resizingAllowed="true"/>
|
||||||
</Property>
|
</Property>
|
||||||
|
|
|
@ -154,26 +154,6 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public JCheckBox getChkAutoScroll()
|
|
||||||
{
|
|
||||||
return chkAutoScroll;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JCheckBox getChkIgnorePlayerCommands()
|
|
||||||
{
|
|
||||||
return chkIgnorePlayerCommands;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JCheckBox getChkIgnoreServerCommands()
|
|
||||||
{
|
|
||||||
return chkIgnoreServerCommands;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JCheckBox getChkShowChatOnly()
|
|
||||||
{
|
|
||||||
return chkShowChatOnly;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void saveServersAndTriggerConnect()
|
public final void saveServersAndTriggerConnect()
|
||||||
{
|
{
|
||||||
String selected_server = (String) txtServer.getSelectedItem();
|
String selected_server = (String) txtServer.getSelectedItem();
|
||||||
|
@ -381,7 +361,8 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
return canEdit [columnIndex];
|
return canEdit [columnIndex];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
tblPlayers.setColumnSelectionAllowed(true);
|
tblPlayers.setRowSelectionAllowed(true);
|
||||||
|
tblPlayers.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
|
||||||
jScrollPane2.setViewportView(tblPlayers);
|
jScrollPane2.setViewportView(tblPlayers);
|
||||||
tblPlayers.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
|
tblPlayers.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
|
||||||
|
|
||||||
|
@ -572,4 +553,29 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
{
|
{
|
||||||
return txtServer;
|
return txtServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JCheckBox getChkAutoScroll()
|
||||||
|
{
|
||||||
|
return chkAutoScroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JCheckBox getChkIgnorePlayerCommands()
|
||||||
|
{
|
||||||
|
return chkIgnorePlayerCommands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JCheckBox getChkIgnoreServerCommands()
|
||||||
|
{
|
||||||
|
return chkIgnoreServerCommands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JCheckBox getChkShowChatOnly()
|
||||||
|
{
|
||||||
|
return chkShowChatOnly;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BTC_ConnectionManager getConnectionManager()
|
||||||
|
{
|
||||||
|
return connectionManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,13 +12,25 @@ import org.json.JSONObject;
|
||||||
public class BTC_PlayerListDecoder
|
public class BTC_PlayerListDecoder
|
||||||
{
|
{
|
||||||
private static final Pattern PLAYER_LIST_MESSAGE = Pattern.compile(":\\[.+@BukkitTelnet\\]\\$ playerList~(.+)");
|
private static final Pattern PLAYER_LIST_MESSAGE = Pattern.compile(":\\[.+@BukkitTelnet\\]\\$ playerList~(.+)");
|
||||||
|
private static final Pattern LOGIN_MESSAGE = Pattern.compile("\\[.+?@BukkitTelnet\\]\\$ Logged in as (.+)\\.");
|
||||||
|
|
||||||
private BTC_PlayerListDecoder()
|
private BTC_PlayerListDecoder()
|
||||||
{
|
{
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Map<String, PlayerInfo> decodePlayerListMessage(String message)
|
public static final String checkForLoginMessage(String message)
|
||||||
|
{
|
||||||
|
final Matcher matcher = LOGIN_MESSAGE.matcher(message);
|
||||||
|
if (matcher.find())
|
||||||
|
{
|
||||||
|
return matcher.group(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Map<String, PlayerInfo> checkForPlayerListMessage(String message)
|
||||||
{
|
{
|
||||||
final Matcher matcher = PLAYER_LIST_MESSAGE.matcher(message);
|
final Matcher matcher = PLAYER_LIST_MESSAGE.matcher(message);
|
||||||
if (matcher.find())
|
if (matcher.find())
|
||||||
|
|
|
@ -73,6 +73,7 @@ public class BukkitTelnetClient
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
mainPanel = new BTC_MainPanel();
|
mainPanel = new BTC_MainPanel();
|
||||||
|
mainPanel.getConnectionManager().updateTitle(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue