]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/tracker.go
Adopt more fixed size array types for struct fields
[rbdr/mobius] / hotline / tracker.go
index 6ee2a9f502010ccd7479f430284feb75a152b1c3..b927986ae65f27d922baf61139143f1e2b69a658 100644 (file)
@@ -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 {
@@ -124,6 +135,7 @@ func GetListing(addr string) ([]ServerRecord, error) {
        var servers []ServerRecord
        for {
                scanner.Scan()
+
                var srv ServerRecord
                _, err = srv.Write(scanner.Bytes())
                if err != nil {