]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/server.go
Fix intermittently failing banner download
[rbdr/mobius] / hotline / server.go
index 9cec83bd793276245f1e09c42fa08a9c00b0fb1a..21b1316d4f233b0e36ae11e6d12b928e9d0f0bc6 100644 (file)
@@ -521,7 +521,7 @@ func dontPanic(logger *zap.SugaredLogger) {
 }
 
 // handleNewConnection takes a new net.Conn and performs the initial login sequence
-func (s *Server) handleNewConnection(ctx context.Context, conn net.Conn, remoteAddr string) error {
+func (s *Server) handleNewConnection(ctx context.Context, conn io.ReadWriteCloser, remoteAddr string) error {
        defer dontPanic(s.Logger)
 
        if err := Handshake(conn); err != nil {
@@ -591,7 +591,7 @@ func (s *Server) handleNewConnection(ctx context.Context, conn net.Conn, remoteA
 
        s.outbox <- c.NewReply(clientLogin,
                NewField(fieldVersion, []byte{0x00, 0xbe}),
-               NewField(fieldCommunityBannerID, []byte{0x00, 0x01}),
+               NewField(fieldCommunityBannerID, []byte{0, 0}),
                NewField(fieldServerName, []byte(s.Config.Name)),
        )
 
@@ -604,10 +604,9 @@ func (s *Server) handleNewConnection(ctx context.Context, conn net.Conn, remoteA
        // 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) {
                c.Agreed = true
-
                c.logger = c.logger.With("name", string(c.UserName))
 
-               c.notifyOthers(
+               for _, t := range c.notifyOthers(
                        *NewTransaction(
                                tranNotifyChangeUser, nil,
                                NewField(fieldUserName, c.UserName),
@@ -615,7 +614,9 @@ func (s *Server) handleNewConnection(ctx context.Context, conn net.Conn, remoteA
                                NewField(fieldUserIconID, *c.Icon),
                                NewField(fieldUserFlags, *c.Flags),
                        ),
-               )
+               ) {
+                       c.Server.outbox <- t
+               }
        }
 
        c.Server.Stats.LoginCount += 1
@@ -638,13 +639,13 @@ func (s *Server) handleNewConnection(ctx context.Context, conn net.Conn, remoteA
                // into a slice of transactions
                var transactions []Transaction
                if transactions, tReadlen, err = readTransactions(tranBuff); err != nil {
-                       c.Server.Logger.Errorw("Error handling transaction", "err", err)
+                       c.logger.Errorw("Error handling transaction", "err", err)
                }
 
                // iterate over all the transactions that were parsed from the byte slice and handle them
                for _, t := range transactions {
                        if err := c.handleTransaction(&t); err != nil {
-                               c.Server.Logger.Errorw("Error handling transaction", "err", err)
+                               c.logger.Errorw("Error handling transaction", "err", err)
                        }
                }
        }
@@ -715,6 +716,10 @@ func (s *Server) handleFileTransfer(ctx context.Context, rwc io.ReadWriter) erro
        )
 
        switch fileTransfer.Type {
+       case bannerDownload:
+               if err := s.bannerDownload(rwc); err != nil {
+                       return err
+               }
        case FileDownload:
                s.Stats.DownloadCounter += 1