mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 16:27:47 +00:00
Add a modfolderfactory. Fix up login payload exposure.
Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
5 files changed
+33
-14
No files matched your search
@@ -38,15 +38,11 @@ import org.apache.logging.log4j.MarkerManager;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.IntSupplier;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static net.minecraftforge.registries.ForgeRegistry.REGISTRIES;
|
||||
@@ -142,7 +138,7 @@ public class FMLHandshakeHandler {
|
||||
* @param <MSG> message type
|
||||
* @return A {@link BiConsumer} for use in message handling
|
||||
*/
|
||||
public static <MSG extends FMLHandshakeMessages.LoginIndexedMessage> BiConsumer<MSG, Supplier<NetworkEvent.Context>> biConsumerFor(ThreeConsumer<FMLHandshakeHandler, ? super MSG, ? super Supplier<NetworkEvent.Context>> consumer)
|
||||
public static <MSG extends IntSupplier> BiConsumer<MSG, Supplier<NetworkEvent.Context>> biConsumerFor(ThreeConsumer<FMLHandshakeHandler, ? super MSG, ? super Supplier<NetworkEvent.Context>> consumer)
|
||||
{
|
||||
return (m, c) -> ThreeConsumer.bindArgs(consumer, m, c).accept(getHandshake(c));
|
||||
}
|
||||
@@ -157,7 +153,7 @@ public class FMLHandshakeHandler {
|
||||
* @param <MSG> message type
|
||||
* @return A {@link BiConsumer} for use in message handling
|
||||
*/
|
||||
public static <MSG extends FMLHandshakeMessages.LoginIndexedMessage> BiConsumer<MSG, Supplier<NetworkEvent.Context>> indexFirst(ThreeConsumer<FMLHandshakeHandler, MSG, Supplier<NetworkEvent.Context>> next)
|
||||
public static <MSG extends IntSupplier> BiConsumer<MSG, Supplier<NetworkEvent.Context>> indexFirst(ThreeConsumer<FMLHandshakeHandler, MSG, Supplier<NetworkEvent.Context>> next)
|
||||
{
|
||||
final BiConsumer<MSG, Supplier<NetworkEvent.Context>> loginIndexedMessageSupplierBiConsumer = biConsumerFor(FMLHandshakeHandler::handleIndexedMessage);
|
||||
return loginIndexedMessageSupplierBiConsumer.andThen(biConsumerFor(next));
|
||||
@@ -194,12 +190,12 @@ public class FMLHandshakeHandler {
|
||||
LOGGER.debug(REGISTRIES, "Expecting {} registries: {}", ()->this.registriesToReceive.size(), ()->this.registriesToReceive);
|
||||
}
|
||||
|
||||
<MSG extends FMLHandshakeMessages.LoginIndexedMessage> void handleIndexedMessage(MSG message, Supplier<NetworkEvent.Context> c)
|
||||
<MSG extends IntSupplier> void handleIndexedMessage(MSG message, Supplier<NetworkEvent.Context> c)
|
||||
{
|
||||
LOGGER.debug(FMLHSMARKER, "Received client indexed reply {} of type {}", message.getLoginIndex(), message.getClass().getName());
|
||||
boolean removed = this.sentMessages.removeIf(i->i==message.getLoginIndex());
|
||||
LOGGER.debug(FMLHSMARKER, "Received client indexed reply {} of type {}", message.getAsInt(), message.getClass().getName());
|
||||
boolean removed = this.sentMessages.removeIf(i-> i == message.getAsInt());
|
||||
if (!removed) {
|
||||
LOGGER.error(FMLHSMARKER, "Recieved unexpected index {} in client reply", message.getLoginIndex());
|
||||
LOGGER.error(FMLHSMARKER, "Recieved unexpected index {} in client reply", message.getAsInt());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.IntSupplier;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -38,7 +40,8 @@ import com.google.common.collect.Maps;
|
||||
|
||||
public class FMLHandshakeMessages
|
||||
{
|
||||
static class LoginIndexedMessage {
|
||||
static class LoginIndexedMessage implements IntSupplier
|
||||
{
|
||||
private int loginIndex;
|
||||
|
||||
void setLoginIndex(final int loginIndex) {
|
||||
@@ -48,6 +51,11 @@ public class FMLHandshakeMessages
|
||||
int getLoginIndex() {
|
||||
return loginIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
return getLoginIndex();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Server to client "list of mods". Always first handshake message.
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.IntSupplier;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class SimpleChannel
|
||||
@@ -112,6 +113,14 @@ public class SimpleChannel
|
||||
context.getPacketDispatcher().sendPacket(instance.getChannelName(), toBuffer(msgToReply).getLeft());
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a new MessageBuilder. The type should implement {@link java.util.function.IntSupplier} if it is a login
|
||||
* packet.
|
||||
* @param type Type of message
|
||||
* @param id id in the indexed codec
|
||||
* @param <M> Type of type
|
||||
* @return a MessageBuilder
|
||||
*/
|
||||
public <M> MessageBuilder<M> messageBuilder(final Class<M> type, int id) {
|
||||
return MessageBuilder.forType(this, type, id);
|
||||
}
|
||||
@@ -179,6 +188,9 @@ public class SimpleChannel
|
||||
message.setLoginIndexSetter(this.loginIndexSetter);
|
||||
}
|
||||
if (this.loginIndexGetter != null) {
|
||||
if (!IntSupplier.class.isAssignableFrom(this.type)) {
|
||||
throw new IllegalArgumentException("Login packet type that does not supply an index as an IntSupplier");
|
||||
}
|
||||
message.setLoginIndexGetter(this.loginIndexGetter);
|
||||
}
|
||||
if (this.loginPacketGenerators != null) {
|
||||
|
||||
Reference in new issue
Block a user