use of de.gg.engine.network.message.DiscoveryResponsePacket in project ProjektGG by eskalon.
the class GameServerDiscoveryTest method testServer.
@Test
public void testServer() throws TimeoutException, InterruptedException {
com.esotericsoftware.minlog.Log.INFO();
waiter = new Waiter();
sdh = new ServerDiscoveryHandler<>(DiscoveryResponsePacket.class, 2500);
assertThrows(IllegalArgumentException.class, () -> {
sdh.discoverHosts(-563, new HostDiscoveryListener<>() {
@Override
public void onHostDiscovered(String address, DiscoveryResponsePacket datagramPacket) {
}
});
});
assertThrows(NullPointerException.class, () -> {
sdh.discoverHosts(123, null);
});
ServerSetup serverSetup = new ServerSetup(gameName, maxPlayerCount, port, true, serverVersion, true);
GameSessionSetup sessionSetup = new GameSessionSetup(GameDifficulty.EASY, GameMap.BAMBERG, 25);
server = new GameServer(serverSetup, sessionSetup, null, Arrays.asList(stub, stub, stub));
server.start(new ISuccessCallback() {
@Override
public void onSuccess(Object param) {
waiter.resume();
}
@Override
public void onFailure(Object param) {
waiter.fail((String) param);
}
});
// Wait for resume() to be called
waiter.await(8000);
testServerDiscovery(waiter);
server.stop();
}
use of de.gg.engine.network.message.DiscoveryResponsePacket in project ProjektGG by eskalon.
the class BaseGameServer method startBroadcastServer.
private void startBroadcastServer() {
broadcastServer = new Server();
broadcastServer.start();
broadcastServer.getKryo().register(DiscoveryResponsePacket.class);
broadcastServer.setDiscoveryHandler(new ServerDiscoveryHandler() {
@Override
public boolean onDiscoverHost(DatagramChannel datagramChannel, InetSocketAddress fromAddress) throws IOException {
DiscoveryResponsePacket packet = new DiscoveryResponsePacket(serverSetup.getPort(), serverSetup.getGameName(), players.size(), serverSetup.getMaxPlayerCount());
ByteBuffer buffer = ByteBuffer.allocate(256);
broadcastServer.getSerialization().write(null, buffer, packet);
buffer.flip();
datagramChannel.send(buffer, fromAddress);
return true;
}
});
try {
broadcastServer.bind(0, UDP_DISCOVER_PORT);
Log.info("Server", "Broadcast server started");
} catch (IOException e1) {
Log.error("Server", "Broadcast server couldn't be started: %s", e1);
}
}
Aggregations