mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-23 03:02:48 +01:00
normalize all unicode input from the client
This commit is contained in:
parent
a2c05ed50d
commit
45bb0d05e7
@ -2,6 +2,7 @@ package irc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Channel struct {
|
type Channel struct {
|
||||||
@ -30,11 +31,11 @@ func NewChannel(s *Server, name string) *Channel {
|
|||||||
InviteMask: []UserMask{},
|
InviteMask: []UserMask{},
|
||||||
},
|
},
|
||||||
members: make(MemberSet),
|
members: make(MemberSet),
|
||||||
name: name,
|
name: strings.ToLower(name),
|
||||||
server: s,
|
server: s,
|
||||||
}
|
}
|
||||||
|
|
||||||
s.channels[name] = channel
|
s.channels.Add(channel)
|
||||||
|
|
||||||
return channel
|
return channel
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ func (s *Server) GenerateGuestNick() string {
|
|||||||
continue // TODO handle error
|
continue // TODO handle error
|
||||||
}
|
}
|
||||||
nick := fmt.Sprintf("guest%d", randInt)
|
nick := fmt.Sprintf("guest%d", randInt)
|
||||||
if s.clients[nick] == nil {
|
if s.clients.Get(nick) == nil {
|
||||||
return nick
|
return nick
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -407,7 +407,7 @@ func (msg *NickCommand) HandleServer(server *Server) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if server.clients.Get(msg.nickname) != nil {
|
if server.clients.Get(msg.nickname) != client {
|
||||||
client.ErrNickNameInUse(msg.nickname)
|
client.ErrNickNameInUse(msg.nickname)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -439,7 +439,7 @@ func (m *JoinCommand) HandleServer(s *Server) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
channel := s.channels[name]
|
channel := s.channels.Get(name)
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
channel = NewChannel(s, name)
|
channel = NewChannel(s, name)
|
||||||
}
|
}
|
||||||
@ -450,7 +450,7 @@ func (m *JoinCommand) HandleServer(s *Server) {
|
|||||||
func (m *PartCommand) HandleServer(server *Server) {
|
func (m *PartCommand) HandleServer(server *Server) {
|
||||||
client := m.Client()
|
client := m.Client()
|
||||||
for _, chname := range m.channels {
|
for _, chname := range m.channels {
|
||||||
channel := server.channels[chname]
|
channel := server.channels.Get(chname)
|
||||||
|
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
m.Client().ErrNoSuchChannel(chname)
|
m.Client().ErrNoSuchChannel(chname)
|
||||||
@ -463,7 +463,7 @@ func (m *PartCommand) HandleServer(server *Server) {
|
|||||||
|
|
||||||
func (msg *TopicCommand) HandleServer(server *Server) {
|
func (msg *TopicCommand) HandleServer(server *Server) {
|
||||||
client := msg.Client()
|
client := msg.Client()
|
||||||
channel := server.channels[msg.channel]
|
channel := server.channels.Get(msg.channel)
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
client.ErrNoSuchChannel(msg.channel)
|
client.ErrNoSuchChannel(msg.channel)
|
||||||
return
|
return
|
||||||
@ -479,7 +479,7 @@ func (msg *TopicCommand) HandleServer(server *Server) {
|
|||||||
func (msg *PrivMsgCommand) HandleServer(server *Server) {
|
func (msg *PrivMsgCommand) HandleServer(server *Server) {
|
||||||
client := msg.Client()
|
client := msg.Client()
|
||||||
if IsChannel(msg.target) {
|
if IsChannel(msg.target) {
|
||||||
channel := server.channels[msg.target]
|
channel := server.channels.Get(msg.target)
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
client.ErrNoSuchChannel(msg.target)
|
client.ErrNoSuchChannel(msg.target)
|
||||||
return
|
return
|
||||||
@ -489,7 +489,7 @@ func (msg *PrivMsgCommand) HandleServer(server *Server) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
target := server.clients[msg.target]
|
target := server.clients.Get(msg.target)
|
||||||
if target == nil {
|
if target == nil {
|
||||||
client.ErrNoSuchNick(msg.target)
|
client.ErrNoSuchNick(msg.target)
|
||||||
return
|
return
|
||||||
@ -586,7 +586,7 @@ func (m *WhoisCommand) HandleServer(server *Server) {
|
|||||||
|
|
||||||
func (msg *ChannelModeCommand) HandleServer(server *Server) {
|
func (msg *ChannelModeCommand) HandleServer(server *Server) {
|
||||||
client := msg.Client()
|
client := msg.Client()
|
||||||
channel := server.channels[msg.channel]
|
channel := server.channels.Get(msg.channel)
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
client.ErrNoSuchChannel(msg.channel)
|
client.ErrNoSuchChannel(msg.channel)
|
||||||
return
|
return
|
||||||
@ -617,14 +617,14 @@ func (msg *WhoCommand) HandleServer(server *Server) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if IsChannel(mask) {
|
} else if IsChannel(mask) {
|
||||||
channel := server.channels[mask]
|
channel := server.channels.Get(mask)
|
||||||
if channel != nil {
|
if channel != nil {
|
||||||
for member := range channel.members {
|
for member := range channel.members {
|
||||||
client.RplWhoReply(channel, member)
|
client.RplWhoReply(channel, member)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mclient := server.clients[mask]
|
mclient := server.clients.Get(mask)
|
||||||
if mclient != nil {
|
if mclient != nil {
|
||||||
client.RplWhoReply(nil, mclient)
|
client.RplWhoReply(nil, mclient)
|
||||||
}
|
}
|
||||||
@ -682,7 +682,7 @@ func (msg *MOTDCommand) HandleServer(server *Server) {
|
|||||||
func (msg *NoticeCommand) HandleServer(server *Server) {
|
func (msg *NoticeCommand) HandleServer(server *Server) {
|
||||||
client := msg.Client()
|
client := msg.Client()
|
||||||
if IsChannel(msg.target) {
|
if IsChannel(msg.target) {
|
||||||
channel := server.channels[msg.target]
|
channel := server.channels.Get(msg.target)
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
client.ErrNoSuchChannel(msg.target)
|
client.ErrNoSuchChannel(msg.target)
|
||||||
return
|
return
|
||||||
@ -703,13 +703,13 @@ func (msg *NoticeCommand) HandleServer(server *Server) {
|
|||||||
func (msg *KickCommand) HandleServer(server *Server) {
|
func (msg *KickCommand) HandleServer(server *Server) {
|
||||||
client := msg.Client()
|
client := msg.Client()
|
||||||
for chname, nickname := range msg.kicks {
|
for chname, nickname := range msg.kicks {
|
||||||
channel := server.channels[chname]
|
channel := server.channels.Get(chname)
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
client.ErrNoSuchChannel(chname)
|
client.ErrNoSuchChannel(chname)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
target := server.clients[nickname]
|
target := server.clients.Get(nickname)
|
||||||
if target == nil {
|
if target == nil {
|
||||||
client.ErrNoSuchNick(nickname)
|
client.ErrNoSuchNick(nickname)
|
||||||
continue
|
continue
|
||||||
@ -737,7 +737,7 @@ func (msg *ListCommand) HandleServer(server *Server) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, chname := range msg.channels {
|
for _, chname := range msg.channels {
|
||||||
channel := server.channels[chname]
|
channel := server.channels.Get(chname)
|
||||||
if channel == nil || (!client.flags[Operator] && channel.flags[Private]) {
|
if channel == nil || (!client.flags[Operator] && channel.flags[Private]) {
|
||||||
client.ErrNoSuchChannel(chname)
|
client.ErrNoSuchChannel(chname)
|
||||||
continue
|
continue
|
||||||
@ -758,7 +758,7 @@ func (msg *NamesCommand) HandleServer(server *Server) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, chname := range msg.channels {
|
for _, chname := range msg.channels {
|
||||||
channel := server.channels[chname]
|
channel := server.channels.Get(chname)
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
client.ErrNoSuchChannel(chname)
|
client.ErrNoSuchChannel(chname)
|
||||||
continue
|
continue
|
||||||
@ -830,10 +830,11 @@ func (msg *InviteCommand) HandleServer(server *Server) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
channel := server.channels[msg.channel]
|
channel := server.channels.Get(msg.channel)
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
client.RplInviting(target, msg.channel)
|
name := strings.ToLower(msg.channel)
|
||||||
target.Reply(RplInviteMsg(client, msg.channel))
|
client.RplInviting(target, name)
|
||||||
|
target.Reply(RplInviteMsg(client, name))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package irc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"code.google.com/p/go.text/unicode/norm"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
@ -23,7 +24,7 @@ type Socket struct {
|
|||||||
func NewSocket(conn net.Conn, commands chan<- editableCommand) *Socket {
|
func NewSocket(conn net.Conn, commands chan<- editableCommand) *Socket {
|
||||||
socket := &Socket{
|
socket := &Socket{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
reader: bufio.NewReader(conn),
|
reader: bufio.NewReader(norm.NFKC.Reader(conn)),
|
||||||
writer: bufio.NewWriter(conn),
|
writer: bufio.NewWriter(conn),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,6 +54,10 @@ func (mode ChannelMode) String() string {
|
|||||||
|
|
||||||
type ChannelNameMap map[string]*Channel
|
type ChannelNameMap map[string]*Channel
|
||||||
|
|
||||||
|
func (channels ChannelNameMap) Get(name string) *Channel {
|
||||||
|
return channels[strings.ToLower(name)]
|
||||||
|
}
|
||||||
|
|
||||||
func (channels ChannelNameMap) Add(channel *Channel) error {
|
func (channels ChannelNameMap) Add(channel *Channel) error {
|
||||||
if channels[channel.name] != nil {
|
if channels[channel.name] != nil {
|
||||||
return fmt.Errorf("%s: already set", channel.name)
|
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 {
|
if clients.Get(client.nick) != client {
|
||||||
return ErrNicknameMismatch
|
return ErrNicknameMismatch
|
||||||
}
|
}
|
||||||
delete(clients, client.nick)
|
delete(clients, strings.ToLower(client.nick))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user