a9f1283dd6
--HG-- branch : nmdc-ircfrontend
116 lines
1.7 KiB
Go
116 lines
1.7 KiB
Go
package main
|
|
|
|
import "net"
|
|
|
|
const (
|
|
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
|
|
)
|
|
|
|
type Server struct {
|
|
eventChan chan Event
|
|
running bool
|
|
name string
|
|
clientMap map[string]*Client // Map of nicks -> clients
|
|
channel Channel // Single blessed channel
|
|
motd string
|
|
}
|
|
|
|
type Client struct {
|
|
server *Server
|
|
connection net.Conn
|
|
signalChan chan signalCode
|
|
outputChan chan string
|
|
nick string
|
|
key string
|
|
registered bool
|
|
connected bool
|
|
operator bool
|
|
}
|
|
|
|
type eventType int
|
|
|
|
const (
|
|
connected eventType = iota
|
|
disconnected
|
|
command
|
|
)
|
|
|
|
type Event struct {
|
|
client *Client
|
|
input string
|
|
event eventType
|
|
}
|
|
|
|
type Channel struct {
|
|
name string
|
|
topic string
|
|
clientMap map[string]*Client
|
|
modeMap map[string]*ClientMode
|
|
}
|
|
|
|
type ClientMode struct {
|
|
operator bool //Channel operator
|
|
}
|
|
|
|
func (m *ClientMode) Prefix() string {
|
|
if m.operator {
|
|
return "@"
|
|
} else {
|
|
return ""
|
|
}
|
|
}
|
|
|
|
func (m *ClientMode) String() string {
|
|
if m.operator {
|
|
return "o"
|
|
} else {
|
|
return ""
|
|
}
|
|
}
|
|
|
|
type signalCode int
|
|
|
|
const (
|
|
signalStop signalCode = iota
|
|
)
|
|
|
|
type replyCode int
|
|
|
|
const (
|
|
rplWelcome replyCode = iota
|
|
rplJoin
|
|
rplPart
|
|
rplTopic
|
|
rplNoTopic
|
|
rplNames
|
|
rplEndOfNames
|
|
rplNickChange
|
|
rplKill
|
|
rplMsg
|
|
rplList
|
|
rplListEnd
|
|
rplOper
|
|
rplChannelModeIs
|
|
rplKick
|
|
rplInfo
|
|
rplVersion
|
|
rplMOTDStart
|
|
rplMOTD
|
|
rplEndOfMOTD
|
|
rplPong
|
|
errMoreArgs
|
|
errNoNick
|
|
errInvalidNick
|
|
errNickInUse
|
|
errAlreadyReg
|
|
errNoSuchNick
|
|
errUnknownCommand
|
|
errNotReg
|
|
errPassword
|
|
errNoPriv
|
|
errCannotSend
|
|
)
|