Fixed a few typos that CovertJaguire found in The Forge entity handeling code. And re-wrote the connection sequance so that clients get a list of mod ids before anything else.

This commit is contained in:
LexManos 2012-03-20 22:04:58 -07:00
parent 7c7b6d8f46
commit 43ac9d6799
7 changed files with 69 additions and 137 deletions

View File

@ -37,11 +37,9 @@ public class PacketHandlerClient implements IPacketHandler
break; break;
case ForgePacket.MODLIST: case ForgePacket.MODLIST:
/*
pkt = new PacketModList(false); pkt = new PacketModList(false);
pkt.readData(data); pkt.readData(data);
*/ onModListCheck(net, (PacketModList)pkt);
onModListCheck(net);
break; break;
case ForgePacket.MOD_MISSING: case ForgePacket.MOD_MISSING:
@ -50,12 +48,6 @@ public class PacketHandlerClient implements IPacketHandler
onMissingMods((PacketMissingMods)pkt, net); onMissingMods((PacketMissingMods)pkt, net);
break; break;
case ForgePacket.MOD_IDS:
pkt = new PacketModIDs();
pkt.readData(data);
onModIDs((PacketModIDs)pkt);
break;
case ForgePacket.OPEN_GUI: case ForgePacket.OPEN_GUI:
pkt = new PacketOpenGUI(); pkt = new PacketOpenGUI();
pkt.readData(data); pkt.readData(data);
@ -104,7 +96,7 @@ public class PacketHandlerClient implements IPacketHandler
} }
entity.serverPosX = packet.posX; entity.serverPosX = packet.posX;
entity.serverPosY = packet.posX; entity.serverPosY = packet.posY;
entity.serverPosZ = packet.posZ; entity.serverPosZ = packet.posZ;
entity.rotationYaw = 0.0F; entity.rotationYaw = 0.0F;
entity.rotationPitch = 0.0F; entity.rotationPitch = 0.0F;
@ -142,16 +134,45 @@ public class PacketHandlerClient implements IPacketHandler
} }
/** /**
* Sets up the list of ID to mod mappings.
* TODO; Make it display an error, and prompt if the user wishes to continue anyways
* if it detects that the server does not have a corresponding mod to one it has installed.
*
* Sends a list of all loaded mods to the server. * Sends a list of all loaded mods to the server.
* For now, it it simple a String[] of mod.toString() * For now, it it simple a String[] of mod.toString()
*
* @param network The network connection to send the packet on. * @param network The network connection to send the packet on.
* @param packet The Server to client packet containing a list of NetworkMod ID's
*/ */
private void onModListCheck(NetClientHandler net) private void onModListCheck(NetClientHandler net, PacketModList packet)
{ {
if (DEBUG) if (DEBUG)
{ {
System.out.println("S->C: " + (new PacketModList(false)).toString(true)); System.out.println("S->C: " + packet.toString(true));
} }
ForgeHooks.networkMods.clear();
NetworkMod[] mods = MinecraftForge.getNetworkMods();
for (NetworkMod mod : mods)
{
for (Entry<Integer, String> entry : packet.ModIDs.entrySet())
{
if (mod.toString().equals(entry.getValue()))
{
ForgeHooks.networkMods.put(entry.getKey(), mod);
}
}
}
ArrayList<NetworkMod> missing = new ArrayList<NetworkMod>();
for (NetworkMod mod : mods)
{
if (MinecraftForge.getModID(mod) == -1 && mod.serverSideRequired())
{
missing.add(mod);
}
}
//TODO: Display error/confirmation screen
PacketModList pkt = new PacketModList(false); PacketModList pkt = new PacketModList(false);
pkt.Mods = new String[ModLoader.getLoadedMods().size()]; pkt.Mods = new String[ModLoader.getLoadedMods().size()];
int x = 0; int x = 0;
@ -185,42 +206,6 @@ public class PacketHandlerClient implements IPacketHandler
mc.displayGuiScreen(new GuiMissingMods(pkt)); mc.displayGuiScreen(new GuiMissingMods(pkt));
} }
/**
* Sets up the list of ID to mod mappings.
* TODO; Make it display an error, and prompt if the user wishes to continue anyways
* if it detects that the server does not have a corresponding mod to one it has installed.
*
* @param pkt The mod id packet
*/
private void onModIDs(PacketModIDs pkt)
{
if (DEBUG)
{
System.out.println("S->C: " + pkt.toString(true));
}
ForgeHooks.networkMods.clear();
NetworkMod[] mods = MinecraftForge.getNetworkMods();
for (NetworkMod mod : mods)
{
for (Entry<Integer, String> entry : pkt.Mods.entrySet())
{
if (mod.toString().equals(entry.getValue()))
{
ForgeHooks.networkMods.put(entry.getKey(), mod);
}
}
}
ArrayList<NetworkMod> missing = new ArrayList<NetworkMod>();
for (NetworkMod mod : mods)
{
if (MinecraftForge.getModID(mod) == -1 && mod.serverSideRequired())
{
missing.add(mod);
}
}
//TODO: Display error/confirmation screen
}
/** /**
* Handles opening the Gui for the player. * Handles opening the Gui for the player.
* *

View File

@ -912,7 +912,7 @@ public class MinecraftForge
for (Map.Entry<Class, EntityTrackerInfo> entry : ForgeHooks.entityTrackerMap.entrySet()) for (Map.Entry<Class, EntityTrackerInfo> entry : ForgeHooks.entityTrackerMap.entrySet())
{ {
EntityTrackerInfo info = entry.getValue(); EntityTrackerInfo info = entry.getValue();
if (type == info.ID && modID == info.Mod.toString().hashCode()) if (type == info.ID && modID == getModID(info.Mod))
{ {
return entry.getKey(); return entry.getKey();
} }

View File

@ -17,7 +17,6 @@ public abstract class ForgePacket
public static final int SPAWN = 1; public static final int SPAWN = 1;
public static final int MODLIST = 2; public static final int MODLIST = 2;
public static final int MOD_MISSING = 3; public static final int MOD_MISSING = 3;
public static final int MOD_IDS = 4;
public static final int OPEN_GUI = 5; public static final int OPEN_GUI = 5;
public Packet getPacket() public Packet getPacket()

View File

@ -1,60 +0,0 @@
package net.minecraft.src.forge.packets;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Map.Entry;
public class PacketModIDs extends ForgePacket
{
public Hashtable<Integer, String> Mods = new Hashtable<Integer, String>();
public int Length;
@Override
public void writeData(DataOutputStream data) throws IOException
{
data.writeInt(Mods.size());
for (Entry<Integer, String> entry : Mods.entrySet())
{
data.writeInt(entry.getKey());
data.writeUTF(entry.getValue());
}
}
@Override
public void readData(DataInputStream data) throws IOException
{
Length = data.readInt();
for (int x = 0; x < Length; x++)
{
Mods.put(data.readInt(), data.readUTF());
}
}
@Override
public int getID()
{
return ForgePacket.MOD_IDS;
}
@Override
public String toString(boolean full)
{
if (full)
{
StringBuilder ret = new StringBuilder();
ret.append(toString()).append('\n');
for (Entry<Integer, String> mod : Mods.entrySet())
{
ret.append(String.format(" %5d ", mod.getKey()) + mod.getValue() + '\n');
}
return ret.toString();
}
else
{
return toString();
}
}
}

View File

@ -3,12 +3,15 @@ package net.minecraft.src.forge.packets;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Hashtable;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
public class PacketModList extends ForgePacket public class PacketModList extends ForgePacket
{ {
private boolean isServer = false; private boolean isServer = false;
public String[] Mods; public String[] Mods;
public Hashtable<Integer, String> ModIDs = new Hashtable<Integer, String>();
public int Length = -1; public int Length = -1;
public PacketModList(boolean server) public PacketModList(boolean server)
@ -27,6 +30,15 @@ public class PacketModList extends ForgePacket
data.writeUTF(mod); data.writeUTF(mod);
} }
} }
else
{
data.writeInt(ModIDs.size());
for (Entry<Integer, String> entry : ModIDs.entrySet())
{
data.writeInt(entry.getKey());
data.writeUTF(entry.getValue());
}
}
} }
@Override @Override
@ -44,6 +56,14 @@ public class PacketModList extends ForgePacket
} }
} }
} }
else
{
Length = data.readInt();
for (int x = 0; x < Length; x++)
{
ModIDs.put(data.readInt(), data.readUTF());
}
}
} }
@Override @Override
@ -66,6 +86,13 @@ public class PacketModList extends ForgePacket
ret.append(" " + mod + '\n'); ret.append(" " + mod + '\n');
} }
} }
else if (ModIDs.size() != 0)
{
for (Entry<Integer, String> mod : ModIDs.entrySet())
{
ret.append(String.format(" %03d ", mod.getKey()) + mod.getValue() + '\n');
}
}
return ret.toString(); return ret.toString();
} }
else else

View File

@ -28,7 +28,14 @@ public class ForgeHooksServer
public static void sendModListRequest(NetworkManager net) public static void sendModListRequest(NetworkManager net)
{ {
NetworkMod[] list = MinecraftForge.getNetworkMods();
PacketModList pkt = new PacketModList(true); PacketModList pkt = new PacketModList(true);
for (NetworkMod mod : list)
{
pkt.ModIDs.put(MinecraftForge.getModID(mod), mod.toString());
}
((NetServerHandler)net.getNetHandler()).sendPacket(pkt.getPacket()); ((NetServerHandler)net.getNetHandler()).sendPacket(pkt.getPacket());
if (((PacketHandlerServer)ForgeHooks.getPacketHandler()).DEBUG) if (((PacketHandlerServer)ForgeHooks.getPacketHandler()).DEBUG)
{ {

View File

@ -91,10 +91,6 @@ public class PacketHandlerServer implements IPacketHandler
{ {
doMissingMods(net, missing); doMissingMods(net, missing);
} }
else
{
sendModIDs(net, serverMods);
}
} }
/** /**
@ -117,29 +113,7 @@ public class PacketHandlerServer implements IPacketHandler
net.sendPacket(pkt.getPacket()); net.sendPacket(pkt.getPacket());
disconnectUser(net); disconnectUser(net);
} }
/**
* Sends a list of mod id mappings to the client.
* Only mod ID's are sent, not item or blocks.
*
* @param net The network handler
* @param list A list of network mods
*/
private void sendModIDs(NetServerHandler net, NetworkMod[] list)
{
PacketModIDs pkt = new PacketModIDs();
for (NetworkMod mod : list)
{
pkt.Mods.put(MinecraftForge.getModID(mod), mod.toString());
}
net.sendPacket(pkt.getPacket());
if (DEBUG)
{
System.out.println("S->C: " + pkt.toString(true));
}
}
/** /**
* Disconnects the player just like kicking them, just without the kick message. * Disconnects the player just like kicking them, just without the kick message.
* @param net The network handler * @param net The network handler