Fixed handling of denied logins

This commit is contained in:
Andreas Neue 2016-07-22 15:56:50 +02:00
parent bf9ff170b0
commit 038a3589c4
2 changed files with 56 additions and 60 deletions

View File

@ -125,6 +125,7 @@ func (cl *RemoteClient) dispatcher() {
cl.writeMsg(msg) cl.writeMsg(msg)
case success := <-cl.registered: case success := <-cl.registered:
if !success { if !success {
cl.name = ""
cl.Destroy() cl.Destroy()
xlog.Debug("User registration failed: '%s'", cl.name) xlog.Debug("User registration failed: '%s'", cl.name)
return return
@ -203,7 +204,6 @@ func (cl *RemoteClient) handleCmd(s string) {
case "NICK": case "NICK":
cl.name = msg.Args[0] cl.name = msg.Args[0]
cl.server.AddClient(cl) cl.server.AddClient(cl)
case "USER": case "USER":
} }
} }

114
server.go
View File

@ -22,26 +22,23 @@ const (
) )
var myinfo string = "%s %s/%s * *" var myinfo string = "%s %s/%s * *"
var isupport string = "ALIAS FRIEND UNFRIEND CASEMAPPING=rfc1459 CHANLIMIT=#:1024 CHANMODES=b,k,l,imnpst CHANNELLEN=200 CHANTYPES=# EXCEPTS=e KICKLEN MAXLIST=b:50,e:50 MODES=1 NETWORK=dnix.de NICKLEN=32 PREFIX=(aohv)&@%%+ SAFELIST STATUSMSG=&@%%+ TOPICLEN" var isupport string = "CASEMAPPING=rfc1459 CHANTYPES=# NICKLEN=32 PREFIX=(aohv)&@%%+"
type Server struct { type Server struct {
queue chan *irc.Message queue chan *irc.Message
addq chan Client addq chan Client
delq chan Client delq chan Client
host string
host string info string
info string software string
software string version string
version string created string
created string motd string
motd string clients map[string]Client
clients map[string]Client chUsers map[string]map[string]string
chUsers map[string]map[string]string chTopics map[string]string
//chModes map[string][]string config *conf.ConfigFile
chTopics map[string]string configPath string
config *conf.ConfigFile
configPath string
packetsTransferred float64 packetsTransferred float64
connectionsCurrent float64 connectionsCurrent float64
connectionsCount float64 connectionsCount float64
@ -132,32 +129,31 @@ func (sv *Server) dispatcher() {
sv.recvMsg(msg) sv.recvMsg(msg)
sv.packetsTransferred++ sv.packetsTransferred++
case cl := <-sv.addq: case cl := <-sv.addq:
lnick := strings.ToLower(cl.Name()) clid := strings.ToLower(cl.Name())
if _, exists := sv.clients[lnick]; exists { if _, exists := sv.clients[clid]; exists {
cl.Register(false) cl.Register(false)
xlog.Info("Client registration failed: '%s'", lnick) xlog.Info("Client registration failed: '%s'", clid)
} else { } else {
sv.clients[lnick] = cl sv.clients[clid] = cl
sv.sendLogon(lnick) sv.sendLogon(cl.Name())
sv.connectionsCurrent = float64(len(sv.clients)) sv.connectionsCurrent = float64(len(sv.clients))
cl.Register(true) cl.Register(true)
xlog.Info("Client registered: '%s'", lnick) xlog.Info("Client registered: '%s'", clid)
xlog.Info("Server has %d client(s)", len(sv.clients)) xlog.Info("Server has %d client(s)", len(sv.clients))
xlog.Debug("Goroutines running: %d", runtime.NumGoroutine()) xlog.Debug("Goroutines running: %d", runtime.NumGoroutine())
} }
case cl := <-sv.delq: case cl := <-sv.delq:
nick := cl.Name() clid := strings.ToLower(cl.Name())
lnick := strings.ToLower(nick)
cl.Destroy() cl.Destroy()
for chname, ch := range sv.chUsers { for chname, ch := range sv.chUsers {
if _, exists := ch[lnick]; exists { if _, exists := ch[clid]; exists {
delete(ch, lnick) delete(ch, clid)
sv.sendMsg(irc.M(nick, "PART", chname, "quit")) sv.sendMsg(irc.M(cl.Name(), "PART", chname, "quit"))
} }
} }
delete(sv.clients, lnick) delete(sv.clients, clid)
sv.connectionsCurrent = float64(len(sv.clients)) sv.connectionsCurrent = float64(len(sv.clients))
xlog.Info("Client deleted: '%s'", lnick) xlog.Info("Client deleted: '%s'", clid)
xlog.Info("Server has %d client(s)", len(sv.clients)) xlog.Info("Server has %d client(s)", len(sv.clients))
xlog.Debug("Goroutines running: %d", runtime.NumGoroutine()) xlog.Debug("Goroutines running: %d", runtime.NumGoroutine())
default: default:
@ -195,36 +191,36 @@ func (sv *Server) recvMsg(msg *irc.Message) {
func (sv *Server) sendMsg(msg *irc.Message) { func (sv *Server) sendMsg(msg *irc.Message) {
if strings.HasPrefix(msg.Args[0], "#") { if strings.HasPrefix(msg.Args[0], "#") {
lch := strings.ToLower(msg.Args[0]) chid := strings.ToLower(msg.Args[0])
if _, exists := sv.chUsers[lch]; !exists { if _, exists := sv.chUsers[chid]; !exists {
sv.sendReply(msg.Pre, ERR_NOSUCHNICK, msg.Args[0], "No such nick/channel") sv.sendReply(msg.Pre, ERR_NOSUCHNICK, msg.Args[0], "No such nick/channel")
return return
} }
for lnick, _ := range sv.chUsers[lch] { for clid, _ := range sv.chUsers[chid] {
if strings.ToLower(msg.Pre) == lnick && msg.Cmd == "PRIVMSG" { if strings.ToLower(msg.Pre) == clid && msg.Cmd == "PRIVMSG" {
continue continue
} }
if cl, exists := sv.clients[lnick]; exists { if cl, exists := sv.clients[clid]; exists {
cl.Receive(msg) cl.Receive(msg)
} }
} }
} else { } else {
lnick := strings.ToLower(msg.Args[0]) clid := strings.ToLower(msg.Args[0])
if _, exists := sv.clients[lnick]; !exists { if _, exists := sv.clients[clid]; !exists {
sv.sendReply(msg.Pre, ERR_NOSUCHNICK, msg.Args[0], "No such nick/channel") sv.sendReply(msg.Pre, ERR_NOSUCHNICK, msg.Args[0], "No such nick/channel")
return return
} }
cl := sv.clients[lnick] cl := sv.clients[clid]
cl.Receive(msg) cl.Receive(msg)
} }
} }
func (sv *Server) sendReply(nick, cmd, args, trail string) { func (sv *Server) sendReply(nick, cmd, args, trail string) {
lnick := strings.ToLower(nick) clid := strings.ToLower(nick)
if _, exists := sv.clients[lnick]; !exists { if _, exists := sv.clients[clid]; !exists {
return return
} }
cl := sv.clients[lnick] cl := sv.clients[clid]
if args != "" { if args != "" {
args = nick + " " + args args = nick + " " + args
} else { } else {
@ -253,46 +249,46 @@ func (sv *Server) sendLogon(nick string) {
} }
func (sv *Server) channelJoin(nick, ch string) { func (sv *Server) channelJoin(nick, ch string) {
lnick := strings.ToLower(nick) clid := strings.ToLower(nick)
lch := strings.ToLower(ch) chid := strings.ToLower(ch)
if _, exists := sv.chUsers[lch]; !exists { if _, exists := sv.chUsers[chid]; !exists {
sv.chUsers[lch] = make(map[string]string) sv.chUsers[chid] = make(map[string]string)
sv.chTopics[lch] = "" sv.chTopics[chid] = ""
} }
if _, exists := sv.chUsers[lch][lnick]; exists { if _, exists := sv.chUsers[chid][clid]; exists {
return return
} }
sv.chUsers[lch][lnick] = "" sv.chUsers[chid][clid] = ""
sv.sendMsg(irc.M(nick, "JOIN", ch, "")) sv.sendMsg(irc.M(nick, "JOIN", ch, ""))
sv.sendReply(nick, RPL_TOPIC, ch, sv.chTopics[ch]) sv.sendReply(nick, RPL_TOPIC, ch, sv.chTopics[ch])
sv.channelNames(nick, ch) sv.channelNames(nick, ch)
} }
func (sv *Server) channelPart(nick, ch, reason string) { func (sv *Server) channelPart(nick, ch, reason string) {
lnick := strings.ToLower(nick) clid := strings.ToLower(nick)
lch := strings.ToLower(nick) chid := strings.ToLower(ch)
if _, exists := sv.chUsers[lch]; !exists { if _, exists := sv.chUsers[chid]; !exists {
return return
} }
if _, exists := sv.chUsers[lch][lnick]; !exists { if _, exists := sv.chUsers[chid][clid]; !exists {
return return
} }
sv.sendMsg(irc.M(nick, "PART", ch, reason)) sv.sendMsg(irc.M(nick, "PART", ch, reason))
delete(sv.chUsers[lch], lnick) delete(sv.chUsers[chid], clid)
} }
func (sv *Server) channelNames(nick, ch string) { func (sv *Server) channelNames(nick, ch string) {
lch := strings.ToLower(ch) chid := strings.ToLower(ch)
if _, exists := sv.chUsers[lch]; !exists { if _, exists := sv.chUsers[chid]; !exists {
return return
} }
names := "" names := ""
for lnick, mode := range sv.chUsers[lch] { for clid, mode := range sv.chUsers[chid] {
nick := sv.clients[lnick].Name() name := sv.clients[clid].Name()
if names != "" { if names != "" {
names += " " names += " "
} }
names = names + mode + nick names = names + mode + name
} }
sv.sendReply(nick, RPL_NAMEREPLY, "= "+ch, names) sv.sendReply(nick, RPL_NAMEREPLY, "= "+ch, names)
sv.sendReply(nick, RPL_ENDOFNAMES, ch, "End of /NAMES list") sv.sendReply(nick, RPL_ENDOFNAMES, ch, "End of /NAMES list")