]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/server.go
Simplify news article timestamping
[rbdr/mobius] / hotline / server.go
index 4e2bde2fdfcd613211620efc2980e65ba67fe1a9..c5a29ba9ea19173b3499be0ab3e1ade4d7e49f95 100644 (file)
@@ -111,7 +111,7 @@ func (s *Server) sendTransaction(t Transaction) error {
        client := s.Clients[uint16(clientID)]
        s.mux.Unlock()
        if client == nil {
-               return errors.New("invalid client")
+               return fmt.Errorf("invalid client id %v", *t.clientID)
        }
        userName := string(client.UserName)
        login := client.Account.Login
@@ -278,8 +278,8 @@ func (s *Server) keepaliveHandler() {
                s.mux.Lock()
 
                for _, c := range s.Clients {
-                       *c.IdleTime += idleCheckInterval
-                       if *c.IdleTime > userIdleSeconds && !c.Idle {
+                       c.IdleTime += idleCheckInterval
+                       if c.IdleTime > userIdleSeconds && !c.Idle {
                                c.Idle = true
 
                                flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(*c.Flags)))
@@ -327,15 +327,13 @@ func (s *Server) NewClientConn(conn net.Conn) *ClientConn {
                Connection: conn,
                Server:     s,
                Version:    &[]byte{},
-               IdleTime:   new(int),
                AutoReply:  &[]byte{},
                Transfers:  make(map[int][]*FileTransfer),
+               Agreed:     false,
        }
        *s.NextGuestID++
        ID := *s.NextGuestID
 
-       *clientConn.IdleTime = 0
-
        binary.BigEndian.PutUint16(*clientConn.ID, ID)
        s.Clients[ID] = clientConn
 
@@ -378,6 +376,9 @@ func (s *Server) connectedUsers() []Field {
 
        var connectedUsers []Field
        for _, c := range sortedClients(s.Clients) {
+               if c.Agreed == false {
+                       continue
+               }
                user := User{
                        ID:    *c.ID,
                        Icon:  *c.Icon,
@@ -536,9 +537,14 @@ func (s *Server) handleNewConnection(conn net.Conn) error {
        // Show agreement to client
        c.Server.outbox <- *NewTransaction(tranShowAgreement, c.ID, NewField(fieldData, s.Agreement))
 
-       if _, err := c.notifyNewUserHasJoined(); err != nil {
-               return err
+       // assume simplified hotline v1.2.3 login flow that does not require agreement
+       if *c.Version == nil {
+               c.Agreed = true
+               if _, err := c.notifyNewUserHasJoined(); err != nil {
+                       return err
+               }
        }
+
        c.Server.Stats.LoginCount += 1
 
        const readBuffSize = 1024000 // 1KB - TODO: what should this be?