Support chat validation
This commit is contained in:
@ -9,6 +9,13 @@ import (
|
||||
pk "github.com/Tnze/go-mc/net/packet"
|
||||
)
|
||||
|
||||
type MessageBody struct {
|
||||
PlainMsg string
|
||||
Timestamp time.Time
|
||||
Salt int64
|
||||
LastSeen []*Signature
|
||||
}
|
||||
|
||||
type PackedMessageBody struct {
|
||||
PlainMsg string
|
||||
Timestamp time.Time
|
||||
@ -37,6 +44,25 @@ func (m *PackedMessageBody) ReadFrom(r io.Reader) (n int64, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (m *PackedMessageBody) Unpack(cache *SignatureCache) (*MessageBody, error) {
|
||||
LastSeen := make([]*Signature, len(m.LastSeen))
|
||||
for i, v := range m.LastSeen {
|
||||
if v.Signature != nil {
|
||||
LastSeen[i] = v.Signature
|
||||
} else if v.ID >= 0 && int(v.ID) < len(cache.signatures) {
|
||||
LastSeen[i] = cache.signatures[v.ID]
|
||||
} else {
|
||||
return nil, UncachedSignature
|
||||
}
|
||||
}
|
||||
return &MessageBody{
|
||||
PlainMsg: m.PlainMsg,
|
||||
Timestamp: m.Timestamp,
|
||||
Salt: m.Salt,
|
||||
LastSeen: LastSeen,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type HistoryMessage struct {
|
||||
Sender uuid.UUID
|
||||
Signature []byte
|
||||
|
Reference in New Issue
Block a user