Remove user from Server map when stopped
This commit is contained in:
parent
6baa15ba14
commit
6598fcf36e
30
server.go
30
server.go
@ -79,12 +79,8 @@ func (s *Server) Run() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
for _, record := range users {
|
for i := range users {
|
||||||
s.Logger.Printf("starting bouncer for user %q", record.Username)
|
s.addUserLocked(&users[i])
|
||||||
u := newUser(s, &record)
|
|
||||||
s.users[u.Username] = u
|
|
||||||
|
|
||||||
go u.run()
|
|
||||||
}
|
}
|
||||||
s.lock.Unlock()
|
s.lock.Unlock()
|
||||||
|
|
||||||
@ -104,11 +100,7 @@ func (s *Server) createUser(user *User) (*user, error) {
|
|||||||
return nil, fmt.Errorf("could not create user in db: %v", err)
|
return nil, fmt.Errorf("could not create user in db: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Logger.Printf("starting bouncer for new user %q", user.Username)
|
return s.addUserLocked(user), nil
|
||||||
u := newUser(s, user)
|
|
||||||
s.users[u.Username] = u
|
|
||||||
go u.run()
|
|
||||||
return u, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) getUser(name string) *user {
|
func (s *Server) getUser(name string) *user {
|
||||||
@ -118,6 +110,22 @@ func (s *Server) getUser(name string) *user {
|
|||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) addUserLocked(user *User) *user {
|
||||||
|
s.Logger.Printf("starting bouncer for user %q", user.Username)
|
||||||
|
u := newUser(s, user)
|
||||||
|
s.users[u.Username] = u
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
u.run()
|
||||||
|
|
||||||
|
s.lock.Lock()
|
||||||
|
delete(s.users, u.Username)
|
||||||
|
s.lock.Unlock()
|
||||||
|
}()
|
||||||
|
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
var lastDownstreamID uint64 = 0
|
var lastDownstreamID uint64 = 0
|
||||||
|
|
||||||
func (s *Server) handle(ic ircConn) {
|
func (s *Server) handle(ic ircConn) {
|
||||||
|
Loading…
Reference in New Issue
Block a user