Add Server.getUser

This commit is contained in:
Simon Ser 2020-02-07 11:39:56 +01:00
parent 3b2bb58c60
commit 3586ca3d26
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 9 additions and 5 deletions

View File

@ -167,11 +167,8 @@ func (c *downstreamConn) handleMessageUnregistered(msg *irc.Message) error {
}
func (c *downstreamConn) register() error {
c.srv.lock.Lock()
u, ok := c.srv.users[c.username]
c.srv.lock.Unlock()
if !ok {
u := c.srv.getUser(c.username)
if u == nil {
c.messages <- &irc.Message{
Prefix: c.srv.prefix(),
Command: irc.ERR_PASSWDMISMATCH,

View File

@ -106,6 +106,13 @@ func (s *Server) Run() {
}
}
func (s *Server) getUser(name string) *user {
s.lock.Lock()
u := s.users[name]
s.lock.Unlock()
return u
}
func (s *Server) Serve(ln net.Listener) error {
for {
netConn, err := ln.Accept()