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
outbox chan Transaction
mux sync.Mutex
+ threadedNewsMux sync.Mutex
+ ThreadedNews *ThreadedNews
+
flatNewsMux sync.Mutex
FlatNews []byte
if err := register(t, tr); err != nil {
server.Logger.Errorw("unable to register with tracker %v", "error", err)
}
- server.Logger.Infow("Sent Tracker registration", "data", tr)
+ server.Logger.Debugw("Sent Tracker registration", "addr", t)
}
time.Sleep(trackerUpdateFrequency * time.Second)
}
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,
}
// 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()
Login: login,
Name: name,
Password: hashAndSalt([]byte(password)),
- Access: &access,
+ Access: access,
}
out, err := yaml.Marshal(&account)
if err != nil {
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()
}
account := s.Accounts[newLogin]
- account.Access = &access
+ account.Access = access
account.Name = name
account.Password = password
)
// Send user access privs so client UI knows how to behave
- c.Server.outbox <- *NewTransaction(tranUserAccess, c.ID, NewField(fieldUserAccess, *c.Account.Access))
-
- // Show agreement to client
- c.Server.outbox <- *NewTransaction(tranShowAgreement, c.ID, NewField(fieldData, s.Agreement))
+ 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
+ // tranShowAgreement but with the NoServerAgreement field set to 1.
+ if c.Authorize(accessNoAgreement) {
+ // If client version is nil, then the client uses the 1.2.3 login behavior
+ if c.Version != nil {
+ c.Server.outbox <- *NewTransaction(tranShowAgreement, c.ID, NewField(fieldNoServerAgreement, []byte{1}))
+ }
+ } else {
+ c.Server.outbox <- *NewTransaction(tranShowAgreement, c.ID, NewField(fieldData, s.Agreement))
+ }
// 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.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(