-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Players can now use the chat to send messages to each other.
- Loading branch information
Showing
4 changed files
with
135 additions
and
4 deletions.
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
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
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,105 @@ | ||
IDENTIFICATION DIVISION. | ||
PROGRAM-ID. SendPacket-PlayerChat. | ||
|
||
DATA DIVISION. | ||
WORKING-STORAGE SECTION. | ||
01 PACKET-ID BINARY-LONG VALUE 55. | ||
*> temporary data used during encoding | ||
01 UINT16 BINARY-SHORT UNSIGNED. | ||
01 INT32 BINARY-LONG. | ||
01 INT64 BINARY-LONG-LONG. | ||
01 BUFFER PIC X(8). | ||
01 BUFFERLEN BINARY-LONG UNSIGNED. | ||
*> buffer used to store the packet data | ||
01 PAYLOAD PIC X(64000). | ||
01 PAYLOADLEN BINARY-LONG UNSIGNED. | ||
LINKAGE SECTION. | ||
01 LK-HNDL PIC X(4). | ||
01 LK-ERRNO PIC 9(3). | ||
01 LK-SENDER-ID BINARY-LONG UNSIGNED. | ||
01 LK-SENDER-NAME PIC X(16). | ||
01 LK-MESSAGE PIC X(256). | ||
01 LK-MESSAGE-LEN BINARY-LONG UNSIGNED. | ||
|
||
PROCEDURE DIVISION USING BY REFERENCE LK-HNDL LK-ERRNO LK-SENDER-ID LK-SENDER-NAME LK-MESSAGE LK-MESSAGE-LEN. | ||
MOVE 0 TO PAYLOADLEN | ||
|
||
*> --- header --- | ||
|
||
*> sender UUID | ||
*> TODO: use a proper UUID, not the entity ID | ||
MOVE X"000000000000" TO PAYLOAD(PAYLOADLEN + 1:12) | ||
ADD 12 TO PAYLOADLEN | ||
CALL "Encode-Int" USING LK-SENDER-ID BUFFER BUFFERLEN | ||
MOVE BUFFER(1:BUFFERLEN) TO PAYLOAD(PAYLOADLEN + 1:BUFFERLEN) | ||
ADD BUFFERLEN TO PAYLOADLEN | ||
|
||
*> index | ||
MOVE 0 TO INT32 | ||
CALL "Encode-VarInt" USING INT32 BUFFER BUFFERLEN | ||
MOVE BUFFER(1:BUFFERLEN) TO PAYLOAD(PAYLOADLEN + 1:BUFFERLEN) | ||
ADD BUFFERLEN TO PAYLOADLEN | ||
|
||
*> message signature present | ||
MOVE X"00" TO PAYLOAD(PAYLOADLEN + 1:1) | ||
ADD 1 TO PAYLOADLEN | ||
|
||
*> --- body --- | ||
|
||
*> message | ||
CALL "Encode-VarInt" USING LK-MESSAGE-LEN BUFFER BUFFERLEN | ||
MOVE BUFFER(1:BUFFERLEN) TO PAYLOAD(PAYLOADLEN + 1:BUFFERLEN) | ||
ADD BUFFERLEN TO PAYLOADLEN | ||
MOVE LK-MESSAGE(1:LK-MESSAGE-LEN) TO PAYLOAD(PAYLOADLEN + 1:LK-MESSAGE-LEN) | ||
ADD LK-MESSAGE-LEN TO PAYLOADLEN | ||
|
||
*> signature timestamp and salt | ||
MOVE X"00000000000000000000000000000000" TO PAYLOAD(PAYLOADLEN + 1:16) | ||
ADD 16 TO PAYLOADLEN | ||
|
||
*> --- previous messages --- | ||
|
||
*> total previous messages | ||
MOVE 0 TO INT32 | ||
CALL "Encode-VarInt" USING INT32 BUFFER BUFFERLEN | ||
MOVE BUFFER(1:BUFFERLEN) TO PAYLOAD(PAYLOADLEN + 1:BUFFERLEN) | ||
ADD BUFFERLEN TO PAYLOADLEN | ||
|
||
*> --- other --- | ||
|
||
*> unsigned content present | ||
MOVE X"00" TO PAYLOAD(PAYLOADLEN + 1:1) | ||
ADD 1 TO PAYLOADLEN | ||
|
||
*> filter type enum (0: not filtered) | ||
MOVE X"00" TO PAYLOAD(PAYLOADLEN + 1:1) | ||
ADD 1 TO PAYLOADLEN | ||
|
||
*> --- chat formatting --- | ||
|
||
*> chat type | ||
*> TODO: This is a reference to the "minecraft:chat_type" registry. Get the correct value from the registry. | ||
MOVE X"00" TO PAYLOAD(PAYLOADLEN + 1:1) | ||
ADD 1 TO PAYLOADLEN | ||
|
||
*> sender name (NBT string tag) | ||
MOVE X"08" TO PAYLOAD(PAYLOADLEN + 1:1) | ||
ADD 1 TO PAYLOADLEN | ||
COMPUTE UINT16 = FUNCTION STORED-CHAR-LENGTH(LK-SENDER-NAME) | ||
CALL "Encode-Short" USING UINT16 BUFFER BUFFERLEN | ||
MOVE BUFFER(1:BUFFERLEN) TO PAYLOAD(PAYLOADLEN + 1:BUFFERLEN) | ||
ADD BUFFERLEN TO PAYLOADLEN | ||
*> TODO: implement modified UTF-8: https://docs.oracle.com/javase/8/docs/api/java/io/DataInput.html#modified-utf-8 | ||
MOVE LK-SENDER-NAME(1:UINT16) TO PAYLOAD(PAYLOADLEN + 1:UINT16) | ||
ADD UINT16 TO PAYLOADLEN | ||
|
||
*> has target name | ||
MOVE X"00" TO PAYLOAD(PAYLOADLEN + 1:1) | ||
ADD 1 TO PAYLOADLEN | ||
|
||
*> Send the packet | ||
CALL "SendPacket" USING LK-HNDL PACKET-ID PAYLOAD PAYLOADLEN LK-ERRNO | ||
|
||
GOBACK. | ||
|
||
END PROGRAM SendPacket-PlayerChat. |
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