nmdc-ircfrontend/rosella.go

146 lines
2.2 KiB
Go
Raw Normal View History

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
const (
VERSION = "1.1.1"
)
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-09-08 19:35:30 +00:00
motd string
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-29 19:50:10 +00:00
key string
2013-08-23 15:24:06 +00:00
registered bool
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-09-08 15:24:17 +00:00
type eventType int
const (
connected eventType = iota
disconnected
command
)
2013-08-24 06:48:28 +00:00
type Event struct {
client *Client
input string
2013-09-08 15:24:17 +00:00
event eventType
2013-08-24 06:48:28 +00:00
}
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 {
secret bool //Channel is hidden from LIST
topicLocked bool //Only ops may change topic
moderated bool //Only ops and voiced may speak
2013-08-29 15:58:50 +00:00
noExternal bool //Only users in the channel may talk to it
2013-08-27 17:24:41 +00:00
}
2013-08-28 15:36:40 +00:00
func (m *ChannelMode) String() string {
2013-08-29 15:58:50 +00:00
modeStr := ""
if m.secret {
modeStr += "s"
}
if m.topicLocked {
modeStr += "t"
}
if m.moderated {
modeStr += "m"
}
if m.noExternal {
modeStr += "n"
}
return modeStr
2013-08-28 15:36:40 +00:00
}
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 ""
}
}
func (m *ClientMode) String() string {
modeStr := ""
if m.operator {
modeStr += "o"
}
if m.voice {
modeStr += "v"
}
return modeStr
}
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
rplJoin
rplPart
2013-08-23 01:03:37 +00:00
rplTopic
rplNoTopic
2013-08-23 01:03:37 +00:00
rplNames
rplEndOfNames
2013-08-23 01:03:37 +00:00
rplNickChange
rplKill
2013-08-23 16:39:10 +00:00
rplMsg
2013-08-23 21:09:29 +00:00
rplList
rplListEnd
2013-08-23 22:59:33 +00:00
rplOper
2013-08-27 18:34:52 +00:00
rplChannelModeIs
2013-08-29 20:10:28 +00:00
rplKick
2013-08-30 22:17:54 +00:00
rplInfo
rplVersion
rplMOTDStart
2013-09-08 15:06:03 +00:00
rplMOTD
rplEndOfMOTD
2013-10-21 12:34:12 +00:00
rplPong
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
)