unified udp and tcp ports into one
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"serverIP": "localhost",
|
"serverIP": "localhost",
|
||||||
"tcpPort": 9090,
|
"port": 9090
|
||||||
"udpPort": 9091
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,5 @@ package io.github.eldek0.config;
|
|||||||
|
|
||||||
public class ClientConfig {
|
public class ClientConfig {
|
||||||
public String serverIP;
|
public String serverIP;
|
||||||
public int udpPort;
|
public int port;
|
||||||
public int tcpPort;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,7 @@ public class GameClient {
|
|||||||
private final Client client;
|
private final Client client;
|
||||||
private final Map<Integer, NetworkPackets.PlayerState> players = new ConcurrentHashMap<>();
|
private final Map<Integer, NetworkPackets.PlayerState> players = new ConcurrentHashMap<>();
|
||||||
private int myId = -1;
|
private int myId = -1;
|
||||||
private int udpPort = Network.DEFAULT_UDP_PORT;
|
private int port = Network.DEFAULT_PORT;
|
||||||
private int tcpPort = Network.DEFAULT_TCP_PORT;
|
|
||||||
private String serverIP;
|
private String serverIP;
|
||||||
|
|
||||||
public GameClient() {
|
public GameClient() {
|
||||||
@@ -68,7 +67,7 @@ public class GameClient {
|
|||||||
|
|
||||||
public void connect(String name) throws IOException {
|
public void connect(String name) throws IOException {
|
||||||
client.start();
|
client.start();
|
||||||
client.connect(5000, this.serverIP, this.tcpPort, this.udpPort);
|
client.connect(5000, this.serverIP, this.port, this.port);
|
||||||
|
|
||||||
NetworkPackets.Login login = new NetworkPackets.Login();
|
NetworkPackets.Login login = new NetworkPackets.Login();
|
||||||
login.name = name;
|
login.name = name;
|
||||||
@@ -106,8 +105,7 @@ public class GameClient {
|
|||||||
ClientConfig config = null;
|
ClientConfig config = null;
|
||||||
try {
|
try {
|
||||||
config = new Gson().fromJson(new FileReader("client-config.json"), ClientConfig.class);
|
config = new Gson().fromJson(new FileReader("client-config.json"), ClientConfig.class);
|
||||||
this.udpPort = config.udpPort;
|
this.port = config.port;
|
||||||
this.tcpPort = config.tcpPort;
|
|
||||||
this.serverIP = config.serverIP;
|
this.serverIP = config.serverIP;
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import com.esotericsoftware.kryonet.EndPoint;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Network {
|
public class Network {
|
||||||
public static final int DEFAULT_TCP_PORT = 54555;
|
public static final int DEFAULT_PORT = 54555;
|
||||||
public static final int DEFAULT_UDP_PORT = 54777;
|
|
||||||
|
|
||||||
public static void register(EndPoint endPoint) {
|
public static void register(EndPoint endPoint) {
|
||||||
Kryo kryo = endPoint.getKryo();
|
Kryo kryo = endPoint.getKryo();
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
{
|
{
|
||||||
"tcpPort": 9090,
|
"port": 9090
|
||||||
"udpPort": 9091
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ public class GameServer {
|
|||||||
|
|
||||||
private final Server server;
|
private final Server server;
|
||||||
private final Map<Integer, NetworkPackets.PlayerState> players = new ConcurrentHashMap<>();
|
private final Map<Integer, NetworkPackets.PlayerState> players = new ConcurrentHashMap<>();
|
||||||
private int udpPort = Network.DEFAULT_UDP_PORT;
|
private int port = Network.DEFAULT_PORT;
|
||||||
private int tcpPort = Network.DEFAULT_TCP_PORT;
|
|
||||||
|
|
||||||
public GameServer() {
|
public GameServer() {
|
||||||
server = new Server();
|
server = new Server();
|
||||||
@@ -62,8 +61,7 @@ public class GameServer {
|
|||||||
ServerConfig config = null;
|
ServerConfig config = null;
|
||||||
try {
|
try {
|
||||||
config = new Gson().fromJson(new FileReader("server-config.json"), ServerConfig.class);
|
config = new Gson().fromJson(new FileReader("server-config.json"), ServerConfig.class);
|
||||||
this.udpPort = config.udpPort;
|
this.port = config.port;
|
||||||
this.tcpPort = config.tcpPort;
|
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -112,7 +110,7 @@ public class GameServer {
|
|||||||
|
|
||||||
public void start() throws IOException {
|
public void start() throws IOException {
|
||||||
server.start();
|
server.start();
|
||||||
server.bind(this.tcpPort, this.udpPort);
|
server.bind(this.port, this.port);
|
||||||
System.out.println("Servidor iniciado.");
|
System.out.println("Servidor iniciado.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package io.github.eldek0.config;
|
package io.github.eldek0.config;
|
||||||
|
|
||||||
public class ServerConfig {
|
public class ServerConfig {
|
||||||
public int tcpPort;
|
public int port;
|
||||||
public int udpPort;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user