2013-08-23 01:03:37 +00:00
|
|
|
package main
|
|
|
|
|
2013-08-24 06:48:28 +00:00
|
|
|
import "net"
|
2013-08-23 01:03:37 +00:00
|
|
|
|
|
|
|
type Server struct {
|
2013-08-23 22:59:33 +00:00
|
|
|
eventChan chan Event
|
|
|
|
running bool
|
|
|
|
name string
|
|
|
|
clientMap map[string]*Client //Map of nicks → clients
|
|
|
|
channelMap map[string]*Channel //Map of channel names → channels
|
|
|
|
operatorMap map[string]string //Map of usernames → SHA1 hashed passwords
|
2013-08-23 01:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Client struct {
|
|
|
|
server *Server
|
|
|
|
connection net.Conn
|
2013-08-24 19:58:38 +00:00
|
|
|
signalChan chan signalCode
|
2013-08-23 01:03:37 +00:00
|
|
|
outputChan chan string
|
|
|
|
nick string
|
2013-08-23 15:24:06 +00:00
|
|
|
registered bool
|
2013-08-23 16:34:45 +00:00
|
|
|
connected bool
|
2013-08-23 22:59:33 +00:00
|
|
|
operator bool
|
2013-08-23 01:03:37 +00:00
|
|
|
channelMap map[string]*Channel
|
|
|
|
}
|
|
|
|
|
2013-08-24 06:48:28 +00:00
|
|
|
type Event struct {
|
|
|
|
client *Client
|
|
|
|
input string
|
|
|
|
}
|
|
|
|
|
2013-08-23 01:03:37 +00:00
|
|
|
type Channel struct {
|
|
|
|
name string
|
|
|
|
topic string
|
|
|
|
clientMap map[string]*Client
|
2013-08-27 17:24:41 +00:00
|
|
|
mode ChannelMode
|
|
|
|
modeMap map[string]*ClientMode
|
|
|
|
}
|
|
|
|
|
|
|
|
type ChannelMode struct {
|
|
|
|
anonymous bool //Nicks are hidden
|
|
|
|
secret bool //Channel is hidden from LIST
|
|
|
|
topicLocked bool //Only ops may change topic
|
|
|
|
moderated bool //Only ops and voiced may speak
|
|
|
|
}
|
|
|
|
|
2013-08-28 15:36:40 +00:00
|
|
|
func (m *ChannelMode) String() string {
|
|
|
|
modeStr := ""
|
|
|
|
if m.anonymous {
|
|
|
|
modeStr += "a"
|
|
|
|
}
|
|
|
|
if m.secret {
|
|
|
|
modeStr += "s"
|
|
|
|
}
|
|
|
|
if m.topicLocked {
|
|
|
|
modeStr += "t"
|
|
|
|
}
|
|
|
|
if m.moderated {
|
|
|
|
modeStr += "m"
|
|
|
|
}
|
|
|
|
return modeStr
|
|
|
|
}
|
|
|
|
|
2013-08-27 17:24:41 +00:00
|
|
|
type ClientMode struct {
|
|
|
|
operator bool //Channel operator
|
|
|
|
voice bool //Has voice
|
2013-08-23 01:03:37 +00:00
|
|
|
}
|
|
|
|
|
2013-08-28 15:38:54 +00:00
|
|
|
func (m *ClientMode) Prefix() string {
|
|
|
|
if m.operator {
|
|
|
|
return "@"
|
|
|
|
} else if m.voice {
|
|
|
|
return "+"
|
|
|
|
} else {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-24 19:58:38 +00:00
|
|
|
type signalCode int
|
|
|
|
|
2013-08-23 01:03:37 +00:00
|
|
|
const (
|
2013-08-24 19:58:38 +00:00
|
|
|
signalStop signalCode = iota
|
2013-08-23 01:03:37 +00:00
|
|
|
)
|
|
|
|
|
2013-08-24 19:58:38 +00:00
|
|
|
type replyCode int
|
|
|
|
|
2013-08-23 01:03:37 +00:00
|
|
|
const (
|
2013-08-24 19:58:38 +00:00
|
|
|
rplWelcome replyCode = iota
|
2013-08-23 01:32:46 +00:00
|
|
|
rplJoin
|
|
|
|
rplPart
|
2013-08-23 01:03:37 +00:00
|
|
|
rplTopic
|
2013-08-23 01:32:46 +00:00
|
|
|
rplNoTopic
|
2013-08-23 01:03:37 +00:00
|
|
|
rplNames
|
|
|
|
rplNickChange
|
2013-08-23 16:34:45 +00:00
|
|
|
rplKill
|
2013-08-23 16:39:10 +00:00
|
|
|
rplMsg
|
2013-08-23 21:09:29 +00:00
|
|
|
rplList
|
2013-08-23 22:59:33 +00:00
|
|
|
rplOper
|
2013-08-27 18:34:52 +00:00
|
|
|
rplChannelModeIs
|
2013-08-23 01:03:37 +00:00
|
|
|
errMoreArgs
|
|
|
|
errNoNick
|
|
|
|
errInvalidNick
|
|
|
|
errNickInUse
|
|
|
|
errAlreadyReg
|
|
|
|
errNoSuchNick
|
2013-08-23 14:39:40 +00:00
|
|
|
errUnknownCommand
|
2013-08-23 15:24:06 +00:00
|
|
|
errNotReg
|
2013-08-23 22:59:33 +00:00
|
|
|
errPassword
|
2013-08-23 23:18:54 +00:00
|
|
|
errNoPriv
|
2013-08-27 18:40:14 +00:00
|
|
|
errCannotSend
|
2013-08-23 01:03:37 +00:00
|
|
|
)
|