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