mirror of
https://github.com/Nan1t/NanoLimbo.git
synced 2026-02-11 03:16:14 +01:00
Added packet pre-encoding. Code style.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package ru.nanit.limbo.server;
|
||||
|
||||
import ru.nanit.limbo.connection.ClientConnection;
|
||||
import ru.nanit.limbo.util.Logger;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -26,9 +27,11 @@ public final class Connections {
|
||||
|
||||
public void addConnection(ClientConnection connection){
|
||||
connections.put(connection.getUuid(), connection);
|
||||
Logger.info("Player %s connected (%s)", connection.getUsername(), connection.getAddress());
|
||||
}
|
||||
|
||||
public void removeConnection(ClientConnection connection){
|
||||
connections.remove(connection.getUuid());
|
||||
Logger.info("Player %s disconnected", connection.getUsername());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,16 +8,12 @@ import ru.nanit.limbo.configuration.LimboConfig;
|
||||
import ru.nanit.limbo.configuration.SocketAddressSerializer;
|
||||
import ru.nanit.limbo.connection.ClientChannelInitializer;
|
||||
import ru.nanit.limbo.connection.ClientConnection;
|
||||
import ru.nanit.limbo.protocol.packets.play.PacketBossBar;
|
||||
import ru.nanit.limbo.protocol.packets.play.PacketChatMessage;
|
||||
import ru.nanit.limbo.server.data.*;
|
||||
import ru.nanit.limbo.util.Logger;
|
||||
import ru.nanit.limbo.util.VelocityUtil;
|
||||
import ru.nanit.limbo.world.DimensionRegistry;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -28,9 +24,6 @@ public final class LimboServer {
|
||||
private Connections connections;
|
||||
private DimensionRegistry dimensionRegistry;
|
||||
|
||||
private PacketChatMessage joinMessage;
|
||||
private PacketBossBar joinBossBar;
|
||||
|
||||
public LimboConfig getConfig(){
|
||||
return config;
|
||||
}
|
||||
@@ -43,14 +36,6 @@ public final class LimboServer {
|
||||
return dimensionRegistry;
|
||||
}
|
||||
|
||||
public PacketChatMessage getJoinMessage() {
|
||||
return joinMessage;
|
||||
}
|
||||
|
||||
public PacketBossBar getJoinBossBar() {
|
||||
return joinBossBar;
|
||||
}
|
||||
|
||||
public void start() throws Exception {
|
||||
Logger.info("Starting server...");
|
||||
|
||||
@@ -65,16 +50,11 @@ public final class LimboServer {
|
||||
|
||||
Logger.setLevel(config.getDebugLevel());
|
||||
|
||||
if (config.getInfoForwarding().isModern()){
|
||||
VelocityUtil.init(config);
|
||||
}
|
||||
|
||||
dimensionRegistry = new DimensionRegistry();
|
||||
dimensionRegistry.load(config.getDimensionType());
|
||||
|
||||
connections = new Connections();
|
||||
|
||||
initInGameData();
|
||||
ClientConnection.preInitPackets(this);
|
||||
|
||||
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||
executor.scheduleAtFixedRate(this::broadcastKeepAlive, 0L, 5L, TimeUnit.SECONDS);
|
||||
@@ -89,21 +69,6 @@ public final class LimboServer {
|
||||
Logger.info("Server started on %s", config.getAddress());
|
||||
}
|
||||
|
||||
private void initInGameData(){
|
||||
if (config.isUseJoinMessage()){
|
||||
joinMessage = new PacketChatMessage();
|
||||
joinMessage.setJsonData(config.getJoinMessage());
|
||||
joinMessage.setPosition(PacketChatMessage.Position.CHAT);
|
||||
joinMessage.setSender(UUID.randomUUID());
|
||||
}
|
||||
|
||||
if (config.isUseBossBar()){
|
||||
joinBossBar = new PacketBossBar();
|
||||
joinBossBar.setBossBar(config.getBossBar());
|
||||
joinBossBar.setUuid(UUID.randomUUID());
|
||||
}
|
||||
}
|
||||
|
||||
private void broadcastKeepAlive(){
|
||||
connections.getAllConnections().forEach(ClientConnection::sendKeepAlive);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user