X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/043c00da52efd5b7d9ef15750945ee55e6f78e7a..436073204c9045126910be2ebc73c63344871c36:/hotline/server.go?ds=inline diff --git a/hotline/server.go b/hotline/server.go index ec83522..bd15a2e 100644 --- a/hotline/server.go +++ b/hotline/server.go @@ -34,6 +34,7 @@ type requestCtx struct { } var nostalgiaVersion = []byte{0, 0, 2, 0x2c} // version ID used by the Nostalgia client +var frogblastVersion = []byte{0, 0, 0, 0xb9} // version ID used by the Frogblast 1.2.4 client type Server struct { Port int @@ -564,8 +565,13 @@ func (s *Server) handleNewConnection(ctx context.Context, rwc io.ReadWriteCloser scanner.Scan() + // Make a new []byte slice and copy the scanner bytes to it. This is critical to avoid a data race as the + // scanner re-uses the buffer for subsequent scans. + buf := make([]byte, len(scanner.Bytes())) + copy(buf, scanner.Bytes()) + var clientLogin Transaction - if _, err := clientLogin.Write(scanner.Bytes()); err != nil { + if _, err := clientLogin.Write(buf); err != nil { return err } @@ -667,7 +673,7 @@ func (s *Server) handleNewConnection(ctx context.Context, rwc io.ReadWriteCloser } // Used simplified hotline v1.2.3 login flow for clients that do not send login info in tranAgreed - if c.Version == nil || bytes.Equal(c.Version, nostalgiaVersion) { + if c.Version == nil || bytes.Equal(c.Version, nostalgiaVersion) || bytes.Equal(c.Version, frogblastVersion) { c.Agreed = true c.logger = c.logger.With("name", string(c.UserName)) c.logger.Infow("Login successful", "clientVersion", fmt.Sprintf("%v", func() int { i, _ := byteToInt(c.Version); return i }())) @@ -748,6 +754,10 @@ func (s *Server) handleFileTransfer(ctx context.Context, rwc io.ReadWriter) erro delete(s.fileTransfers, t.ReferenceNumber) s.mux.Unlock() + // Wait a few seconds before closing the connection: this is a workaround for problems + // observed with Windows clients where the client must initiate close of the TCP connection before + // the server does. This is gross and seems unnecessary. TODO: Revisit? + time.Sleep(3 * time.Second) }() s.mux.Lock() @@ -782,7 +792,9 @@ func (s *Server) handleFileTransfer(ctx context.Context, rwc io.ReadWriter) erro case FileDownload: s.Stats.DownloadCounter += 1 s.Stats.DownloadsInProgress += 1 - defer func() { s.Stats.DownloadsInProgress -= 1 }() + defer func() { + s.Stats.DownloadsInProgress -= 1 + }() var dataOffset int64 if fileTransfer.fileResumeData != nil {