-
-
Notifications
You must be signed in to change notification settings - Fork 116
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
base: fabric
Are you sure you want to change the base?
Conversation
Sorry if this is a strange request but could you perhaps extract the C2C packet changes to a separate PR? |
I can't completely remove them from this one or it'll break this one. but I can have them as a seperate branch that this one is based uppon |
Sure, thanks! |
Would it be useful to use 2048 bit keys? A wikipedia article |
yes, but they don't fit in a minecraft chat message, xd and for our purposes I don't think that'll be an issue |
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 don't understand much of the technical stuff so these are mostly style related changes.
import net.minecraft.network.PacketByteBuf; | ||
|
||
public interface C2CPacket { | ||
void write(PacketByteBuf buf); | ||
|
||
void apply(CCPacketListener listener); | ||
void apply(CCPacketListener listener) throws CommandSyntaxException; |
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.
public static void register() { | ||
CCPacketHandler.register(DiceRollInitC2CPacket.class, DiceRollInitC2CPacket::new); | ||
CCPacketHandler.register(DiceRollAcceptedC2CPacket.class, DiceRollAcceptedC2CPacket::new); | ||
CCPacketHandler.register(DiceRollResultC2CPacket.class, DiceRollResultC2CPacket::new); | ||
} |
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.
Not sure if it's necessary to register them here. I don't know why CCPacketHandler#register
wasn't private in the first place.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import.
import io.netty.buffer.Unpooled; |
import java.security.SecureRandom; | ||
import java.util.*; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicInteger; |
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.
Unused import.
import java.util.concurrent.atomic.AtomicInteger; |
dispatcher.register(literal("cdiceroll") | ||
.executes(ctx -> localDiceroll(ctx.getSource(), 6)) | ||
.then(argument("sides", integer(2, 100)) | ||
.executes(ctx -> localDiceroll(ctx.getSource(), getInteger(ctx, "sides"))) | ||
.then(argument("player", gameProfile()) | ||
.executes(ctx -> diceroll(ctx.getSource(), getCProfileArgument(ctx, "player"), getInteger(ctx, "sides"))))) | ||
.then(argument("player", gameProfile()) | ||
.executes(ctx -> diceroll(ctx.getSource(), getCProfileArgument(ctx, "player"), 6)))); |
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.
Inconsistent indentation.
"commands.diceroll.diceroll": "dice roll (%s side)", | ||
"commands.diceroll.coinflip": "coin flip", | ||
"commands.diceroll.sent": "Sent %s request to %s", | ||
"commands.diceroll.received": "Received %s request from %s", | ||
"commands.diceroll.value": "%s result from %s: %s", | ||
"commands.diceroll.heads": "Heads", | ||
"commands.diceroll.tails": "Tails", | ||
"commands.diceroll.cheater": "I think %s is cheating, they got a different value.", | ||
"commands.diceroll.timeout": "Timeout waiting for %s's response to %s request", | ||
"commands.diceroll.waitingForResponse": "Waiting for %s's response already", |
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.
It should be cdiceroll
. Also I think some of these shouldn't be a subkey of commands
, but rather of ccpacket
.
try { | ||
md = MessageDigest.getInstance("SHA-1"); | ||
} | ||
catch(NoSuchAlgorithmException e) { |
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.
catch(NoSuchAlgorithmException e) { | |
catch (NoSuchAlgorithmException e) { |
System.out.println("expected: " + byteArrayToHexString(opponentHash.get(packet.sender))); | ||
System.out.println("actual: " + byteArrayToHexString(toSHA1(B.toByteArray()))); |
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.
This should probably be removed.
|
||
public class DiceRollCommand { | ||
private static final Logger LOGGER = LogUtils.getLogger(); | ||
private static final SimpleCommandExceptionType PLAYER_NOT_FOUND_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.cwe.playerNotFound")); |
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.
Perhaps it's an idea to add a few common exceptions for c2c related stuff to a certain class, I don't like the commands.cwe
translation key being used here.
might i ask: how does this work, can't i just generate these values on my client over and over until i get the one i want, then send it? |
A simpler solution for fairness could be implemented:
This is secure, as:
|
uses a modified diffie-hellman key exchange to prevent cheating