Nicks and channels should be now case insensitive
This commit is contained in:
parent
eb8f0ac3d8
commit
76308cbd56
69
server.go
69
server.go
|
@ -120,31 +120,32 @@ func (sv *Server) dispatch() {
|
||||||
sv.recvMsg(msg)
|
sv.recvMsg(msg)
|
||||||
sv.packetsTransferred++
|
sv.packetsTransferred++
|
||||||
case cl := <-sv.AddClient:
|
case cl := <-sv.AddClient:
|
||||||
nick := cl.Name()
|
lnick := strings.ToLower(cl.Name())
|
||||||
if _, exists := sv.clients[nick]; exists {
|
if _, exists := sv.clients[lnick]; exists {
|
||||||
cl.Register(false)
|
cl.Register(false)
|
||||||
xlog.Info("Client registration failed: '%s'", nick)
|
xlog.Info("Client registration failed: '%s'", lnick)
|
||||||
} else {
|
} else {
|
||||||
sv.clients[nick] = cl
|
sv.clients[lnick] = cl
|
||||||
sv.sendLogon(cl.Name())
|
sv.sendLogon(lnick)
|
||||||
sv.connectionsCurrent = float64(len(sv.clients))
|
sv.connectionsCurrent = float64(len(sv.clients))
|
||||||
cl.Register(true)
|
cl.Register(true)
|
||||||
xlog.Info("Client registered: '%s'", nick)
|
xlog.Info("Client registered: '%s'", lnick)
|
||||||
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.DelClient:
|
case cl := <-sv.DelClient:
|
||||||
nick := cl.Name()
|
nick := 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[nick]; exists {
|
if _, exists := ch[lnick]; exists {
|
||||||
delete(ch, nick)
|
delete(ch, lnick)
|
||||||
sv.sendMsg(irc.M(nick, "PART", chname, "quit"))
|
sv.sendMsg(irc.M(nick, "PART", chname, "quit"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete(sv.clients, nick)
|
delete(sv.clients, lnick)
|
||||||
sv.connectionsCurrent = float64(len(sv.clients))
|
sv.connectionsCurrent = float64(len(sv.clients))
|
||||||
xlog.Info("Client deleted: '%s'", nick)
|
xlog.Info("Client deleted: '%s'", lnick)
|
||||||
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:
|
||||||
|
@ -182,34 +183,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], "#") {
|
||||||
ch := msg.Args[0]
|
lch := strings.ToLower(msg.Args[0])
|
||||||
if _, exists := sv.chUsers[ch]; !exists {
|
if _, exists := sv.chUsers[lch]; !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 nick, _ := range sv.chUsers[ch] {
|
for lnick, _ := range sv.chUsers[lch] {
|
||||||
if msg.Pre == nick && msg.Cmd == "PRIVMSG" {
|
if strings.ToLower(msg.Pre) == lnick && msg.Cmd == "PRIVMSG" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if cl, exists := sv.clients[nick]; exists {
|
if cl, exists := sv.clients[lnick]; exists {
|
||||||
cl.Receive(msg)
|
cl.Receive(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if _, exists := sv.clients[msg.Args[0]]; !exists {
|
lnick := strings.ToLower(msg.Args[0])
|
||||||
|
if _, exists := sv.clients[lnick]; !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[msg.Args[0]]
|
cl := sv.clients[lnick]
|
||||||
cl.Receive(msg)
|
cl.Receive(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sv *Server) sendReply(tar, cmd, args, trail string) {
|
func (sv *Server) sendReply(tar, cmd, args, trail string) {
|
||||||
if _, exists := sv.clients[tar]; !exists {
|
lnick := strings.ToLower(tar)
|
||||||
|
if _, exists := sv.clients[lnick]; !exists {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cl := sv.clients[tar]
|
cl := sv.clients[lnick]
|
||||||
if args != "" {
|
if args != "" {
|
||||||
args = tar + " " + args
|
args = tar + " " + args
|
||||||
} else {
|
} else {
|
||||||
|
@ -238,40 +241,46 @@ func (sv *Server) sendLogon(nick string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sv *Server) channelJoin(nick, ch string) {
|
func (sv *Server) channelJoin(nick, ch string) {
|
||||||
if _, exists := sv.chUsers[ch]; !exists {
|
lnick := strings.ToLower(nick)
|
||||||
sv.chUsers[ch] = make(map[string]string)
|
lch := strings.ToLower(ch)
|
||||||
sv.chTopics[ch] = ""
|
if _, exists := sv.chUsers[lch]; !exists {
|
||||||
|
sv.chUsers[lch] = make(map[string]string)
|
||||||
|
sv.chTopics[lch] = ""
|
||||||
}
|
}
|
||||||
if _, exists := sv.chUsers[ch][nick]; exists {
|
if _, exists := sv.chUsers[lch][lnick]; exists {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sv.chUsers[ch][nick] = ""
|
sv.chUsers[lch][lnick] = ""
|
||||||
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) {
|
||||||
if _, exists := sv.chUsers[ch]; !exists {
|
lnick := strings.ToLower(nick)
|
||||||
|
lch := strings.ToLower(nick)
|
||||||
|
if _, exists := sv.chUsers[lch]; !exists {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, exists := sv.chUsers[ch][nick]; !exists {
|
if _, exists := sv.chUsers[lch][lnick]; !exists {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sv.sendMsg(irc.M(nick, "PART", ch, reason))
|
sv.sendMsg(irc.M(nick, "PART", ch, reason))
|
||||||
delete(sv.chUsers[ch], nick)
|
delete(sv.chUsers[lch], lnick)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sv *Server) channelNames(nick, ch string) {
|
func (sv *Server) channelNames(nick, ch string) {
|
||||||
if _, exists := sv.chUsers[ch]; !exists {
|
lch := strings.ToLower(ch)
|
||||||
|
if _, exists := sv.chUsers[lch]; !exists {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
names := ""
|
names := ""
|
||||||
for name, mode := range sv.chUsers[ch] {
|
for lnick, mode := range sv.chUsers[lch] {
|
||||||
|
nick := sv.clients[lnick].Name()
|
||||||
if names != "" {
|
if names != "" {
|
||||||
names += " "
|
names += " "
|
||||||
}
|
}
|
||||||
names = names + mode + name
|
names = names + mode + nick
|
||||||
}
|
}
|
||||||
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")
|
||||||
|
|
Loading…
Reference in New Issue