Fixed null pointers in ClientSender and increased reliability of Forwarder

This commit is contained in:
Josh Larson
2016-01-10 21:53:18 -06:00
parent e0dd8671d4
commit 7454481411
3 changed files with 44 additions and 31 deletions

View File

@@ -21,7 +21,7 @@ The way it works is by creating a very basic UDP server on each client, and havi
### Single Instance ###
1. Start up the forwarder
2. Open up login.cfg and set "loginServerAddress" to "127.0.0.1" and "loginServerPort" to whatever is listed next to the server connection status (e.x. 44453)
2. Open up login.cfg and set "loginServerAddress" to "127.0.0.1" and "loginServerPort" to whatever is listed next to the client connection status (e.x. 44453)
3. Start up the SWG client
### Multiple Instances ###

View File

@@ -73,16 +73,19 @@ public class ClientSender {
public void stop() {
disconnect(DisconnectReason.APPLICATION);
executor.shutdownNow();
if (executor != null)
executor.shutdownNow();
safeCloseServers();
}
public void setLoginCallback(UDPCallback callback) {
loginServer.setCallback(callback);
if (loginServer != null)
loginServer.setCallback(callback);
}
public void setZoneCallback(UDPCallback callback) {
zoneServer.setCallback(callback);
if (zoneServer != null)
zoneServer.setCallback(callback);
}
public void setSenderCallback(ClientSenderCallback callback) {
@@ -175,10 +178,12 @@ public class ClientSender {
}
public void sendRaw(int port, byte [] data) {
if (zone)
if (zone && zoneServer != null)
zoneServer.send(port, ADDR, data);
else
else if (!zone && loginServer != null)
loginServer.send(port, ADDR, data);
else
return;
if (callback != null)
callback.onUdpSent(zone, data);
}

View File

@@ -34,7 +34,7 @@ public class Forwarder extends Application implements ConnectionCallback {
private final Button serverSetButton;
private final Text serverConnectionText;
private final Text clientConnectionText;
private final Text serverConnectionPort;
private final Text clientConnectionPort;
private final Text serverRxText;
private final Text serverTxText;
private final Text clientRxText;
@@ -52,7 +52,7 @@ public class Forwarder extends Application implements ConnectionCallback {
serverSetButton = new Button("Set");
serverConnectionText = new Text(getConnectionStatus(false));
clientConnectionText = new Text(getConnectionStatus(false));
serverConnectionPort = new Text(Integer.toString(connections.getLoginPort()));
clientConnectionPort = new Text(Integer.toString(connections.getLoginPort()));
serverRxText = new Text(getByteName(connections.getTcpRecv()));
serverTxText = new Text(getByteName(connections.getTcpSent()));
clientRxText = new Text(getByteName(connections.getUdpRecv()));
@@ -158,29 +158,9 @@ public class Forwarder extends Application implements ConnectionCallback {
@Override
public void start(Stage primaryStage) throws Exception {
connections.initialize();
serverConnectionPort.setText(Integer.toString(connections.getLoginPort()));
clientConnectionPort.setText(Integer.toString(connections.getLoginPort()));
GridPane root = new GridPane();
for (int i = 0; i < 4; i++) {
ColumnConstraints cc = new ColumnConstraints();
cc.setPercentWidth(25);
root.getColumnConstraints().add(cc);
}
root.add(serverIpField, 0, 0, 2, 1);
root.add(serverPortField, 2, 0, 1, 1);
root.add(serverSetButton, 3, 0, 1, 1);
root.add(new Text("Server Connection:"), 0, 1, 2, 1);
root.add(serverConnectionText, 2, 1, 1, 1);
root.add(serverConnectionPort, 3, 1, 1, 1);
root.add(new Text("Client Connection:"), 0, 2, 2, 1);
root.add(clientConnectionText, 2, 2, 2, 1);
root.add(new Text("Sent"), 1, 3, 1, 1);
root.add(new Text("Recv"), 2, 3, 1, 1);
root.add(new Text("TCP"), 0, 4, 1, 1);
root.add(serverTxText, 1, 4, 1, 1);
root.add(serverRxText, 2, 4, 1, 1);
root.add(new Text("UDP"), 0, 5, 1, 1);
root.add(clientTxText, 1, 5, 1, 1);
root.add(clientRxText, 2, 5, 1, 1);
setupGridPane(root);
Scene scene = new Scene(root, 300, 160);
primaryStage.setTitle("Holocore Forwarder");
primaryStage.setScene(scene);
@@ -193,13 +173,41 @@ public class Forwarder extends Application implements ConnectionCallback {
primaryStage.show();
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
public void handle(WindowEvent we) {
connections.terminate();
try {
connections.terminate();
} catch (Exception e) {
e.printStackTrace();
}
primaryStage.close();
System.exit(0);
}
});
}
private void setupGridPane(GridPane root) {
for (int i = 0; i < 4; i++) {
ColumnConstraints cc = new ColumnConstraints();
cc.setPercentWidth(25);
root.getColumnConstraints().add(cc);
}
root.add(serverIpField, 0, 0, 2, 1);
root.add(serverPortField, 2, 0, 1, 1);
root.add(serverSetButton, 3, 0, 1, 1);
root.add(new Text("Server Connection:"), 0, 1, 2, 1);
root.add(serverConnectionText, 2, 1, 1, 1);
root.add(new Text("Client Connection:"), 0, 2, 2, 1);
root.add(clientConnectionText, 2, 2, 2, 1);
root.add(clientConnectionPort, 3, 2, 1, 1);
root.add(new Text("Sent"), 1, 3, 1, 1);
root.add(new Text("Recv"), 2, 3, 1, 1);
root.add(new Text("TCP"), 0, 4, 1, 1);
root.add(serverTxText, 1, 4, 1, 1);
root.add(serverRxText, 2, 4, 1, 1);
root.add(new Text("UDP"), 0, 5, 1, 1);
root.add(clientTxText, 1, 5, 1, 1);
root.add(clientRxText, 2, 5, 1, 1);
}
private static String getByteName(long bytes) {
int index = 0;
double reduced = bytes;