Setup .gitignore for eclipse bin dirs.

Fixed line endings in install.sh
Added mod_MinecraftForge for simpler logging of minecraft version in crash reports
Added new hooks for connection events, See IConnectionHandler for more details.
Added Packet250CustomPayload handeling and channel registraction management, see MessageManager and IPacketHandler for more details.
Forge now uses unsed fields in C->S Packet1Login to identify itself. None Forge clients will get a graceful disconnect message instead of the 'Unknown packet 230'
This commit is contained in:
LexManos 2012-02-07 03:16:57 -08:00
parent 9265b690ab
commit ebdc9b9464
13 changed files with 867 additions and 12 deletions

1
forge/forge_client/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/bin/

View File

@ -14,6 +14,8 @@ import net.minecraft.src.ItemStack;
import net.minecraft.src.Item;
import net.minecraft.src.EnumStatus;
import net.minecraft.src.ModLoader;
import net.minecraft.src.NetworkManager;
import net.minecraft.src.Packet1Login;
import net.minecraft.src.World;
import java.util.*;
@ -103,6 +105,31 @@ public class ForgeHooks {
}
static LinkedList<IMinecartHandler> minecartHandlers = new LinkedList<IMinecartHandler>();
public static void onConnect(NetworkManager network)
{
for (IConnectionHandler handler : connectionHandlers)
{
handler.OnConnect(network);
}
}
public static void onLogin(NetworkManager network, Packet1Login login)
{
for (IConnectionHandler handler : connectionHandlers)
{
handler.OnLogin(network, login);
}
}
public static void onDisconnect(NetworkManager network, String message, Object[] args)
{
for (IConnectionHandler handler : connectionHandlers)
{
handler.OnDisconnect(network, message, args);
}
}
static LinkedList<IConnectionHandler> connectionHandlers = new LinkedList<IConnectionHandler>();
// Plant Management
// ------------------------------------------------------------

View File

@ -0,0 +1,36 @@
package net.minecraft.src.forge;
import net.minecraft.src.NetworkManager;
import net.minecraft.src.Packet1Login;
public interface IConnectionHandler
{
/**
* Raised when a Client successfully connects it's socket to the Server.
* @param network The new NetworkManager associated with this connection.
*/
public void OnConnect(NetworkManager network);
/**
* Raised when you receive a Packet1Login.
* On the server, it is raised after the NetHandler is switched, and the
* initial user placement/info packets are sent.
*
* On the client, this is raised after the packet is parsed, and the user
* is sitting at the 'Downloading Terrain' screen.
*
* @param network The NetoworkManager associated with this connection.
* @param login The login packet
*/
public void OnLogin(NetworkManager network, Packet1Login login);
/**
* Raised whenever the socket is closed, can be caused by various reasons.
*
* @param network The NetworkManager associated with this connection.
* @param message The translated message to be displayed for this disconnection.
* @param args Any additional arguments that the code may of provided.
* Sometimes this is further explanation, or a Throwable, in the case of errors.
*/
public void OnDisconnect(NetworkManager network, String message, Object[] args);
}

View File

@ -0,0 +1,16 @@
package net.minecraft.src.forge;
import net.minecraft.src.NetworkManager;
public interface IPacketHandler
{
/**
* Called when we receive a Packet250CustomPayload for a channel that this
* handler is registered to.
*
* @param network The NetworkManager for the current connection.
* @param channel The Channel the message came on.
* @param data The message payload.
*/
public void onPacketData(NetworkManager network, String channel, byte[] data);
}

View File

@ -0,0 +1,433 @@
package net.minecraft.src.forge;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Map.Entry;
import net.minecraft.src.NetworkManager;
public class MessageManager
{
private Hashtable<NetworkManager, ConnectionInstance> connections = new Hashtable<NetworkManager, ConnectionInstance>();
private static MessageManager instance;
public static MessageManager getInstance()
{
if (instance == null)
{
instance = new MessageManager();
}
return instance;
}
public class ConnectionInstance
{
private NetworkManager network;
private Hashtable<String, ArrayList<IPacketHandler>> channelToHandlers = new Hashtable<String, ArrayList<IPacketHandler>>();
private Hashtable<IPacketHandler, ArrayList<String>> handlerToChannels = new Hashtable<IPacketHandler, ArrayList<String>>();
private HashSet<String> activeChannels = new HashSet<String>();
public ConnectionInstance(NetworkManager mgr)
{
network = mgr;
}
/**
* Retrieves the associated NetworkManager
* @return The associated NetworkManager;
*/
public NetworkManager getNetwork()
{
return network;
}
/**
* Removes all channels and handlers from the registration.
*
* @return An array of channels that were in the registration
* If the connection is still active, you should send UNREGISTER messages for these.
*/
public String[] unregisterAll()
{
String[] ret = getRegisteredChannels();
channelToHandlers.clear();
handlerToChannels.clear();
return ret;
}
/**
* Registers a channel to a specific handler.
*
* @param handler The handler to register
* @param channel The channel to register on
* @return True if the channel was not previously registered to any handlers.
* If True, the connection is still active, and this is not the OnLogin event,
* you should send a REGISTER command for this channel.
*/
public boolean registerChannel(IPacketHandler handler, String channel)
{
ArrayList<IPacketHandler> handlers = channelToHandlers.get(channel);
ArrayList<String> channels = handlerToChannels.get(handler);
if (handlers == null)
{
handlers = new ArrayList<IPacketHandler>();
channelToHandlers.put(channel, handlers);
}
if (channels == null)
{
channels = new ArrayList<String>();
handlerToChannels.put(handler, channels);
}
boolean ret = false;
if (!channels.contains(channel))
{
channels.add(channel);
ret = true;
}
if (!handlers.contains(handler))
{
handlers.add(handler);
ret = true;
}
return ret;
}
/**
* Unregisters a channel from the specified handler.
*
* @param handler The handler to remove the channel from.
* @param channel The channel to remove from the handler registration.
* @return True if this was the last handler registered with the specified channel.
* If this is the case, and the network connection is still alive, you should send
* a UNREGISTER message for this channel.
*/
public boolean unregisterChannel(IPacketHandler handler, String channel)
{
boolean ret = false;
ArrayList<IPacketHandler> handlers = channelToHandlers.get(channel);
ArrayList<String> channels = handlerToChannels.get(handler);
if (handlers != null && handlers.contains(handler))
{
ret = true;
handlers.remove(handler);
if (handlers.size() == 0)
{
channelToHandlers.remove(channel);
}
}
if (channels != null && channels.contains(channel))
{
ret = true;
channels.remove(channel);
if (handlers.size() == 0)
{
handlerToChannels.remove(handler);
}
}
return ret;
}
/**
* Unregisters a handler from all of it's associated channels.
*
* @param handler The handler to unregister
* @return A list of channels that now have no handlers.
* If the connection is still active, you should send a UNREGISTER
* message for each channel in this list.
*/
public String[] unregisterHandler(IPacketHandler handler)
{
ArrayList<String> tmp = handlerToChannels.get(handler);
if (tmp != null)
{
String[] channels = tmp.toArray(new String[0]);
tmp = new ArrayList<String>();
for (String channel : channels)
{
if (unregisterChannel(handler, channel))
{
tmp.add(channel);
}
}
return tmp.toArray(new String[0]);
}
return new String[0];
}
/**
* Retrieves a list of all unique channels that currently have valid handlers.
*
* @return The channel list
*/
public String[] getRegisteredChannels()
{
int x = 0;
String[] ret = new String[channelToHandlers.size()];
for (String value : channelToHandlers.keySet())
{
ret[x++] = value;
}
return ret;
}
/**
* Retrieves a list of all handlers currently registered to the specified channel.
*
* @param channel The channel to get the handlers for.
* @return A array containing all handlers for this channel.
*/
public IPacketHandler[] getChannelHandlers(String channel)
{
ArrayList<IPacketHandler> handlers = channelToHandlers.get(channel);
if (handlers != null)
{
return handlers.toArray(new IPacketHandler[0]);
}
return new IPacketHandler[0];
}
/**
* Adds a channel to the active set.
* This is a set that the other end of the connection has registered a channel.
*
* @param channel The channel name
*/
public void addActiveChannel(String channel)
{
if (!activeChannels.contains(channel))
{
activeChannels.add(channel);
}
}
/**
* Removes a channel from the active set.
* This should be done with the other end of the connection unregisters a channel.
*
* @param channel
*/
public void removeActiveChannel(String channel)
{
if (activeChannels.contains(channel))
{
activeChannels.remove(channel);
}
}
/**
* Checks if the specified channel is registered as active by the other end of the connection.
*
* @param channel The channel to check
* @return True if it's active, false otherwise.
*/
public boolean isActiveChannel(String channel)
{
return activeChannels.contains(channel);
}
}
/**
* Retrieves, or creates a ConnectionInstance associated with the specific NetworkManager.
*
* @param manager The NetworkManager to look for.
* @return A ConnectionInstance channel manager for this NetworkManager
*/
public ConnectionInstance getConnection(NetworkManager manager)
{
ConnectionInstance ret = connections.get(manager);
if (ret == null)
{
ret = new ConnectionInstance(manager);
connections.put(manager, ret);
}
return ret;
}
/**
* Removes the associated channel manager, and unregisters all channels/handlers from it.
*
* @param manager The NetworkManager to look for.
* @return An array of all channels that were still registered to this NetowrkManager.
* If the connection is still active, you should send a UNREGISTER request for
* all of these channels.
*/
public String[] removeConnection(NetworkManager manager)
{
if (connections.containsKey(manager))
{
ConnectionInstance con = getConnection(manager);
String[] ret = con.unregisterAll();
connections.remove(manager);
return ret;
}
return new String[0];
}
/**
* Registers a channel to a specific handler.
*
* @param manager The manager to register to
* @param handler The handler to register
* @param channel The channel to register on
* @return True if the channel was not previously registered to any handlers.
* If True, the connection is still active, and this is not the OnLogin event,
* you should send a REGISTER command for this channel.
*/
public boolean registerChannel(NetworkManager manager, IPacketHandler handler, String channel)
{
ConnectionInstance con = getConnection(manager);
return con.registerChannel(handler, channel);
}
/**
* Unregisters a channel from the specified handler.
*
* @param manager The manager to register to
* @param handler The handler to remove the channel from.
* @param channel The channel to remove from the handler registration.
* @return True if this was the last handler registered with the specified channel.
* If this is the case, and the network connection is still alive, you should send
* a UNREGISTER message for this channel.
*/
public boolean unregisterChannel(NetworkManager manager, IPacketHandler handler, String channel)
{
if (connections.containsKey(manager))
{
ConnectionInstance con = getConnection(manager);
return con.unregisterChannel(handler, channel);
}
return false;
}
/**
* Unregisters a handler from all of it's associated channels.
*
* @param manager The manager to register to
* @param handler The handler to unregister
* @return A list of channels that now have no handlers.
* If the connection is still active, you should send a UNREGISTER
* message for each channel in this list.
*/
public String[] unregisterHandler(NetworkManager manager, IPacketHandler handler)
{
if (connections.containsKey(manager))
{
ConnectionInstance con = getConnection(manager);
return con.unregisterHandler(handler);
}
return new String[0];
}
/**
* Retrieves a list of all unique channels that currently have valid handlers.
*
* @param manager The NetworkManager to look for.
* @return The channel list
*/
public String[] getRegisteredChannels(NetworkManager manager)
{
if (connections.containsKey(manager))
{
ConnectionInstance con = getConnection(manager);
return con.getRegisteredChannels();
}
return new String[0];
}
/**
* Retrieves a list of all handlers currently registered to the specified channel.
*
* @param manager The NetworkManager to look for.
* @param channel The channel to get the handlers for.
* @return A array containing all handlers for this channel.
*/
public IPacketHandler[] getChannelHandlers(NetworkManager manager, String channel)
{
if (connections.containsKey(manager))
{
ConnectionInstance con = getConnection(manager);
return con.getChannelHandlers(channel);
}
return new IPacketHandler[0];
}
/**
* Adds a channel to the active set.
* This is a set that the other end of the connection has registered a channel.
*
* @param manager The NetworkManager to look for.
* @param channel The channel name
*/
public void addActiveChannel(NetworkManager manager, String channel)
{
ConnectionInstance con = getConnection(manager);
con.addActiveChannel(channel);
}
/**
* Removes a channel from the active set.
* This should be done with the other end of the connection unregisters a channel.
*
* @param manager The NetworkManager to look for.
* @param channel
*/
public void removeActiveChannel(NetworkManager manager, String channel)
{
if (connections.containsKey(manager))
{
ConnectionInstance con = getConnection(manager);
con.removeActiveChannel(channel);
}
}
/**
* Checks if the specified channel is registered as active by the other end of the connection.
*
* @param manager The NetworkManager to look for.
* @param channel The channel to check
* @return True if it's active, false otherwise.
*/
public boolean isActiveChannel(NetworkManager manager, String channel)
{
if (connections.containsKey(manager))
{
ConnectionInstance con = getConnection(manager);
return con.isActiveChannel(channel);
}
return false;
}
public void dispatchIncomingMessage(NetworkManager manager, String channel, byte[] data)
{
if (channel.equals("Forge"))
{
/* Currently Forge has no custom tasks, but will eventually have
* Mod list testing, and whatever, when we remove ModLoaderMP
*
byte[] tmpData = new byte[data.length];
System.arraycopy(data, 0, tmpData, 0, data.length);
*/
}
if (connections.contains(manager))
{
ConnectionInstance con = getConnection(manager);
IPacketHandler[] handlers = con.getChannelHandlers(channel);
byte[] tmpData = new byte[data.length];
for (IPacketHandler handler : handlers)
{
System.arraycopy(data, 0, tmpData, 0, data.length);
handler.onPacketData(manager, channel, tmpData);
}
}
}
}

View File

@ -16,45 +16,58 @@ import java.util.*;
public class MinecraftForge {
private static LinkedList<IBucketHandler> bucketHandlers = new LinkedList<IBucketHandler>();
/**
* Register a new custom bucket handler.
* @param handler The Handler to be registered
*/
public static void registerCustomBucketHandler(IBucketHandler handler) {
public static void registerCustomBucketHandler(IBucketHandler handler)
{
bucketHandlers.add(handler);
}
/**
* Registers a new sleeping handler.
* @param handler The Handler to be registered
*/
public static void registerSleepHandler(ISleepHandler handler) {
ForgeHooks.sleepHandlers.add(handler);
public static void registerSleepHandler(ISleepHandler handler)
{
ForgeHooks.sleepHandlers.add(handler);
}
/**
* Registers a new bonemeal handler.
* @param handler The Handler to be registered
*/
public static void registerBonemealHandler(IBonemealHandler handler) {
ForgeHooks.bonemealHandlers.add(handler);
public static void registerBonemealHandler(IBonemealHandler handler)
{
ForgeHooks.bonemealHandlers.add(handler);
}
/**
* Registers a new hoe handler.
* @param handler The Handler to be registered
*/
public static void registerHoeHandler(IHoeHandler handler) {
ForgeHooks.hoeHandlers.add(handler);
public static void registerHoeHandler(IHoeHandler handler)
{
ForgeHooks.hoeHandlers.add(handler);
}
/**
* Registers a new destroy tool handler.
* @param handler The Handler to be registered
*/
public static void registerDestroyToolHandler(IDestroyToolHandler handler) {
ForgeHooks.destroyToolHandlers.add(handler);
public static void registerDestroyToolHandler(IDestroyToolHandler handler)
{
ForgeHooks.destroyToolHandlers.add(handler);
}
/**
* Registers a new crafting handler.
* @param handler The Handler to be registered
*/
public static void registerCraftingHandler(ICraftingHandler handler) {
public static void registerCraftingHandler(ICraftingHandler handler)
{
ForgeHooks.craftingHandlers.add(handler);
}
@ -66,6 +79,15 @@ public class MinecraftForge {
{
ForgeHooks.minecartHandlers.add(handler);
}
/**
* Registers a new Connection event handler
* @param handler The Handler to be registered
*/
public static void registerConnectionHandler(IConnectionHandler handler)
{
ForgeHooks.connectionHandlers.add(handler);
}
/**
* This is not supposed to be called outside of Minecraft internals.

View File

@ -0,0 +1,24 @@
package net.minecraft.src;
import net.minecraft.src.forge.ForgeHooks;
import net.minecraft.src.forge.MinecraftForge;
/**
* This class is just here to make the Forge version show up nicely in the ModLoader logs/Crash Screen
*/
public class mod_MinecraftForge extends BaseModMp
{
@Override
public String getVersion()
{
return String.format("%d.%d.%d.%d",
ForgeHooks.majorVersion, ForgeHooks.minorVersion,
ForgeHooks.revisionVersion, ForgeHooks.buildVersion);
}
@Override
public void load()
{
MinecraftForge.getDungeonLootTries(); //Random thing to make things Initialize
}
}

1
forge/forge_server/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/bin/

View File

@ -0,0 +1,135 @@
--- ../src_base/minecraft/net/minecraft/src/NetClientHandler.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft/net/minecraft/src/NetClientHandler.java 0000-00-00 00:00:00.000000000 -0000
@@ -7,6 +7,8 @@
import java.util.*;
import java.util.logging.Logger;
import net.minecraft.client.Minecraft;
+import net.minecraft.src.forge.ForgeHooks;
+import net.minecraft.src.forge.MessageManager;
public class NetClientHandler extends NetHandler
{
@@ -35,6 +37,8 @@
mc = minecraft;
Socket socket = new Socket(InetAddress.getByName(s), i);
netManager = new NetworkManager(socket, "Client", this);
+
+ ForgeHooks.onConnect(netManager);
}
public void processReadPackets()
@@ -58,6 +62,27 @@
mc.thePlayer.entityId = packet1login.protocolVersion;
currentServerMaxPlayers = packet1login.maxPlayers;
((PlayerControllerMP)mc.playerController).setCreative(packet1login.serverMode == 1);
+
+ ForgeHooks.onLogin(netManager, packet1login);
+
+ 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;
+ addToSendQueue(pkt);
+
}
public void handlePickupSpawn(Packet21PickupSpawn packet21pickupspawn)
@@ -608,7 +633,19 @@
}
else if (packet2handshake.username.equals("-"))
{
- addToSendQueue(new Packet1Login(mc.session.username, 23));
+ /**
+ * We use some of the unused fields in Packet 001 Login to identify the user as having Forge installed.
+ * This allows modded clients to connect to Vinella server without crashing.
+ * It also allows unmodded clients to connect to Forge server without crashing.
+ * Its a bit of a dirty hack, but it doesnt interrupt the login flow, and its unused data.
+ * The C->S serverMode is set to the hash code of the string "Forge", this should provide a fairly unique
+ * identifier so we are certain it is not random, and it is Forge installed.
+ * The C->S mapSeed is set to the current Forge build number, in case we need to do any quick version checks.
+ */
+ Packet1Login pkt = new Packet1Login(mc.session.username, 23);
+ pkt.serverMode = 0x040E9B47; //"Forge".hashCode();
+ pkt.mapSeed = ForgeHooks.buildVersion;
+ addToSendQueue(pkt);
}
else
{
@@ -620,7 +657,19 @@
bufferedreader.close();
if (s1.equalsIgnoreCase("ok"))
{
- addToSendQueue(new Packet1Login(mc.session.username, 23));
+ /**
+ * We use some of the unused fields in Packet 001 Login to identify the user as having Forge installed.
+ * This allows modded clients to connect to Vinella server without crashing.
+ * It also allows unmodded clients to connect to Forge server without crashing.
+ * Its a bit of a dirty hack, but it doesnt interrupt the login flow, and its unused data.
+ * The C->S serverMode is set to the hash code of the string "Forge", this should provide a fairly unique
+ * identifier so we are certain it is not random, and it is Forge installed.
+ * The C->S mapSeed is set to the current Forge build number, in case we need to do any quick version checks.
+ */
+ Packet1Login pkt = new Packet1Login(mc.session.username, 23);
+ pkt.serverMode = 0x040E9B47; //"Forge".hashCode();
+ pkt.mapSeed = ForgeHooks.buildVersion;
+ addToSendQueue(pkt);
}
else
{
@@ -1017,4 +1066,44 @@
{
addToSendQueue(new Packet0KeepAlive(packet0keepalive.randomId));
}
+
+ @Override
+ public void handleCustomPayload(Packet250CustomPayload pkt)
+ {
+ MessageManager inst = MessageManager.getInstance();
+ if (pkt.channel.equals("REGISTER"))
+ {
+ try
+ {
+ String channels = new String(pkt.data, "UTF8");
+ for (String channel : channels.split("\0"))
+ {
+ inst.addActiveChannel(netManager, channel);
+ }
+ }
+ catch (UnsupportedEncodingException ex)
+ {
+ ModLoader.ThrowException("NetClientHandler.handleCustomPayload", ex);
+ }
+ }
+ else if (pkt.channel.equals("UNREGISTER"))
+ {
+ try
+ {
+ String channels = new String(pkt.data, "UTF8");
+ for (String channel : channels.split("\0"))
+ {
+ inst.removeActiveChannel(netManager, channel);
+ }
+ }
+ catch (UnsupportedEncodingException ex)
+ {
+ ModLoader.ThrowException("NetClientHandler.handleCustomPayload", ex);
+ }
+ }
+ else
+ {
+ inst.dispatchIncomingMessage(netManager, pkt.channel, pkt.data);
+ }
+ }
}

View File

@ -0,0 +1,19 @@
--- ../src_base/minecraft/net/minecraft/src/NetworkManager.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft/net/minecraft/src/NetworkManager.java 0000-00-00 00:00:00.000000000 -0000
@@ -4,6 +4,8 @@
import java.net.*;
import java.util.*;
+import net.minecraft.src.forge.ForgeHooks;
+
public class NetworkManager
{
public static final Object threadSyncObject = new Object();
@@ -201,6 +203,7 @@
networkSocket = null;
}
catch (Throwable throwable2) { }
+ ForgeHooks.onDisconnect(this, s, aobj);
}
public void processReadPackets()

View File

@ -0,0 +1,63 @@
--- ../src_base/minecraft_server/net/minecraft/src/NetLoginHandler.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft_server/net/minecraft/src/NetLoginHandler.java 0000-00-00 00:00:00.000000000 -0000
@@ -1,10 +1,13 @@
package net.minecraft.src;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.net.Socket;
import java.util.*;
import java.util.logging.Logger;
import net.minecraft.server.MinecraftServer;
+import net.minecraft.src.forge.ForgeHooks;
+import net.minecraft.src.forge.MessageManager;
public class NetLoginHandler extends NetHandler
{
@@ -29,6 +32,7 @@
mcServer = minecraftserver;
netManager = new NetworkManager(socket, s, this);
netManager.chunkDataSendCounter = 0;
+ ForgeHooks.onConnect(netManager);
}
public void tryLogin()
@@ -129,7 +133,37 @@
}
entityplayermp.func_20057_k();
- ModLoaderMp.HandleAllLogins(entityplayermp);
+
+ if (packet1login.serverMode == 0x040E9B47) //"Forge".hashCode();
+ {
+ //pkt.mapSeed = ForgeHooks.buildVersion;
+ ForgeHooks.onLogin(netManager, packet1login);
+
+ 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;
+ netserverhandler.sendPacket(pkt);
+
+ ModLoaderMp.HandleAllLogins(entityplayermp);
+ }
+ else
+ {
+ netserverhandler.kickPlayer("This server requires you to have Minecraft Forge installed.");
+ }
+
}
finishedProcessing = true;
}

View File

@ -1,6 +1,18 @@
--- ../src_base/minecraft_server/net/minecraft/src/NetServerHandler.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft_server/net/minecraft/src/NetServerHandler.java 0000-00-00 00:00:00.000000000 -0000
@@ -295,7 +295,9 @@
@@ -1,9 +1,11 @@
package net.minecraft.src;
import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
import java.util.*;
import java.util.logging.Logger;
import net.minecraft.server.MinecraftServer;
+import net.minecraft.src.forge.MessageManager;
public class NetServerHandler extends NetHandler
implements ICommandListener
@@ -295,7 +297,9 @@
double d1 = (playerEntity.posY - ((double)j + 0.5D)) + 1.5D;
double d3 = playerEntity.posZ - ((double)k + 0.5D);
double d5 = d * d + d1 * d1 + d3 * d3;
@ -11,7 +23,7 @@
{
return;
}
@@ -366,7 +368,9 @@
@@ -366,7 +370,9 @@
{
j1 = i1;
}
@ -22,3 +34,48 @@
{
playerEntity.itemInWorldManager.activeBlockOrUseItem(playerEntity, worldserver, itemstack, i, j, k, l);
}
@@ -764,4 +770,44 @@
{
return true;
}
+
+ @Override
+ public void handleCustomPayload(Packet250CustomPayload pkt)
+ {
+ MessageManager inst = MessageManager.getInstance();
+ if (pkt.channel.equals("REGISTER"))
+ {
+ try
+ {
+ String channels = new String(pkt.data, "UTF8");
+ for (String channel : channels.split("\0"))
+ {
+ inst.addActiveChannel(netManager, channel);
+ }
+ }
+ catch (UnsupportedEncodingException ex)
+ {
+ ModLoader.ThrowException("NetServerHandler.handleCustomPayload", ex);
+ }
+ }
+ else if (pkt.channel.equals("UNREGISTER"))
+ {
+ try
+ {
+ String channels = new String(pkt.data, "UTF8");
+ for (String channel : channels.split("\0"))
+ {
+ inst.removeActiveChannel(netManager, channel);
+ }
+ }
+ catch (UnsupportedEncodingException ex)
+ {
+ ModLoader.ThrowException("NetServerHandler.handleCustomPayload", ex);
+ }
+ }
+ else
+ {
+ inst.dispatchIncomingMessage(netManager, pkt.channel, pkt.data);
+ }
+ }
}

View File

@ -0,0 +1,21 @@
--- ../src_base/minecraft_server/net/minecraft/src/NetworkManager.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft_server/net/minecraft/src/NetworkManager.java 0000-00-00 00:00:00.000000000 -0000
@@ -4,6 +4,9 @@
import java.net.*;
import java.util.*;
+import net.minecraft.src.forge.ForgeHooks;
+import net.minecraft.src.forge.MessageManager;
+
public class NetworkManager
{
public static final Object threadSyncObject = new Object();
@@ -206,6 +209,8 @@
networkSocket = null;
}
catch (Throwable throwable2) { }
+ ForgeHooks.onDisconnect(this, s, aobj);
+ MessageManager.getInstance().removeConnection(this);
}
public void processReadPackets()