add Hash for Chat Header and PlayerMessage
This commit is contained in:
@ -52,6 +52,16 @@ func (m *MessageHeader) ReadFrom(r io.Reader) (n int64, err error) {
|
|||||||
return n + n3, err
|
return n + n3, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MessageHeader) Hash(bodyHash []byte) []byte {
|
||||||
|
hash := sha256.New()
|
||||||
|
if m.PrevSignature != nil {
|
||||||
|
hash.Write(m.PrevSignature)
|
||||||
|
}
|
||||||
|
hash.Write(m.Sender[:])
|
||||||
|
hash.Write(bodyHash)
|
||||||
|
return hash.Sum(nil)
|
||||||
|
}
|
||||||
|
|
||||||
type MessageBody struct {
|
type MessageBody struct {
|
||||||
PlainMsg string
|
PlainMsg string
|
||||||
DecoratedMsg json.RawMessage
|
DecoratedMsg json.RawMessage
|
||||||
@ -182,6 +192,10 @@ func (msg *PlayerMessage) WriteTo(w io.Writer) (n int64, err error) {
|
|||||||
}.WriteTo(w)
|
}.WriteTo(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (msg *PlayerMessage) Hash() []byte {
|
||||||
|
return msg.MessageHeader.Hash(msg.MessageBody.Hash())
|
||||||
|
}
|
||||||
|
|
||||||
func genSalt() (salt int64) {
|
func genSalt() (salt int64) {
|
||||||
err := binary.Read(rand.Reader, binary.BigEndian, &salt)
|
err := binary.Read(rand.Reader, binary.BigEndian, &salt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -145,6 +145,7 @@ const (
|
|||||||
ClientboundUpdateMobEffect
|
ClientboundUpdateMobEffect
|
||||||
ClientboundUpdateRecipes
|
ClientboundUpdateRecipes
|
||||||
ClientboundUpdateTags
|
ClientboundUpdateTags
|
||||||
|
ClientboundPacketIDGuard
|
||||||
)
|
)
|
||||||
|
|
||||||
// Game Serverbound
|
// Game Serverbound
|
||||||
@ -200,4 +201,5 @@ const (
|
|||||||
ServerboundTeleportToEntity
|
ServerboundTeleportToEntity
|
||||||
ServerboundUseItemOn
|
ServerboundUseItemOn
|
||||||
ServerboundUseItem
|
ServerboundUseItem
|
||||||
|
ServerboundPacketIDGuard
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user