Allow vanilla connections properly, and allow mods to decide.
Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
parent
c219416bb8
commit
2a4e05c982
3 changed files with 32 additions and 10 deletions
|
@ -35,10 +35,7 @@ import org.apache.logging.log4j.Logger;
|
|||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
@ -188,8 +185,13 @@ public class FMLHandshakeHandler {
|
|||
{
|
||||
this.direction = side;
|
||||
this.manager = networkManager;
|
||||
this.messageList = NetworkRegistry.gatherLoginPayloads(this.direction);
|
||||
LOGGER.debug(FMLHSMARKER, "Starting new modded network connection. Found {} messages to dispatch.", this.messageList.size());
|
||||
if (NetworkHooks.getConnectionType(()->this.manager)==ConnectionType.VANILLA) {
|
||||
this.messageList = Collections.emptyList();
|
||||
LOGGER.debug(FMLHSMARKER, "Starting new vanilla network connection.");
|
||||
} else {
|
||||
this.messageList = NetworkRegistry.gatherLoginPayloads(this.direction);
|
||||
LOGGER.debug(FMLHSMARKER, "Starting new modded network connection. Found {} messages to dispatch.", this.messageList.size());
|
||||
}
|
||||
}
|
||||
|
||||
private void handleServerModListOnClient(FMLHandshakeMessages.S2CModList serverModList, Supplier<NetworkEvent.Context> c)
|
||||
|
|
|
@ -54,7 +54,7 @@ public class NetworkHooks
|
|||
|
||||
public static boolean accepts(final CPacketHandshake packet)
|
||||
{
|
||||
return Objects.equals(packet.getFMLVersion(), NETVERSION) || NetworkRegistry.acceptsVanillaConnections();
|
||||
return Objects.equals(packet.getFMLVersion(), NETVERSION) || NetworkRegistry.acceptsVanillaClientConnections();
|
||||
}
|
||||
|
||||
public static ConnectionType getConnectionType(final Supplier<NetworkManager> connection)
|
||||
|
|
|
@ -60,13 +60,16 @@ public class NetworkRegistry
|
|||
@SuppressWarnings("RedundantStringConstructorCall")
|
||||
public static String ABSENT = new String("ABSENT \uD83E\uDD14");
|
||||
|
||||
@SuppressWarnings("RedundantStringConstructorCall")
|
||||
public static String ACCEPTVANILLA = new String("ALLOWVANILLA \uD83D\uDC93\uD83D\uDC93\uD83D\uDC93");
|
||||
|
||||
public static List<String> getNonVanillaNetworkMods()
|
||||
{
|
||||
return instances.keySet().stream().map(Object::toString).collect(Collectors.toList());
|
||||
return listRejectedVanillaMods(NetworkInstance::tryClientVersionOnServer);
|
||||
}
|
||||
|
||||
static boolean acceptsVanillaConnections() {
|
||||
return instances.isEmpty();
|
||||
static boolean acceptsVanillaClientConnections() {
|
||||
return instances.isEmpty() || getNonVanillaNetworkMods().isEmpty();
|
||||
}
|
||||
|
||||
|
||||
|
@ -150,6 +153,23 @@ public class NetworkRegistry
|
|||
}).collect(Collectors.toCollection(NBTTagList::new));
|
||||
}
|
||||
|
||||
static List<String> listRejectedVanillaMods(BiFunction<NetworkInstance, String, Boolean> testFunction) {
|
||||
final List<Pair<ResourceLocation, Boolean>> results = instances.values().stream().
|
||||
map(ni -> {
|
||||
final String incomingVersion = ACCEPTVANILLA;
|
||||
final boolean test = testFunction.apply(ni, incomingVersion);
|
||||
LOGGER.debug(NETREGISTRY, "Channel '{}' : Vanilla acceptance test: {}", ni.getChannelName(), test ? "ACCEPTED" : "REJECTED");
|
||||
return Pair.of(ni.getChannelName(), test);
|
||||
}).filter(p->!p.getRight()).collect(Collectors.toList());
|
||||
|
||||
if (!results.isEmpty()) {
|
||||
LOGGER.error(NETREGISTRY, "Channels [{}] rejected vanilla connections",
|
||||
results.stream().map(Pair::getLeft).map(Object::toString).collect(Collectors.joining(",")));
|
||||
return results.stream().map(Pair::getLeft).map(Object::toString).collect(Collectors.toList());
|
||||
}
|
||||
LOGGER.debug(NETREGISTRY, "Accepting channel list from vanilla");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
/**
|
||||
* Validate the channels from the server on the client. Tests the client predicates against the server
|
||||
* supplied network protocol version.
|
||||
|
|
Loading…
Reference in a new issue