Added better error handling and updated dependencies

This commit is contained in:
Obique PSWG
2018-06-10 14:45:15 -05:00
parent 2e15ae7268
commit 450ce04c13
5 changed files with 52 additions and 29 deletions

View File

@@ -2,8 +2,8 @@ plugins {
id 'java'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceCompatibility = 9
targetCompatibility = 9
repositories {
jcenter()
@@ -14,6 +14,3 @@ dependencies {
testCompile 'junit:junit:4.12'
}
task wrapper(type: Wrapper) {
gradleVersion = "4.7"
}

View File

@@ -4,7 +4,6 @@ import com.projectswg.common.network.NetBuffer;
import com.projectswg.common.network.packets.swg.holo.HoloConnectionStarted;
import com.projectswg.common.network.packets.swg.holo.HoloConnectionStopped;
import com.projectswg.common.network.packets.swg.holo.HoloSetProtocolVersion;
import com.projectswg.connection.packets.RawPacket;
import me.joshlarson.jlcommon.log.Log;
import me.joshlarson.jlcommon.network.TCPSocket;
import me.joshlarson.jlcommon.network.TCPSocket.TCPSocketCallback;
@@ -125,6 +124,14 @@ public class HolocoreSocket {
* @return the server status as a string
*/
public String getServerStatus(long timeout) {
Log.t("Requesting server status from %s", address);
if (!udpServer.isRunning()) {
try {
udpServer.bind();
} catch (SocketException e) {
return "UNKNOWN";
}
}
udpServer.send(address, new byte[]{1});
try {
DatagramPacket packet = udpInboundQueue.poll(timeout, TimeUnit.MILLISECONDS);
@@ -301,7 +308,7 @@ public class HolocoreSocket {
private UDPServer createUDPServer() {
try {
UDPServer server = new UDPServer(new InetSocketAddress(0), 1500, udpInboundQueue::offer);
UDPServer server = new UDPServer(new InetSocketAddress(0), 1500, udpInboundQueue::add);
server.bind();
return server;
} catch (SocketException e) {

View File

@@ -0,0 +1,41 @@
/***********************************************************************************
* Copyright (C) 2018 /// Project SWG /// www.projectswg.com *
* *
* This file is part of the ProjectSWG Launcher. *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
***********************************************************************************/
package com.projectswg.connection;
public class RawPacket {
private final int crc;
private final byte[] data;
public RawPacket(int crc, byte[] data) {
this.crc = crc;
this.data = data;
}
public int getCrc() {
return crc;
}
public byte[] getData() {
return data;
}
}

View File

@@ -1,7 +1,6 @@
package com.projectswg.connection;
import com.projectswg.common.network.NetBuffer;
import com.projectswg.connection.packets.RawPacket;
class SWGProtocol {

View File

@@ -1,21 +0,0 @@
package com.projectswg.connection.packets;
public class RawPacket {
private final int crc;
private final byte[] data;
public RawPacket(int crc, byte[] data) {
this.crc = crc;
this.data = data;
}
public int getCrc() {
return crc;
}
public byte[] getData() {
return data;
}
}