3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

normalize all unicode input from the client

This commit is contained in:
Jeremy Latt 2014-02-25 20:17:26 -08:00
parent a2c05ed50d
commit 45bb0d05e7
4 changed files with 29 additions and 22 deletions

View File

@ -2,6 +2,7 @@ package irc
import (
"strconv"
"strings"
)
type Channel struct {
@ -30,11 +31,11 @@ func NewChannel(s *Server, name string) *Channel {
InviteMask: []UserMask{},
},
members: make(MemberSet),
name: name,
name: strings.ToLower(name),
server: s,
}
s.channels[name] = channel
s.channels.Add(channel)
return channel
}

View File

@ -226,7 +226,7 @@ func (s *Server) GenerateGuestNick() string {
continue // TODO handle error
}
nick := fmt.Sprintf("guest%d", randInt)
if s.clients[nick] == nil {
if s.clients.Get(nick) == nil {
return nick
}
}
@ -407,7 +407,7 @@ func (msg *NickCommand) HandleServer(server *Server) {
return
}
if server.clients.Get(msg.nickname) != nil {
if server.clients.Get(msg.nickname) != client {
client.ErrNickNameInUse(msg.nickname)
return
}
@ -439,7 +439,7 @@ func (m *JoinCommand) HandleServer(s *Server) {
continue
}
channel := s.channels[name]
channel := s.channels.Get(name)
if channel == nil {
channel = NewChannel(s, name)
}
@ -450,7 +450,7 @@ func (m *JoinCommand) HandleServer(s *Server) {
func (m *PartCommand) HandleServer(server *Server) {
client := m.Client()
for _, chname := range m.channels {
channel := server.channels[chname]
channel := server.channels.Get(chname)
if channel == nil {
m.Client().ErrNoSuchChannel(chname)
@ -463,7 +463,7 @@ func (m *PartCommand) HandleServer(server *Server) {
func (msg *TopicCommand) HandleServer(server *Server) {
client := msg.Client()
channel := server.channels[msg.channel]
channel := server.channels.Get(msg.channel)
if channel == nil {
client.ErrNoSuchChannel(msg.channel)
return
@ -479,7 +479,7 @@ func (msg *TopicCommand) HandleServer(server *Server) {
func (msg *PrivMsgCommand) HandleServer(server *Server) {
client := msg.Client()
if IsChannel(msg.target) {
channel := server.channels[msg.target]
channel := server.channels.Get(msg.target)
if channel == nil {
client.ErrNoSuchChannel(msg.target)
return
@ -489,7 +489,7 @@ func (msg *PrivMsgCommand) HandleServer(server *Server) {
return
}
target := server.clients[msg.target]
target := server.clients.Get(msg.target)
if target == nil {
client.ErrNoSuchNick(msg.target)
return
@ -586,7 +586,7 @@ func (m *WhoisCommand) HandleServer(server *Server) {
func (msg *ChannelModeCommand) HandleServer(server *Server) {
client := msg.Client()
channel := server.channels[msg.channel]
channel := server.channels.Get(msg.channel)
if channel == nil {
client.ErrNoSuchChannel(msg.channel)
return
@ -617,14 +617,14 @@ func (msg *WhoCommand) HandleServer(server *Server) {
}
}
} else if IsChannel(mask) {
channel := server.channels[mask]
channel := server.channels.Get(mask)
if channel != nil {
for member := range channel.members {
client.RplWhoReply(channel, member)
}
}
} else {
mclient := server.clients[mask]
mclient := server.clients.Get(mask)
if mclient != nil {
client.RplWhoReply(nil, mclient)
}
@ -682,7 +682,7 @@ func (msg *MOTDCommand) HandleServer(server *Server) {
func (msg *NoticeCommand) HandleServer(server *Server) {
client := msg.Client()
if IsChannel(msg.target) {
channel := server.channels[msg.target]
channel := server.channels.Get(msg.target)
if channel == nil {
client.ErrNoSuchChannel(msg.target)
return
@ -703,13 +703,13 @@ func (msg *NoticeCommand) HandleServer(server *Server) {
func (msg *KickCommand) HandleServer(server *Server) {
client := msg.Client()
for chname, nickname := range msg.kicks {
channel := server.channels[chname]
channel := server.channels.Get(chname)
if channel == nil {
client.ErrNoSuchChannel(chname)
continue
}
target := server.clients[nickname]
target := server.clients.Get(nickname)
if target == nil {
client.ErrNoSuchNick(nickname)
continue
@ -737,7 +737,7 @@ func (msg *ListCommand) HandleServer(server *Server) {
}
} else {
for _, chname := range msg.channels {
channel := server.channels[chname]
channel := server.channels.Get(chname)
if channel == nil || (!client.flags[Operator] && channel.flags[Private]) {
client.ErrNoSuchChannel(chname)
continue
@ -758,7 +758,7 @@ func (msg *NamesCommand) HandleServer(server *Server) {
}
for _, chname := range msg.channels {
channel := server.channels[chname]
channel := server.channels.Get(chname)
if channel == nil {
client.ErrNoSuchChannel(chname)
continue
@ -830,10 +830,11 @@ func (msg *InviteCommand) HandleServer(server *Server) {
return
}
channel := server.channels[msg.channel]
channel := server.channels.Get(msg.channel)
if channel == nil {
client.RplInviting(target, msg.channel)
target.Reply(RplInviteMsg(client, msg.channel))
name := strings.ToLower(msg.channel)
client.RplInviting(target, name)
target.Reply(RplInviteMsg(client, name))
return
}

View File

@ -2,6 +2,7 @@ package irc
import (
"bufio"
"code.google.com/p/go.text/unicode/norm"
"io"
"log"
"net"
@ -23,7 +24,7 @@ type Socket struct {
func NewSocket(conn net.Conn, commands chan<- editableCommand) *Socket {
socket := &Socket{
conn: conn,
reader: bufio.NewReader(conn),
reader: bufio.NewReader(norm.NFKC.Reader(conn)),
writer: bufio.NewWriter(conn),
}

View File

@ -54,6 +54,10 @@ func (mode ChannelMode) String() string {
type ChannelNameMap map[string]*Channel
func (channels ChannelNameMap) Get(name string) *Channel {
return channels[strings.ToLower(name)]
}
func (channels ChannelNameMap) Add(channel *Channel) error {
if channels[channel.name] != nil {
return fmt.Errorf("%s: already set", channel.name)
@ -100,7 +104,7 @@ func (clients ClientNameMap) Remove(client *Client) error {
if clients.Get(client.nick) != client {
return ErrNicknameMismatch
}
delete(clients, client.nick)
delete(clients, strings.ToLower(client.nick))
return nil
}