Lots of network cleanup. Gui packets now work too!
This commit is contained in:
parent
e4d2f73fe2
commit
3e0285e508
5 changed files with 127 additions and 611 deletions
|
@ -116,7 +116,14 @@ public class FMLCommonHandler
|
|||
*/
|
||||
public ModContainer findContainerFor(Object mod)
|
||||
{
|
||||
return Loader.instance().getReversedModObjectList().get(mod);
|
||||
if (mod instanceof String)
|
||||
{
|
||||
return Loader.instance().getIndexedModList().get(mod);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Loader.instance().getReversedModObjectList().get(mod);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the forge mod loader logging instance (goes to the forgemodloader log file)
|
||||
|
|
|
@ -24,6 +24,8 @@ import java.util.Set;
|
|||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.network.INetHandler;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
@ -125,6 +127,15 @@ public enum NetworkRegistry
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* INTERNAL Create a new channel pair with the specified name and channel handlers.
|
||||
* This is used internally in forge and FML
|
||||
*
|
||||
* @param container The container to associate the channel with
|
||||
* @param name The name for the channel
|
||||
* @param handlers Some {@link ChannelHandler} for the channel
|
||||
* @return an {@link EnumMap} of the pair of channels. keys are {@link Side}. There will always be two entries.
|
||||
*/
|
||||
public EnumMap<Side,FMLEmbeddedChannel> newChannel(ModContainer container, String name, ChannelHandler... handlers)
|
||||
{
|
||||
if (channels.containsKey(name) || name.startsWith("MC|") || name.startsWith("\u0001") || (name.startsWith("FML") && !("FML".equals(container.getModId()))))
|
||||
|
@ -146,213 +157,12 @@ public enum NetworkRegistry
|
|||
{
|
||||
return channels.get(source).get(name);
|
||||
}
|
||||
/*
|
||||
*//**
|
||||
* Get the packet 250 channel registration string
|
||||
* @return the {@link Packet250CustomPayload} channel registration string
|
||||
*//*
|
||||
byte[] getPacketRegistry(Side side)
|
||||
{
|
||||
return Joiner.on('\0').join(Iterables.concat(Arrays.asList("FML"),universalPacketHandlers.keySet(), side.isClient() ? clientPacketHandlers.keySet() : serverPacketHandlers.keySet())).getBytes(Charsets.UTF_8);
|
||||
}
|
||||
*//**
|
||||
* Is the specified channel active for the player?
|
||||
* @param channel
|
||||
* @param player
|
||||
*//*
|
||||
public boolean isChannelActive(String channel, Player player)
|
||||
{
|
||||
return activeChannels.containsEntry(player,channel);
|
||||
}
|
||||
*//**
|
||||
* register a channel to a mod
|
||||
* @param handler the packet handler
|
||||
* @param channelName the channel name to register it with
|
||||
*//*
|
||||
public void registerChannel(IPacketHandler handler, String channelName)
|
||||
{
|
||||
if (Strings.isNullOrEmpty(channelName) || (channelName!=null && channelName.length()>16))
|
||||
{
|
||||
FMLLog.severe("Invalid channel name '%s' : %s", channelName, Strings.isNullOrEmpty(channelName) ? "Channel name is empty" : "Channel name is too long (16 chars is maximum)");
|
||||
throw new RuntimeException("Channel name is invalid");
|
||||
|
||||
}
|
||||
universalPacketHandlers.put(channelName, handler);
|
||||
}
|
||||
|
||||
public void registerChannel(IPacketHandler handler, String channelName, Side side)
|
||||
{
|
||||
if (side == null)
|
||||
{
|
||||
registerChannel(handler, channelName);
|
||||
return;
|
||||
}
|
||||
if (Strings.isNullOrEmpty(channelName) || (channelName!=null && channelName.length()>16))
|
||||
{
|
||||
FMLLog.severe("Invalid channel name '%s' : %s", channelName, Strings.isNullOrEmpty(channelName) ? "Channel name is empty" : "Channel name is too long (16 chars is maximum)");
|
||||
throw new RuntimeException("Channel name is invalid");
|
||||
|
||||
}
|
||||
if (side.isClient())
|
||||
{
|
||||
clientPacketHandlers.put(channelName, handler);
|
||||
}
|
||||
else
|
||||
{
|
||||
serverPacketHandlers.put(channelName, handler);
|
||||
}
|
||||
}
|
||||
*//**
|
||||
* Activate the channel for the player
|
||||
* @param player
|
||||
*//*
|
||||
void activateChannel(Player player, String channel)
|
||||
{
|
||||
activeChannels.put(player, channel);
|
||||
}
|
||||
*//**
|
||||
* Deactivate the channel for the player
|
||||
* @param player
|
||||
* @param channel
|
||||
*//*
|
||||
void deactivateChannel(Player player, String channel)
|
||||
{
|
||||
activeChannels.remove(player, channel);
|
||||
}
|
||||
*//**
|
||||
* Register a connection handler
|
||||
/**
|
||||
* Register an {@link IGuiHandler} for the supplied mod object.
|
||||
*
|
||||
* @param handler
|
||||
*//*
|
||||
public void registerConnectionHandler(IConnectionHandler handler)
|
||||
{
|
||||
connectionHandlers.add(handler);
|
||||
}
|
||||
|
||||
*//**
|
||||
* Register a chat listener
|
||||
* @param listener
|
||||
*//*
|
||||
public void registerChatListener(IChatListener listener)
|
||||
{
|
||||
chatListeners.add(listener);
|
||||
}
|
||||
|
||||
void playerLoggedIn(EntityPlayerMP player, NetServerHandler netHandler, INetworkManager manager)
|
||||
{
|
||||
generateChannelRegistration(player, netHandler, manager);
|
||||
for (IConnectionHandler handler : connectionHandlers)
|
||||
{
|
||||
handler.playerLoggedIn((Player)player, netHandler, manager);
|
||||
}
|
||||
}
|
||||
|
||||
String connectionReceived(NetLoginHandler netHandler, INetworkManager manager)
|
||||
{
|
||||
for (IConnectionHandler handler : connectionHandlers)
|
||||
{
|
||||
String kick = handler.connectionReceived(netHandler, manager);
|
||||
if (!Strings.isNullOrEmpty(kick))
|
||||
{
|
||||
return kick;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void connectionOpened(NetHandler netClientHandler, String server, int port, INetworkManager networkManager)
|
||||
{
|
||||
for (IConnectionHandler handler : connectionHandlers)
|
||||
{
|
||||
handler.connectionOpened(netClientHandler, server, port, networkManager);
|
||||
}
|
||||
}
|
||||
|
||||
void connectionOpened(NetHandler netClientHandler, MinecraftServer server, INetworkManager networkManager)
|
||||
{
|
||||
for (IConnectionHandler handler : connectionHandlers)
|
||||
{
|
||||
handler.connectionOpened(netClientHandler, server, networkManager);
|
||||
}
|
||||
}
|
||||
|
||||
void clientLoggedIn(NetHandler clientHandler, INetworkManager manager, Packet1Login login)
|
||||
{
|
||||
generateChannelRegistration(clientHandler.getPlayer(), clientHandler, manager);
|
||||
for (IConnectionHandler handler : connectionHandlers)
|
||||
{
|
||||
handler.clientLoggedIn(clientHandler, manager, login);
|
||||
}
|
||||
}
|
||||
|
||||
void connectionClosed(INetworkManager manager, EntityPlayer player)
|
||||
{
|
||||
for (IConnectionHandler handler : connectionHandlers)
|
||||
{
|
||||
handler.connectionClosed(manager);
|
||||
}
|
||||
activeChannels.removeAll(player);
|
||||
}
|
||||
|
||||
void generateChannelRegistration(EntityPlayer player, NetHandler netHandler, INetworkManager manager)
|
||||
{
|
||||
Packet250CustomPayload pkt = new Packet250CustomPayload();
|
||||
pkt.field_73630_a = "REGISTER";
|
||||
pkt.field_73629_c = getPacketRegistry(player instanceof EntityPlayerMP ? Side.SERVER : Side.CLIENT);
|
||||
pkt.field_73628_b = pkt.field_73629_c.length;
|
||||
manager.func_74429_a(pkt);
|
||||
}
|
||||
|
||||
void handleCustomPacket(Packet250CustomPayload packet, INetworkManager network, NetHandler handler)
|
||||
{
|
||||
if ("REGISTER".equals(packet.field_73630_a))
|
||||
{
|
||||
handleRegistrationPacket(packet, (Player)handler.getPlayer());
|
||||
}
|
||||
else if ("UNREGISTER".equals(packet.field_73630_a))
|
||||
{
|
||||
handleUnregistrationPacket(packet, (Player)handler.getPlayer());
|
||||
}
|
||||
else
|
||||
{
|
||||
handlePacket(packet, network, (Player)handler.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void handlePacket(Packet250CustomPayload packet, INetworkManager network, Player player)
|
||||
{
|
||||
String channel = packet.field_73630_a;
|
||||
for (IPacketHandler handler : Iterables.concat(universalPacketHandlers.get(channel), player instanceof EntityPlayerMP ? serverPacketHandlers.get(channel) : clientPacketHandlers.get(channel)))
|
||||
{
|
||||
handler.onPacketData(network, packet, player);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleRegistrationPacket(Packet250CustomPayload packet, Player player)
|
||||
{
|
||||
List<String> channels = extractChannelList(packet);
|
||||
for (String channel : channels)
|
||||
{
|
||||
activateChannel(player, channel);
|
||||
}
|
||||
}
|
||||
private void handleUnregistrationPacket(Packet250CustomPayload packet, Player player)
|
||||
{
|
||||
List<String> channels = extractChannelList(packet);
|
||||
for (String channel : channels)
|
||||
{
|
||||
deactivateChannel(player, channel);
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> extractChannelList(Packet250CustomPayload packet)
|
||||
{
|
||||
String request = new String(packet.field_73629_c, Charsets.UTF_8);
|
||||
List<String> channels = Lists.newArrayList(Splitter.on('\0').split(request));
|
||||
return channels;
|
||||
}
|
||||
*/
|
||||
* @param mod The mod to handle GUIs for
|
||||
* @param handler A handler for creating GUI related objects
|
||||
*/
|
||||
public void registerGuiHandler(Object mod, IGuiHandler handler)
|
||||
{
|
||||
ModContainer mc = FMLCommonHandler.instance().findContainerFor(mod);
|
||||
|
@ -364,37 +174,67 @@ public enum NetworkRegistry
|
|||
serverGuiHandlers.put(mc, handler);
|
||||
clientGuiHandlers.put(mc, handler);
|
||||
}
|
||||
/* void openRemoteGui(ModContainer mc, EntityPlayerMP player, int modGuiId, World world, int x, int y, int z)
|
||||
|
||||
/**
|
||||
* INTERNAL method for accessing the Gui registry
|
||||
* @param mc Mod Container
|
||||
* @param player Player
|
||||
* @param modGuiId guiId
|
||||
* @param world World
|
||||
* @param x X coord
|
||||
* @param y Y coord
|
||||
* @param z Z coord
|
||||
* @return The server side GUI object (An instance of {@link Container})
|
||||
*/
|
||||
public Container getRemoteGuiContainer(ModContainer mc, EntityPlayerMP player, int modGuiId, World world, int x, int y, int z)
|
||||
{
|
||||
IGuiHandler handler = serverGuiHandlers.get(mc);
|
||||
NetworkModHolder nmh = mc.getNetworkModHolder();
|
||||
if (handler != null && nmh != null)
|
||||
|
||||
if (handler != null)
|
||||
{
|
||||
Container container = (Container)handler.getServerGuiElement(modGuiId, player, world, x, y, z);
|
||||
if (container != null)
|
||||
{
|
||||
player.func_71117_bO();
|
||||
player.func_71128_l();
|
||||
int windowId = player.field_71139_cq;
|
||||
Packet pkt = PacketManager.INSTANCE.makeGuiPacket(windowId, nmh.getNetworkId(), modGuiId, x, y, z);
|
||||
player.field_71135_a.func_72567_b(pkt);
|
||||
player.field_71070_bA = container;
|
||||
player.field_71070_bA.field_75152_c = windowId;
|
||||
player.field_71070_bA.func_75132_a(player);
|
||||
}
|
||||
return (Container)handler.getServerGuiElement(modGuiId, player, world, x, y, z);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
*/ void openLocalGui(ModContainer mc, EntityPlayer player, int modGuiId, World world, int x, int y, int z)
|
||||
|
||||
/**
|
||||
* INTERNAL method for accessing the Gui registry
|
||||
* @param mc Mod Container
|
||||
* @param player Player
|
||||
* @param modGuiId guiId
|
||||
* @param world World
|
||||
* @param x X coord
|
||||
* @param y Y coord
|
||||
* @param z Z coord
|
||||
* @return The client side GUI object (An instance of {@link GUI})
|
||||
*/
|
||||
public Object getLocalGuiContainer(ModContainer mc, EntityPlayer player, int modGuiId, World world, int x, int y, int z)
|
||||
{
|
||||
IGuiHandler handler = clientGuiHandlers.get(mc);
|
||||
FMLCommonHandler.instance().showGuiScreen(handler.getClientGuiElement(modGuiId, player, world, x, y, z));
|
||||
return handler.getClientGuiElement(modGuiId, player, world, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is there a channel with this name on this side?
|
||||
* @param channelName The name
|
||||
* @param source the side
|
||||
* @return if there's a channel
|
||||
*/
|
||||
public boolean hasChannel(String channelName, Side source)
|
||||
{
|
||||
return channels.get(source).containsKey(channelName);
|
||||
}
|
||||
|
||||
/**
|
||||
* INTERNAL method for registering a mod as a network capable thing
|
||||
* @param fmlModContainer The fml mod container
|
||||
* @param clazz a class
|
||||
* @param remoteVersionRange the acceptable remote range
|
||||
* @param asmHarvestedData internal data
|
||||
*/
|
||||
public void register(ModContainer fmlModContainer, Class<?> clazz, String remoteVersionRange, ASMDataTable asmHarvestedData)
|
||||
{
|
||||
NetworkModHolder networkModHolder = new NetworkModHolder(fmlModContainer, clazz, remoteVersionRange, asmHarvestedData);
|
||||
|
@ -406,11 +246,21 @@ public enum NetworkRegistry
|
|||
return ImmutableMap.copyOf(registry);
|
||||
}
|
||||
|
||||
/**
|
||||
* All the valid channel names for a side
|
||||
* @param side the side
|
||||
* @return the set of channel names
|
||||
*/
|
||||
public Set<String> channelNamesFor(Side side)
|
||||
{
|
||||
return channels.get(side).keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* INTERNAL fire a handshake to all channels
|
||||
* @param networkDispatcher The dispatcher firing
|
||||
* @param origin which side the dispatcher is on
|
||||
*/
|
||||
public void fireNetworkHandshake(NetworkDispatcher networkDispatcher, Side origin)
|
||||
{
|
||||
NetworkHandshakeEstablished handshake = new NetworkHandshakeEstablished(networkDispatcher, networkDispatcher.getNetHandler(), origin);
|
||||
|
|
|
@ -40,16 +40,28 @@ public abstract class FMLMessage {
|
|||
}
|
||||
public static class OpenGui extends FMLMessage {
|
||||
int windowId;
|
||||
int networkId;
|
||||
String modId;
|
||||
int modGuiId;
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
|
||||
public OpenGui() {}
|
||||
OpenGui(int windowId, String modId, int modGuiId, int x, int y, int z)
|
||||
{
|
||||
this.windowId = windowId;
|
||||
this.modId = modId;
|
||||
this.modGuiId = modGuiId;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
void toBytes(ByteBuf buf)
|
||||
{
|
||||
buf.writeInt(windowId);
|
||||
buf.writeInt(networkId);
|
||||
ByteBufUtils.writeUTF8String(buf, modId);
|
||||
buf.writeInt(modGuiId);
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
|
@ -60,7 +72,7 @@ public abstract class FMLMessage {
|
|||
void fromBytes(ByteBuf buf)
|
||||
{
|
||||
windowId = buf.readInt();
|
||||
networkId = buf.readInt();
|
||||
modId = ByteBufUtils.readUTF8String(buf);
|
||||
modGuiId = buf.readInt();
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Map.Entry;
|
|||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.server.management.ServerConfigurationManager;
|
||||
|
@ -32,6 +33,7 @@ import org.apache.logging.log4j.core.helpers.Integers;
|
|||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.FMLContainer;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
|
@ -53,389 +55,6 @@ public class FMLNetworkHandler
|
|||
public static final int LOGIN_TIMEOUT = Integers.parseInt(System.getProperty("fml.loginTimeout","600"),600);
|
||||
private static EnumMap<Side, FMLEmbeddedChannel> channelPair;
|
||||
|
||||
/* private static final int FML_HASH = Hashing.murmur3_32().hashString("FML").asInt();
|
||||
private static final int PROTOCOL_VERSION = 0x2;
|
||||
private static final FMLNetworkHandler INSTANCE = new FMLNetworkHandler();
|
||||
|
||||
// List of states for connections from clients to server
|
||||
static final int LOGIN_RECEIVED = 1;
|
||||
static final int CONNECTION_VALID = 2;
|
||||
static final int FML_OUT_OF_DATE = -1;
|
||||
static final int MISSING_MODS_OR_VERSIONS = -2;
|
||||
|
||||
private Map<NetLoginHandler, Integer> loginStates = Maps.newHashMap();
|
||||
private Map<ModContainer, NetworkModHandler> networkModHandlers = Maps.newHashMap();
|
||||
|
||||
private Map<Integer, NetworkModHandler> networkIdLookup = Maps.newHashMap();
|
||||
|
||||
public static void handlePacket250Packet(Packet250CustomPayload packet, INetworkManager network, NetHandler handler)
|
||||
{
|
||||
String target = packet.field_73630_a;
|
||||
|
||||
if (target.startsWith("MC|"))
|
||||
{
|
||||
handler.handleVanilla250Packet(packet);
|
||||
}
|
||||
if (target.equals("FML"))
|
||||
{
|
||||
instance().handleFMLPacket(packet, network, handler);
|
||||
}
|
||||
else
|
||||
{
|
||||
NetworkRegistry.instance().handleCustomPacket(packet, network, handler);
|
||||
}
|
||||
}
|
||||
|
||||
public static void onConnectionEstablishedToServer(NetHandler clientHandler, INetworkManager manager, Packet1Login login)
|
||||
{
|
||||
NetworkRegistry.instance().clientLoggedIn(clientHandler, manager, login);
|
||||
}
|
||||
|
||||
private void handleFMLPacket(Packet250CustomPayload packet, INetworkManager network, NetHandler netHandler)
|
||||
{
|
||||
FMLPacket pkt = FMLPacket.readPacket(network, packet.field_73629_c);
|
||||
// Part of an incomplete multipart packet
|
||||
if (pkt == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
String userName = "";
|
||||
if (netHandler instanceof NetLoginHandler)
|
||||
{
|
||||
userName = ((NetLoginHandler) netHandler).field_72543_h;
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityPlayer pl = netHandler.getPlayer();
|
||||
if (pl != null)
|
||||
{
|
||||
userName = pl.func_70005_c_();
|
||||
}
|
||||
}
|
||||
|
||||
pkt.execute(network, this, netHandler, userName);
|
||||
}
|
||||
|
||||
public static void onConnectionReceivedFromClient(NetLoginHandler netLoginHandler, MinecraftServer server, SocketAddress address, String userName)
|
||||
{
|
||||
instance().handleClientConnection(netLoginHandler, server, address, userName);
|
||||
}
|
||||
|
||||
private void handleClientConnection(NetLoginHandler netLoginHandler, MinecraftServer server, SocketAddress address, String userName)
|
||||
{
|
||||
if (!loginStates.containsKey(netLoginHandler))
|
||||
{
|
||||
if (handleVanillaLoginKick(netLoginHandler, server, address, userName))
|
||||
{
|
||||
// No FML on the client
|
||||
FMLLog.fine("Connection from %s rejected - no FML packet received from client", userName);
|
||||
netLoginHandler.completeConnection("You don't have FML installed, you cannot connect to this server");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Vanilla kicked us for some reason - bye now!
|
||||
FMLLog.fine("Connection from %s was closed by vanilla minecraft", userName);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
switch (loginStates.get(netLoginHandler))
|
||||
{
|
||||
case LOGIN_RECEIVED:
|
||||
// mods can try and kick undesireables here
|
||||
String modKick = NetworkRegistry.instance().connectionReceived(netLoginHandler, netLoginHandler.field_72538_b);
|
||||
if (modKick != null)
|
||||
{
|
||||
netLoginHandler.completeConnection(modKick);
|
||||
loginStates.remove(netLoginHandler);
|
||||
return;
|
||||
}
|
||||
// The vanilla side wanted to kick
|
||||
if (!handleVanillaLoginKick(netLoginHandler, server, address, userName))
|
||||
{
|
||||
loginStates.remove(netLoginHandler);
|
||||
return;
|
||||
}
|
||||
// Reset the "connection completed" flag so processing can continue
|
||||
NetLoginHandler.func_72531_a(netLoginHandler, false);
|
||||
// Send the mod list request packet to the client from the server
|
||||
netLoginHandler.field_72538_b.func_74429_a(getModListRequestPacket());
|
||||
loginStates.put(netLoginHandler, CONNECTION_VALID);
|
||||
break;
|
||||
case CONNECTION_VALID:
|
||||
netLoginHandler.completeConnection(null);
|
||||
loginStates.remove(netLoginHandler);
|
||||
break;
|
||||
case MISSING_MODS_OR_VERSIONS:
|
||||
netLoginHandler.completeConnection("The server requires mods that are absent or out of date on your client");
|
||||
loginStates.remove(netLoginHandler);
|
||||
break;
|
||||
case FML_OUT_OF_DATE:
|
||||
netLoginHandler.completeConnection("Your client is not running a new enough version of FML to connect to this server");
|
||||
loginStates.remove(netLoginHandler);
|
||||
break;
|
||||
default:
|
||||
netLoginHandler.completeConnection("There was a problem during FML negotiation");
|
||||
loginStates.remove(netLoginHandler);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
*//**
|
||||
* @param netLoginHandler
|
||||
* @param server
|
||||
* @param address
|
||||
* @param userName
|
||||
* @return if the user can carry on
|
||||
*//*
|
||||
private boolean handleVanillaLoginKick(NetLoginHandler netLoginHandler, MinecraftServer server, SocketAddress address, String userName)
|
||||
{
|
||||
// Vanilla reasons first
|
||||
ServerConfigurationManager playerList = server.func_71203_ab();
|
||||
String kickReason = playerList.func_72399_a(address, userName);
|
||||
|
||||
if (kickReason != null)
|
||||
{
|
||||
netLoginHandler.completeConnection(kickReason);
|
||||
}
|
||||
return kickReason == null;
|
||||
}
|
||||
|
||||
public static void handleLoginPacketOnServer(NetLoginHandler handler, Packet1Login login)
|
||||
{
|
||||
if (login.field_73561_a == FML_HASH)
|
||||
{
|
||||
if (login.field_73558_e == PROTOCOL_VERSION)
|
||||
{
|
||||
FMLLog.finest("Received valid FML login packet from %s", handler.field_72538_b.func_74430_c());
|
||||
instance().loginStates.put(handler, LOGIN_RECEIVED);
|
||||
}
|
||||
else if (login.field_73558_e != PROTOCOL_VERSION)
|
||||
{
|
||||
FMLLog.finest("Received incorrect FML (%x) login packet from %s", login.field_73558_e, handler.field_72538_b.func_74430_c());
|
||||
instance().loginStates.put(handler, FML_OUT_OF_DATE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FMLLog.fine("Received invalid login packet (%x, %x) from %s", login.field_73561_a, login.field_73558_e,
|
||||
handler.field_72538_b.func_74430_c());
|
||||
}
|
||||
}
|
||||
|
||||
static void setHandlerState(NetLoginHandler handler, int state)
|
||||
{
|
||||
instance().loginStates.put(handler, state);
|
||||
}
|
||||
|
||||
public static FMLNetworkHandler instance()
|
||||
{
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static Packet1Login getFMLFakeLoginPacket()
|
||||
{
|
||||
// Always reset compat to zero before sending our fake packet
|
||||
FMLCommonHandler.instance().getSidedDelegate().setClientCompatibilityLevel((byte) 0);
|
||||
Packet1Login fake = new Packet1Login();
|
||||
// Hash FML using a simple function
|
||||
fake.field_73561_a = FML_HASH;
|
||||
// The FML protocol version
|
||||
fake.field_73558_e = PROTOCOL_VERSION;
|
||||
fake.field_73557_d = EnumGameType.NOT_SET;
|
||||
fake.field_73559_b = WorldType.field_77139_a[0];
|
||||
return fake;
|
||||
}
|
||||
|
||||
public Packet250CustomPayload getModListRequestPacket()
|
||||
{
|
||||
return PacketDispatcher.getPacket("FML", FMLPacket.makePacket(MOD_LIST_REQUEST));
|
||||
}
|
||||
|
||||
public void registerNetworkMod(NetworkModHandler handler)
|
||||
{
|
||||
networkModHandlers.put(handler.getContainer(), handler);
|
||||
networkIdLookup.put(handler.getNetworkId(), handler);
|
||||
}
|
||||
public boolean registerNetworkMod(ModContainer container, Class<?> networkModClass, ASMDataTable asmData)
|
||||
{
|
||||
NetworkModHandler handler = new NetworkModHandler(container, networkModClass, asmData);
|
||||
if (handler.isNetworkMod())
|
||||
{
|
||||
registerNetworkMod(handler);
|
||||
}
|
||||
|
||||
return handler.isNetworkMod();
|
||||
}
|
||||
|
||||
public NetworkModHandler findNetworkModHandler(Object mc)
|
||||
{
|
||||
if (mc instanceof InjectedModContainer)
|
||||
{
|
||||
return networkModHandlers.get(((InjectedModContainer)mc).wrappedContainer);
|
||||
}
|
||||
if (mc instanceof ModContainer)
|
||||
{
|
||||
return networkModHandlers.get(mc);
|
||||
}
|
||||
else if (mc instanceof Integer)
|
||||
{
|
||||
return networkIdLookup.get(mc);
|
||||
}
|
||||
else
|
||||
{
|
||||
return networkModHandlers.get(FMLCommonHandler.instance().findContainerFor(mc));
|
||||
}
|
||||
}
|
||||
|
||||
public Set<ModContainer> getNetworkModList()
|
||||
{
|
||||
return networkModHandlers.keySet();
|
||||
}
|
||||
|
||||
public static void handlePlayerLogin(EntityPlayerMP player, NetServerHandler netHandler, INetworkManager manager)
|
||||
{
|
||||
NetworkRegistry.instance().playerLoggedIn(player, netHandler, manager);
|
||||
GameRegistry.onPlayerLogin(player);
|
||||
}
|
||||
|
||||
public Map<Integer, NetworkModHandler> getNetworkIdMap()
|
||||
{
|
||||
return networkIdLookup;
|
||||
}
|
||||
|
||||
public void bindNetworkId(String key, Integer value)
|
||||
{
|
||||
Map<String, ModContainer> mods = Loader.instance().getIndexedModList();
|
||||
NetworkModHandler handler = findNetworkModHandler(mods.get(key));
|
||||
if (handler != null)
|
||||
{
|
||||
handler.setNetworkId(value);
|
||||
networkIdLookup.put(value, handler);
|
||||
}
|
||||
}
|
||||
|
||||
public static void onClientConnectionToRemoteServer(NetHandler netClientHandler, String server, int port, INetworkManager networkManager)
|
||||
{
|
||||
NetworkRegistry.instance().connectionOpened(netClientHandler, server, port, networkManager);
|
||||
}
|
||||
|
||||
public static void onClientConnectionToIntegratedServer(NetHandler netClientHandler, MinecraftServer server, INetworkManager networkManager)
|
||||
{
|
||||
NetworkRegistry.instance().connectionOpened(netClientHandler, server, networkManager);
|
||||
}
|
||||
|
||||
public static void onConnectionClosed(INetworkManager manager, EntityPlayer player)
|
||||
{
|
||||
NetworkRegistry.instance().connectionClosed(manager, player);
|
||||
}
|
||||
|
||||
|
||||
public static void openGui(EntityPlayer player, Object mod, int modGuiId, World world, int x, int y, int z)
|
||||
{
|
||||
ModContainer mc = FMLCommonHandler.instance().findContainerFor(mod);
|
||||
if (mc == null)
|
||||
{
|
||||
NetworkModHandler nmh = instance().findNetworkModHandler(mod);
|
||||
if (nmh != null)
|
||||
{
|
||||
mc = nmh.getContainer();
|
||||
}
|
||||
else
|
||||
{
|
||||
FMLLog.warning("A mod tried to open a gui on the server without being a NetworkMod");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (player instanceof EntityPlayerMP)
|
||||
{
|
||||
NetworkRegistry.instance().openRemoteGui(mc, (EntityPlayerMP) player, modGuiId, world, x, y, z);
|
||||
}
|
||||
else if (FMLCommonHandler.instance().getSide().equals(Side.CLIENT))
|
||||
{
|
||||
NetworkRegistry.instance().openLocalGui(mc, player, modGuiId, world, x, y, z);
|
||||
}
|
||||
else
|
||||
{
|
||||
FMLLog.fine("Invalid attempt to open a local GUI on a dedicated server. This is likely a bug. GUIID: %s,%d", mc.getModId(), modGuiId);
|
||||
}
|
||||
}
|
||||
|
||||
public static Packet getEntitySpawningPacket(Entity entity)
|
||||
{
|
||||
EntityRegistration er = EntityRegistry.instance().lookupModSpawn(entity.getClass(), false);
|
||||
if (er == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (er.usesVanillaSpawning())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return PacketDispatcher.getPacket("FML", FMLPacket.makePacket(Type.ENTITYSPAWN, er, entity, instance().findNetworkModHandler(er.getContainer())));
|
||||
}
|
||||
|
||||
public static void makeEntitySpawnAdjustment(int entityId, EntityPlayerMP player, int serverX, int serverY, int serverZ)
|
||||
{
|
||||
Packet250CustomPayload pkt = PacketDispatcher.getPacket("FML", FMLPacket.makePacket(Type.ENTITYSPAWNADJUSTMENT, entityId, serverX, serverY, serverZ));
|
||||
player.field_71135_a.func_72567_b(pkt);
|
||||
}
|
||||
|
||||
public static InetAddress computeLocalHost() throws IOException
|
||||
{
|
||||
InetAddress add = null;
|
||||
List<InetAddress> addresses = Lists.newArrayList();
|
||||
InetAddress localHost = InetAddress.getLocalHost();
|
||||
for (NetworkInterface ni : Collections.list(NetworkInterface.getNetworkInterfaces()))
|
||||
{
|
||||
if (!ni.isLoopback() && ni.isUp())
|
||||
{
|
||||
addresses.addAll(Collections.list(ni.getInetAddresses()));
|
||||
if (addresses.contains(localHost))
|
||||
{
|
||||
add = localHost;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (add == null && !addresses.isEmpty())
|
||||
{
|
||||
for (InetAddress addr: addresses)
|
||||
{
|
||||
if (addr.getAddress().length == 4)
|
||||
{
|
||||
add = addr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (add == null)
|
||||
{
|
||||
add = localHost;
|
||||
}
|
||||
return add;
|
||||
}
|
||||
|
||||
public static Packet3Chat handleChatMessage(NetHandler handler, Packet3Chat chat)
|
||||
{
|
||||
return NetworkRegistry.instance().handleChat(handler, chat);
|
||||
}
|
||||
|
||||
public static void handlePacket131Packet(NetHandler handler, Packet131MapData mapData)
|
||||
{
|
||||
if (handler instanceof NetServerHandler || mapData.field_73438_a != Item.field_77744_bd.field_77779_bT)
|
||||
{
|
||||
// Server side and not "map" packets are always handled by us
|
||||
NetworkRegistry.instance().handleTinyPacket(handler, mapData);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback to the net client handler implementation
|
||||
FMLCommonHandler.instance().handleTinyPacket(handler, mapData);
|
||||
}
|
||||
}
|
||||
*/
|
||||
public static void fmlServerHandshake(ServerConfigurationManager scm, NetworkManager manager, EntityPlayerMP player)
|
||||
{
|
||||
NetworkDispatcher dispatcher = NetworkDispatcher.allocAndSet(manager, scm);
|
||||
|
@ -450,6 +69,34 @@ public class FMLNetworkHandler
|
|||
|
||||
public static void openGui(EntityPlayer entityPlayer, Object mod, int modGuiId, World world, int x, int y, int z)
|
||||
{
|
||||
ModContainer mc = FMLCommonHandler.instance().findContainerFor(mod);
|
||||
if (entityPlayer instanceof EntityPlayerMP)
|
||||
{
|
||||
EntityPlayerMP entityPlayerMP = (EntityPlayerMP) entityPlayer;
|
||||
Container remoteGuiContainer = NetworkRegistry.INSTANCE.getRemoteGuiContainer(mc, entityPlayerMP, modGuiId, world, x, y, z);
|
||||
if (remoteGuiContainer != null)
|
||||
{
|
||||
entityPlayerMP.func_71117_bO();
|
||||
entityPlayerMP.func_71128_l();
|
||||
int windowId = entityPlayerMP.field_71139_cq;
|
||||
new FMLMessage.OpenGui(windowId, mc.getModId(), modGuiId, x, y, z);
|
||||
EmbeddedChannel embeddedChannel = channelPair.get(Side.SERVER);
|
||||
embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.PLAYER);
|
||||
embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(entityPlayerMP);
|
||||
entityPlayerMP.field_71070_bA = remoteGuiContainer;
|
||||
entityPlayerMP.field_71070_bA.field_75152_c = windowId;
|
||||
entityPlayerMP.field_71070_bA.func_75132_a(entityPlayerMP);
|
||||
}
|
||||
}
|
||||
else if (FMLCommonHandler.instance().getSide().equals(Side.CLIENT))
|
||||
{
|
||||
Object guiContainer = NetworkRegistry.INSTANCE.getLocalGuiContainer(mc, entityPlayer, modGuiId, world, x, y, z);
|
||||
FMLCommonHandler.instance().showGuiScreen(guiContainer);
|
||||
}
|
||||
else
|
||||
{
|
||||
FMLLog.fine("Invalid attempt to open a local GUI on a dedicated server. This is likely a bug. GUIID: %s,%d", mc.getModId(), modGuiId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ public class OpenGuiHandler extends SimpleChannelInboundHandler<FMLMessage.OpenG
|
|||
protected void channelRead0(ChannelHandlerContext ctx, OpenGui msg) throws Exception
|
||||
{
|
||||
EntityPlayer player = FMLClientHandler.instance().getClient().field_71439_g;
|
||||
player.openGui(msg.networkId, msg.modGuiId, player.field_70170_p, msg.x, msg.y, msg.z);
|
||||
player.openGui(msg.modId, msg.modGuiId, player.field_70170_p, msg.x, msg.y, msg.z);
|
||||
player.field_71070_bA.field_75152_c = msg.windowId;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue