This commit is contained in:
Andreas Neue 2016-08-02 00:20:42 +02:00
parent 3424c8e396
commit f51618e559
1 changed files with 48 additions and 40 deletions

View File

@ -171,47 +171,9 @@ func (sv *Server) dispatcher() (err error) {
sv.recvMsg(msg) sv.recvMsg(msg)
sv.packetsTransferred++ sv.packetsTransferred++
case cl := <-sv.addq: case cl := <-sv.addq:
clid := strings.ToLower(cl.Name()) sv.addClient(cl)
if _, exists := sv.clients[clid]; exists {
cl.Receive(irc.M(sv.host, ERR_NICKNAMEINUSE, cl.Name(), "Nickname is already in use"))
go func() {
time.Sleep(5 * time.Second)
cl.Register(false)
}()
xlog.Info("Client registration failed: '%s' (client exists)", clid)
continue
}
if !sv.authCallback(cl.Name(), cl.Password()) {
cl.Receive(irc.M(sv.host, ERR_PASSWDMISMATCH, "", "Password incorrect"))
go func() {
time.Sleep(5 * time.Second)
cl.Register(false)
}()
xlog.Info("Client registration failed: '%s' (wrong password)", clid)
continue
}
sv.clients[clid] = cl
sv.clients[clid] = cl
sv.sendLogon(cl.Name())
sv.connectionsCurrent = float64(len(sv.clients))
cl.Register(true)
xlog.Info("Client registered: '%s'", clid)
xlog.Info("Server has %d client(s)", len(sv.clients))
xlog.Debug("Goroutines running: %d", runtime.NumGoroutine())
case cl := <-sv.delq: case cl := <-sv.delq:
clid := strings.ToLower(cl.Name()) sv.delClient(cl)
cl.Destroy()
for chname, ch := range sv.chUsers {
if _, exists := ch[clid]; exists {
delete(ch, clid)
sv.sendMsg(irc.M(cl.Name(), "PART", chname, "quit"))
}
}
delete(sv.clients, clid)
sv.connectionsCurrent = float64(len(sv.clients))
xlog.Info("Client deleted: '%s'", clid)
xlog.Info("Server has %d client(s)", len(sv.clients))
xlog.Debug("Goroutines running: %d", runtime.NumGoroutine())
default: default:
time.Sleep(100 * time.Microsecond) time.Sleep(100 * time.Microsecond)
} }
@ -228,6 +190,52 @@ func (sv *Server) loadConfig() {
sv.config = cfg sv.config = cfg
} }
func (sv *Server) addClient(cl Client) {
clid := strings.ToLower(cl.Name())
if _, exists := sv.clients[clid]; exists {
cl.Receive(irc.M(sv.host, ERR_NICKNAMEINUSE, cl.Name(), "Nickname is already in use"))
go func() {
time.Sleep(5 * time.Second)
cl.Register(false)
}()
xlog.Info("Client registration failed: '%s' (client exists)", clid)
return
}
if !sv.authCallback(cl.Name(), cl.Password()) {
cl.Receive(irc.M(sv.host, ERR_PASSWDMISMATCH, "", "Password incorrect"))
go func() {
time.Sleep(5 * time.Second)
cl.Register(false)
}()
xlog.Info("Client registration failed: '%s' (wrong password)", clid)
return
}
sv.clients[clid] = cl
sv.clients[clid] = cl
sv.sendLogon(cl.Name())
sv.connectionsCurrent = float64(len(sv.clients))
cl.Register(true)
xlog.Info("Client registered: '%s'", clid)
xlog.Info("Server has %d client(s)", len(sv.clients))
xlog.Debug("Goroutines running: %d", runtime.NumGoroutine())
}
func (sv *Server) delClient(cl Client) {
clid := strings.ToLower(cl.Name())
cl.Destroy()
for chname, ch := range sv.chUsers {
if _, exists := ch[clid]; exists {
delete(ch, clid)
sv.sendMsg(irc.M(cl.Name(), "PART", chname, "quit"))
}
}
delete(sv.clients, clid)
sv.connectionsCurrent = float64(len(sv.clients))
xlog.Info("Client deleted: '%s'", clid)
xlog.Info("Server has %d client(s)", len(sv.clients))
xlog.Debug("Goroutines running: %d", runtime.NumGoroutine())
}
func (sv *Server) recvMsg(msg *irc.Message) { func (sv *Server) recvMsg(msg *irc.Message) {
cmd := msg.Cmd cmd := msg.Cmd
hook, exists := svCommandHooks[cmd] hook, exists := svCommandHooks[cmd]