Skip to content

Commit 46d4c7f

Browse files
committed
feat: refine handshake process
1 parent 0a43259 commit 46d4c7f

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

src/main/java/com/mcdiamondfire/proto/ModAPIMessages.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.mcdiamondfire.proto.messages.clientbound.plot.*;
66
import com.mcdiamondfire.proto.messages.clientbound.server.*;
77
import com.mcdiamondfire.proto.messages.serverbound.player.*;
8-
import com.mcdiamondfire.proto.messages.serverbound.server.C2SModAPIConnect;
8+
import com.mcdiamondfire.proto.messages.serverbound.server.C2SHandshakeRequest;
99

1010
import java.util.*;
1111

@@ -22,8 +22,8 @@ public final class ModAPIMessages {
2222
// Client-bound.
2323

2424
// Server.
25-
registerMessage(S2CServerInfo.class, "s2c_server_info");
26-
registerMessage(S2CConnectionResult.class, "s2c_connection_result");
25+
registerMessage(S2CHello.class, "s2c_hlelo");
26+
registerMessage(S2CHandshakeResponse.class, "s2c_handshake_response");
2727
registerMessage(S2CServerBooster.class, "s2c_server_booster");
2828

2929
// Plot.
@@ -42,13 +42,15 @@ public final class ModAPIMessages {
4242

4343
// Server-bound.
4444

45+
// Server.
46+
registerMessage(C2SHandshakeRequest.class, "mc2s_handshake_request");
47+
4548
// Plot.
4649
registerMessage(C2SCodeOperation.class, "c2s_code_operation");
4750
registerMessage(C2SMultiCodeOperations.class, "c2s_multi_code_operations");
4851

4952
// Player.
5053
registerMessage(C2SPlayerTeleport.class, "c2s_player_teleport");
51-
registerMessage(C2SModAPIConnect.class, "mc2s_modapi_connect");
5254

5355
}
5456

src/main/proto/clientbound_server.proto

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ syntax = "proto3";
33
option java_package = "com.mcdiamondfire.proto.messages.clientbound.server";
44
option java_multiple_files = true;
55

6-
// Sent when the player joins the server, the server is ready to accept a S2CModAPIConnect message.
7-
message S2CServerInfo {
6+
// Sent by the server when the player connects to it, respond with C2SHandshakeRequest.
7+
message S2CHello {
8+
9+
}
10+
11+
// Represents information about the server.
12+
message ServerInfo {
813
// Represents a server type.
914
enum DFServerType {
1015
MAIN = 0; // Main nodes.
@@ -22,14 +27,18 @@ message S2CServerInfo {
2227
DFServerType server_type = 4; // The type of the server.
2328
}
2429

25-
// Sent as a response to a C2SModAPIConnect message.
26-
message S2CConnectionResult {
30+
// Sent as a response to a C2SHandshakeRequest message.
31+
message S2CHandshakeResponse {
2732
enum Error {
2833
NONE = 0; // No error, the connection was successful.
2934
INVALID_PROTOCOL = 1; // The given protocol version is invalid.
3035
INCOMPATIBLE_PROTOCOL = 2; // The given protocol version is incompatible with the server.
36+
ALREADY_CONNECTED = 3; // The player is already connected.
37+
}
38+
oneof result {
39+
Error error = 1; // The error that occurred, if any.
40+
ServerInfo server_info = 2; // The server info, if the connection was successful.
3141
}
32-
optional Error error = 1; // The error, if any.
3342
}
3443

3544
// Sent when the player joins the server.

src/main/proto/serverbound_server.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ option java_multiple_files = true;
77
// Notifies the server you are interested in receiving ModAPI messages.
88
// This must be sent before any ModAPI messages are sent by the client.
99
// A S2CConnectionResult message will be sent in response.
10-
message C2SModAPIConnect {
10+
message C2SHandshakeRequest {
1111
string protocol_version = 1; // The version of the protocol the client is using.
1212
}

0 commit comments

Comments
 (0)