From 4e575f353f02edf4da53a1731355622ab716516f Mon Sep 17 00:00:00 2001 From: LexManos Date: Fri, 6 Apr 2012 22:59:58 -0700 Subject: [PATCH] Rewrote the login code to delay full login untill forge fnishes negotiating network IDs. Should fix entities not having proper ID mapings. --- .../net/minecraft/src/mod_MinecraftForge.java | 2 + .../minecraft/src/forge/ForgeHooksServer.java | 34 ++++++++++++ .../src/forge/PacketHandlerServer.java | 32 ++++++++++++ .../minecraft/src/NetLoginHandler.java.patch | 52 ++++++++----------- .../minecraft/src/NetServerHandler.java.patch | 9 ++++ 5 files changed, 98 insertions(+), 31 deletions(-) diff --git a/forge/forge_client/src/net/minecraft/src/mod_MinecraftForge.java b/forge/forge_client/src/net/minecraft/src/mod_MinecraftForge.java index 5a9505afa..5d00027d9 100644 --- a/forge/forge_client/src/net/minecraft/src/mod_MinecraftForge.java +++ b/forge/forge_client/src/net/minecraft/src/mod_MinecraftForge.java @@ -2,6 +2,7 @@ package net.minecraft.src; import net.minecraft.src.forge.ForgeHooks; import net.minecraft.src.forge.MinecraftForge; +import net.minecraft.src.forge.MinecraftForgeClient; import net.minecraft.src.forge.NetworkMod; /** @@ -21,6 +22,7 @@ public class mod_MinecraftForge extends NetworkMod public void load() { MinecraftForge.getDungeonLootTries(); //Random thing to make things Initialize + MinecraftForgeClient.init(); } @Override diff --git a/forge/forge_server/src/net/minecraft/src/forge/ForgeHooksServer.java b/forge/forge_server/src/net/minecraft/src/forge/ForgeHooksServer.java index d59008477..f1a92397c 100644 --- a/forge/forge_server/src/net/minecraft/src/forge/ForgeHooksServer.java +++ b/forge/forge_server/src/net/minecraft/src/forge/ForgeHooksServer.java @@ -1,8 +1,10 @@ package net.minecraft.src.forge; +import java.io.UnsupportedEncodingException; import java.util.Map; import net.minecraft.src.*; +import net.minecraft.src.forge.packets.ForgePacket; import net.minecraft.src.forge.packets.PacketModList; public class ForgeHooksServer @@ -42,6 +44,38 @@ public class ForgeHooksServer System.out.println("S->C: " + pkt.toString(true)); } } + + public static void handleLoginPacket(Packet1Login pktLogin, NetServerHandler net, NetworkManager manager) + { + init(); + if (pktLogin.serverMode == ForgePacket.FORGE_ID) + { + ForgeHooks.onLogin(manager, pktLogin); + + String[] channels = MessageManager.getInstance().getRegisteredChannels(manager); + StringBuilder tmp = new StringBuilder(); + tmp.append("Forge"); + for(String channel : channels) + { + tmp.append("\0"); + tmp.append(channel); + } + Packet250CustomPayload pkt = new Packet250CustomPayload(); + pkt.channel = "REGISTER"; + try { + pkt.data = tmp.toString().getBytes("UTF8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + pkt.length = pkt.data.length; + net.sendPacket(pkt); + ForgeHooksServer.sendModListRequest(manager); + } + else + { + net.kickPlayer("This server requires you to have Minecraft Forge installed."); + } + } private static boolean hasInit = false; diff --git a/forge/forge_server/src/net/minecraft/src/forge/PacketHandlerServer.java b/forge/forge_server/src/net/minecraft/src/forge/PacketHandlerServer.java index d5b8ca7d0..cf87d0dd6 100644 --- a/forge/forge_server/src/net/minecraft/src/forge/PacketHandlerServer.java +++ b/forge/forge_server/src/net/minecraft/src/forge/PacketHandlerServer.java @@ -91,6 +91,10 @@ public class PacketHandlerServer implements IPacketHandler { doMissingMods(net, missing); } + else + { + finishLogin(net); + } } /** @@ -127,4 +131,32 @@ public class PacketHandlerServer implements IPacketHandler mc.configManager.playerLoggedOut(net.getPlayerEntity()); net.connectionClosed = true; } + + private void finishLogin(NetServerHandler net) + { + EntityPlayerMP player = net.getPlayerEntity(); + WorldServer world = net.mcServer.getWorldManager(player.dimension); + ChunkCoordinates spawn = world.getSpawnPoint(); + + net.sendPacket(new Packet1Login("", player.entityId, world.getWorldInfo().getTerrainType(), + player.itemInWorldManager.getGameType(), world.worldProvider.worldType, + (byte)world.difficultySetting, (byte)world.getHeight(), + (byte)net.mcServer.configManager.getMaxPlayers())); + + net.sendPacket(new Packet6SpawnPosition(spawn.posX, spawn.posY, spawn.posZ)); + net.sendPacket(new Packet202PlayerAbilities(player.capabilities)); + net.mcServer.configManager.updateTimeAndWeather(player, world); + net.mcServer.configManager.sendPacketToAllPlayers(new Packet3Chat("\u00a7e" + player.username + " joined the game.")); + net.mcServer.configManager.playerLoggedIn(player); + + net.teleportTo(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch); + net.sendPacket(new Packet4UpdateTime(world.getWorldTime())); + + for (Object efx : player.getActivePotionEffects()) + { + net.sendPacket(new Packet41EntityEffect(player.entityId, (PotionEffect)efx)); + } + + player.func_20057_k(); + } } diff --git a/forge/patches/minecraft_server/net/minecraft/src/NetLoginHandler.java.patch b/forge/patches/minecraft_server/net/minecraft/src/NetLoginHandler.java.patch index 6b9ad32f1..657fe5e0b 100644 --- a/forge/patches/minecraft_server/net/minecraft/src/NetLoginHandler.java.patch +++ b/forge/patches/minecraft_server/net/minecraft/src/NetLoginHandler.java.patch @@ -18,40 +18,30 @@ } /** -@@ -164,6 +168,36 @@ +@@ -146,6 +150,7 @@ + ChunkCoordinates var4 = var3.getSpawnPoint(); + var2.itemInWorldManager.func_35695_b(var3.getWorldInfo().getGameType()); + NetServerHandler var5 = new NetServerHandler(this.mcServer, this.netManager, var2); ++ /* + var5.sendPacket(new Packet1Login("", var2.entityId, var3.getWorldInfo().getTerrainType(), var2.itemInWorldManager.getGameType(), var3.worldProvider.worldType, (byte)var3.difficultySetting, (byte)var3.getHeight(), (byte)this.mcServer.configManager.getMaxPlayers())); + var5.sendPacket(new Packet6SpawnPosition(var4.posX, var4.posY, var4.posZ)); + var5.sendPacket(new Packet202PlayerAbilities(var2.capabilities)); +@@ -153,7 +158,9 @@ + this.mcServer.configManager.sendPacketToAllPlayers(new Packet3Chat("\u00a7e" + var2.username + " joined the game.")); + this.mcServer.configManager.playerLoggedIn(var2); + var5.teleportTo(var2.posX, var2.posY, var2.posZ, var2.rotationYaw, var2.rotationPitch); ++ */ + this.mcServer.networkServer.addPlayer(var5); ++ /* + var5.sendPacket(new Packet4UpdateTime(var3.getWorldTime())); + Iterator var6 = var2.getActivePotionEffects().iterator(); + +@@ -164,6 +171,8 @@ } var2.func_20057_k(); -+ if (par1Packet1Login.serverMode == ForgePacket.FORGE_ID) -+ { -+ //Pretty hackish place to put it, but it needs to go somewhere -+ ForgeHooksServer.init(); -+ //pkt.mapSeed = ForgeHooks.buildVersion; -+ ForgeHooks.onLogin(netManager, par1Packet1Login); -+ -+ String[] channels = MessageManager.getInstance().getRegisteredChannels(netManager); -+ StringBuilder tmp = new StringBuilder(); -+ tmp.append("Forge"); -+ for(String channel : channels) -+ { -+ tmp.append("\0"); -+ tmp.append(channel); -+ } -+ Packet250CustomPayload pkt = new Packet250CustomPayload(); -+ pkt.channel = "REGISTER"; -+ try { -+ pkt.data = tmp.toString().getBytes("UTF8"); -+ } catch (UnsupportedEncodingException e) { -+ e.printStackTrace(); -+ } -+ pkt.length = pkt.data.length; -+ var5.sendPacket(pkt); -+ ForgeHooksServer.sendModListRequest(netManager); -+ } -+ else -+ { -+ var5.kickPlayer("This server requires you to have Minecraft Forge installed."); -+ } ++ */ ++ ForgeHooksServer.handleLoginPacket(par1Packet1Login, var5, netManager); } this.finishedProcessing = true; diff --git a/forge/patches/minecraft_server/net/minecraft/src/NetServerHandler.java.patch b/forge/patches/minecraft_server/net/minecraft/src/NetServerHandler.java.patch index 0657417e2..80b31a2b4 100644 --- a/forge/patches/minecraft_server/net/minecraft/src/NetServerHandler.java.patch +++ b/forge/patches/minecraft_server/net/minecraft/src/NetServerHandler.java.patch @@ -10,6 +10,15 @@ public class NetServerHandler extends NetHandler implements ICommandListener { +@@ -19,7 +22,7 @@ + public boolean connectionClosed = false; + + /** Reference to the MinecraftServer object. */ +- private MinecraftServer mcServer; ++ public MinecraftServer mcServer; + + /** Reference to the EntityPlayerMP object. */ + private EntityPlayerMP playerEntity; @@ -374,8 +377,11 @@ double var10 = this.playerEntity.posY - ((double)var6 + 0.5D) + 1.5D; double var12 = this.playerEntity.posZ - ((double)var7 + 0.5D);