Skip to content

Commit

Permalink
Close #4365
Browse files Browse the repository at this point in the history
  • Loading branch information
yrsegal committed Oct 7, 2023
1 parent fec6624 commit a083b44
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public static BitSet compileFlagInfo() {
return set;
}

public static int expectedLength() {
return allFlags.size();
}

public static int expectedHash() {
return allFlags.hashCode();
}

private static Set<String> decodeFlags(BitSet bitSet) {
Set<String> enabledFlags = new HashSet<>();

Expand All @@ -48,7 +56,7 @@ public static void receiveFlagInfoFromServer(BitSet bitSet) {
}

public static void sendFlagInfoToPlayers() {
QuarkNetwork.sendToPlayers(new S2CUpdateFlag(), flagsFromPlayers.keySet());
QuarkNetwork.sendToPlayers(S2CUpdateFlag.createPacket(), flagsFromPlayers.keySet());
}

private static final WeakHashMap<PacketListener, Set<String>> flagsFromServer = new WeakHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,32 @@
public class C2SLoginFlag extends HandshakeMessage {

public BitSet flags;
public int expectedLength;
public int expectedHash;

public C2SLoginFlag() {
flags = SyncedFlagHandler.compileFlagInfo();
expectedLength = SyncedFlagHandler.expectedLength();
expectedHash = SyncedFlagHandler.expectedHash();
}

public C2SLoginFlag(FriendlyByteBuf buf) {
this.flags = BitSet.valueOf(buf.readLongArray());
this.expectedLength = buf.readInt();
this.expectedHash = buf.readInt();
}

@Override
public void encode(FriendlyByteBuf buf) {
buf.writeLongArray(flags.toLongArray());
buf.writeInt(expectedLength);
buf.writeInt(expectedHash);
}

@Override
public boolean consume(NetworkEvent.Context context, BiConsumer<HandshakeMessage, NetworkEvent.Context> reply) {
SyncedFlagHandler.receiveFlagInfoFromPlayer(context.getSender(), flags);
if (expectedLength == SyncedFlagHandler.expectedLength() && expectedHash == SyncedFlagHandler.expectedHash())
SyncedFlagHandler.receiveFlagInfoFromPlayer(context.getSender(), flags);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,30 @@
public class C2SUpdateFlag implements IMessage {

@Serial
private static final long serialVersionUID = 7483741039149504284L;
private static final long serialVersionUID = 5243197411999379903L;

public BitSet flags;
public int expectedLength;
public int expectedHash;

@Override
public boolean receive(NetworkEvent.Context context) {
SyncedFlagHandler.receiveFlagInfoFromPlayer(context.getSender(), flags);
if (expectedLength == SyncedFlagHandler.expectedLength() && expectedHash == SyncedFlagHandler.expectedHash())
SyncedFlagHandler.receiveFlagInfoFromPlayer(context.getSender(), flags);
return true;
}

public C2SUpdateFlag() {
// NO-OP
}

private C2SUpdateFlag(BitSet flags) {
private C2SUpdateFlag(BitSet flags, int expectedLength, int expectedHash) {
this.flags = flags;
this.expectedLength = expectedLength;
this.expectedHash = expectedHash;
}

public static C2SUpdateFlag createPacket() {
return new C2SUpdateFlag(SyncedFlagHandler.compileFlagInfo());
return new C2SUpdateFlag(SyncedFlagHandler.compileFlagInfo(), SyncedFlagHandler.expectedLength(), SyncedFlagHandler.expectedHash());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,26 @@
public class S2CLoginFlag extends HandshakeMessage {

public BitSet flags;
public int expectedLength;
public int expectedHash;

public S2CLoginFlag() {
flags = SyncedFlagHandler.compileFlagInfo();
expectedLength = SyncedFlagHandler.expectedLength();
expectedHash = SyncedFlagHandler.expectedHash();
}

public S2CLoginFlag(FriendlyByteBuf buf) {
this.flags = BitSet.valueOf(buf.readLongArray());
this.expectedLength = buf.readInt();
this.expectedHash = buf.readInt();
}

@Override
public void encode(FriendlyByteBuf buf) {
buf.writeLongArray(flags.toLongArray());
buf.writeInt(expectedLength);
buf.writeInt(expectedHash);
}

public static List<Pair<String, S2CLoginFlag>> generateRegistryPackets(boolean isLocal) {
Expand All @@ -35,7 +43,8 @@ public static List<Pair<String, S2CLoginFlag>> generateRegistryPackets(boolean i

@Override
public boolean consume(NetworkEvent.Context context, BiConsumer<HandshakeMessage, NetworkEvent.Context> reply) {
SyncedFlagHandler.receiveFlagInfoFromServer(flags);
if (expectedLength == SyncedFlagHandler.expectedLength() && expectedHash == SyncedFlagHandler.expectedHash())
SyncedFlagHandler.receiveFlagInfoFromServer(flags);
reply.accept(new C2SLoginFlag(), context);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,30 @@
public class S2CUpdateFlag implements IMessage {

@Serial
private static final long serialVersionUID = 2346906475290526858L;
private static final long serialVersionUID = 5889504104199410797L;

public BitSet flags;
public int expectedLength;
public int expectedHash;

@Override
public boolean receive(NetworkEvent.Context context) {
SyncedFlagHandler.receiveFlagInfoFromServer(flags);
if (expectedLength == SyncedFlagHandler.expectedLength() && expectedHash == SyncedFlagHandler.expectedHash())
SyncedFlagHandler.receiveFlagInfoFromServer(flags);
return true;
}

public S2CUpdateFlag() {
// NO-OP
}

private S2CUpdateFlag(BitSet flags) {
private S2CUpdateFlag(BitSet flags, int expectedLength, int expectedHash) {
this.flags = flags;
this.expectedLength = expectedLength;
this.expectedHash = expectedHash;
}

public static S2CUpdateFlag createPacket() {
return new S2CUpdateFlag(SyncedFlagHandler.compileFlagInfo());
return new S2CUpdateFlag(SyncedFlagHandler.compileFlagInfo(), SyncedFlagHandler.expectedLength(), SyncedFlagHandler.expectedHash());
}
}
3 changes: 2 additions & 1 deletion src/main/java/vazkii/quark/base/proxy/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ public void handleQuarkConfigChange() {
super.handleQuarkConfigChange();

ModuleLoader.INSTANCE.configChangedClient();
QuarkNetwork.sendToServer(C2SUpdateFlag.createPacket());
if (Minecraft.getInstance().getConnection() != null)
QuarkNetwork.sendToServer(C2SUpdateFlag.createPacket());
IngameConfigHandler.INSTANCE.refresh();

Minecraft mc = Minecraft.getInstance();
Expand Down

0 comments on commit a083b44

Please sign in to comment.