Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public WorkerTunnel route(UUID playerID){
*/
public WorkerTunnel transferClientToWorker(UUID playerId, int workerId){
WorkerTunnel newTunnel = workerTunnels.get(workerId);
playerWorkerTunnels.put(playerId,newTunnel);//Set this player to this tunnel. All route() operations now point to this tunnel
playerWorkerTunnels.put(playerId,newTunnel); //Set this player to this tunnel. All route() operations now point to this tunnel
return newTunnel;
}

Expand Down Expand Up @@ -224,6 +224,7 @@ public static boolean isChunkInWorkerDomain(long pChunkPos){
*/
public static int defaultSpawnWorkerId(MinecraftServer server, int nWorkers, int regionSize){
BlockPos pos = server.overworld().getSharedSpawnPos();
System.out.println("Spawn Pos: "+pos.toString());
return computeWorkerId(pos.getX(),pos.getZ(),nWorkers,regionSize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,59 @@

import com.manwe.dsl.dedicatedServer.proxy.back.listeners.ProxyListener;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.*;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.chunkloading.ProxyBoundFakePlayerDisconnectPacket;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.chunkloading.ProxyBoundFakePlayerInformationPacket;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.chunkloading.ProxyBoundFakePlayerLoginPacket;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.chunkloading.ProxyBoundFakePlayerMovePacket;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.login.ProxyBoundPlayerInitACKPacket;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.transfer.ProxyBoundPlayerTransferACKPacket;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.transfer.ProxyBoundPlayerTransferPacket;
import com.manwe.dsl.dedicatedServer.worker.packets.*;
import com.manwe.dsl.dedicatedServer.worker.listeners.WorkerListener;
import com.manwe.dsl.dedicatedServer.worker.packets.chunkloading.WorkerBoundFakePlayerInformationPacket;
import com.manwe.dsl.dedicatedServer.worker.packets.chunkloading.WorkerBoundFakePlayerLoginPacket;
import com.manwe.dsl.dedicatedServer.worker.packets.chunkloading.WorkerBoundFakePlayerMovePacket;
import com.manwe.dsl.dedicatedServer.worker.packets.login.WorkerBoundPlayerLoginACKPacket;
import com.manwe.dsl.dedicatedServer.worker.packets.login.WorkerBoundPlayerLoginPacket;
import com.manwe.dsl.dedicatedServer.worker.packets.transfer.WorkerBoundPlayerDisconnectPacket;
import com.manwe.dsl.dedicatedServer.worker.packets.transfer.WorkerBoundPlayerEndTransferPacket;
import com.manwe.dsl.dedicatedServer.worker.packets.transfer.WorkerBoundPlayerTransferPacket;
import net.minecraft.network.ConnectionProtocol;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.ProtocolInfo;
import net.minecraft.network.protocol.ProtocolInfoBuilder;

public class InternalGameProtocols {
public static final ProtocolInfo.Unbound<WorkerListener, FriendlyByteBuf> SERVERBOUND_TEMPLATE = ProtocolInfoBuilder.serverboundProtocol(
ConnectionProtocol.PLAY, consumer ->
consumer.addPacket(InternalPacketTypes.PROXY_WORKER_PACKET_CONTAINER, WorkerBoundContainerPacket.STREAM_CODEC)
.addPacket(InternalPacketTypes.PROXY_WORKER_CLIENT_LOGIN, WorkerBoundPlayerInitPacket.STREAM_CODEC)
.addPacket(InternalPacketTypes.PROXY_WORKER_CLIENT_DISCONNECT, WorkerBoundPlayerDisconnectPacket.STREAM_CODEC)
ConnectionProtocol.PLAY, consumer -> consumer
.addPacket(InternalPacketTypes.PROXY_WORKER_PACKET_CONTAINER, WorkerBoundContainerPacket.STREAM_CODEC)

.addPacket(InternalPacketTypes.PROXY_WORKER_PLAYER_LOGIN, WorkerBoundPlayerLoginPacket.STREAM_CODEC)
.addPacket(InternalPacketTypes.PROXY_WORKER_PLAYER_LOGIN_ACK, WorkerBoundPlayerLoginACKPacket.STREAM_CODEC)
.addPacket(InternalPacketTypes.PROXY_WORKER_PLAYER_DISCONNECT, WorkerBoundPlayerDisconnectPacket.STREAM_CODEC)
.addPacket(InternalPacketTypes.PROXY_WORKER_PLAYER_TRANSFER, WorkerBoundPlayerTransferPacket.STREAM_CODEC)
.addPacket(InternalPacketTypes.PROXY_WORKER_PLAYER_INIT_ACK, WorkerBoundPlayerInitACKPacket.STREAM_CODEC)
.addPacket(InternalPacketTypes.PROXY_WORKER_PLAYER_END_TRANSFER, WorkerBoundPlayerEndTransferPacket.STREAM_CODEC)

.addPacket(InternalPacketTypes.PROXY_WORKER_FAKE_PLAYER_LOGIN, WorkerBoundFakePlayerLoginPacket.STREAM_CODEC)
.addPacket(InternalPacketTypes.PROXY_WORKER_FAKE_PLAYER_MOVE, WorkerBoundFakePlayerMovePacket.STREAM_CODEC)
.addPacket(InternalPacketTypes.PROXY_WORKER_FAKE_PLAYER_INFORMATION, WorkerBoundFakePlayerInformationPacket.STREAM_CODEC)
);
public static final ProtocolInfo<WorkerListener> SERVERBOUND = SERVERBOUND_TEMPLATE.bind(FriendlyByteBuf::new);

//De momento los worker no devuelven nada
public static final ProtocolInfo.Unbound<ProxyListener, FriendlyByteBuf> CLIENTBOUND_TEMPLATE = ProtocolInfoBuilder.clientboundProtocol(
ConnectionProtocol.PLAY, consumer ->
consumer.addPacket(InternalPacketTypes.WORKER_PROXY_PACKET_CONTAINER, ProxyBoundContainerPacket.STREAM_CODEC)
.addPacket(InternalPacketTypes.WORKER_PROXY_PLAYER_TRANSFER, ProxyBoundPlayerTransferPacket.STREAM_CODEC)
.addPacket(InternalPacketTypes.WORKER_PROXY_PLAYER_TRANSFER_ACK, ProxyBoundPlayerTransferACKPacket.STREAM_CODEC)
.addPacket(InternalPacketTypes.WORKER_PROXY_SAVE_PLAYER_STATE, ProxyBoundSavePlayerStatePacket.STREAM_CODEC)
.addPacket(InternalPacketTypes.WORKER_PROXY_PLAYER_INIT_ACK, ProxyBoundPlayerInitACKPacket.STREAM_CODEC)
ConnectionProtocol.PLAY, consumer -> consumer
.addPacket(InternalPacketTypes.WORKER_PROXY_PACKET_CONTAINER, ProxyBoundContainerPacket.STREAM_CODEC)

.addPacket(InternalPacketTypes.WORKER_PROXY_SAVE_PLAYER_STATE, ProxyBoundSavePlayerStatePacket.STREAM_CODEC)

.addPacket(InternalPacketTypes.WORKER_PROXY_PLAYER_LOGIN_ACK, ProxyBoundPlayerInitACKPacket.STREAM_CODEC)
.addPacket(InternalPacketTypes.WORKER_PROXY_PLAYER_TRANSFER, ProxyBoundPlayerTransferPacket.STREAM_CODEC)
.addPacket(InternalPacketTypes.WORKER_PROXY_PLAYER_TRANSFER_ACK, ProxyBoundPlayerTransferACKPacket.STREAM_CODEC)

.addPacket(InternalPacketTypes.WORKER_PROXY_FAKE_PLAYER_LOGIN, ProxyBoundFakePlayerLoginPacket.STREAM_CODEC)
.addPacket(InternalPacketTypes.WORKER_PROXY_FAKE_PLAYER_MOVE, ProxyBoundFakePlayerMovePacket.STREAM_CODEC)
.addPacket(InternalPacketTypes.WORKER_PROXY_FAKE_PLAYER_INFORMATION, ProxyBoundFakePlayerInformationPacket.STREAM_CODEC)
.addPacket(InternalPacketTypes.WORKER_PROXY_FAKE_PLAYER_DISCONNECT, ProxyBoundFakePlayerDisconnectPacket.STREAM_CODEC)
);

public static final ProtocolInfo<ProxyListener> CLIENTBOUND = CLIENTBOUND_TEMPLATE.bind(FriendlyByteBuf::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,57 @@

import com.manwe.dsl.dedicatedServer.proxy.back.listeners.ProxyListener;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.*;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.chunkloading.ProxyBoundFakePlayerDisconnectPacket;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.chunkloading.ProxyBoundFakePlayerInformationPacket;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.chunkloading.ProxyBoundFakePlayerLoginPacket;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.chunkloading.ProxyBoundFakePlayerMovePacket;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.login.ProxyBoundPlayerInitACKPacket;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.transfer.ProxyBoundPlayerTransferACKPacket;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.transfer.ProxyBoundPlayerTransferPacket;
import com.manwe.dsl.dedicatedServer.worker.packets.*;
import com.manwe.dsl.dedicatedServer.worker.listeners.WorkerListener;
import com.manwe.dsl.dedicatedServer.worker.packets.chunkloading.WorkerBoundFakePlayerInformationPacket;
import com.manwe.dsl.dedicatedServer.worker.packets.chunkloading.WorkerBoundFakePlayerLoginPacket;
import com.manwe.dsl.dedicatedServer.worker.packets.chunkloading.WorkerBoundFakePlayerMovePacket;
import com.manwe.dsl.dedicatedServer.worker.packets.login.WorkerBoundPlayerLoginACKPacket;
import com.manwe.dsl.dedicatedServer.worker.packets.login.WorkerBoundPlayerLoginPacket;
import com.manwe.dsl.dedicatedServer.worker.packets.transfer.WorkerBoundPlayerDisconnectPacket;
import com.manwe.dsl.dedicatedServer.worker.packets.transfer.WorkerBoundPlayerEndTransferPacket;
import com.manwe.dsl.dedicatedServer.worker.packets.transfer.WorkerBoundPlayerTransferPacket;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.PacketFlow;
import net.minecraft.network.protocol.PacketType;
import net.minecraft.resources.ResourceLocation;

public class InternalPacketTypes {
public static final PacketType<WorkerBoundPlayerInitPacket> PROXY_WORKER_CLIENT_LOGIN = createServerbound("worker_player_login");
public static final PacketType<WorkerBoundPlayerInitACKPacket> PROXY_WORKER_PLAYER_INIT_ACK = createServerbound("worker_player_init_ack");
public static final PacketType<WorkerBoundPlayerDisconnectPacket> PROXY_WORKER_CLIENT_DISCONNECT = createServerbound("worker_player_disconnect");
public static final PacketType<WorkerBoundContainerPacket> PROXY_WORKER_PACKET_CONTAINER = createServerbound("worker_packet_container");

public static final PacketType<WorkerBoundPlayerLoginPacket> PROXY_WORKER_PLAYER_LOGIN = createServerbound("worker_player_login");
public static final PacketType<WorkerBoundPlayerLoginACKPacket> PROXY_WORKER_PLAYER_LOGIN_ACK = createServerbound("worker_player_login_ack");
public static final PacketType<WorkerBoundPlayerDisconnectPacket> PROXY_WORKER_PLAYER_DISCONNECT = createServerbound("worker_player_disconnect");
public static final PacketType<WorkerBoundPlayerTransferPacket> PROXY_WORKER_PLAYER_TRANSFER = createServerbound("worker_player_transfer");
public static final PacketType<WorkerBoundPlayerEndTransferPacket> PROXY_WORKER_PLAYER_END_TRANSFER = createServerbound("worker_player_end_transfer");

public static final PacketType<WorkerBoundFakePlayerLoginPacket> PROXY_WORKER_FAKE_PLAYER_LOGIN = createServerbound("worker_fake_player_login");
public static final PacketType<WorkerBoundFakePlayerMovePacket> PROXY_WORKER_FAKE_PLAYER_MOVE = createServerbound("worker_fake_player_move");
public static final PacketType<WorkerBoundFakePlayerInformationPacket> PROXY_WORKER_FAKE_PLAYER_INFORMATION = createServerbound("worker_fake_player_information");

private static <T extends Packet<WorkerListener>> PacketType<T> createServerbound(String pName) {
return new PacketType<>(PacketFlow.SERVERBOUND, ResourceLocation.withDefaultNamespace(pName));
}

public static final PacketType<ProxyBoundContainerPacket> WORKER_PROXY_PACKET_CONTAINER = createClientbound("proxy_packet_container");

public static final PacketType<ProxyBoundSavePlayerStatePacket> WORKER_PROXY_SAVE_PLAYER_STATE = createClientbound("proxy_save_player_state");

public static final PacketType<ProxyBoundPlayerInitACKPacket> WORKER_PROXY_PLAYER_LOGIN_ACK = createClientbound("proxy_player_login_ack");
public static final PacketType<ProxyBoundPlayerTransferPacket> WORKER_PROXY_PLAYER_TRANSFER = createClientbound("proxy_player_transfer");
public static final PacketType<ProxyBoundPlayerTransferACKPacket> WORKER_PROXY_PLAYER_TRANSFER_ACK = createClientbound("proxy_player_transfer_ack");
public static final PacketType<ProxyBoundSavePlayerStatePacket> WORKER_PROXY_SAVE_PLAYER_STATE = createClientbound("proxy_save_player_state");
public static final PacketType<ProxyBoundPlayerInitACKPacket> WORKER_PROXY_PLAYER_INIT_ACK = createClientbound("proxy_player_init_ack");

public static final PacketType<ProxyBoundFakePlayerLoginPacket> WORKER_PROXY_FAKE_PLAYER_LOGIN = createClientbound("proxy_fake_player_login");
public static final PacketType<ProxyBoundFakePlayerMovePacket> WORKER_PROXY_FAKE_PLAYER_MOVE = createClientbound("proxy_fake_player_move");
public static final PacketType<ProxyBoundFakePlayerInformationPacket> WORKER_PROXY_FAKE_PLAYER_INFORMATION = createClientbound("proxy_fake_player_information");
public static final PacketType<ProxyBoundFakePlayerDisconnectPacket> WORKER_PROXY_FAKE_PLAYER_DISCONNECT = createClientbound("proxy_fake_player_disconnect");

private static <T extends Packet<ProxyListener>> PacketType<T> createClientbound(String pId) {
return new PacketType<>(PacketFlow.CLIENTBOUND, ResourceLocation.withDefaultNamespace(pId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,18 @@
import com.manwe.dsl.config.DSLServerConfigs;
import com.manwe.dsl.connectionRouting.RegionRouter;
import com.manwe.dsl.dedicatedServer.proxy.front.listeners.ProxyServerGameListener;
import com.manwe.dsl.dedicatedServer.worker.packets.WorkerBoundPlayerInitPacket;
import com.manwe.dsl.dedicatedServer.worker.packets.login.WorkerBoundPlayerLoginPacket;
import com.manwe.dsl.mixin.accessors.PlayerListAccessor;
import com.mojang.authlib.GameProfile;
import com.mojang.serialization.Dynamic;
import net.minecraft.ChatFormatting;
import net.minecraft.core.LayeredRegistryAccess;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.Tag;
import net.minecraft.network.Connection;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.protocol.game.*;
import net.minecraft.network.protocol.status.ServerStatus;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.RegistryLayer;
import net.minecraft.server.dedicated.DedicatedPlayerList;
Expand All @@ -28,15 +24,13 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.CommonListenerCookie;
import net.minecraft.server.players.GameProfileCache;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.storage.LevelData;
import net.minecraft.world.level.storage.PlayerDataStorage;
import net.minecraft.world.phys.Vec3;

import java.util.*;
import java.util.concurrent.CompletableFuture;

/**
* Modified PlaceNewPlayer, set up RemoteServerGamePacketListenerImpl instead of ServerGamePacketListenerImpl
Expand Down Expand Up @@ -114,15 +108,16 @@ public void placeNewPlayer(Connection pConnection, ServerPlayer pPlayer, CommonL
//Register this Client<->Proxy connection to be used by outgoing client packets from workers to clients. The proxy redirects these packets to the client.
this.router.addOutgoingConnection(pPlayer.getUUID(),pConnection);
//Create init message
WorkerBoundPlayerInitPacket initPacket = new WorkerBoundPlayerInitPacket(pPlayer.getGameProfile(), pPlayer.clientInformation());
WorkerBoundPlayerLoginPacket initPacket = new WorkerBoundPlayerLoginPacket(pPlayer.getGameProfile(), pPlayer.clientInformation());

//Set worker for player if saved in disk
if(workerId != 0) this.router.transferClientToWorker(pPlayer.getUUID(),workerId);

//If not Saved in memory
if(!this.router.hasTunnel(pPlayer.getUUID())){ //Default spawn position
this.router.transferClientToWorker(pPlayer.getUUID(), RegionRouter.defaultSpawnWorkerId(getServer(), DSLServerConfigs.WORKER_SIZE.get(),DSLServerConfigs.REGION_SIZE.get()));
System.out.println("This player has no tunnel set defaulting to server spawn");
workerId = RegionRouter.defaultSpawnWorkerId(getServer(), DSLServerConfigs.WORKER_SIZE.get(),DSLServerConfigs.REGION_SIZE.get());
this.router.transferClientToWorker(pPlayer.getUUID(), workerId);
System.out.println("This player has no tunnel set defaulting to server spawn - Worker: "+workerId);
}
System.out.println("Has ["+pPlayer.getUUID()+"] tunnel "+this.router.hasTunnel(pPlayer.getUUID()));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package com.manwe.dsl.dedicatedServer.proxy.back.listeners;

import com.manwe.dsl.dedicatedServer.proxy.back.packets.*;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.chunkloading.ProxyBoundFakePlayerDisconnectPacket;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.chunkloading.ProxyBoundFakePlayerInformationPacket;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.chunkloading.ProxyBoundFakePlayerLoginPacket;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.chunkloading.ProxyBoundFakePlayerMovePacket;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.login.ProxyBoundPlayerInitACKPacket;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.transfer.ProxyBoundPlayerTransferACKPacket;
import com.manwe.dsl.dedicatedServer.proxy.back.packets.transfer.ProxyBoundPlayerTransferPacket;
import net.minecraft.network.ClientboundPacketListener;
import net.minecraft.network.ConnectionProtocol;

Expand All @@ -27,4 +34,12 @@ default ConnectionProtocol protocol() {
void handleSavePlayerState(ProxyBoundSavePlayerStatePacket packet);

void handlePlayerInitACK(ProxyBoundPlayerInitACKPacket packet);

void handleFakePlayerLogin(ProxyBoundFakePlayerLoginPacket packet);

void handleFakePlayerMove(ProxyBoundFakePlayerMovePacket packet);

void handleFakePlayerDisconnect(ProxyBoundFakePlayerDisconnectPacket packet);

void handleFakePlayerInformation(ProxyBoundFakePlayerInformationPacket packet);
}
Loading
Loading