Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
c632513e4c
|
|||
|
918db26698
|
|||
|
68a288c525
|
|||
|
47e6c3e76f
|
@@ -54,13 +54,13 @@ public enum State {
|
|||||||
),
|
),
|
||||||
// client bound
|
// client bound
|
||||||
Map.of(
|
Map.of(
|
||||||
|
SChatPacket.class, 0x0F,
|
||||||
PingPacket.class, 0x1F,
|
PingPacket.class, 0x1F,
|
||||||
JoinGamePacket.class, 0x23,
|
JoinGamePacket.class, 0x23,
|
||||||
SpawnPositionPacket.class, 0x46,
|
SpawnPositionPacket.class, 0x46,
|
||||||
ChunkDataPacket.class, 0x20,
|
ChunkDataPacket.class, 0x20,
|
||||||
PlayerAbilitiesPacket.class,0x2C,
|
PlayerAbilitiesPacket.class,0x2C,
|
||||||
SPlayerPositionAndLookPacket.class, 0x2F,
|
SPlayerPositionAndLookPacket.class, 0x2F
|
||||||
TitlePacket.class, 0x48
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,12 @@ public enum TextColor {
|
|||||||
WHITE ("white", 'f');
|
WHITE ("white", 'f');
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
|
|
||||||
|
public static final char SPECIAL_CHAR = '\u00a7';
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final char code;
|
private final char code;
|
||||||
|
|
||||||
|
public String toLegacy() {
|
||||||
|
return "" + SPECIAL_CHAR + code;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package mc.protocol.model.text;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public enum TextStyleLegacy {
|
||||||
|
|
||||||
|
OBFUSCATED('k'),
|
||||||
|
BOLD('l'),
|
||||||
|
STRIKETHOUGH('m'),
|
||||||
|
UNDERLINE('n'),
|
||||||
|
ITALIC('o'),
|
||||||
|
RESET('r');
|
||||||
|
|
||||||
|
private final char code;
|
||||||
|
|
||||||
|
public String toLegacy() {
|
||||||
|
return "" + TextColor.SPECIAL_CHAR + code;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package mc.protocol.packets.server;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import mc.protocol.io.NetByteBuf;
|
||||||
|
import mc.protocol.model.text.Text;
|
||||||
|
import mc.protocol.model.text.TextColor;
|
||||||
|
import mc.protocol.model.text.TextStyle;
|
||||||
|
import mc.protocol.packets.ServerSidePacket;
|
||||||
|
import mc.protocol.serializer.TextSerializer;
|
||||||
|
import mc.protocol.utils.ChatPosition;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chat packet.
|
||||||
|
*
|
||||||
|
* <p>Структура пакета</p>
|
||||||
|
* <pre>
|
||||||
|
* | FIELD | TYPE | NOTES |
|
||||||
|
* |-----------|------|-----------------------------------------------|
|
||||||
|
* | JSON Data | Text | Текст* |
|
||||||
|
* | Position | Byte | 0 - сообщение чата |
|
||||||
|
* | | | 1 - системное сообщение (отображается в чате) |
|
||||||
|
* | | | 2 - над панелью быстрого доступа (hotbar) |
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* * - стоит обратить внимание, что {@link TextColor} и {@link TextStyle} не работают: клиент не применяет
|
||||||
|
* стилистику в таком виде. Однако метод через символ "§" (\<span>u00a7</span>) работает.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=14204#Chat_Message_.28clientbound.29">Chat Message (clientbound)</a>
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class SChatPacket implements ServerSidePacket {
|
||||||
|
|
||||||
|
private Text message;
|
||||||
|
private ChatPosition position;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeSelf(NetByteBuf netByteBuf) {
|
||||||
|
netByteBuf.writeString(TextSerializer.toJsonObject(this.message).toString());
|
||||||
|
netByteBuf.writeByte(this.position.getCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
package mc.protocol.packets.server;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import mc.protocol.io.NetByteBuf;
|
|
||||||
import mc.protocol.model.text.Text;
|
|
||||||
import mc.protocol.model.text.TextColor;
|
|
||||||
import mc.protocol.model.text.TextStyle;
|
|
||||||
import mc.protocol.packets.ServerSidePacket;
|
|
||||||
import mc.protocol.serializer.TextSerializer;
|
|
||||||
import mc.protocol.utils.TitleAction;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Title packet.
|
|
||||||
*
|
|
||||||
* <p>Структура пакета</p>
|
|
||||||
* <pre>
|
|
||||||
* | FIELD | TYPE | NOTES |
|
|
||||||
* |-------------|-------------|----------------------------------|
|
|
||||||
* | Action | VarInt | Определяет остальные поля пакета |
|
|
||||||
* | Data fields | - | зависят от "Action" |
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* <p>Варианты "Action"</p>
|
|
||||||
* <pre>
|
|
||||||
* | ACTION | FIELD | TYPE | NOTES |
|
|
||||||
* | VALUE | DESCRIPTION | | | |
|
|
||||||
* |-------|-----------------------|-----------------|---------|-------------------------------------------------|
|
|
||||||
* | 0 | set title | Title Text | Text | |
|
|
||||||
* | 1 | set subtitle | Subtitle Text | Text | |
|
|
||||||
* | 2 | set action bar | Action bar text | Text | [*] |
|
|
||||||
* | 3 | set times and display | Fade In | Integer | Время (в тиках (tick)) на эфект появления |
|
|
||||||
* | | | Stay | Integer | Время (в тиках (tick)) на отображение на экране |
|
|
||||||
* | | | Fade Out | Integer | Время (в тиках (tick)) на эфект исчезания |
|
|
||||||
* | 4 | hide | - | - | |
|
|
||||||
* | 5 | reset | - | - | |
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* * - стоит обратить внимание, что {@link TextColor} и {@link TextStyle} не работают: клиент не применяет
|
|
||||||
* стилистику в таком виде. Однако метод через символ "§" (\<span>u00a7</span>) работает.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=14204#Title">Title</a>
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class TitlePacket implements ServerSidePacket {
|
|
||||||
|
|
||||||
private TitleAction action;
|
|
||||||
|
|
||||||
private Text title;
|
|
||||||
private Text subtitle;
|
|
||||||
private Text actionbar;
|
|
||||||
private Integer fadeIn;
|
|
||||||
private Integer stay;
|
|
||||||
private Integer fadeOut;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeSelf(NetByteBuf netByteBuf) {
|
|
||||||
netByteBuf.writeVarInt(this.action.getCode());
|
|
||||||
|
|
||||||
switch (this.action) {
|
|
||||||
case SET_TITLE:
|
|
||||||
netByteBuf.writeString(TextSerializer.toJsonObject(this.title).toString());
|
|
||||||
break;
|
|
||||||
case SET_SUBTITLE:
|
|
||||||
netByteBuf.writeString(TextSerializer.toJsonObject(this.subtitle).toString());
|
|
||||||
break;
|
|
||||||
case SET_ACTIONBAR:
|
|
||||||
netByteBuf.writeString(TextSerializer.toJsonObject(this.actionbar).toString());
|
|
||||||
break;
|
|
||||||
case SET_TIMES_AND_DISPLAY:
|
|
||||||
netByteBuf.writeInt(fadeIn);
|
|
||||||
netByteBuf.writeInt(stay);
|
|
||||||
netByteBuf.writeInt(fadeOut);
|
|
||||||
break;
|
|
||||||
case HIDE:
|
|
||||||
case RESET:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,13 +4,11 @@ import lombok.Getter;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public enum TitleAction {
|
public enum ChatPosition {
|
||||||
SET_TITLE(0),
|
|
||||||
SET_SUBTITLE(1),
|
CHAT(0),
|
||||||
SET_ACTIONBAR(2),
|
SYSTEM(1),
|
||||||
SET_TIMES_AND_DISPLAY(3),
|
HOTBAR(2);
|
||||||
HIDE(4),
|
|
||||||
RESET(5);
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final int code;
|
private final int code;
|
||||||
@@ -8,16 +8,18 @@ import mc.protocol.model.Location;
|
|||||||
import mc.protocol.model.Look;
|
import mc.protocol.model.Look;
|
||||||
import mc.protocol.model.ServerInfo;
|
import mc.protocol.model.ServerInfo;
|
||||||
import mc.protocol.model.text.Text;
|
import mc.protocol.model.text.Text;
|
||||||
|
import mc.protocol.model.text.TextColor;
|
||||||
|
import mc.protocol.model.text.TextStyleLegacy;
|
||||||
import mc.protocol.packets.PingPacket;
|
import mc.protocol.packets.PingPacket;
|
||||||
import mc.protocol.packets.client.HandshakePacket;
|
import mc.protocol.packets.client.HandshakePacket;
|
||||||
import mc.protocol.packets.client.LoginStartPacket;
|
import mc.protocol.packets.client.LoginStartPacket;
|
||||||
import mc.protocol.packets.client.StatusServerRequestPacket;
|
import mc.protocol.packets.client.StatusServerRequestPacket;
|
||||||
import mc.protocol.packets.server.*;
|
import mc.protocol.packets.server.*;
|
||||||
import mc.protocol.serializer.TextSerializer;
|
import mc.protocol.serializer.TextSerializer;
|
||||||
|
import mc.protocol.utils.ChatPosition;
|
||||||
import mc.protocol.utils.Difficulty;
|
import mc.protocol.utils.Difficulty;
|
||||||
import mc.protocol.utils.GameMode;
|
import mc.protocol.utils.GameMode;
|
||||||
import mc.protocol.utils.LevelType;
|
import mc.protocol.utils.LevelType;
|
||||||
import mc.protocol.utils.TitleAction;
|
|
||||||
import mc.server.config.Config;
|
import mc.server.config.Config;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
|
||||||
@@ -127,11 +129,25 @@ public class PacketHandler {
|
|||||||
|
|
||||||
// -- Эксперименты -- //
|
// -- Эксперименты -- //
|
||||||
|
|
||||||
var titlePacket = new TitlePacket();
|
var chatPacket = new SChatPacket();
|
||||||
titlePacket.setAction(TitleAction.SET_TITLE);
|
chatPacket.setMessage(Text.of(TextColor.RED.toLegacy() + "== Hello! =="));
|
||||||
titlePacket.setTitle(Text.of("HELLO"));
|
chatPacket.setPosition(ChatPosition.CHAT);
|
||||||
|
|
||||||
context.sendNow(titlePacket);
|
context.send(chatPacket);
|
||||||
|
|
||||||
|
var systemChatPacket = new SChatPacket();
|
||||||
|
systemChatPacket.setMessage(Text.of(TextColor.RED.toLegacy() + "[SYSTEM]"));
|
||||||
|
systemChatPacket.setPosition(ChatPosition.SYSTEM);
|
||||||
|
|
||||||
|
context.send(systemChatPacket);
|
||||||
|
|
||||||
|
var hotbarChatPacket = new SChatPacket();
|
||||||
|
hotbarChatPacket.setMessage(Text.of(TextColor.RED.toLegacy() + TextStyleLegacy.BOLD.toLegacy() + "In game info"));
|
||||||
|
hotbarChatPacket.setPosition(ChatPosition.HOTBAR);
|
||||||
|
|
||||||
|
context.send(hotbarChatPacket);
|
||||||
|
|
||||||
|
context.flushSending();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String faviconToBase64(Path iconPath) {
|
private static String faviconToBase64(Path iconPath) {
|
||||||
|
|||||||
Reference in New Issue
Block a user