]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/tracker.go
Account for the root
[rbdr/mobius] / hotline / tracker.go
index d0ccff4658a3a19bf32f7f14a8dcfe1362f95dde..52963bf1ba6fe34dae227aa4f7fca24db41eb575 100644 (file)
@@ -18,6 +18,7 @@ type TrackerRegistration struct {
        PassID      [4]byte // Random number generated by the server
        Name        string  // Server Name
        Description string  // Description of the server
+       Password    string  // Tracker password, if required by tracker
 
        readOffset int // Internal offset to track read progress
 }
@@ -37,6 +38,8 @@ func (tr *TrackerRegistration) Read(p []byte) (int, error) {
                []byte(tr.Name),
                []byte{uint8(len(tr.Description))},
                []byte(tr.Description),
+               []byte{uint8(len(tr.Password))},
+               []byte(tr.Password),
        )
 
        if tr.readOffset >= len(buf) {
@@ -64,7 +67,7 @@ func (d *RealDialer) Dial(network, address string) (net.Conn, error) {
 func register(dialer Dialer, tracker string, tr io.Reader) error {
        conn, err := dialer.Dial("udp", tracker)
        if err != nil {
-               return fmt.Errorf("failed to dial tracker: %w", err)
+               return fmt.Errorf("failed to dial tracker: %v", err)
        }
        defer conn.Close()
 
@@ -139,8 +142,13 @@ func GetListing(conn io.ReadWriteCloser) ([]ServerRecord, error) {
        for {
                scanner.Scan()
 
+               // Make a new []byte slice and copy the scanner bytes to it.  This is critical as the
+               // scanner re-uses the buffer for subsequent scans.
+               buf := make([]byte, len(scanner.Bytes()))
+               copy(buf, scanner.Bytes())
+
                var srv ServerRecord
-               _, err = srv.Write(scanner.Bytes())
+               _, err = srv.Write(buf)
                if err != nil {
                        return nil, err
                }