forked from Tnze/go-mc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d174dfb
commit a6f4dc3
Showing
13 changed files
with
181 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,52 @@ | ||
package chat | ||
|
||
import ( | ||
"crypto/rand" | ||
"encoding/binary" | ||
pk "github.com/Edouard127/go-mc/net/packet" | ||
"io" | ||
"time" | ||
) | ||
|
||
type SignedMessage struct { | ||
Message string | ||
Timestamp int64 | ||
Salt int64 | ||
HasSignature bool | ||
Signature []byte | ||
Count int | ||
Ack pk.FixedBitSet | ||
} | ||
|
||
func SignMessage(msg Message, signature []byte) *SignedMessage { | ||
var salt int64 | ||
binary.Read(rand.Reader, binary.BigEndian, &salt) | ||
|
||
return &SignedMessage{ | ||
Message: msg.Text, | ||
Timestamp: time.Now().Unix(), | ||
Salt: salt, | ||
HasSignature: false, | ||
Signature: nil, | ||
Count: 0, | ||
Ack: pk.NewFixedBitSet(20), | ||
} | ||
} | ||
|
||
func (s SignedMessage) WriteTo(w io.Writer) (int64, error) { | ||
return pk.Tuple{ | ||
pk.String(s.Message), | ||
pk.Long(s.Timestamp), | ||
pk.Long(s.Salt), | ||
pk.Boolean(s.HasSignature), | ||
pk.Optional[pk.ByteArray, *pk.ByteArray]{ | ||
Has: s.Signature != nil, | ||
Value: s.Signature, | ||
}, | ||
pk.VarInt(s.Count), | ||
pk.Optional[pk.FixedBitSet, *pk.FixedBitSet]{ | ||
Has: s.Count > 0, | ||
Value: s.Ack, | ||
}, | ||
}.WriteTo(w) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.