X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/5954ccad9c87063231f3a8bb3e5d01675a9865ca..45ca5d60383cbe270624c713b916da29af7ba88f:/hotline/tracker.go diff --git a/hotline/tracker.go b/hotline/tracker.go index 6ee2a9f..8f8ddd1 100644 --- a/hotline/tracker.go +++ b/hotline/tracker.go @@ -18,6 +18,8 @@ type TrackerRegistration struct { PassID [4]byte // Random number generated by the server Name string // Server Name Description string // Description of the server + + readOffset int // Internal offset to track read progress } // Read implements io.Reader to write tracker registration payload bytes to slice @@ -25,7 +27,7 @@ func (tr *TrackerRegistration) Read(p []byte) (int, error) { userCount := make([]byte, 2) binary.BigEndian.PutUint16(userCount, uint16(tr.UserCount)) - return copy(p, slices.Concat( + buf := slices.Concat( []byte{0x00, 0x01}, // Magic number, always 1 tr.Port[:], userCount, @@ -35,7 +37,16 @@ func (tr *TrackerRegistration) Read(p []byte) (int, error) { []byte(tr.Name), []byte{uint8(len(tr.Description))}, []byte(tr.Description), - )[:]), io.EOF + ) + + if tr.readOffset >= len(buf) { + return 0, io.EOF // All bytes have been read + } + + n := copy(p, buf[tr.readOffset:]) + tr.readOffset += n + + return n, nil } func register(tracker string, tr *TrackerRegistration) error {