Skip to content

Commit 362c197

Browse files
committed
various fixes for the rpc
1 parent 8db0525 commit 362c197

File tree

9 files changed

+163
-162
lines changed

9 files changed

+163
-162
lines changed

common/src/main/java/com/lambda/mixin/network/LoginHelloC2SPacketMixin.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,28 @@
1919

2020
import com.lambda.event.EventFlow;
2121
import com.lambda.event.events.ConnectionEvent;
22-
import net.minecraft.network.packet.c2s.login.LoginHelloC2SPacket;
22+
import net.minecraft.network.PacketByteBuf;
23+
import net.minecraft.network.encryption.NetworkEncryptionException;
24+
import net.minecraft.network.packet.s2c.login.LoginHelloS2CPacket;
25+
import org.spongepowered.asm.mixin.Final;
2326
import org.spongepowered.asm.mixin.Mixin;
27+
import org.spongepowered.asm.mixin.Shadow;
2428
import org.spongepowered.asm.mixin.injection.At;
2529
import org.spongepowered.asm.mixin.injection.Inject;
2630
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
2731

28-
import java.util.UUID;
32+
import java.security.PublicKey;
2933

30-
@Mixin(LoginHelloC2SPacket.class)
31-
public class LoginHelloC2SPacketMixin {
32-
@Inject(method = "<init>(Ljava/lang/String;Ljava/util/UUID;)V", at = @At("TAIL"))
33-
private void onLoginHelloC2SPacket(String string, UUID uUID, CallbackInfo ci) {
34-
EventFlow.post(new ConnectionEvent.Connect.Login.Hello(string, uUID));
34+
@Mixin(LoginHelloS2CPacket.class)
35+
public abstract class LoginHelloC2SPacketMixin {
36+
@Shadow @Final private String serverId;
37+
38+
@Shadow @Final private byte[] nonce;
39+
40+
@Shadow public abstract PublicKey getPublicKey() throws NetworkEncryptionException;
41+
42+
@Inject(method = "<init>(Lnet/minecraft/network/PacketByteBuf;)V", at = @At("TAIL"))
43+
private void onLoginHelloC2SPacket(PacketByteBuf buf, CallbackInfo ci) throws NetworkEncryptionException {
44+
EventFlow.post(new ConnectionEvent.Connect.Login.EncryptionRequest(serverId, getPublicKey(), nonce));
3545
}
3646
}

common/src/main/java/com/lambda/mixin/network/LoginKeyC2SPacketMixin.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
public class LoginKeyC2SPacketMixin {
3333
@Inject(method = "<init>(Ljavax/crypto/SecretKey;Ljava/security/PublicKey;[B)V", at = @At("TAIL"))
3434
private void onLoginKeyC2SPacket(SecretKey secretKey, PublicKey publicKey, byte[] nonce, CallbackInfo ci) {
35-
// Please note this won't work if the server is offline mode because the player doesn't
36-
// fetch the server's public key.
37-
EventFlow.post(new ConnectionEvent.Connect.Login.Key(secretKey, publicKey, nonce));
35+
EventFlow.post(new ConnectionEvent.Connect.Login.EncryptionResponse(secretKey, publicKey, nonce));
3836
}
3937
}

common/src/main/kotlin/com/lambda/command/commands/RpcCommand.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,5 @@ object RpcCommand : LambdaCommand(
3838
}
3939
}
4040
}
41-
42-
required(literal("accept")) {
43-
execute {
44-
DiscordRPC.join()
45-
}
46-
}
4741
}
4842
}

common/src/main/kotlin/com/lambda/event/events/ConnectionEvent.kt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import net.minecraft.network.listener.PacketListener
2525
import net.minecraft.network.packet.c2s.handshake.ConnectionIntent
2626
import net.minecraft.text.Text
2727
import java.security.PublicKey
28-
import java.util.UUID
2928
import javax.crypto.SecretKey
3029

3130
/**
@@ -69,26 +68,28 @@ sealed class ConnectionEvent : Event {
6968
*/
7069
sealed class Login : ConnectionEvent() {
7170
/**
72-
* Event representing a hello message during login.
73-
* @property name The name associated with the login.
74-
* @property uuid The UUID associated with the login.
71+
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=19208#Encryption_Request">Encryption Request</a>
7572
*/
76-
class Hello(
77-
val name: String,
78-
val uuid: UUID,
73+
class EncryptionRequest(
74+
val serverId: String,
75+
val publicKey: PublicKey,
76+
val nonce: ByteArray,
7977
) : ConnectionEvent()
8078

8179
/**
82-
* Event representing the exchange of cryptographic keys during login.
83-
* @property secretKey The secret key exchanged during login.
84-
* @property publicKey The public key exchanged during login.
85-
* @property nonce The nonce associated with the login.
80+
* Event representing the exchange of cryptographic keys during login
81+
* from the client to the server
82+
*
83+
* Note that this event won't be posted if the server is in offline mode
84+
* because the player doesn't fetch the server's public key
85+
*
86+
* The secret key must be destroyed if stored for long periods
87+
* This can be done by calling the `destroy()` method on the secret key object
88+
* We are not responsible for any incidents that may occur due to improper handling of cryptographic keys
8689
*
87-
* The secret key MUST ABSOLUTELY be, if stored, destroyed after use to avoid security vulnerabilities.
88-
* This can be done by calling the `destroy()` method on the secret key object.
89-
* We are NOT responsible for any incidents that may occur due to improper handling of cryptographic keys.
90+
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=19208#Encryption_Response">Encryption Response</a>
9091
*/
91-
class Key(
92+
class EncryptionResponse(
9293
val secretKey: SecretKey,
9394
val publicKey: PublicKey,
9495
val nonce: ByteArray,
@@ -105,7 +106,6 @@ sealed class ConnectionEvent : Event {
105106
}
106107

107108
/**
108-
* Event representing a disconnection.
109109
* @property reason The reason for disconnection.
110110
*/
111111
class Disconnect(val reason: Text) : ConnectionEvent()

common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/UpdateParty.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,13 @@ fun editParty(
3333
// Whether the party is public or not.
3434
// If false can only be joined by invite.
3535
// example: true
36-
public: Boolean = true,
36+
// public: Boolean = true,
3737
) =
3838
request("$endpoint/api/$version/party/edit") {
3939
method(Method.PATCH)
4040

4141
parameters(
42-
mapOf(
43-
"max_players" to maxPlayers,
44-
"public" to public,
45-
)
42+
mapOf("max_players" to maxPlayers)
4643
)
4744

4845
headers(

common/src/main/kotlin/com/lambda/http/api/rpc/v1/models/Party.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
package com.lambda.http.api.rpc.v1.models
1919

2020
import com.google.gson.annotations.SerializedName
21+
import java.util.UUID
2122

2223
data class Party(
2324
// The ID of the party.
2425
// It is a random string of 30 characters.
2526
@SerializedName("id")
26-
val id: String,
27+
val id: UUID,
2728

2829
// The join secret of the party.
2930
// It is a random string of 100 characters.

common/src/main/kotlin/com/lambda/http/api/rpc/v1/models/Player.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.lambda.http.api.rpc.v1.models
1919

2020
import com.google.gson.annotations.SerializedName
21+
import java.util.UUID
2122

2223
data class Player(
2324
// The player's name.
@@ -27,11 +28,15 @@ data class Player(
2728

2829
// The player's UUID.
2930
// example: 069a79f4-44e9-4726-a5be-fca90e38aaf5
30-
@SerializedName("uuid")
31-
val uuid: String,
31+
@SerializedName("id")
32+
val uuid: UUID,
3233

3334
// The player's Discord ID.
3435
// example: "385441179069579265"
3536
@SerializedName("discord_id")
3637
val discordId: String,
38+
39+
// Whether the player is verified or not
40+
@SerializedName("unsafe")
41+
val unsafe: Boolean,
3742
)

common/src/main/kotlin/com/lambda/http/api/rpc/v1/models/Settings.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ data class Settings(
2828
// Whether the party is public or not.
2929
// If false can only be joined by invite.
3030
// example: true
31-
@SerializedName("public")
32-
val public: Boolean,
31+
// @SerializedName("public")
32+
// val public: Boolean,
3333
)

0 commit comments

Comments
 (0)