X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/a322be023434b4fbdfdc607b73212089ce7d077c..7e6b49e4d6bf07cbd0df374460c92c1d88be0599:/hotline/server.go diff --git a/hotline/server.go b/hotline/server.go index 0d66e08..392c8f3 100644 --- a/hotline/server.go +++ b/hotline/server.go @@ -43,12 +43,10 @@ const ( var nostalgiaVersion = []byte{0, 0, 2, 0x2c} // version ID used by the Nostalgia client type Server struct { - Port int - Accounts map[string]*Account - Agreement []byte - Clients map[uint16]*ClientConn - ThreadedNews *ThreadedNews - + Port int + Accounts map[string]*Account + Agreement []byte + Clients map[uint16]*ClientConn fileTransfers map[[4]byte]*FileTransfer Config *Config @@ -64,6 +62,9 @@ type Server struct { outbox chan Transaction mux sync.Mutex + threadedNewsMux sync.Mutex + ThreadedNews *ThreadedNews + flatNewsMux sync.Mutex FlatNews []byte @@ -342,14 +343,14 @@ func (s *Server) writeBanList() error { } func (s *Server) writeThreadedNews() error { - s.mux.Lock() - defer s.mux.Unlock() + s.threadedNewsMux.Lock() + defer s.threadedNewsMux.Unlock() out, err := yaml.Marshal(s.ThreadedNews) if err != nil { return err } - err = ioutil.WriteFile( + err = s.FS.WriteFile( filepath.Join(s.ConfigDir, "ThreadedNews.yaml"), out, 0666, @@ -392,7 +393,7 @@ func (s *Server) NewClientConn(conn io.ReadWriteCloser, remoteAddr string) *Clie } // NewUser creates a new user account entry in the server map and config file -func (s *Server) NewUser(login, name, password string, access []byte) error { +func (s *Server) NewUser(login, name, password string, access accessBitmap) error { s.mux.Lock() defer s.mux.Unlock() @@ -400,7 +401,7 @@ func (s *Server) NewUser(login, name, password string, access []byte) error { Login: login, Name: name, Password: hashAndSalt([]byte(password)), - Access: &access, + Access: access, } out, err := yaml.Marshal(&account) if err != nil { @@ -411,7 +412,7 @@ func (s *Server) NewUser(login, name, password string, access []byte) error { return s.FS.WriteFile(filepath.Join(s.ConfigDir, "Users", login+".yaml"), out, 0666) } -func (s *Server) UpdateUser(login, newLogin, name, password string, access []byte) error { +func (s *Server) UpdateUser(login, newLogin, name, password string, access accessBitmap) error { s.mux.Lock() defer s.mux.Unlock() @@ -426,7 +427,7 @@ func (s *Server) UpdateUser(login, newLogin, name, password string, access []byt } account := s.Accounts[newLogin] - account.Access = &access + account.Access = access account.Name = name account.Password = password @@ -651,7 +652,7 @@ func (s *Server) handleNewConnection(ctx context.Context, rwc io.ReadWriteCloser ) // Send user access privs so client UI knows how to behave - c.Server.outbox <- *NewTransaction(tranUserAccess, c.ID, NewField(fieldUserAccess, *c.Account.Access)) + c.Server.outbox <- *NewTransaction(tranUserAccess, c.ID, NewField(fieldUserAccess, c.Account.Access[:])) // Accounts with accessNoAgreement do not receive the server agreement on login. The behavior is different between // client versions. For 1.2.3 client, we do not send tranShowAgreement. For other client versions, we send @@ -669,7 +670,7 @@ func (s *Server) handleNewConnection(ctx context.Context, rwc io.ReadWriteCloser if c.Version == nil || bytes.Equal(c.Version, nostalgiaVersion) { c.Agreed = true c.logger = c.logger.With("name", string(c.UserName)) - c.logger.Infow("Login successful", "clientVersion", fmt.Sprintf("%x", c.Version)) + c.logger.Infow("Login successful", "clientVersion", fmt.Sprintf("%v", func() int { i, _ := byteToInt(c.Version); return i }())) for _, t := range c.notifyOthers( *NewTransaction(