diff --git a/client.go b/client.go index 4d07ac1..af43a75 100644 --- a/client.go +++ b/client.go @@ -125,6 +125,7 @@ func (cl *RemoteClient) dispatcher() { cl.writeMsg(msg) case success := <-cl.registered: if !success { + cl.name = "" cl.Destroy() xlog.Debug("User registration failed: '%s'", cl.name) return @@ -203,7 +204,6 @@ func (cl *RemoteClient) handleCmd(s string) { case "NICK": cl.name = msg.Args[0] cl.server.AddClient(cl) - case "USER": } } diff --git a/server.go b/server.go index 4022f76..b17e9a8 100644 --- a/server.go +++ b/server.go @@ -22,26 +22,23 @@ const ( ) 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 { - queue chan *irc.Message - addq chan Client - delq chan Client - - host string - info string - software string - version string - created string - motd string - clients map[string]Client - chUsers map[string]map[string]string - //chModes map[string][]string - chTopics map[string]string - config *conf.ConfigFile - configPath string - + queue chan *irc.Message + addq chan Client + delq chan Client + host string + info string + software string + version string + created string + motd string + clients map[string]Client + chUsers map[string]map[string]string + chTopics map[string]string + config *conf.ConfigFile + configPath string packetsTransferred float64 connectionsCurrent float64 connectionsCount float64 @@ -132,32 +129,31 @@ func (sv *Server) dispatcher() { sv.recvMsg(msg) sv.packetsTransferred++ case cl := <-sv.addq: - lnick := strings.ToLower(cl.Name()) - if _, exists := sv.clients[lnick]; exists { + clid := strings.ToLower(cl.Name()) + if _, exists := sv.clients[clid]; exists { cl.Register(false) - xlog.Info("Client registration failed: '%s'", lnick) + xlog.Info("Client registration failed: '%s'", clid) } else { - sv.clients[lnick] = cl - sv.sendLogon(lnick) + sv.clients[clid] = cl + sv.sendLogon(cl.Name()) sv.connectionsCurrent = float64(len(sv.clients)) 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.Debug("Goroutines running: %d", runtime.NumGoroutine()) } case cl := <-sv.delq: - nick := cl.Name() - lnick := strings.ToLower(nick) + clid := strings.ToLower(cl.Name()) cl.Destroy() for chname, ch := range sv.chUsers { - if _, exists := ch[lnick]; exists { - delete(ch, lnick) - sv.sendMsg(irc.M(nick, "PART", chname, "quit")) + if _, exists := ch[clid]; exists { + delete(ch, clid) + sv.sendMsg(irc.M(cl.Name(), "PART", chname, "quit")) } } - delete(sv.clients, lnick) + delete(sv.clients, clid) 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.Debug("Goroutines running: %d", runtime.NumGoroutine()) default: @@ -195,36 +191,36 @@ func (sv *Server) recvMsg(msg *irc.Message) { func (sv *Server) sendMsg(msg *irc.Message) { if strings.HasPrefix(msg.Args[0], "#") { - lch := strings.ToLower(msg.Args[0]) - if _, exists := sv.chUsers[lch]; !exists { + chid := strings.ToLower(msg.Args[0]) + if _, exists := sv.chUsers[chid]; !exists { sv.sendReply(msg.Pre, ERR_NOSUCHNICK, msg.Args[0], "No such nick/channel") return } - for lnick, _ := range sv.chUsers[lch] { - if strings.ToLower(msg.Pre) == lnick && msg.Cmd == "PRIVMSG" { + for clid, _ := range sv.chUsers[chid] { + if strings.ToLower(msg.Pre) == clid && msg.Cmd == "PRIVMSG" { continue } - if cl, exists := sv.clients[lnick]; exists { + if cl, exists := sv.clients[clid]; exists { cl.Receive(msg) } } } else { - lnick := strings.ToLower(msg.Args[0]) - if _, exists := sv.clients[lnick]; !exists { + clid := strings.ToLower(msg.Args[0]) + if _, exists := sv.clients[clid]; !exists { sv.sendReply(msg.Pre, ERR_NOSUCHNICK, msg.Args[0], "No such nick/channel") return } - cl := sv.clients[lnick] + cl := sv.clients[clid] cl.Receive(msg) } } func (sv *Server) sendReply(nick, cmd, args, trail string) { - lnick := strings.ToLower(nick) - if _, exists := sv.clients[lnick]; !exists { + clid := strings.ToLower(nick) + if _, exists := sv.clients[clid]; !exists { return } - cl := sv.clients[lnick] + cl := sv.clients[clid] if args != "" { args = nick + " " + args } else { @@ -253,46 +249,46 @@ func (sv *Server) sendLogon(nick string) { } func (sv *Server) channelJoin(nick, ch string) { - lnick := strings.ToLower(nick) - lch := strings.ToLower(ch) - if _, exists := sv.chUsers[lch]; !exists { - sv.chUsers[lch] = make(map[string]string) - sv.chTopics[lch] = "" + clid := strings.ToLower(nick) + chid := strings.ToLower(ch) + if _, exists := sv.chUsers[chid]; !exists { + sv.chUsers[chid] = make(map[string]string) + sv.chTopics[chid] = "" } - if _, exists := sv.chUsers[lch][lnick]; exists { + if _, exists := sv.chUsers[chid][clid]; exists { return } - sv.chUsers[lch][lnick] = "" + sv.chUsers[chid][clid] = "" sv.sendMsg(irc.M(nick, "JOIN", ch, "")) sv.sendReply(nick, RPL_TOPIC, ch, sv.chTopics[ch]) sv.channelNames(nick, ch) } func (sv *Server) channelPart(nick, ch, reason string) { - lnick := strings.ToLower(nick) - lch := strings.ToLower(nick) - if _, exists := sv.chUsers[lch]; !exists { + clid := strings.ToLower(nick) + chid := strings.ToLower(ch) + if _, exists := sv.chUsers[chid]; !exists { return } - if _, exists := sv.chUsers[lch][lnick]; !exists { + if _, exists := sv.chUsers[chid][clid]; !exists { return } 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) { - lch := strings.ToLower(ch) - if _, exists := sv.chUsers[lch]; !exists { + chid := strings.ToLower(ch) + if _, exists := sv.chUsers[chid]; !exists { return } names := "" - for lnick, mode := range sv.chUsers[lch] { - nick := sv.clients[lnick].Name() + for clid, mode := range sv.chUsers[chid] { + name := sv.clients[clid].Name() if names != "" { names += " " } - names = names + mode + nick + names = names + mode + name } sv.sendReply(nick, RPL_NAMEREPLY, "= "+ch, names) sv.sendReply(nick, RPL_ENDOFNAMES, ch, "End of /NAMES list")