-
-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement over-engineered diceroll #479
Open
wagyourtail
wants to merge
12
commits into
Earthcomputer:fabric
Choose a base branch
from
wagyourtail:ccoinflip
base: fabric
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1ea760b
implement over-engineered coinflip
wagyourtail d818e3c
exchange hashes first so player2 cant easily cheat via guess/check
wagyourtail 186fba9
fix self coinflip and multi coinflips with new method
wagyourtail 99fd970
generalize to dice rolling
wagyourtail 8cde399
fix function names
wagyourtail 46d4223
bump to 1024 bytes, add timeout safety. make message too long say cal…
wagyourtail 7ec2e3d
forgot to make dynamic change on decrypt
wagyourtail b0e6c37
missed a spot
wagyourtail f00d2da
fix timeout breaking things
wagyourtail fb0fe94
Merge branch 'fabric' into ccoinflip
wagyourtail 9858c62
Merge branch 'fabric' into ccoinflip
wagyourtail b9fba3e
update
wagyourtail File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/main/java/net/earthcomputer/clientcommands/c2c/C2CPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package net.earthcomputer.clientcommands.c2c; | ||
|
||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import net.minecraft.network.PacketByteBuf; | ||
|
||
public interface C2CPacket { | ||
void write(PacketByteBuf buf); | ||
|
||
void apply(CCPacketListener listener); | ||
void apply(CCPacketListener listener) throws CommandSyntaxException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -4,7 +4,10 @@ | |||
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; | ||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; | ||||
import com.mojang.logging.LogUtils; | ||||
import io.netty.buffer.Unpooled; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused import.
Suggested change
|
||||
import net.earthcomputer.clientcommands.c2c.packets.DiceRollC2CPackets; | ||||
import net.earthcomputer.clientcommands.c2c.packets.MessageC2CPacket; | ||||
import net.earthcomputer.clientcommands.command.DiceRollCommand; | ||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; | ||||
import net.minecraft.client.MinecraftClient; | ||||
import net.minecraft.client.network.PlayerListEntry; | ||||
|
@@ -97,4 +100,19 @@ public void onMessageC2CPacket(MessageC2CPacket packet) { | |||
Text text = prefix.append(Text.translatable("ccpacket.messageC2CPacket.incoming", sender, message).formatted(Formatting.GRAY)); | ||||
MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(text); | ||||
} | ||||
|
||||
@Override | ||||
public void onCoinflipInitC2CPacket(DiceRollC2CPackets.DiceRollInitC2CPacket packet) throws CommandSyntaxException { | ||||
DiceRollCommand.initDiceroll(packet); | ||||
} | ||||
|
||||
@Override | ||||
public void onCoinflipAcceptedC2CPacket(DiceRollC2CPackets.DiceRollAcceptedC2CPacket packet) throws CommandSyntaxException { | ||||
DiceRollCommand.acceptDiceroll(packet); | ||||
} | ||||
|
||||
@Override | ||||
public void onCoinflipResultC2CPacket(DiceRollC2CPackets.DiceRollResultC2CPacket packet) { | ||||
DiceRollCommand.completeDiceroll(packet); | ||||
} | ||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/net/earthcomputer/clientcommands/c2c/CCPacketListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
package net.earthcomputer.clientcommands.c2c; | ||
|
||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import net.earthcomputer.clientcommands.c2c.packets.DiceRollC2CPackets; | ||
import net.earthcomputer.clientcommands.c2c.packets.MessageC2CPacket; | ||
|
||
public interface CCPacketListener { | ||
void onMessageC2CPacket(MessageC2CPacket packet); | ||
|
||
void onCoinflipInitC2CPacket(DiceRollC2CPackets.DiceRollInitC2CPacket packet) throws CommandSyntaxException; | ||
|
||
void onCoinflipAcceptedC2CPacket(DiceRollC2CPackets.DiceRollAcceptedC2CPacket packet) throws CommandSyntaxException; | ||
|
||
void onCoinflipResultC2CPacket(DiceRollC2CPackets.DiceRollResultC2CPacket packet); | ||
} |
102 changes: 102 additions & 0 deletions
102
src/main/java/net/earthcomputer/clientcommands/c2c/packets/DiceRollC2CPackets.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package net.earthcomputer.clientcommands.c2c.packets; | ||
|
||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import net.earthcomputer.clientcommands.c2c.C2CPacket; | ||
import net.earthcomputer.clientcommands.c2c.CCPacketHandler; | ||
import net.earthcomputer.clientcommands.c2c.CCPacketListener; | ||
import net.minecraft.network.PacketByteBuf; | ||
|
||
import java.math.BigInteger; | ||
import java.util.BitSet; | ||
|
||
public class DiceRollC2CPackets { | ||
// use a diffie hellman key exchange in order to ensure that the coinflip is fair | ||
|
||
public static class DiceRollInitC2CPacket implements C2CPacket { | ||
public final String sender; | ||
public final int sides; | ||
public final byte[] ABHash; | ||
|
||
public DiceRollInitC2CPacket(String sender, int sides, byte[] ABHash) { | ||
this.sender = sender; | ||
this.sides = sides; | ||
this.ABHash = ABHash; | ||
} | ||
|
||
public DiceRollInitC2CPacket(PacketByteBuf raw) { | ||
this.sender = raw.readString(); | ||
this.sides = raw.readInt(); | ||
this.ABHash = raw.readByteArray(); | ||
} | ||
|
||
@Override | ||
public void write(PacketByteBuf buf) { | ||
buf.writeString(this.sender); | ||
buf.writeInt(this.sides); | ||
buf.writeByteArray(this.ABHash); | ||
} | ||
|
||
@Override | ||
public void apply(CCPacketListener listener) throws CommandSyntaxException { | ||
listener.onCoinflipInitC2CPacket(this); | ||
} | ||
} | ||
|
||
public static class DiceRollAcceptedC2CPacket implements C2CPacket { | ||
public final String sender; | ||
public final BigInteger AB; | ||
|
||
public DiceRollAcceptedC2CPacket(String sender, BigInteger publicKey) { | ||
this.sender = sender; | ||
this.AB = publicKey; | ||
} | ||
|
||
public DiceRollAcceptedC2CPacket(PacketByteBuf stringBuf) { | ||
this.sender = stringBuf.readString(); | ||
this.AB = new BigInteger(stringBuf.readBitSet().toByteArray()); | ||
} | ||
|
||
@Override | ||
public void write(PacketByteBuf buf) { | ||
buf.writeString(this.sender); | ||
buf.writeBitSet(BitSet.valueOf(this.AB.toByteArray())); | ||
} | ||
|
||
@Override | ||
public void apply(CCPacketListener listener) throws CommandSyntaxException { | ||
listener.onCoinflipAcceptedC2CPacket(this); | ||
} | ||
} | ||
|
||
public static class DiceRollResultC2CPacket implements C2CPacket { | ||
public final String sender; | ||
public final BigInteger s; | ||
|
||
public DiceRollResultC2CPacket(String sender, BigInteger s) { | ||
this.sender = sender; | ||
this.s = s; | ||
} | ||
|
||
public DiceRollResultC2CPacket(PacketByteBuf stringBuf) { | ||
this.sender = stringBuf.readString(); | ||
this.s = new BigInteger(stringBuf.readBitSet().toByteArray()); | ||
} | ||
|
||
@Override | ||
public void write(PacketByteBuf buf) { | ||
buf.writeString(this.sender); | ||
buf.writeBitSet(BitSet.valueOf(this.s.toByteArray())); | ||
} | ||
|
||
@Override | ||
public void apply(CCPacketListener listener) { | ||
listener.onCoinflipResultC2CPacket(this); | ||
} | ||
} | ||
|
||
public static void register() { | ||
CCPacketHandler.register(DiceRollInitC2CPacket.class, DiceRollInitC2CPacket::new); | ||
CCPacketHandler.register(DiceRollAcceptedC2CPacket.class, DiceRollAcceptedC2CPacket::new); | ||
CCPacketHandler.register(DiceRollResultC2CPacket.class, DiceRollResultC2CPacket::new); | ||
} | ||
Comment on lines
+97
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if it's necessary to register them here. I don't know why |
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this is out of the scope of command syntax exceptions. Perhaps we should create our own exception class or just
return
instead of throwing an exception.