Update packetid name
This commit is contained in:
@ -18,9 +18,9 @@ type Player struct {
|
||||
func NewPlayer(c *bot.Client, settings Settings) *Player {
|
||||
b := &Player{c: c, Settings: settings}
|
||||
c.Events.AddListener(
|
||||
bot.PacketHandler{Priority: 0, ID: packetid.Login, F: b.handleJoinGamePacket},
|
||||
bot.PacketHandler{Priority: 0, ID: packetid.KeepAliveClientbound, F: b.handleKeepAlivePacket},
|
||||
bot.PacketHandler{Priority: 0, ID: packetid.PositionClientbound, F: b.handlePlayerPositionAndLook},
|
||||
bot.PacketHandler{Priority: 0, ID: packetid.ClientboundLogin, F: b.handleJoinGamePacket},
|
||||
bot.PacketHandler{Priority: 0, ID: packetid.ClientboundKeepAlive, F: b.handleKeepAlivePacket},
|
||||
bot.PacketHandler{Priority: 0, ID: packetid.ClientboundPlayerPosition, F: b.handlePlayerPositionAndLook},
|
||||
)
|
||||
return b
|
||||
}
|
||||
@ -29,7 +29,7 @@ func (p *Player) Respawn() error {
|
||||
const PerformRespawn = 0
|
||||
|
||||
err := p.c.Conn.WritePacket(pk.Marshal(
|
||||
packetid.ClientCommand,
|
||||
packetid.ServerboundClientCommand,
|
||||
pk.VarInt(PerformRespawn),
|
||||
))
|
||||
if err != nil {
|
||||
|
@ -19,10 +19,10 @@ type EventsListener struct {
|
||||
|
||||
func (e EventsListener) Attach(c *bot.Client) {
|
||||
c.Events.AddListener(
|
||||
bot.PacketHandler{Priority: 64, ID: packetid.Login, F: e.onJoinGame},
|
||||
bot.PacketHandler{Priority: 64, ID: packetid.ChatClientbound, F: e.onChatMsg},
|
||||
bot.PacketHandler{Priority: 64, ID: packetid.KickDisconnect, F: e.onDisconnect},
|
||||
bot.PacketHandler{Priority: 64, ID: packetid.UpdateHealth, F: e.onUpdateHealth},
|
||||
bot.PacketHandler{Priority: 64, ID: packetid.ClientboundLogin, F: e.onJoinGame},
|
||||
bot.PacketHandler{Priority: 64, ID: packetid.ClientboundChat, F: e.onChatMsg},
|
||||
bot.PacketHandler{Priority: 64, ID: packetid.ClientboundDisconnect, F: e.onDisconnect},
|
||||
bot.PacketHandler{Priority: 64, ID: packetid.ClientboundSetHealth, F: e.onUpdateHealth},
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ func (p *Player) handleJoinGamePacket(packet pk.Packet) error {
|
||||
p.WorldNames = *(*[]string)(unsafe.Pointer(&WorldNames))
|
||||
|
||||
err = p.c.Conn.WritePacket(pk.Marshal( //PluginMessage packet
|
||||
packetid.CustomPayloadServerbound,
|
||||
packetid.ServerboundCustomPayload,
|
||||
pk.Identifier("minecraft:brand"),
|
||||
pk.String(p.Settings.Brand),
|
||||
))
|
||||
@ -82,7 +82,7 @@ func (p *Player) handleJoinGamePacket(packet pk.Packet) error {
|
||||
}
|
||||
|
||||
err = p.c.Conn.WritePacket(pk.Marshal(
|
||||
packetid.Settings, // Client settings
|
||||
packetid.ServerboundClientInformation, // Client settings
|
||||
pk.String(p.Settings.Locale),
|
||||
pk.Byte(p.Settings.ViewDistance),
|
||||
pk.VarInt(p.Settings.ChatMode),
|
||||
|
@ -12,7 +12,7 @@ func (p Player) handleKeepAlivePacket(packet pk.Packet) error {
|
||||
}
|
||||
// Response
|
||||
err := p.c.Conn.WritePacket(pk.Packet{
|
||||
ID: packetid.KeepAliveServerbound,
|
||||
ID: packetid.ServerboundKeepAlive,
|
||||
Data: packet.Data,
|
||||
})
|
||||
if err != nil {
|
||||
@ -35,7 +35,7 @@ func (p *Player) handlePlayerPositionAndLook(packet pk.Packet) error {
|
||||
|
||||
// Teleport Confirm
|
||||
err := p.c.Conn.WritePacket(pk.Marshal(
|
||||
packetid.TeleportConfirm,
|
||||
packetid.ServerboundAcceptTeleportation,
|
||||
TeleportID,
|
||||
))
|
||||
if err != nil {
|
||||
@ -45,7 +45,7 @@ func (p *Player) handlePlayerPositionAndLook(packet pk.Packet) error {
|
||||
if !p.isSpawn {
|
||||
// PlayerPositionAndRotation to confirm the spawn position
|
||||
err = p.c.Conn.WritePacket(pk.Marshal(
|
||||
packetid.PositionLook,
|
||||
packetid.ServerboundMoveVehicle,
|
||||
X, Y-1.62, Z,
|
||||
Yaw, Pitch,
|
||||
pk.Boolean(true),
|
||||
|
@ -111,7 +111,7 @@ func (c *Client) join(d *net.Dialer, addr string) error {
|
||||
|
||||
//Handle Packet
|
||||
switch p.ID {
|
||||
case packetid.Disconnect: //Disconnect
|
||||
case packetid.LoginDisconnect: //LoginDisconnect
|
||||
var reason chat.Message
|
||||
err = p.Scan(&reason)
|
||||
if err != nil {
|
||||
@ -119,12 +119,12 @@ func (c *Client) join(d *net.Dialer, addr string) error {
|
||||
}
|
||||
return LoginErr{"disconnect", DisconnectErr(reason)}
|
||||
|
||||
case packetid.EncryptionBeginClientbound: //Encryption Request
|
||||
case packetid.LoginEncryptionRequest: //Encryption Request
|
||||
if err := handleEncryptionRequest(c, p); err != nil {
|
||||
return LoginErr{"encryption", err}
|
||||
}
|
||||
|
||||
case packetid.Success: //Login Success
|
||||
case packetid.LoginSuccess: //Login Success
|
||||
err := p.Scan(
|
||||
(*pk.UUID)(&c.UUID),
|
||||
(*pk.String)(&c.Name),
|
||||
@ -134,7 +134,7 @@ func (c *Client) join(d *net.Dialer, addr string) error {
|
||||
}
|
||||
return nil
|
||||
|
||||
case packetid.Compress: //Set Compression
|
||||
case packetid.SetCompression: //Set Compression
|
||||
var threshold pk.VarInt
|
||||
if err := p.Scan(&threshold); err != nil {
|
||||
return LoginErr{"compression", err}
|
||||
|
@ -77,7 +77,7 @@ func pingAndList(addr string, conn *mcnet.Conn) ([]byte, time.Duration, error) {
|
||||
//LIST
|
||||
//请求服务器状态
|
||||
err = conn.WritePacket(pk.Marshal(
|
||||
packetid.PingStart,
|
||||
packetid.StatusRequest,
|
||||
))
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("bot: send list packect fail: %v", err)
|
||||
@ -97,7 +97,7 @@ func pingAndList(addr string, conn *mcnet.Conn) ([]byte, time.Duration, error) {
|
||||
//PING
|
||||
startTime := time.Now()
|
||||
err = conn.WritePacket(pk.Marshal(
|
||||
packetid.PingServerbound,
|
||||
packetid.StatusPing,
|
||||
pk.Long(startTime.Unix()),
|
||||
))
|
||||
if err != nil {
|
||||
|
@ -25,10 +25,10 @@ func NewManager(c *bot.Client, e EventsListener) *Manager {
|
||||
}
|
||||
m.Screens[0] = &m.Inventory
|
||||
c.Events.AddListener(
|
||||
bot.PacketHandler{Priority: 0, ID: packetid.OpenWindow, F: m.onOpenScreen},
|
||||
bot.PacketHandler{Priority: 0, ID: packetid.WindowItems, F: m.onSetContentPacket},
|
||||
bot.PacketHandler{Priority: 0, ID: packetid.CloseWindowClientbound, F: m.onCloseScreen},
|
||||
bot.PacketHandler{Priority: 0, ID: packetid.SetSlot, F: m.onSetSlot},
|
||||
bot.PacketHandler{Priority: 0, ID: packetid.ClientboundOpenScreen, F: m.onOpenScreen},
|
||||
bot.PacketHandler{Priority: 0, ID: packetid.ClientboundContainerSetContent, F: m.onSetContentPacket},
|
||||
bot.PacketHandler{Priority: 0, ID: packetid.ClientboundContainerClose, F: m.onCloseScreen},
|
||||
bot.PacketHandler{Priority: 0, ID: packetid.ClientboundContainerSetSlot, F: m.onSetSlot},
|
||||
)
|
||||
return m
|
||||
}
|
||||
|
@ -1,187 +0,0 @@
|
||||
//go:build generate
|
||||
// +build generate
|
||||
|
||||
//gen_packetid.go generates the enumeration of packet IDs used on the wire.
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"text/template"
|
||||
|
||||
"github.com/iancoleman/strcase"
|
||||
)
|
||||
|
||||
const (
|
||||
version = "1.17.1"
|
||||
protocolURL = "https://raw.githubusercontent.com/PrismarineJS/minecraft-data/master/data/pc/" + version + "/protocol.json"
|
||||
//language=gohtml
|
||||
packetidTmpl = `// This file is automatically generated by gen_packetIDs.go. DO NOT EDIT.
|
||||
|
||||
package packetid
|
||||
|
||||
// Login state
|
||||
const (
|
||||
// Clientbound
|
||||
{{range $ID, $Name := .Login.Clientbound}} {{$Name}} = {{$ID | printf "%#x"}}
|
||||
{{end}}
|
||||
// Serverbound
|
||||
{{range $ID, $Name := .Login.Serverbound}} {{$Name}} = {{$ID | printf "%#x"}}
|
||||
{{end}}
|
||||
)
|
||||
|
||||
// Ping state
|
||||
const (
|
||||
// Clientbound
|
||||
{{range $ID, $Name := .Status.Clientbound}} {{$Name}} = {{$ID | printf "%#x"}}
|
||||
{{end}}
|
||||
// Serverbound
|
||||
{{range $ID, $Name := .Status.Serverbound}} {{$Name}} = {{$ID | printf "%#x"}}
|
||||
{{end}}
|
||||
)
|
||||
|
||||
// Play state
|
||||
const (
|
||||
// Clientbound
|
||||
{{range $ID, $Name := .Play.Clientbound}} {{$Name}} = {{$ID | printf "%#x"}}
|
||||
{{end}}
|
||||
// Serverbound
|
||||
{{range $ID, $Name := .Play.Serverbound}} {{$Name}} = {{$ID | printf "%#x"}}
|
||||
{{end}}
|
||||
)
|
||||
`
|
||||
)
|
||||
|
||||
// unnest is a utility function to unpack a value from a nested map, given
|
||||
// an arbitrary set of keys to reach through.
|
||||
func unnest(input map[string]interface{}, keys ...string) (map[string]interface{}, error) {
|
||||
for _, k := range keys {
|
||||
sub, ok := input[k]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("key %q not found", k)
|
||||
}
|
||||
next, ok := sub.(map[string]interface{})
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("key %q was %T, expected a string map", k, sub)
|
||||
}
|
||||
input = next
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
type duplexMappings struct {
|
||||
Clientbound map[int32]string
|
||||
Serverbound map[int32]string
|
||||
}
|
||||
|
||||
func (m *duplexMappings) EnsureUniqueNames() {
|
||||
// Assemble a slice of keys to check across both maps, because we cannot
|
||||
// mutate a map while iterating it.
|
||||
clientBounds := make(map[string]int32)
|
||||
for sk, sv := range m.Clientbound {
|
||||
clientBounds[sv] = sk
|
||||
}
|
||||
for sk, sv := range m.Serverbound {
|
||||
if ck, ok := clientBounds[sv]; ok {
|
||||
m.Clientbound[ck] = sv + "Clientbound"
|
||||
m.Serverbound[sk] = sv + "Serverbound"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unpackMapping returns the set of packet IDs and their names for a given
|
||||
// game state.
|
||||
func unpackMapping(data map[string]interface{}, gameState string) (duplexMappings, error) {
|
||||
out := duplexMappings{
|
||||
Clientbound: make(map[int32]string),
|
||||
Serverbound: make(map[int32]string),
|
||||
}
|
||||
|
||||
info, err := unnest(data, gameState, "toClient", "types")
|
||||
if err != nil {
|
||||
return duplexMappings{}, err
|
||||
}
|
||||
pType := info["packet"].([]interface{})[1].([]interface{})[0].(map[string]interface{})["type"]
|
||||
mappings := pType.([]interface{})[1].(map[string]interface{})["mappings"].(map[string]interface{})
|
||||
for k, v := range mappings {
|
||||
out.Clientbound[mustAtoi(k)] = strcase.ToCamel(v.(string))
|
||||
}
|
||||
info, err = unnest(data, gameState, "toServer", "types")
|
||||
if err != nil {
|
||||
return duplexMappings{}, err
|
||||
}
|
||||
pType = info["packet"].([]interface{})[1].([]interface{})[0].(map[string]interface{})["type"]
|
||||
mappings = pType.([]interface{})[1].(map[string]interface{})["mappings"].(map[string]interface{})
|
||||
for k, v := range mappings {
|
||||
out.Serverbound[mustAtoi(k)] = strcase.ToCamel(v.(string))
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func mustAtoi(num string) int32 {
|
||||
if n, err := strconv.ParseInt(num, 0, 32); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return int32(n)
|
||||
}
|
||||
}
|
||||
|
||||
type protocolIDs struct {
|
||||
Login duplexMappings
|
||||
Play duplexMappings
|
||||
Status duplexMappings
|
||||
// Handshake state has no packets
|
||||
}
|
||||
|
||||
func downloadInfo() (*protocolIDs, error) {
|
||||
resp, err := http.Get(protocolURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
var data map[string]interface{}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var out protocolIDs
|
||||
if out.Login, err = unpackMapping(data, "login"); err != nil {
|
||||
return nil, fmt.Errorf("login: %v", err)
|
||||
}
|
||||
out.Login.EnsureUniqueNames()
|
||||
if out.Play, err = unpackMapping(data, "play"); err != nil {
|
||||
return nil, fmt.Errorf("play: %v", err)
|
||||
}
|
||||
out.Play.EnsureUniqueNames()
|
||||
if out.Status, err = unpackMapping(data, "status"); err != nil {
|
||||
return nil, fmt.Errorf("play: %v", err)
|
||||
}
|
||||
out.Status.EnsureUniqueNames()
|
||||
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
//go:generate go run $GOFILE
|
||||
//go:generate go fmt packetid.go
|
||||
func main() {
|
||||
fmt.Println("generating packetid.go")
|
||||
pIDs, err := downloadInfo()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
f, err := os.Create("packetid.go")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
tmpl := template.Must(template.New("packetIDs").Parse(packetidTmpl))
|
||||
if err := tmpl.Execute(f, pIDs); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
@ -1,187 +1,179 @@
|
||||
// This file is automatically generated by gen_packetIDs.go. DO NOT EDIT.
|
||||
|
||||
package packetid
|
||||
|
||||
// Login state
|
||||
// Login Clientbound
|
||||
const (
|
||||
// Clientbound
|
||||
Disconnect = 0x0
|
||||
EncryptionBeginClientbound = 0x1
|
||||
Success = 0x2
|
||||
Compress = 0x3
|
||||
LoginPluginRequest = 0x4
|
||||
|
||||
// Serverbound
|
||||
LoginStart = 0x0
|
||||
EncryptionBeginServerbound = 0x1
|
||||
LoginPluginResponse = 0x2
|
||||
LoginDisconnect = iota
|
||||
LoginEncryptionRequest
|
||||
LoginSuccess
|
||||
SetCompression
|
||||
LoginPluginRequest
|
||||
)
|
||||
|
||||
// Ping state
|
||||
// Login Serverbound
|
||||
const (
|
||||
// Clientbound
|
||||
ServerInfo = 0x0
|
||||
PingClientbound = 0x1
|
||||
|
||||
// Serverbound
|
||||
PingStart = 0x0
|
||||
PingServerbound = 0x1
|
||||
LoginStart = iota
|
||||
LoginEncryptionResponse
|
||||
LoginPluginResponse
|
||||
)
|
||||
|
||||
// Play state
|
||||
// Status Clientbound
|
||||
const (
|
||||
// Clientbound
|
||||
SpawnEntity = 0x0
|
||||
SpawnEntityExperienceOrb = 0x1
|
||||
SpawnEntityLiving = 0x2
|
||||
SpawnEntityPainting = 0x3
|
||||
NamedEntitySpawn = 0x4
|
||||
SculkVibrationSignal = 0x5
|
||||
Animation = 0x6
|
||||
Statistics = 0x7
|
||||
AcknowledgePlayerDigging = 0x8
|
||||
BlockBreakAnimation = 0x9
|
||||
TileEntityData = 0xa
|
||||
BlockAction = 0xb
|
||||
BlockChange = 0xc
|
||||
BossBar = 0xd
|
||||
Difficulty = 0xe
|
||||
ChatClientbound = 0xf
|
||||
ClearTitles = 0x10
|
||||
TabCompleteClientbound = 0x11
|
||||
DeclareCommands = 0x12
|
||||
CloseWindowClientbound = 0x13
|
||||
WindowItems = 0x14
|
||||
CraftProgressBar = 0x15
|
||||
SetSlot = 0x16
|
||||
SetCooldown = 0x17
|
||||
CustomPayloadClientbound = 0x18
|
||||
NamedSoundEffect = 0x19
|
||||
KickDisconnect = 0x1a
|
||||
EntityStatus = 0x1b
|
||||
Explosion = 0x1c
|
||||
UnloadChunk = 0x1d
|
||||
GameStateChange = 0x1e
|
||||
OpenHorseWindow = 0x1f
|
||||
InitializeWorldBorder = 0x20
|
||||
KeepAliveClientbound = 0x21
|
||||
MapChunk = 0x22
|
||||
WorldEvent = 0x23
|
||||
WorldParticles = 0x24
|
||||
UpdateLight = 0x25
|
||||
Login = 0x26
|
||||
Map = 0x27
|
||||
TradeList = 0x28
|
||||
RelEntityMove = 0x29
|
||||
EntityMoveLook = 0x2a
|
||||
EntityLook = 0x2b
|
||||
VehicleMoveClientbound = 0x2c
|
||||
OpenBook = 0x2d
|
||||
OpenWindow = 0x2e
|
||||
OpenSignEntity = 0x2f
|
||||
Ping = 0x30
|
||||
CraftRecipeResponse = 0x31
|
||||
AbilitiesClientbound = 0x32
|
||||
EndCombatEvent = 0x33
|
||||
EnterCombatEvent = 0x34
|
||||
DeathCombatEvent = 0x35
|
||||
PlayerInfo = 0x36
|
||||
FacePlayer = 0x37
|
||||
PositionClientbound = 0x38
|
||||
UnlockRecipes = 0x39
|
||||
DestroyEntity = 0x3a
|
||||
RemoveEntityEffect = 0x3b
|
||||
ResourcePackSend = 0x3c
|
||||
Respawn = 0x3d
|
||||
EntityHeadRotation = 0x3e
|
||||
MultiBlockChange = 0x3f
|
||||
SelectAdvancementTab = 0x40
|
||||
ActionBar = 0x41
|
||||
WorldBorderCenter = 0x42
|
||||
WorldBorderLerpSize = 0x43
|
||||
WorldBorderSize = 0x44
|
||||
WorldBorderWarningDelay = 0x45
|
||||
WorldBorderWarningReach = 0x46
|
||||
Camera = 0x47
|
||||
HeldItemSlotClientbound = 0x48
|
||||
UpdateViewPosition = 0x49
|
||||
UpdateViewDistance = 0x4a
|
||||
SpawnPosition = 0x4b
|
||||
ScoreboardDisplayObjective = 0x4c
|
||||
EntityMetadata = 0x4d
|
||||
AttachEntity = 0x4e
|
||||
EntityVelocity = 0x4f
|
||||
EntityEquipment = 0x50
|
||||
Experience = 0x51
|
||||
UpdateHealth = 0x52
|
||||
ScoreboardObjective = 0x53
|
||||
SetPassengers = 0x54
|
||||
Teams = 0x55
|
||||
ScoreboardScore = 0x56
|
||||
SetTitleSubtitle = 0x57
|
||||
UpdateTime = 0x58
|
||||
SetTitleText = 0x59
|
||||
SetTitleTime = 0x5a
|
||||
EntitySoundEffect = 0x5b
|
||||
SoundEffect = 0x5c
|
||||
StopSound = 0x5d
|
||||
PlayerlistHeader = 0x5e
|
||||
NbtQueryResponse = 0x5f
|
||||
Collect = 0x60
|
||||
EntityTeleport = 0x61
|
||||
Advancements = 0x62
|
||||
EntityUpdateAttributes = 0x63
|
||||
EntityEffect = 0x64
|
||||
DeclareRecipes = 0x65
|
||||
Tags = 0x66
|
||||
|
||||
// Serverbound
|
||||
TeleportConfirm = 0x0
|
||||
QueryBlockNbt = 0x1
|
||||
SetDifficulty = 0x2
|
||||
ChatServerbound = 0x3
|
||||
ClientCommand = 0x4
|
||||
Settings = 0x5
|
||||
TabCompleteServerbound = 0x6
|
||||
EnchantItem = 0x7
|
||||
WindowClick = 0x8
|
||||
CloseWindowServerbound = 0x9
|
||||
CustomPayloadServerbound = 0xa
|
||||
EditBook = 0xb
|
||||
QueryEntityNbt = 0xc
|
||||
UseEntity = 0xd
|
||||
GenerateStructure = 0xe
|
||||
KeepAliveServerbound = 0xf
|
||||
LockDifficulty = 0x10
|
||||
PositionServerbound = 0x11
|
||||
PositionLook = 0x12
|
||||
Look = 0x13
|
||||
Flying = 0x14
|
||||
VehicleMoveServerbound = 0x15
|
||||
SteerBoat = 0x16
|
||||
PickItem = 0x17
|
||||
CraftRecipeRequest = 0x18
|
||||
AbilitiesServerbound = 0x19
|
||||
BlockDig = 0x1a
|
||||
EntityAction = 0x1b
|
||||
SteerVehicle = 0x1c
|
||||
Pong = 0x1d
|
||||
DisplayedRecipe = 0x1e
|
||||
RecipeBook = 0x1f
|
||||
NameItem = 0x20
|
||||
ResourcePackReceive = 0x21
|
||||
AdvancementTab = 0x22
|
||||
SelectTrade = 0x23
|
||||
SetBeaconEffect = 0x24
|
||||
HeldItemSlotServerbound = 0x25
|
||||
UpdateCommandBlock = 0x26
|
||||
UpdateCommandBlockMinecart = 0x27
|
||||
SetCreativeSlot = 0x28
|
||||
UpdateJigsawBlock = 0x29
|
||||
UpdateStructureBlock = 0x2a
|
||||
UpdateSign = 0x2b
|
||||
ArmAnimation = 0x2c
|
||||
Spectate = 0x2d
|
||||
BlockPlace = 0x2e
|
||||
UseItem = 0x2f
|
||||
StatusResponse = iota
|
||||
StatusPong
|
||||
)
|
||||
|
||||
// Game Serverbound
|
||||
const (
|
||||
StatusRequest = iota
|
||||
StatusPing
|
||||
)
|
||||
|
||||
// Game Clientbound
|
||||
const (
|
||||
ClientboundAddEntity = iota
|
||||
ClientboundAddExperienceOrb
|
||||
ClientboundAddMob
|
||||
ClientboundAddPainting
|
||||
ClientboundAddPlayer
|
||||
ClientboundAddVibrationSignal
|
||||
ClientboundAnimate
|
||||
ClientboundAwardStats
|
||||
ClientboundBlockBreakAck
|
||||
ClientboundBlockDestruction
|
||||
ClientboundBlockEntityData
|
||||
ClientboundBlockEvent
|
||||
ClientboundBlockUpdate
|
||||
ClientboundBossEvent
|
||||
ClientboundChangeDifficulty
|
||||
ClientboundChat
|
||||
ClientboundClearTitles
|
||||
ClientboundCommandSuggestions
|
||||
ClientboundCommands
|
||||
ClientboundContainerClose
|
||||
ClientboundContainerSetContent
|
||||
ClientboundContainerSetData
|
||||
ClientboundContainerSetSlot
|
||||
ClientboundCooldown
|
||||
ClientboundCustomPayload
|
||||
ClientboundCustomSound
|
||||
ClientboundDisconnect
|
||||
ClientboundEntityEvent
|
||||
ClientboundExplode
|
||||
ClientboundForgetLevelChunk
|
||||
ClientboundGameEvent
|
||||
ClientboundHorseScreenOpen
|
||||
ClientboundInitializeBorder
|
||||
ClientboundKeepAlive
|
||||
ClientboundLevelChunk
|
||||
ClientboundLevelEvent
|
||||
ClientboundLevelParticles
|
||||
ClientboundLightUpdate
|
||||
ClientboundLogin
|
||||
ClientboundMapItemData
|
||||
ClientboundMerchantOffers
|
||||
ClientboundMoveVehicle
|
||||
ClientboundOpenBook
|
||||
ClientboundOpenScreen
|
||||
ClientboundOpenSignEditor
|
||||
ClientboundPing
|
||||
ClientboundPlaceGhostRecipe
|
||||
ClientboundPlayerAbilities
|
||||
ClientboundPlayerCombatEnd
|
||||
ClientboundPlayerCombatEnter
|
||||
ClientboundPlayerCombatKill
|
||||
ClientboundPlayerInfo
|
||||
ClientboundPlayerLookAt
|
||||
ClientboundPlayerPosition
|
||||
ClientboundRecipe
|
||||
ClientboundRemoveEntities
|
||||
ClientboundRemoveMobEffect
|
||||
ClientboundResourcePack
|
||||
ClientboundRespawn
|
||||
ClientboundRotateHead
|
||||
ClientboundSectionBlocksUpdate
|
||||
ClientboundSelectAdvancementsTab
|
||||
ClientboundSetActionBarText
|
||||
ClientboundSetBorderCenter
|
||||
ClientboundSetBorderLerpSize
|
||||
ClientboundSetBorderSize
|
||||
ClientboundSetBorderWarningDelay
|
||||
ClientboundSetBorderWarningDistance
|
||||
ClientboundSetCamera
|
||||
ClientboundSetCarriedItem
|
||||
ClientboundSetChunkCacheCenter
|
||||
ClientboundSetChunkCacheRadius
|
||||
ClientboundSetDefaultSpawnPosition
|
||||
ClientboundSetDisplayObjective
|
||||
ClientboundSetEntityData
|
||||
ClientboundSetEntityLink
|
||||
ClientboundSetEntityMotion
|
||||
ClientboundSetEquipment
|
||||
ClientboundSetExperience
|
||||
ClientboundSetHealth
|
||||
ClientboundSetObjective
|
||||
ClientboundSetPassengers
|
||||
ClientboundSetPlayerTeam
|
||||
ClientboundSetScore
|
||||
ClientboundSetSubtitleText
|
||||
ClientboundSetTime
|
||||
ClientboundSetTitleText
|
||||
ClientboundSetTitlesAnimation
|
||||
ClientboundSoundEntity
|
||||
ClientboundSound
|
||||
ClientboundStopSound
|
||||
ClientboundTabList
|
||||
ClientboundTagQuery
|
||||
ClientboundTakeItemEntity
|
||||
ClientboundTeleportEntity
|
||||
ClientboundUpdateAdvancements
|
||||
ClientboundUpdateAttributes
|
||||
ClientboundUpdateMobEffect
|
||||
ClientboundUpdateRecipes
|
||||
ClientboundUpdateTags
|
||||
)
|
||||
|
||||
// Game Serverbound
|
||||
const (
|
||||
ServerboundAcceptTeleportation = iota
|
||||
ServerboundChangeDifficulty
|
||||
ServerboundChat
|
||||
ServerboundClientCommand
|
||||
ServerboundClientInformation
|
||||
ServerboundCommandSuggestion
|
||||
ServerboundContainerButtonClick
|
||||
ServerboundContainerClick
|
||||
ServerboundContainerClose
|
||||
ServerboundCustomPayload
|
||||
ServerboundEditBook
|
||||
ServerboundInteract
|
||||
ServerboundJigsawGenerate
|
||||
ServerboundKeepAlive
|
||||
ServerboundLockDifficulty
|
||||
ServerboundMoveVehicle
|
||||
ServerboundPaddleBoat
|
||||
ServerboundPickItem
|
||||
ServerboundPlaceRecipe
|
||||
ServerboundPlayerAbilities
|
||||
ServerboundPlayerAction
|
||||
ServerboundPlayerCommand
|
||||
ServerboundPlayerInput
|
||||
ServerboundPong
|
||||
ServerboundRecipeBookChangeSettings
|
||||
ServerboundRecipeBookSeenRecipe
|
||||
ServerboundRenameItem
|
||||
ServerboundResourcePack
|
||||
ServerboundSeenAdvancements
|
||||
ServerboundSelectTrade
|
||||
ServerboundSetBeacon
|
||||
ServerboundSetCarriedItem
|
||||
ServerboundSetCommandBlock
|
||||
ServerboundSetCommandMinecart
|
||||
ServerboundSetCreativeModeSlot
|
||||
ServerboundSetJigsawBlock
|
||||
ServerboundSetStructureBlock
|
||||
ServerboundSignUpdate
|
||||
ServerboundSwing
|
||||
ServerboundTeleportToEntity
|
||||
ServerboundUseItemOn
|
||||
ServerboundUseItem
|
||||
)
|
||||
|
@ -68,7 +68,7 @@ func onGameStart() error {
|
||||
}
|
||||
|
||||
var soundListener = bot.PacketHandler{
|
||||
ID: packetid.SoundEffect,
|
||||
ID: packetid.ClientboundSound,
|
||||
Priority: 0,
|
||||
F: func(p pk.Packet) error {
|
||||
var (
|
||||
@ -86,7 +86,7 @@ var soundListener = bot.PacketHandler{
|
||||
|
||||
func UseItem(hand int32) error {
|
||||
return c.Conn.WritePacket(pk.Marshal(
|
||||
packetid.UseItem,
|
||||
packetid.ServerboundUseItem,
|
||||
pk.VarInt(hand),
|
||||
))
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ func (m *MyServer) AcceptPlayer(name string, id uuid.UUID, protocol int32, conn
|
||||
ID: id,
|
||||
})
|
||||
if remove == nil {
|
||||
err := conn.WritePacket(pk.Marshal(packetid.KickDisconnect,
|
||||
err := conn.WritePacket(pk.Marshal(packetid.ClientboundDisconnect,
|
||||
chat.TranslateMsg("multiplayer.disconnect.server_full"),
|
||||
))
|
||||
if err != nil {
|
||||
@ -83,7 +83,7 @@ var dimensionCodecSNBT string
|
||||
var dimensionSNBT string
|
||||
|
||||
func (m *MyServer) joinGame(conn *net.Conn) error {
|
||||
return conn.WritePacket(pk.Marshal(packetid.Login,
|
||||
return conn.WritePacket(pk.Marshal(packetid.ClientboundLogin,
|
||||
pk.Int(0), // EntityID
|
||||
pk.Boolean(false), // Is hardcore
|
||||
pk.UnsignedByte(1), // Gamemode
|
||||
@ -105,8 +105,7 @@ func (m *MyServer) joinGame(conn *net.Conn) error {
|
||||
}
|
||||
|
||||
func (m *MyServer) playerPositionAndLook(conn *net.Conn) error {
|
||||
return conn.WritePacket(pk.Marshal(packetid.PositionClientbound,
|
||||
// https://wiki.vg/index.php?title=Protocol&oldid=16067#Player_Position_And_Look_.28clientbound.29
|
||||
return conn.WritePacket(pk.Marshal(packetid.ClientboundPlayerPosition,
|
||||
pk.Double(0), pk.Double(0), pk.Double(0), // XYZ
|
||||
pk.Float(0), pk.Float(0), // Yaw Pitch
|
||||
pk.Byte(0), // flag
|
||||
|
@ -1,12 +1,8 @@
|
||||
package save
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/Tnze/go-mc/data/packetid"
|
||||
pk "github.com/Tnze/go-mc/net/packet"
|
||||
"github.com/Tnze/go-mc/save/region"
|
||||
"testing"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func TestColumn(t *testing.T) {
|
||||
@ -54,74 +50,3 @@ func BenchmarkColumn_Load(b *testing.B) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleColumn_send() {
|
||||
r, err := region.Open("/path/to/r.0.0.mca")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
chunkPos := [2]int{0, 0}
|
||||
data, err := r.ReadSector(chunkPos[0], chunkPos[1])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var c Column
|
||||
if err := c.Load(data); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
var PrimaryBitMask pk.VarInt
|
||||
for _, v := range c.Level.Sections {
|
||||
if int8(v.Y) >= 0 && int8(v.Y) < 16 {
|
||||
PrimaryBitMask |= 1 << v.Y
|
||||
|
||||
bpb := len(v.BlockStates) * 64 / (16 * 16 * 16)
|
||||
hasPalette := pk.Boolean(bpb >= 9)
|
||||
paletteLength := pk.VarInt(len(v.Palette))
|
||||
dataArrayLength := pk.VarInt(len(v.BlockStates))
|
||||
dataArray := (*[]pk.Long)(unsafe.Pointer(&v.BlockStates))
|
||||
_, err := pk.Tuple{
|
||||
pk.Short(0), // Block count
|
||||
pk.UnsignedByte(bpb), // Bits Per Block
|
||||
hasPalette, pk.Opt{
|
||||
Has: &hasPalette,
|
||||
Field: pk.Tuple{
|
||||
paletteLength, pk.Ary{
|
||||
Len: &paletteLength,
|
||||
Ary: nil, // TODO: We need translate v.Palette (with type of []Block) to state ID
|
||||
},
|
||||
},
|
||||
}, // Palette
|
||||
dataArrayLength, pk.Ary{
|
||||
Len: &dataArrayLength,
|
||||
Ary: dataArray,
|
||||
}, // Data Array
|
||||
}.WriteTo(&buf)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size := pk.VarInt(buf.Len())
|
||||
bal := pk.VarInt(len(c.Level.Biomes))
|
||||
_ = pk.Marshal(
|
||||
packetid.WorldParticles,
|
||||
pk.Int(chunkPos[0]), // Chunk X
|
||||
pk.Int(chunkPos[1]), // Chunk Y
|
||||
pk.Boolean(true), // Full chunk
|
||||
PrimaryBitMask, // PrimaryBitMask
|
||||
pk.NBT(c.Level.Heightmaps), // Heightmaps
|
||||
bal, pk.Ary{
|
||||
Len: bal, // Biomes array length
|
||||
Ary: *(*[]pk.VarInt)(unsafe.Pointer(&c.Level.Biomes)), // Biomes
|
||||
},
|
||||
size, pk.Ary{
|
||||
Len: size, // Size
|
||||
Ary: pk.ByteArray(buf.Bytes()), // Data
|
||||
},
|
||||
pk.VarInt(0), // Block entities array length
|
||||
)
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ func encryptionRequest(conn *net.Conn, publicKey []byte) ([]byte, error) {
|
||||
return nil, err
|
||||
}
|
||||
err = conn.WritePacket(pk.Marshal(
|
||||
packetid.EncryptionBeginClientbound,
|
||||
packetid.LoginEncryptionRequest,
|
||||
pk.String(""),
|
||||
pk.ByteArray(publicKey),
|
||||
pk.ByteArray(verifyToken[:]),
|
||||
@ -103,7 +103,7 @@ func encryptionResponse(conn *net.Conn) ([]byte, []byte, error) {
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if p.ID != packetid.EncryptionBeginServerbound {
|
||||
if p.ID != packetid.LoginEncryptionResponse {
|
||||
return nil, nil, fmt.Errorf("0x%02X is not Encryption Response", p.ID)
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ func (d *MojangLoginHandler) AcceptLogin(conn *net.Conn, protocol int32) (name s
|
||||
//set compression
|
||||
if d.Threshold >= 0 {
|
||||
err = conn.WritePacket(pk.Marshal(
|
||||
packetid.Compress, pk.VarInt(d.Threshold),
|
||||
packetid.SetCompression, pk.VarInt(d.Threshold),
|
||||
))
|
||||
if err != nil {
|
||||
return
|
||||
@ -64,7 +64,7 @@ func (d *MojangLoginHandler) AcceptLogin(conn *net.Conn, protocol int32) (name s
|
||||
}
|
||||
|
||||
// send login success
|
||||
err = conn.WritePacket(pk.Marshal(packetid.Success,
|
||||
err = conn.WritePacket(pk.Marshal(packetid.LoginSuccess,
|
||||
pk.UUID(id),
|
||||
pk.String(name),
|
||||
))
|
||||
|
@ -33,14 +33,14 @@ func (s *Server) acceptListPing(conn *net.Conn) {
|
||||
}
|
||||
|
||||
switch p.ID {
|
||||
case packetid.ServerInfo: //List
|
||||
case packetid.StatusResponse: //List
|
||||
var resp []byte
|
||||
resp, err = s.listResp()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
err = conn.WritePacket(pk.Marshal(0x00, pk.String(resp)))
|
||||
case packetid.PingClientbound: //Ping
|
||||
case packetid.StatusPong: //Ping
|
||||
err = conn.WritePacket(p)
|
||||
}
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user