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
|
|
|
|
2013-09-02 00:55:19 +00:00
|
|
|
const (
|
2016-05-03 06:00:40 +00:00
|
|
|
VERSION = "1.0.0"
|
|
|
|
APP_DESCRIPTION = "nmdc-ircfrontend v" + VERSION
|
|
|
|
BLESSED_CHANNEL = "#chat" // must be lowercase
|
|
|
|
BLESSED_CHANNEL_MODE = "n" // means that you have to be in the channel to chat, but that's it
|
2013-09-02 00:55:19 +00:00
|
|
|
)
|
|
|
|
|
2013-08-23 01:03:37 +00:00
|
|
|
type Server struct {
|
2016-05-02 07:23:15 +00:00
|
|
|
eventChan chan Event
|
|
|
|
running bool
|
|
|
|
name string
|
|
|
|
clientMap map[string]*Client // Map of nicks -> clients
|
|
|
|
channel Channel // Single blessed channel
|
|
|
|
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
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
modeMap map[string]*ClientMode
|
|
|
|
}
|
|
|
|
|
|
|
|
type ClientMode struct {
|
|
|
|
operator bool //Channel operator
|
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 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-29 16:57:33 +00:00
|
|
|
func (m *ClientMode) String() string {
|
|
|
|
if m.operator {
|
2016-05-03 06:02:10 +00:00
|
|
|
return "o"
|
|
|
|
} else {
|
|
|
|
return ""
|
2013-08-29 16:57:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2016-03-09 08:04:04 +00:00
|
|
|
rplEndOfNames
|
2013-08-23 01:03:37 +00:00
|
|
|
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
|
2016-03-13 09:07:16 +00:00
|
|
|
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
|
2013-09-02 00:55:19 +00:00
|
|
|
rplVersion
|
2016-03-13 06:51:10 +00:00
|
|
|
rplMOTDStart
|
2013-09-08 15:06:03 +00:00
|
|
|
rplMOTD
|
2016-03-13 06:51:10 +00:00
|
|
|
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
|
|
|
)
|