]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/server.go
patch: v0.10.16
[rbdr/mobius] / hotline / server.go
index bd15a2ecea697b8ed88a2e34c29e870b6866e034..b17102e9ac5f3ebb46eb81a4ff5c96aef4e4f2e7 100644 (file)
@@ -2,7 +2,6 @@ package hotline
 
 import (
        "bufio"
-       "bytes"
        "context"
        "encoding/binary"
        "errors"
@@ -33,9 +32,6 @@ type requestCtx struct {
        name       string
 }
 
-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
        Accounts      map[string]*Account
@@ -153,18 +149,18 @@ func (s *Server) sendTransaction(t Transaction) error {
 
        s.mux.Lock()
        client := s.Clients[uint16(clientID)]
+       s.mux.Unlock()
        if client == nil {
                return fmt.Errorf("invalid client id %v", *t.clientID)
        }
 
-       s.mux.Unlock()
-
        b, err := t.MarshalBinary()
        if err != nil {
                return err
        }
 
-       if _, err := client.Connection.Write(b); err != nil {
+       _, err = client.Connection.Write(b)
+       if err != nil {
                return err
        }
 
@@ -381,7 +377,6 @@ func (s *Server) NewClientConn(conn io.ReadWriteCloser, remoteAddr string) *Clie
                Version:    []byte{},
                AutoReply:  []byte{},
                transfers:  map[int]map[[4]byte]*FileTransfer{},
-               Agreed:     false,
                RemoteAddr: remoteAddr,
        }
        clientConn.transfers = map[int]map[[4]byte]*FileTransfer{
@@ -468,9 +463,6 @@ func (s *Server) connectedUsers() []Field {
 
        var connectedUsers []Field
        for _, c := range sortedClients(s.Clients) {
-               if !c.Agreed {
-                       continue
-               }
                user := User{
                        ID:    *c.ID,
                        Icon:  c.Icon,
@@ -673,22 +665,20 @@ 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) || 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 }()))
-
-               for _, t := range c.notifyOthers(
-                       *NewTransaction(
-                               tranNotifyChangeUser, nil,
-                               NewField(fieldUserName, c.UserName),
-                               NewField(fieldUserID, *c.ID),
-                               NewField(fieldUserIconID, c.Icon),
-                               NewField(fieldUserFlags, c.Flags),
-                       ),
-               ) {
-                       c.Server.outbox <- t
-               }
+       // TODO: figure out a generalized solution that doesn't require playing whack-a-mole for specific client versions
+       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 }()))
+
+       for _, t := range c.notifyOthers(
+               *NewTransaction(
+                       tranNotifyChangeUser, nil,
+                       NewField(fieldUserName, c.UserName),
+                       NewField(fieldUserID, *c.ID),
+                       NewField(fieldUserIconID, c.Icon),
+                       NewField(fieldUserFlags, c.Flags),
+               ),
+       ) {
+               c.Server.outbox <- t
        }
 
        c.Server.Stats.ConnectionCounter += 1