Skip to content

Commit 55addd8

Browse files
committed
- Global Chat #14
- Cleanup
1 parent 5dbeecb commit 55addd8

24 files changed

Lines changed: 397 additions & 129 deletions

src/main/java/com/manwe/dsl/connectionRouting/RegionRouter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
import com.manwe.dsl.DistributedServerLevels;
44
import com.manwe.dsl.arbiter.ConnectionInfo;
55
import com.manwe.dsl.config.DSLServerConfigs;
6-
import com.manwe.dsl.dedicatedServer.proxy.ProxyDedicatedServer;
6+
import com.manwe.dsl.dedicatedServer.CustomDedicatedServer;
77
import com.manwe.dsl.dedicatedServer.proxy.WorkerTunnel;
88
import com.manwe.dsl.dedicatedServer.worker.packets.login.WorkerBoundRequestLevelInformationPacket;
99
import io.netty.channel.EventLoopGroup;
1010
import io.netty.channel.nio.NioEventLoopGroup;
1111
import net.minecraft.core.BlockPos;
1212
import net.minecraft.network.Connection;
1313
import net.minecraft.network.protocol.Packet;
14-
import net.minecraft.server.MinecraftServer;
1514

1615
import java.net.InetSocketAddress;
1716
import java.util.HashMap;
@@ -42,7 +41,7 @@ public class RegionRouter {
4241
private static final int regionSize = DSLServerConfigs.REGION_SIZE.get();
4342
private static final int workerId = DSLServerConfigs.WORKER_ID.get();
4443

45-
public RegionRouter(ProxyDedicatedServer server){
44+
public RegionRouter(CustomDedicatedServer server){
4645
this.ioGroup = new NioEventLoopGroup(1); //TODO especificar numero correcto de hilos
4746

4847
List<ConnectionInfo> workers = server.getWorkers();

src/main/java/com/manwe/dsl/dedicatedServer/proxy/ProxyDedicatedServer.java renamed to src/main/java/com/manwe/dsl/dedicatedServer/CustomDedicatedServer.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
package com.manwe.dsl.dedicatedServer.proxy;
1+
package com.manwe.dsl.dedicatedServer;
22

33
import com.manwe.dsl.DistributedServerLevels;
4+
import com.manwe.dsl.dedicatedServer.proxy.RemotePlayerList;
45
import com.manwe.dsl.mixinExtension.SetConnectionIntf;
56
import com.manwe.dsl.arbiter.ArbiterClient;
67
import com.manwe.dsl.arbiter.ConnectionInfo;
@@ -35,7 +36,7 @@
3536
import java.util.Locale;
3637
import java.util.function.BooleanSupplier;
3738

38-
public class ProxyDedicatedServer extends DedicatedServer {
39+
public class CustomDedicatedServer extends DedicatedServer {
3940

4041
URI arbiterUri = URI.create(DSLServerConfigs.ARBITER_ADDR.get());
4142
boolean isProxy = DSLServerConfigs.IS_PROXY.get();
@@ -46,12 +47,12 @@ public class ProxyDedicatedServer extends DedicatedServer {
4647
private ArbiterClient.ArbiterRes topology;
4748
private static final int SHARD_MAX_ENTITIES = 1_000_000;
4849

49-
public ProxyDedicatedServer(Thread pServerThread, LevelStorageSource.LevelStorageAccess pStorageSource, PackRepository pPackRepository, WorldStem pWorldStem, DedicatedServerSettings pSettings, DataFixer pFixerUpper, Services pServices, ChunkProgressListenerFactory pProgressListenerFactory) {
50+
public CustomDedicatedServer(Thread pServerThread, LevelStorageSource.LevelStorageAccess pStorageSource, PackRepository pPackRepository, WorldStem pWorldStem, DedicatedServerSettings pSettings, DataFixer pFixerUpper, Services pServices, ChunkProgressListenerFactory pProgressListenerFactory) {
5051
super(pServerThread, pStorageSource, pPackRepository, pWorldStem, pSettings, pFixerUpper, pServices, pProgressListenerFactory);
5152

5253
//Scuffed stuff here, convert the connection variable to mutable and set it after initialization by MinecraftServer
5354
//Interface used only to compile
54-
((SetConnectionIntf) this).setConnection(new ProxyServerConnectionListener(this));
55+
((SetConnectionIntf) this).setConnection(new CustomServerConnectionListener(this));
5556
}
5657

5758
@Override
@@ -76,13 +77,13 @@ public boolean initServer() throws IOException {
7677
Thread thread = new Thread("Server console handler") {
7778
@Override
7879
public void run() {
79-
if (net.neoforged.neoforge.server.console.TerminalHandler.handleCommands(ProxyDedicatedServer.this)) return;
80+
if (net.neoforged.neoforge.server.console.TerminalHandler.handleCommands(CustomDedicatedServer.this)) return;
8081
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
8182

8283
String s1;
8384
try {
84-
while (!ProxyDedicatedServer.this.isStopped() && ProxyDedicatedServer.this.isRunning() && (s1 = bufferedreader.readLine()) != null) {
85-
ProxyDedicatedServer.this.handleConsoleInput(s1, ProxyDedicatedServer.this.createCommandSourceStack());
85+
while (!CustomDedicatedServer.this.isStopped() && CustomDedicatedServer.this.isRunning() && (s1 = bufferedreader.readLine()) != null) {
86+
CustomDedicatedServer.this.handleConsoleInput(s1, CustomDedicatedServer.this.createCommandSourceStack());
8687
}
8788
} catch (IOException ioexception1) {
8889
DistributedServerLevels.LOGGER.error("Exception handling console input", (Throwable)ioexception1);
@@ -128,10 +129,10 @@ public void run() {
128129

129130
try {
130131

131-
if(this.getConnection() instanceof ProxyServerConnectionListener pServerConnectionListener){ //Listener custom
132+
if(this.getConnection() instanceof CustomServerConnectionListener pServerConnectionListener){ //Listener custom
132133
pServerConnectionListener.startTcpServerListener(inetaddress,this.getPort());
133134
} else { //Default listener
134-
System.out.println("Connection is not an instance of ProxyServerConnectionListener");
135+
System.out.println("Connection is not an instance of CustomServerConnectionListener");
135136
this.getConnection().startTcpServerListener(inetaddress, this.getPort());
136137
}
137138

src/main/java/com/manwe/dsl/dedicatedServer/proxy/ProxyServerConnectionListener.java renamed to src/main/java/com/manwe/dsl/dedicatedServer/CustomServerConnectionListener.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
package com.manwe.dsl.dedicatedServer.proxy;
1+
package com.manwe.dsl.dedicatedServer;
22

33
import com.manwe.dsl.DistributedServerLevels;
4+
import com.manwe.dsl.dedicatedServer.CustomDedicatedServer;
45
import com.manwe.dsl.dedicatedServer.proxy.front.ProxyFrontendInit;
56
import com.manwe.dsl.dedicatedServer.worker.WorkerFrontendInit;
67
import com.manwe.dsl.mixin.accessors.ServerConnectionListenerAccessor;
@@ -17,9 +18,9 @@
1718
import java.io.IOException;
1819
import java.net.InetAddress;
1920

20-
public class ProxyServerConnectionListener extends ServerConnectionListener {
21+
public class CustomServerConnectionListener extends ServerConnectionListener {
2122

22-
public ProxyServerConnectionListener(MinecraftServer pServer) {
23+
public CustomServerConnectionListener(MinecraftServer pServer) {
2324
super(pServer);
2425
}
2526

@@ -28,7 +29,7 @@ public ProxyServerConnectionListener(MinecraftServer pServer) {
2829
*/
2930
public void startTcpServerListener(@Nullable InetAddress pAddress, int pPort) throws IOException {
3031
System.out.println("Proxy - startTcpServerListener");
31-
if(!(this.getServer() instanceof ProxyDedicatedServer server)) throw new RuntimeException("ProxyServerConnectionListener not called from a ProxyDedicatedServer");
32+
if(!(this.getServer() instanceof CustomDedicatedServer server)) throw new RuntimeException("CustomServerConnectionListener not called from a CustomDedicatedServer");
3233

3334
if (pAddress == null) pAddress = new java.net.InetSocketAddress(pPort).getAddress();
3435
net.neoforged.neoforge.network.DualStackUtils.checkIPv6(pAddress);
@@ -46,8 +47,8 @@ public void startTcpServerListener(@Nullable InetAddress pAddress, int pPort) th
4647
}
4748

4849
ChannelInitializer<Channel> initializer = server.isProxy()
49-
? new ProxyFrontendInit((ProxyDedicatedServer) this.getServer(), this)
50-
: new WorkerFrontendInit((ProxyDedicatedServer) this.getServer(),this);
50+
? new ProxyFrontendInit((CustomDedicatedServer) this.getServer(), this)
51+
: new WorkerFrontendInit((CustomDedicatedServer) this.getServer(),this);
5152

5253
((ServerConnectionListenerAccessor) this).getChannels().add(
5354
new ServerBootstrap()
@@ -59,6 +60,10 @@ public void startTcpServerListener(@Nullable InetAddress pAddress, int pPort) th
5960
.syncUninterruptibly()
6061
);
6162
}
63+
}
6264

65+
@Override
66+
public void tick() {
67+
super.tick();
6368
}
6469
}

src/main/java/com/manwe/dsl/dedicatedServer/InternalGameProtocols.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public class InternalGameProtocols {
4646
.addPacket(InternalPacketTypes.PROXY_WORKER_FAKE_PLAYER_LOGIN, WorkerBoundFakePlayerLoginPacket.STREAM_CODEC)
4747
.addPacket(InternalPacketTypes.PROXY_WORKER_FAKE_PLAYER_MOVE, WorkerBoundFakePlayerMovePacket.STREAM_CODEC)
4848
.addPacket(InternalPacketTypes.PROXY_WORKER_FAKE_PLAYER_INFORMATION, WorkerBoundFakePlayerInformationPacket.STREAM_CODEC)
49+
50+
.addPacket(InternalPacketTypes.PROXY_WORKER_CHAT_MESSAGE, WorkerBoundChatPacket.STREAM_CODEC)
4951
);
5052
public static final ProtocolInfo<WorkerListener> SERVERBOUND = SERVERBOUND_TEMPLATE.bind(FriendlyByteBuf::new);
5153

src/main/java/com/manwe/dsl/dedicatedServer/InternalPacketTypes.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public class InternalPacketTypes {
4545
public static final PacketType<WorkerBoundFakePlayerMovePacket> PROXY_WORKER_FAKE_PLAYER_MOVE = createServerbound("worker_fake_player_move");
4646
public static final PacketType<WorkerBoundFakePlayerInformationPacket> PROXY_WORKER_FAKE_PLAYER_INFORMATION = createServerbound("worker_fake_player_information");
4747

48+
public static final PacketType<WorkerBoundChatPacket> PROXY_WORKER_CHAT_MESSAGE = createServerbound("worker_chat_message");
49+
4850
private static <T extends Packet<WorkerListener>> PacketType<T> createServerbound(String pName) {
4951
return new PacketType<>(PacketFlow.SERVERBOUND, ResourceLocation.withDefaultNamespace(pName));
5052
}

src/main/java/com/manwe/dsl/dedicatedServer/proxy/RemotePlayerList.java

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.manwe.dsl.dedicatedServer.proxy;
22

33
import com.manwe.dsl.DistributedServerLevels;
4-
import com.manwe.dsl.config.DSLServerConfigs;
54
import com.manwe.dsl.connectionRouting.RegionRouter;
5+
import com.manwe.dsl.dedicatedServer.CustomDedicatedServer;
66
import com.manwe.dsl.dedicatedServer.proxy.front.listeners.ProxyServerGameListener;
77
import com.manwe.dsl.dedicatedServer.worker.packets.login.WorkerBoundPlayerLoginPacket;
88
import com.manwe.dsl.mixin.accessors.PlayerListAccessor;
@@ -26,7 +26,6 @@
2626
import net.minecraft.server.players.GameProfileCache;
2727
import net.minecraft.world.level.Level;
2828
import net.minecraft.world.level.dimension.DimensionType;
29-
import net.minecraft.world.level.storage.LevelData;
3029
import net.minecraft.world.level.storage.PlayerDataStorage;
3130
import net.minecraft.world.phys.Vec3;
3231

@@ -41,18 +40,18 @@ public class RemotePlayerList extends DedicatedPlayerList {
4140

4241
public RemotePlayerList(DedicatedServer pServer, LayeredRegistryAccess<RegistryLayer> pRegistries, PlayerDataStorage pPlayerIo) {
4342
super(pServer, pRegistries, pPlayerIo);
44-
if(!(((PlayerListAccessor) this).getServer() instanceof ProxyDedicatedServer proxyDedicatedServer)) throw new RuntimeException("placeNewPlayer from RemotePlayerList was not called in a ProxyDedicatedServer");
43+
if(!(((PlayerListAccessor) this).getServer() instanceof CustomDedicatedServer customDedicatedServer)) throw new RuntimeException("placeNewPlayer from RemotePlayerList was not called in a CustomDedicatedServer");
4544
//Create router
46-
this.router = new RegionRouter(proxyDedicatedServer);
45+
this.router = new RegionRouter(customDedicatedServer);
4746
}
4847

4948
@Override
5049
public void placeNewPlayer(Connection pConnection, ServerPlayer pPlayer, CommonListenerCookie pCookie) {
51-
if(!(((PlayerListAccessor) this).getServer() instanceof ProxyDedicatedServer proxyDedicatedServer)) throw new RuntimeException("placeNewPlayer from RemotePlayerList was not called in a ProxyDedicatedServer");
52-
if(!proxyDedicatedServer.isProxy()) throw new RuntimeException("Worker cannot have a remotePlayerList");
50+
if(!(((PlayerListAccessor) this).getServer() instanceof CustomDedicatedServer customDedicatedServer)) throw new RuntimeException("placeNewPlayer from RemotePlayerList was not called in a CustomDedicatedServer");
51+
if(!customDedicatedServer.isProxy()) throw new RuntimeException("Worker cannot have a remotePlayerList");
5352

5453
GameProfile gameprofile = pPlayer.getGameProfile();
55-
GameProfileCache gameprofilecache = proxyDedicatedServer.getProfileCache();
54+
GameProfileCache gameprofilecache = customDedicatedServer.getProfileCache();
5655
String s;
5756
if (gameprofilecache != null) {
5857
Optional<GameProfile> optional = gameprofilecache.get(gameprofile.getId());
@@ -92,7 +91,7 @@ public void placeNewPlayer(Connection pConnection, ServerPlayer pPlayer, CommonL
9291
}
9392
//CUSTOM STATE LOADED
9493

95-
ServerLevel serverlevel1 = dim != null ? proxyDedicatedServer.getLevel(dim) : proxyDedicatedServer.overworld();
94+
ServerLevel serverlevel1 = dim != null ? customDedicatedServer.getLevel(dim) : customDedicatedServer.overworld();
9695
if(serverlevel1 == null) throw new RuntimeException("RemotePlayerList tried to get a null ServerLevel");
9796
//LevelData leveldata = serverlevel1.getLevelData();
9897
//pPlayer.loadGameTypes(optional1.orElse(null));
@@ -116,17 +115,41 @@ public void placeNewPlayer(Connection pConnection, ServerPlayer pPlayer, CommonL
116115

117116
System.out.println("Has ["+pPlayer.getUUID()+"] tunnel "+this.router.hasTunnel(pPlayer.getUUID()));
118117

119-
ProxyServerGameListener servergamepacketlistenerimpl = new ProxyServerGameListener(proxyDedicatedServer, pConnection, pPlayer, pCookie, this.router);
118+
ProxyServerGameListener servergamepacketlistenerimpl = new ProxyServerGameListener(customDedicatedServer, pConnection, pPlayer, pCookie, this.router);
120119

121120
pConnection.setupInboundProtocol(
122-
GameProtocols.SERVERBOUND_TEMPLATE.bind(RegistryFriendlyByteBuf.decorator(proxyDedicatedServer.registryAccess(), servergamepacketlistenerimpl.getConnectionType())), servergamepacketlistenerimpl
121+
GameProtocols.SERVERBOUND_TEMPLATE.bind(RegistryFriendlyByteBuf.decorator(customDedicatedServer.registryAccess(), servergamepacketlistenerimpl.getConnectionType())), servergamepacketlistenerimpl
123122
);
124123

125124
//net.neoforged.neoforge.common.NeoForge.EVENT_BUS.post(new net.neoforged.neoforge.event.OnDatapackSyncEvent(this, pPlayer));
126125
pPlayer.getStats().markAllDirty();
127-
proxyDedicatedServer.invalidateStatus();
126+
customDedicatedServer.invalidateStatus();
128127

129128

130129
this.router.route(pPlayer.getUUID()).send(initPacket); //Send init to worker
131130
}
131+
132+
/*
133+
@Override
134+
public void broadcastChatMessage(PlayerChatMessage pMessage, ServerPlayer pSender, ChatType.Bound pBoundChatType) {
135+
this.broadcastChatMessage(pMessage, pSender::shouldFilterMessageTo, pSender, pBoundChatType);
136+
}
137+
138+
private void broadcastChatMessage(PlayerChatMessage pMessage, Predicate<ServerPlayer> pShouldFilterMessageTo, @Nullable ServerPlayer pSender, ChatType.Bound pBoundChatType) {
139+
boolean flag = true;//pMessage.hasSignature() && !pMessage.hasExpiredServer(Instant.now());
140+
this.getServer().logChatMessage(pMessage.decoratedContent(), pBoundChatType, flag ? null : "Not Secure");
141+
OutgoingChatMessage outgoingchatmessage = OutgoingChatMessage.create(pMessage);
142+
boolean flag1 = false;
143+
144+
for (ServerPlayer serverplayer : this.getPlayers()) {
145+
boolean flag2 = pShouldFilterMessageTo.test(serverplayer);
146+
serverplayer.sendChatMessage(outgoingchatmessage, flag2, pBoundChatType);
147+
flag1 |= flag2 && pMessage.isFullyFiltered();
148+
}
149+
150+
if (flag1 && pSender != null) {
151+
pSender.sendSystemMessage(CHAT_FILTERED_FULL);
152+
}
153+
}
154+
*/
132155
}

src/main/java/com/manwe/dsl/dedicatedServer/proxy/TeleportSyncHelper.java

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/main/java/com/manwe/dsl/dedicatedServer/proxy/WorkerTunnel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public WorkerTunnel(InetSocketAddress workerAddress, RegionRouter router, Minecr
3232
Path playerDir = server.getWorldPath(LevelResource.PLAYER_DATA_DIR);
3333

3434
this.workerAddress = workerAddress;
35-
this.connection = new Connection(PacketFlow.CLIENTBOUND);
35+
this.connection = new Connection(PacketFlow.CLIENTBOUND);
3636
this.channel = new Bootstrap() // Inicialización del cliente
3737
.group(router.getEventLoopGroup())
3838
.channel(NioSocketChannel.class)

src/main/java/com/manwe/dsl/dedicatedServer/proxy/front/ProxyFrontendInit.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.manwe.dsl.dedicatedServer.proxy.front;
22

3-
import com.manwe.dsl.dedicatedServer.proxy.ProxyDedicatedServer;
4-
import com.manwe.dsl.dedicatedServer.proxy.ProxyServerConnectionListener;
3+
import com.manwe.dsl.dedicatedServer.CustomDedicatedServer;
4+
import com.manwe.dsl.dedicatedServer.CustomServerConnectionListener;
55
import com.manwe.dsl.dedicatedServer.proxy.front.listeners.ProxyServerHandshakeListener;
66
import io.netty.channel.*;
77
import io.netty.handler.timeout.ReadTimeoutHandler;
@@ -10,12 +10,12 @@
1010
import net.minecraft.server.network.LegacyQueryHandler;
1111

1212
public class ProxyFrontendInit extends ChannelInitializer<Channel> {
13-
private final ProxyDedicatedServer server;
14-
private final ProxyServerConnectionListener listener;
13+
private final CustomDedicatedServer server;
14+
private final CustomServerConnectionListener listener;
1515

1616
private static final int READ_TIMEOUT = Integer.parseInt(System.getProperty("neoforge.readTimeout", "30"));
1717

18-
public ProxyFrontendInit(ProxyDedicatedServer server, ProxyServerConnectionListener listener) {
18+
public ProxyFrontendInit(CustomDedicatedServer server, CustomServerConnectionListener listener) {
1919
this.server = server;
2020
this.listener = listener;
2121
}

0 commit comments

Comments
 (0)