Skip to content

如何在新版mc发送命令? #238

Answered by cxzlw
cxzlw asked this question in Q&A
Apr 15, 2023 · 3 comments · 9 replies
Discussion options

You must be logged in to vote

我还没研究过,后面的Message Count和Acknowledged应该和SendMessage这里是一样的

go-mc/bot/msg/chat.go

Lines 171 to 173 in fd4a4bd

sign.HistoryUpdate{
Acknowledged: pk.NewFixedBitSet(20),
},

不过也只是发了一个空的数据过去,还没有完全实现。
前面的Array of argument signatures……不懂,试试发个空数组试试,不行就只能逆向看看了。

空数组工作了,最后工作的代码是这样的

func sendCommand(cmd string) error {
	var salt int64
	if err := binary.Read(rand.Reader, binary.BigEndian, &salt); err != nil {
		return err
	}

	err := client.Conn.WritePacket(pk.Marshal(
		packetid.ServerboundChatCommand,
		pk.String(cmd),
		pk.Long(time.Now().UnixMilli()),
		pk.Long(salt),
		pk.VarInt(0), // signature
		pk.VarInt(0),
		pk.NewFixedBitSet(20),
	))
	return err
}

Replies: 3 comments 9 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
8 replies
@Tnze
Comment options

@cxzlw
Comment options

@patyhank
Comment options

@cxzlw
Comment options

Answer selected by cxzlw
@cxzlw
Comment options

Comment options

You must be logged in to vote
1 reply
@Tnze
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants