mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
server: Fix
This commit is contained in:
parent
2a519c8061
commit
9e7a590f23
@ -338,7 +338,7 @@ func (channel *Channel) applyModeMember(client *Client, mode ChannelMode,
|
|||||||
if target == nil {
|
if target == nil {
|
||||||
//TODO(dan): investigate using NOSUCHNICK and NOSUCHCHANNEL specifically as that other IRCd (insp?) does,
|
//TODO(dan): investigate using NOSUCHNICK and NOSUCHCHANNEL specifically as that other IRCd (insp?) does,
|
||||||
// since I think that would make sense
|
// since I think that would make sense
|
||||||
client.Send(nil, client.server.nameString, ERR_NOSUCHNICK, nick, "No such nick/channel")
|
client.Send(nil, client.server.nameString, ERR_NOSUCHNICK, nick, "No such nick")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ type Client struct {
|
|||||||
nickString string // cache for nick string since it's used with most numerics
|
nickString string // cache for nick string since it's used with most numerics
|
||||||
nickMaskString string // cache for nickmask string since it's used with lots of replies
|
nickMaskString string // cache for nickmask string since it's used with lots of replies
|
||||||
quitTimer *time.Timer
|
quitTimer *time.Timer
|
||||||
realname Text
|
realname string
|
||||||
registered bool
|
registered bool
|
||||||
server *Server
|
server *Server
|
||||||
socket *Socket
|
socket *Socket
|
||||||
|
@ -11,6 +11,8 @@ import "github.com/DanielOaks/girc-go/ircmsg"
|
|||||||
type Command struct {
|
type Command struct {
|
||||||
handler func(server *Server, client *Client, msg ircmsg.IrcMessage) bool
|
handler func(server *Server, client *Client, msg ircmsg.IrcMessage) bool
|
||||||
usablePreReg bool
|
usablePreReg bool
|
||||||
|
leaveClientActive bool // if true, leaves the client active time alone. reversed because we can't default a struct element to True
|
||||||
|
leaveClientIdle bool
|
||||||
minParams int
|
minParams int
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,6 +26,12 @@ func (cmd *Command) Run(server *Server, client *Client, msg ircmsg.IrcMessage) b
|
|||||||
client.Send(nil, server.nameString, ERR_NEEDMOREPARAMS, client.nickString, msg.Command, "Not enough parameters")
|
client.Send(nil, server.nameString, ERR_NEEDMOREPARAMS, client.nickString, msg.Command, "Not enough parameters")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if !cmd.leaveClientActive {
|
||||||
|
client.Active()
|
||||||
|
}
|
||||||
|
if !cmd.leaveClientIdle {
|
||||||
|
client.Touch()
|
||||||
|
}
|
||||||
exiting := cmd.handler(server, client, msg)
|
exiting := cmd.handler(server, client, msg)
|
||||||
|
|
||||||
// after each command, see if we can send registration to the client
|
// after each command, see if we can send registration to the client
|
||||||
@ -95,11 +103,10 @@ var Commands = map[string]Command{
|
|||||||
handler: noticeHandler,
|
handler: noticeHandler,
|
||||||
minParams: 2,
|
minParams: 2,
|
||||||
},
|
},
|
||||||
/*TODO(dan): ADD THIS BACK
|
|
||||||
"ONICK": Command{
|
"ONICK": Command{
|
||||||
handler: onickHandler,
|
handler: onickHandler,
|
||||||
minParams: 2,
|
minParams: 2,
|
||||||
},*/
|
},
|
||||||
"OPER": Command{
|
"OPER": Command{
|
||||||
handler: operHandler,
|
handler: operHandler,
|
||||||
minParams: 2,
|
minParams: 2,
|
||||||
@ -117,11 +124,13 @@ var Commands = map[string]Command{
|
|||||||
handler: pingHandler,
|
handler: pingHandler,
|
||||||
usablePreReg: true,
|
usablePreReg: true,
|
||||||
minParams: 1,
|
minParams: 1,
|
||||||
|
leaveClientActive: true,
|
||||||
},
|
},
|
||||||
"PONG": Command{
|
"PONG": Command{
|
||||||
handler: pongHandler,
|
handler: pongHandler,
|
||||||
usablePreReg: true,
|
usablePreReg: true,
|
||||||
minParams: 1,
|
minParams: 1,
|
||||||
|
leaveClientActive: true,
|
||||||
},
|
},
|
||||||
"PRIVMSG": Command{
|
"PRIVMSG": Command{
|
||||||
handler: privmsgHandler,
|
handler: privmsgHandler,
|
||||||
|
@ -3,22 +3,19 @@
|
|||||||
|
|
||||||
package irc
|
package irc
|
||||||
|
|
||||||
import (
|
import "fmt"
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ISupportList holds a list of ISUPPORT tokens
|
// ISupportList holds a list of ISUPPORT tokens
|
||||||
type ISupportList struct {
|
type ISupportList struct {
|
||||||
Tokens map[string]*string
|
Tokens map[string]*string
|
||||||
CachedReply []string
|
CachedReply [][]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewISupportList returns a new ISupportList
|
// NewISupportList returns a new ISupportList
|
||||||
func NewISupportList() *ISupportList {
|
func NewISupportList() *ISupportList {
|
||||||
var il ISupportList
|
var il ISupportList
|
||||||
il.Tokens = make(map[string]*string)
|
il.Tokens = make(map[string]*string)
|
||||||
il.CachedReply = make([]string, 0)
|
il.CachedReply = make([][]string, 0)
|
||||||
return &il
|
return &il
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +31,7 @@ func (il *ISupportList) AddNoValue(name string) {
|
|||||||
|
|
||||||
// RegenerateCachedReply regenerates the cached RPL_ISUPPORT reply
|
// RegenerateCachedReply regenerates the cached RPL_ISUPPORT reply
|
||||||
func (il *ISupportList) RegenerateCachedReply() {
|
func (il *ISupportList) RegenerateCachedReply() {
|
||||||
il.CachedReply = make([]string, 0)
|
il.CachedReply = make([][]string, 0)
|
||||||
maxlen := 400 // Max length of a single ISUPPORT token line
|
maxlen := 400 // Max length of a single ISUPPORT token line
|
||||||
var length int // Length of the current cache
|
var length int // Length of the current cache
|
||||||
var cache []string // Token list cache
|
var cache []string // Token list cache
|
||||||
@ -57,13 +54,21 @@ func (il *ISupportList) RegenerateCachedReply() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(cache) == 13 || len(token)+length >= maxlen {
|
if len(cache) == 13 || len(token)+length >= maxlen {
|
||||||
il.CachedReply = append(il.CachedReply, strings.Join(cache, " "))
|
cache = append(cache, "are supported by this server")
|
||||||
|
il.CachedReply = append(il.CachedReply, cache)
|
||||||
cache = make([]string, 0)
|
cache = make([]string, 0)
|
||||||
length = 0
|
length = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(cache) > 0 {
|
if len(cache) > 0 {
|
||||||
il.CachedReply = append(il.CachedReply, strings.Join(cache, " "))
|
cache = append(cache, "are supported by this server")
|
||||||
|
il.CachedReply = append(il.CachedReply, cache)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (client *Client) RplISupport() {
|
||||||
|
for _, tokenline := range client.server.isupport.CachedReply {
|
||||||
|
client.Send(nil, client.server.nameString, RPL_ISUPPORT, tokenline...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,8 @@ var (
|
|||||||
SupportedUserModes = UserModes{
|
SupportedUserModes = UserModes{
|
||||||
Away, Invisible, Operator,
|
Away, Invisible, Operator,
|
||||||
}
|
}
|
||||||
|
// supportedUserModesString acts as a cache for when we introduce users
|
||||||
|
supportedUserModesString = SupportedUserModes.String()
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -98,6 +100,8 @@ var (
|
|||||||
BanMask, ExceptMask, InviteMask, InviteOnly, Key, NoOutside,
|
BanMask, ExceptMask, InviteMask, InviteOnly, Key, NoOutside,
|
||||||
OpOnlyTopic, Persistent, Secret, Theater, UserLimit,
|
OpOnlyTopic, Persistent, Secret, Theater, UserLimit,
|
||||||
}
|
}
|
||||||
|
// supportedChannelModesString acts as a cache for when we introduce users
|
||||||
|
supportedChannelModesString = SupportedChannelModes.String()
|
||||||
|
|
||||||
DefaultChannelModes = ChannelModes{
|
DefaultChannelModes = ChannelModes{
|
||||||
NoOutside, OpOnlyTopic,
|
NoOutside, OpOnlyTopic,
|
||||||
|
@ -494,7 +494,7 @@ func (target *Client) ErrBadChannelKey(channel *Channel) {
|
|||||||
|
|
||||||
func (target *Client) ErrNoSuchNick(nick Name) {
|
func (target *Client) ErrNoSuchNick(nick Name) {
|
||||||
target.NumericReply(ERR_NOSUCHNICK,
|
target.NumericReply(ERR_NOSUCHNICK,
|
||||||
"%s :No such nick/channel", nick)
|
"%s :No such nick", nick)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (target *Client) ErrPasswdMismatch() {
|
func (target *Client) ErrPasswdMismatch() {
|
||||||
|
512
irc/server.go
512
irc/server.go
@ -66,14 +66,6 @@ func NewServer(config *Config) *Server {
|
|||||||
theaters: config.Theaters(),
|
theaters: config.Theaters(),
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure that there is a minimum number of args specified for every command
|
|
||||||
for name, _ := range parseCommandFuncs {
|
|
||||||
_, exists := commandMinimumArgs[name]
|
|
||||||
if !exists {
|
|
||||||
log.Fatal("commandMinArgs not found for ", name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.Server.MOTD != "" {
|
if config.Server.MOTD != "" {
|
||||||
file, err := os.Open(config.Server.MOTD)
|
file, err := os.Open(config.Server.MOTD)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -86,6 +78,9 @@ func NewServer(config *Config) *Server {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
line = strings.TrimRight(line, "\r\n")
|
line = strings.TrimRight(line, "\r\n")
|
||||||
|
// "- " is the required prefix for MOTD, we just add it here to make
|
||||||
|
// bursting it out to clients easier
|
||||||
|
line = fmt.Sprintf("- %s", line)
|
||||||
|
|
||||||
server.motdLines = append(server.motdLines, line)
|
server.motdLines = append(server.motdLines, line)
|
||||||
}
|
}
|
||||||
@ -160,8 +155,8 @@ func (server *Server) loadChannels() {
|
|||||||
for _, flag := range flags {
|
for _, flag := range flags {
|
||||||
channel.flags[ChannelMode(flag)] = true
|
channel.flags[ChannelMode(flag)] = true
|
||||||
}
|
}
|
||||||
channel.key = NewText(key)
|
channel.key = key
|
||||||
channel.topic = NewText(topic)
|
channel.topic = topic
|
||||||
channel.userLimit = userLimit
|
channel.userLimit = userLimit
|
||||||
loadChannelList(channel, banList, BanMask)
|
loadChannelList(channel, banList, BanMask)
|
||||||
loadChannelList(channel, exceptList, ExceptMask)
|
loadChannelList(channel, exceptList, ExceptMask)
|
||||||
@ -169,51 +164,10 @@ func (server *Server) loadChannels() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) processCommand(cmd Command) {
|
|
||||||
client := cmd.Client()
|
|
||||||
|
|
||||||
numCmd, ok := cmd.(*NeedMoreParamsCommand)
|
|
||||||
if ok {
|
|
||||||
client.ErrNeedMoreParams(numCmd.code)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !client.registered {
|
|
||||||
regCmd, ok := cmd.(RegServerCommand)
|
|
||||||
if !ok {
|
|
||||||
client.Quit("unexpected command")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
regCmd.HandleRegServer(server)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
srvCmd, ok := cmd.(ServerCommand)
|
|
||||||
if !ok {
|
|
||||||
client.ErrUnknownCommand(cmd.Code())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
switch srvCmd.(type) {
|
|
||||||
case *PingCommand, *PongCommand:
|
|
||||||
client.Touch()
|
|
||||||
|
|
||||||
case *QuitCommand:
|
|
||||||
// no-op
|
|
||||||
|
|
||||||
default:
|
|
||||||
client.Active()
|
|
||||||
client.Touch()
|
|
||||||
}
|
|
||||||
|
|
||||||
srvCmd.HandleServer(server)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (server *Server) Shutdown() {
|
func (server *Server) Shutdown() {
|
||||||
server.db.Close()
|
server.db.Close()
|
||||||
for _, client := range server.clients.byNick {
|
for _, client := range server.clients.byNick {
|
||||||
client.Send("notice")
|
client.Notice("Server is shutting down")
|
||||||
client.Reply(RplNotice(server, client, "shutting down"))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,8 +182,10 @@ func (server *Server) Run() {
|
|||||||
case conn := <-server.newConns:
|
case conn := <-server.newConns:
|
||||||
NewClient(server, conn)
|
NewClient(server, conn)
|
||||||
|
|
||||||
|
/*TODO(dan): LOOK AT THIS MORE CLOSELY
|
||||||
case cmd := <-server.commands:
|
case cmd := <-server.commands:
|
||||||
server.processCommand(cmd)
|
server.processCommand(cmd)
|
||||||
|
*/
|
||||||
|
|
||||||
case client := <-server.idle:
|
case client := <-server.idle:
|
||||||
client.Idle()
|
client.Idle()
|
||||||
@ -326,32 +282,31 @@ func (s *Server) tryRegister(c *Client) {
|
|||||||
(c.capState == CapNegotiating) {
|
(c.capState == CapNegotiating) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.registered = true
|
|
||||||
|
|
||||||
c.Send("Intro to the network")
|
|
||||||
c.Register()
|
c.Register()
|
||||||
c.RplWelcome()
|
|
||||||
c.RplYourHost()
|
// send welcome text
|
||||||
c.RplCreated()
|
//NOTE(dan): we specifically use the NICK here instead of the nickmask
|
||||||
c.RplMyInfo()
|
// see http://modern.ircdocs.horse/#rplwelcome-001 for details on why we avoid using the nickmask
|
||||||
|
c.Send(nil, s.nameString, RPL_WELCOME, fmt.Sprintf("Welcome to the Internet Relay Network %s", c.nickString))
|
||||||
|
c.Send(nil, s.nameString, RPL_YOURHOST, fmt.Sprintf("Your host is %s, running version %s", s.nameString, SEM_VER))
|
||||||
|
c.Send(nil, s.nameString, RPL_CREATED, fmt.Sprintf("This server was created %s", s.ctime.Format(time.RFC1123)))
|
||||||
|
//TODO(dan): Look at adding last optional [<channel modes with a parameter>] parameter
|
||||||
|
c.Send(nil, s.nameString, RPL_MYINFO, s.nameString, SEM_VER, supportedUserModesString, supportedChannelModesString)
|
||||||
c.RplISupport()
|
c.RplISupport()
|
||||||
s.MOTD(c)
|
s.MOTD(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) MOTD(client *Client) {
|
func (server *Server) MOTD(client *Client) {
|
||||||
if len(server.motdLines) < 1 {
|
if len(server.motdLines) < 1 {
|
||||||
c.Send("send")
|
client.Send(nil, server.nameString, ERR_NOMOTD, client.nickString, "MOTD File is missing")
|
||||||
client.ErrNoMOTD()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
client.RplMOTDStart()
|
client.Send(nil, server.nameString, RPL_MOTDSTART, client.nickString, fmt.Sprintf("- %s Message of the day - ", server.nameString))
|
||||||
for _, line := range server.motdLines {
|
for _, line := range server.motdLines {
|
||||||
c.Send("send")
|
client.Send(nil, server.nameString, RPL_MOTD, client.nickString, line)
|
||||||
client.RplMOTD(line)
|
|
||||||
}
|
}
|
||||||
c.Send("send")
|
client.Send(nil, server.nameString, RPL_ENDOFMOTD, client.nickString, "End of MOTD command")
|
||||||
client.RplMOTDEnd()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Id() Name {
|
func (s *Server) Id() Name {
|
||||||
@ -372,17 +327,14 @@ func (s *Server) Nick() Name {
|
|||||||
|
|
||||||
// PASS <password>
|
// PASS <password>
|
||||||
func passHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
func passHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
if client.Registered {
|
if client.registered {
|
||||||
client.Send("send")
|
client.Send(nil, server.nameString, ERR_ALREADYREGISTRED, client.nickString, "You may not reregister")
|
||||||
client.ErrAlreadyRegistered()
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the provided password
|
// check the provided password
|
||||||
logger.Fatal("Implement PASS command")
|
password := []byte(msg.Params[0])
|
||||||
password := []byte(args[0])
|
|
||||||
if ComparePassword(server.password, password) != nil {
|
if ComparePassword(server.password, password) != nil {
|
||||||
logger.Fatal("SEND BACK REJECTION")
|
|
||||||
client.Quit("bad password")
|
client.Quit("bad password")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -410,14 +362,13 @@ func proxyHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
|
|
||||||
// USER <username> * 0 <realname>
|
// USER <username> * 0 <realname>
|
||||||
func userHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
func userHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
if client.Registered {
|
if client.registered {
|
||||||
client.Send("send")
|
client.Send(nil, server.nameString, ERR_ALREADYREGISTRED, client.nickString, "You may not reregister")
|
||||||
client.ErrAlreadyRegistered()
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if !client.authorized {
|
if !client.authorized {
|
||||||
client.Quit("bad password")
|
client.Quit("Bad password")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -433,16 +384,17 @@ func userHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
server.clients.Remove(client)
|
server.clients.Remove(client)
|
||||||
|
|
||||||
if client.username != "" {
|
if client.username != "" {
|
||||||
client.username = msg.username
|
client.username = Name(msg.Params[0])
|
||||||
|
client.updateNickMask()
|
||||||
}
|
}
|
||||||
if client.realname != "" {
|
if client.realname != "" {
|
||||||
client.realname = msg.realname
|
client.realname = msg.Params[3]
|
||||||
}
|
}
|
||||||
client.updateNickMask()
|
|
||||||
|
|
||||||
server.clients.Add(client)
|
server.clients.Add(client)
|
||||||
|
|
||||||
server.tryRegister(client)
|
server.tryRegister(client)
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// QUIT [<reason>]
|
// QUIT [<reason>]
|
||||||
@ -451,7 +403,7 @@ func quitHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
if len(msg.Params) > 0 {
|
if len(msg.Params) > 0 {
|
||||||
reason += ": " + msg.Params[0]
|
reason += ": " + msg.Params[0]
|
||||||
}
|
}
|
||||||
client.Quit(msg.message)
|
client.Quit(reason)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,7 +430,7 @@ func joinHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
// handle JOIN 0
|
// handle JOIN 0
|
||||||
if msg.Params[0] == "0" {
|
if msg.Params[0] == "0" {
|
||||||
for channel := range client.channels {
|
for channel := range client.channels {
|
||||||
channel.Part(client, client.Nick().Text())
|
channel.Part(client, client.nickString)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -490,15 +442,17 @@ func joinHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
keys = strings.Split(msg.Params[1], ",")
|
keys = strings.Split(msg.Params[1], ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, name := range channels {
|
var name Name
|
||||||
|
for i, nameString := range channels {
|
||||||
|
name = Name(nameString)
|
||||||
if !name.IsChannel() {
|
if !name.IsChannel() {
|
||||||
log.Fatal("Implement ErrNoSuchChannel")
|
client.Send(nil, server.nameString, ERR_NOSUCHCHANNEL, client.nickString, nameString, "No such channel")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
channel := s.channels.Get(name)
|
channel := server.channels.Get(name)
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
channel = NewChannel(s, name, true)
|
channel = NewChannel(server, name, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
var key string
|
var key string
|
||||||
@ -508,34 +462,36 @@ func joinHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
|
|
||||||
channel.Join(client, key)
|
channel.Join(client, key)
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// PART <channel>{,<channel>} [<reason>]
|
// PART <channel>{,<channel>} [<reason>]
|
||||||
func partHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
func partHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
channels := strings.Split(msg.Params[0], ",")
|
channels := strings.Split(msg.Params[0], ",")
|
||||||
var reason string //TODO(dan): should this be the user's nickname instead of empty?
|
var reason string //TODO(dan): if this isn't supplied here, make sure the param doesn't exist in the PART message sent to other users
|
||||||
if len(msg.Params) > 1 {
|
if len(msg.Params) > 1 {
|
||||||
reason = msg.Params[1]
|
reason = msg.Params[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, chname := range channels {
|
for _, chname := range channels {
|
||||||
channel := server.channels.Get(chname)
|
channel := server.channels.Get(Name(chname))
|
||||||
|
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
log.Fatal("Implement ErrNoSuchChannel")
|
client.Send(nil, server.nameString, ERR_NOSUCHCHANNEL, client.nickString, chname, "No such channel")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.Part(client, m.Message())
|
channel.Part(client, reason)
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// TOPIC <channel> [<topic>]
|
// TOPIC <channel> [<topic>]
|
||||||
func topicHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
func topicHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
channel := server.channels.Get(msg.Params[0])
|
channel := server.channels.Get(Name(msg.Params[0]))
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
log.Fatal("Implement ErrNoSuchChannel")
|
client.Send(nil, server.nameString, ERR_NOSUCHCHANNEL, client.nickString, msg.Params[0], "No such channel")
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(msg.Params) > 1 {
|
if len(msg.Params) > 1 {
|
||||||
@ -543,6 +499,7 @@ func topicHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
} else {
|
} else {
|
||||||
channel.GetTopic(client)
|
channel.GetTopic(client)
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// PRIVMSG <target>{,<target>} <message>
|
// PRIVMSG <target>{,<target>} <message>
|
||||||
@ -550,28 +507,30 @@ func privmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool
|
|||||||
targets := strings.Split(msg.Params[0], ",")
|
targets := strings.Split(msg.Params[0], ",")
|
||||||
message := msg.Params[1]
|
message := msg.Params[1]
|
||||||
|
|
||||||
for _, target := range targets {
|
var target Name
|
||||||
|
for _, targetString := range targets {
|
||||||
|
target = Name(targetString)
|
||||||
if target.IsChannel() {
|
if target.IsChannel() {
|
||||||
channel := server.channels.Get(target)
|
channel := server.channels.Get(target)
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
client.Send("send")
|
client.Send(nil, server.nameString, ERR_NOSUCHCHANNEL, client.nickString, targetString, "No such channel")
|
||||||
client.ErrNoSuchChannel(target)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
channel.PrivMsg(client, message)
|
channel.PrivMsg(client, message)
|
||||||
} else {
|
} else {
|
||||||
user := server.clients.Get(target)
|
user := server.clients.Get(target)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
client.Send("send")
|
client.Send(nil, server.nameString, ERR_NOSUCHNICK, targetString, "No such nick")
|
||||||
client.ErrNoSuchNick(target)
|
continue
|
||||||
return
|
|
||||||
}
|
}
|
||||||
user.Send("content here")
|
user.Send(nil, client.nickMaskString, "PRIVMSG", user.nickString, message)
|
||||||
if user.flags[Away] {
|
if user.flags[Away] {
|
||||||
client.Send("target is AWAY")
|
//TODO(dan): possibly implement cooldown of away notifications to users
|
||||||
|
client.Send(nil, server.nameString, RPL_AWAY, user.nickString, user.awayMessage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) WhoisChannelsNames(target *Client) []string {
|
func (client *Client) WhoisChannelsNames(target *Client) []string {
|
||||||
@ -591,35 +550,79 @@ func (client *Client) WhoisChannelsNames(target *Client) []string {
|
|||||||
|
|
||||||
// WHOIS [ <target> ] <mask> *( "," <mask> )
|
// WHOIS [ <target> ] <mask> *( "," <mask> )
|
||||||
func whoisHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
func whoisHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
var masks string
|
var masksString string
|
||||||
var target string
|
var target string
|
||||||
|
|
||||||
if len(msg.Params) > 1 {
|
if len(msg.Params) > 1 {
|
||||||
target = msg.Params[0]
|
target = msg.Params[0]
|
||||||
masks = msg.Params[1]
|
masksString = msg.Params[1]
|
||||||
} else {
|
} else {
|
||||||
masks = msg.Params[0]
|
masksString = msg.Params[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO implement target query
|
if client.flags[Operator] {
|
||||||
|
masks := strings.Split(masksString, ",")
|
||||||
for _, mask := range masks {
|
for _, mask := range masks {
|
||||||
matches := server.clients.FindAll(mask)
|
matches := server.clients.FindAll(Name(mask))
|
||||||
if len(matches) == 0 {
|
if len(matches) == 0 {
|
||||||
client.ErrNoSuchNick(mask)
|
client.Send(nil, client.server.nameString, ERR_NOSUCHNICK, mask, "No such nick")
|
||||||
client.Send("NOSUCHNICK")
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for mclient := range matches {
|
for mclient := range matches {
|
||||||
client.RplWhois(mclient)
|
mclient.getWhoisOf(client)
|
||||||
client.Send("WHOIS")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// specifically treat this as a single lookup rather than splitting as we do above
|
||||||
|
// this is by design
|
||||||
|
mclient := server.clients.Get(Name(masksString))
|
||||||
|
if mclient == nil {
|
||||||
|
client.Send(nil, client.server.nameString, ERR_NOSUCHNICK, masksString, "No such nick")
|
||||||
|
// fall through, ENDOFWHOIS is always sent
|
||||||
|
} else {
|
||||||
|
client.getWhoisOf(mclient)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
client.Send(nil, server.nameString, RPL_ENDOFWHOIS, client.nickString, masksString, "End of /WHOIS list")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (client *Client) getWhoisOf(target *Client) {
|
||||||
|
client.Send(nil, client.server.nameString, RPL_WHOISUSER, client.nickString, target.nickString, target.username.String(), target.hostname.String(), "*", target.realname)
|
||||||
|
if target.flags[Operator] {
|
||||||
|
client.Send(nil, client.server.nameString, RPL_WHOISOPERATOR, client.nickString, target.nickString, "is an IRC operator")
|
||||||
|
}
|
||||||
|
client.Send(nil, client.server.nameString, RPL_WHOISIDLE, client.nickString, target.nickString, string(target.IdleSeconds()), string(target.SignonTime()), "seconds idle, signon time")
|
||||||
|
for _, line := range client.WhoisChannelsNames(target) {
|
||||||
|
client.Send(nil, client.server.nameString, RPL_WHOISCHANNELS, client.nickString, target.nickString, line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// <channel> <user> <host> <server> <nick> ( "H" / "G" ) ["*"] [ ( "@" / "+" ) ]
|
||||||
|
// :<hopcount> <real name>
|
||||||
|
func (target *Client) RplWhoReply(channel *Channel, client *Client) {
|
||||||
|
channelName := "*"
|
||||||
|
flags := ""
|
||||||
|
|
||||||
|
if client.flags[Away] {
|
||||||
|
flags = "G"
|
||||||
|
} else {
|
||||||
|
flags = "H"
|
||||||
|
}
|
||||||
|
if client.flags[Operator] {
|
||||||
|
flags += "*"
|
||||||
|
}
|
||||||
|
|
||||||
|
if channel != nil {
|
||||||
|
flags += channel.members[client].Prefixes(target.capabilities[MultiPrefix])
|
||||||
|
channelName = channel.name.String()
|
||||||
|
}
|
||||||
|
target.Send(nil, target.server.nameString, RPL_WHOREPLY, target.nickString, channelName, client.username.String(), client.hostname.String(), client.server.nameString, client.nickString, flags, string(client.hops), client.realname)
|
||||||
}
|
}
|
||||||
|
|
||||||
func whoChannel(client *Client, channel *Channel, friends ClientSet) {
|
func whoChannel(client *Client, channel *Channel, friends ClientSet) {
|
||||||
for member := range channel.members {
|
for member := range channel.members {
|
||||||
if !client.flags[Invisible] || friends[client] {
|
if !client.flags[Invisible] || friends[client] {
|
||||||
client.Send("send")
|
|
||||||
client.RplWhoReply(channel, member)
|
client.RplWhoReply(channel, member)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -629,15 +632,15 @@ func whoChannel(client *Client, channel *Channel, friends ClientSet) {
|
|||||||
func whoHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
func whoHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
friends := client.Friends()
|
friends := client.Friends()
|
||||||
|
|
||||||
var mask string
|
var mask Name
|
||||||
if len(msg.Params) > 0 {
|
if len(msg.Params) > 0 {
|
||||||
mask = NewName(msg.Params[0])
|
mask = Name(msg.Params[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO(dan): is this used and would I put this param in the Modern doc?
|
//TODO(dan): is this used and would I put this param in the Modern doc?
|
||||||
// if not, can we remove it?
|
// if not, can we remove it?
|
||||||
var operatorOnly bool
|
var operatorOnly bool
|
||||||
if len(msg.Params) > 1 && msr.Params[1] == "o" {
|
if len(msg.Params) > 1 && msg.Params[1] == "o" {
|
||||||
operatorOnly = true
|
operatorOnly = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -647,6 +650,7 @@ func whoHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
}
|
}
|
||||||
} else if mask.IsChannel() {
|
} else if mask.IsChannel() {
|
||||||
// TODO implement wildcard matching
|
// TODO implement wildcard matching
|
||||||
|
//TODO(dan): ^ only for opers
|
||||||
channel := server.channels.Get(mask)
|
channel := server.channels.Get(mask)
|
||||||
if channel != nil {
|
if channel != nil {
|
||||||
whoChannel(client, channel, friends)
|
whoChannel(client, channel, friends)
|
||||||
@ -654,37 +658,35 @@ func whoHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
} else {
|
} else {
|
||||||
for mclient := range server.clients.FindAll(mask) {
|
for mclient := range server.clients.FindAll(mask) {
|
||||||
client.RplWhoReply(nil, mclient)
|
client.RplWhoReply(nil, mclient)
|
||||||
client.Send("REPLY")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client.RplEndOfWho(mask)
|
client.Send(nil, server.nameString, RPL_ENDOFWHO, client.nickString, mask.String(), "End of WHO list")
|
||||||
client.Send("ENDOFWHO")
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// OPER <name> <password>
|
// OPER <name> <password>
|
||||||
func operHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
func operHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
name = NewName(msg.Params[0])
|
name := NewName(msg.Params[0])
|
||||||
hash = server.operators[name]
|
hash := server.operators[name]
|
||||||
password = []byte(msg.Params[1])
|
password := []byte(msg.Params[1])
|
||||||
|
|
||||||
err = ComparePassword(hash, password)
|
err := ComparePassword(hash, password)
|
||||||
|
|
||||||
if (hash == nil) || (err != nil) {
|
if (hash == nil) || (err != nil) {
|
||||||
client.ErrPasswdMismatch()
|
client.Send(nil, server.nameString, ERR_PASSWDMISMATCH, client.nickString, "Password incorrect")
|
||||||
client.Send("PASSWDBAD")
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO(dan): Split this into client.makeOper() ??
|
|
||||||
client.flags[Operator] = true
|
client.flags[Operator] = true
|
||||||
client.RplYoureOper()
|
client.Send(nil, server.nameString, RPL_YOUREOPER, client.nickString, "You are not an IRC operator")
|
||||||
client.Send("YOUROPER")
|
//TODO(dan): Should this be sent automagically as part of setting the flag/mode?
|
||||||
client.Reply(RplModeChanges(client, client, ModeChanges{&ModeChange{
|
modech := ModeChanges{&ModeChange{
|
||||||
mode: Operator,
|
mode: Operator,
|
||||||
op: Add,
|
op: Add,
|
||||||
}}))
|
}}
|
||||||
client.Send("OPERMODECHANGE")
|
client.Send(nil, server.nameString, "MODE", client.nickString, client.nickString, modech.String())
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// AWAY [<message>]
|
// AWAY [<message>]
|
||||||
@ -692,8 +694,8 @@ func awayHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
var isAway bool
|
var isAway bool
|
||||||
var text string
|
var text string
|
||||||
if len(msg.Params) > 0 {
|
if len(msg.Params) > 0 {
|
||||||
isAway = True
|
isAway = true
|
||||||
text = NewText(msg.Params[0])
|
text = msg.Params[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
if isAway {
|
if isAway {
|
||||||
@ -706,33 +708,33 @@ func awayHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
var op ModeOp
|
var op ModeOp
|
||||||
if client.flags[Away] {
|
if client.flags[Away] {
|
||||||
op = Add
|
op = Add
|
||||||
client.Send("imaway")
|
client.Send(nil, server.nameString, RPL_NOWAWAY, client.nickString, "You have been marked as being away")
|
||||||
client.RplNowAway()
|
|
||||||
} else {
|
} else {
|
||||||
op = Remove
|
op = Remove
|
||||||
client.Send("unaway")
|
client.Send(nil, server.nameString, RPL_UNAWAY, client.nickString, "You are no longer marked as being away")
|
||||||
client.RplUnAway()
|
|
||||||
}
|
}
|
||||||
client.Send("mode changes I guess?")
|
//TODO(dan): Should this be sent automagically as part of setting the flag/mode?
|
||||||
client.Reply(RplModeChanges(client, client, ModeChanges{&ModeChange{
|
modech := ModeChanges{&ModeChange{
|
||||||
mode: Away,
|
mode: Away,
|
||||||
op: op,
|
op: op,
|
||||||
}}))
|
}}
|
||||||
|
client.Send(nil, server.nameString, "MODE", client.nickString, client.nickString, modech.String())
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// ISON <nick>{ <nick>}
|
// ISON <nick>{ <nick>}
|
||||||
func isonHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
func isonHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
var nicks = NewNames(msg.Params)
|
var nicks = msg.Params
|
||||||
|
|
||||||
ison := make([]string, 0)
|
ison := make([]string, 0)
|
||||||
for _, nick := range nicks {
|
for _, nick := range nicks {
|
||||||
if iclient := server.clients.Get(nick); iclient != nil {
|
if iclient := server.clients.Get(Name(nick)); iclient != nil {
|
||||||
ison = append(ison, iclient.Nick().String())
|
ison = append(ison, iclient.Nick().String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client.Send("ISON")
|
client.Send(nil, server.nameString, RPL_ISON, client.nickString, strings.Join(nicks, " "))
|
||||||
client.RplIsOn(ison)
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// MOTD [<target>]
|
// MOTD [<target>]
|
||||||
@ -740,51 +742,50 @@ func motdHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
//TODO(dan): hook this up when we have multiple servers I guess???
|
//TODO(dan): hook this up when we have multiple servers I guess???
|
||||||
var target string
|
var target string
|
||||||
if len(msg.Params) > 0 {
|
if len(msg.Params) > 0 {
|
||||||
target = NewName(msg.Params[0])
|
target = msg.Params[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
client.Send("MOTD")
|
server.MOTD(client)
|
||||||
server.MOTD(msg.Client())
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTICE <target>{,<target>} <message>
|
// NOTICE <target>{,<target>} <message>
|
||||||
func noticeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
func noticeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
targetName := NewName(msg.Params[0])
|
targets := strings.Split(msg.Params[0], ",")
|
||||||
message := NewText(msg.Params[1])
|
message := msg.Params[1]
|
||||||
|
|
||||||
if targetName.IsChannel() {
|
var target Name
|
||||||
channel := server.channels.Get(targetName)
|
for _, targetString := range targets {
|
||||||
|
target = Name(targetString)
|
||||||
|
if target.IsChannel() {
|
||||||
|
channel := server.channels.Get(target)
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
client.Send("ERRNOSUCHCHAN")
|
// errors silently ignored with NOTICE as per RFC
|
||||||
client.ErrNoSuchChannel(targetName)
|
continue
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
channel.PrivMsg(client, message)
|
||||||
channel.Notice(client, message)
|
} else {
|
||||||
return
|
user := server.clients.Get(target)
|
||||||
|
if user == nil {
|
||||||
|
// errors silently ignored with NOTICE as per RFC
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
user.Send(nil, client.nickMaskString, "NOTICE", user.nickString, message)
|
||||||
target := server.clients.Get(targetName)
|
|
||||||
if target == nil {
|
|
||||||
client.Send("ERRNOSUCHNICK")
|
|
||||||
client.ErrNoSuchNick(targetName)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
client.Send("NOTICE")
|
}
|
||||||
target.Reply(RplNotice(client, target, message))
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// KICK <channel>{,<channel>} <user>{,<user>} [<comment>]
|
// KICK <channel>{,<channel>} <user>{,<user>} [<comment>]
|
||||||
func kickHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
func kickHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
channels := NewNames(strings.Split(msg.Params[0], ","))
|
channels := strings.Split(msg.Params[0], ",")
|
||||||
users := NewNames(strings.Split(msg.Params[1], ","))
|
users := strings.Split(msg.Params[1], ",")
|
||||||
if (len(channels) != len(users)) && (len(users) != 1) {
|
if (len(channels) != len(users)) && (len(users) != 1) {
|
||||||
client.Send("NotEnoughArgs??")
|
client.Send(nil, server.nameString, ERR_NEEDMOREPARAMS, client.nickString, "KICK", "Not enough parameters")
|
||||||
return false
|
return false
|
||||||
// not needed return nil, NotEnoughArgsError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
kicks := make(map[Name]Name)
|
kicks := make(map[string]string)
|
||||||
for index, channel := range channels {
|
for index, channel := range channels {
|
||||||
if len(users) == 1 {
|
if len(users) == 1 {
|
||||||
kicks[channel] = users[0]
|
kicks[channel] = users[0]
|
||||||
@ -798,17 +799,15 @@ func kickHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
comment = msg.Params[2]
|
comment = msg.Params[2]
|
||||||
}
|
}
|
||||||
for chname, nickname := range kicks {
|
for chname, nickname := range kicks {
|
||||||
channel := server.channels.Get(chname)
|
channel := server.channels.Get(Name(chname))
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
client.ErrNoSuchChannel(chname)
|
client.Send(nil, server.nameString, ERR_NOSUCHCHANNEL, client.nickString, chname, "No such channel")
|
||||||
client.Send("send")
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
target := server.clients.Get(nickname)
|
target := server.clients.Get(Name(nickname))
|
||||||
if target == nil {
|
if target == nil {
|
||||||
client.ErrNoSuchNick(nickname)
|
client.Send(nil, server.nameString, ERR_NOSUCHNICK, nickname, "No such nick")
|
||||||
client.Send("send")
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -836,29 +835,28 @@ func kickHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
channel.Kick(client, target, comment)
|
channel.Kick(client, target, comment)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
client.ErrChanOPrivIsNeeded(channel)
|
client.Send(nil, client.server.nameString, ERR_CHANOPRIVSNEEDED, chname, "You're not a channel operator")
|
||||||
client.Send("send")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// LIST [<channel>{,<channel>} [<server>]]
|
// LIST [<channel>{,<channel>} [<server>]]
|
||||||
func listHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
func listHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
var channels []Name
|
var channels []string
|
||||||
if len(args) > 0 {
|
if len(msg.Params) > 0 {
|
||||||
channels = NewNames(strings.Split(args[0], ","))
|
channels = strings.Split(msg.Params[0], ",")
|
||||||
}
|
}
|
||||||
var target Name
|
var target string
|
||||||
if len(args) > 1 {
|
if len(msg.Params) > 1 {
|
||||||
target = NewName(args[1])
|
target = msg.Params[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO(dan): target server when we have multiple servers
|
//TODO(dan): target server when we have multiple servers
|
||||||
//TODO(dan): we should continue just fine if it's this current server though
|
//TODO(dan): we should continue just fine if it's this current server though
|
||||||
if target != "" {
|
if target != "" {
|
||||||
client.ErrNoSuchServer(msg.target)
|
client.Send(nil, server.nameString, ERR_NOSUCHSERVER, client.nickString, target, "No such server")
|
||||||
client.Send("send")
|
return false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(channels) == 0 {
|
if len(channels) == 0 {
|
||||||
@ -867,33 +865,46 @@ func listHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
client.RplList(channel)
|
client.RplList(channel)
|
||||||
client.Send("send")
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, chname := range channels {
|
for _, chname := range channels {
|
||||||
channel := server.channels.Get(chname)
|
channel := server.channels.Get(Name(chname))
|
||||||
if channel == nil || (!client.flags[Operator] && channel.flags[Secret]) {
|
if channel == nil || (!client.flags[Operator] && channel.flags[Secret]) {
|
||||||
client.ErrNoSuchChannel(chname)
|
client.Send(nil, server.nameString, ERR_NOSUCHCHANNEL, client.nickString, chname, "No such channel")
|
||||||
client.Send("send")
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
client.RplList(channel)
|
client.RplList(channel)
|
||||||
client.Send("send")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
client.RplListEnd(server)
|
client.Send(nil, server.nameString, RPL_LISTEND, client.nickString, "End of LIST")
|
||||||
client.Send("send")
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (target *Client) RplList(channel *Channel) {
|
||||||
|
// get the correct number of channel members
|
||||||
|
var memberCount int
|
||||||
|
if target.flags[Operator] || channel.members.Has(target) {
|
||||||
|
memberCount = len(channel.members)
|
||||||
|
} else {
|
||||||
|
for member := range channel.members {
|
||||||
|
if !member.flags[Invisible] {
|
||||||
|
memberCount += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
target.Send(nil, target.server.nameString, RPL_LIST, target.nickString, channel.nameString, string(memberCount), channel.topic)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NAMES [<channel>{,<channel>}]
|
// NAMES [<channel>{,<channel>}]
|
||||||
func namesHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
func namesHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
var channels []Name
|
var channels []string
|
||||||
if len(args) > 0 {
|
if len(msg.Params) > 0 {
|
||||||
channels = NewNames(strings.Split(args[0], ","))
|
channels = strings.Split(msg.Params[0], ",")
|
||||||
}
|
}
|
||||||
var target Name
|
var target string
|
||||||
if len(args) > 1 {
|
if len(msg.Params) > 1 {
|
||||||
target = NewName(args[1])
|
target = msg.Params[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(channels) == 0 {
|
if len(channels) == 0 {
|
||||||
@ -904,121 +915,112 @@ func namesHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, chname := range channels {
|
for _, chname := range channels {
|
||||||
channel := server.channels.Get(chname)
|
channel := server.channels.Get(Name(chname))
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
client.ErrNoSuchChannel(chname)
|
client.Send(nil, server.nameString, ERR_NOSUCHCHANNEL, client.nickString, chname, "No such channel")
|
||||||
client.Send("send")
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
channel.Names(client)
|
channel.Names(client)
|
||||||
client.Send("send")
|
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// VERSION [<server>]
|
// VERSION [<server>]
|
||||||
func versionHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
func versionHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
var target Name
|
var target string
|
||||||
if len(args) > 0 {
|
if len(msg.Params) > 0 {
|
||||||
target = NewName(args[0])
|
target = msg.Params[0]
|
||||||
}
|
}
|
||||||
if (target != "") && (target != server.name) {
|
if (target != "") && (Name(target) != server.name) {
|
||||||
client.ErrNoSuchServer(target)
|
client.Send(nil, server.nameString, ERR_NOSUCHSERVER, client.nickString, target, "No such server")
|
||||||
client.Send("send")
|
return false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
client.RplVersion()
|
client.Send(nil, server.nameString, RPL_VERSION, client.nickString, SEM_VER, server.nameString)
|
||||||
client.Send("send")
|
|
||||||
client.RplISupport()
|
client.RplISupport()
|
||||||
client.Send("send")
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// INVITE <nickname> <channel>
|
// INVITE <nickname> <channel>
|
||||||
func inviteHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
func inviteHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
nickname := NewName(msg.Params[0])
|
nickname := msg.Params[0]
|
||||||
channelName := NewName(msg.Params[1])
|
channelName := msg.Params[1]
|
||||||
|
|
||||||
target := server.clients.Get(nickname)
|
target := server.clients.Get(Name(nickname))
|
||||||
if target == nil {
|
if target == nil {
|
||||||
client.ErrNoSuchNick(nickname)
|
client.Send(nil, server.nameString, ERR_NOSUCHNICK, client.nickString, nickname, "No such nick")
|
||||||
client.Send("send")
|
return false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
channel := server.channels.Get(channelName)
|
channel := server.channels.Get(Name(channelName))
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
client.RplInviting(target, channelName)
|
client.Send(nil, server.nameString, RPL_INVITING, client.nickString, target.nickString, channelName)
|
||||||
client.Send("send")
|
target.Send(nil, client.nickMaskString, "INVITE", target.nickString, channel.nameString)
|
||||||
target.Reply(RplInviteMsg(client, target, channelName))
|
return true
|
||||||
client.Send("send")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.Invite(target, client)
|
channel.Invite(target, client)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// TIME [<server>]
|
// TIME [<server>]
|
||||||
func timeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
func timeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
var target Name
|
var target string
|
||||||
if len(msg.Params) > 0 {
|
if len(msg.Params) > 0 {
|
||||||
target = NewName(msg.Params[0])
|
target = msg.Params[0]
|
||||||
}
|
}
|
||||||
if (target != "") && (target != server.name) {
|
if (target != "") && (Name(target) != server.name) {
|
||||||
client.ErrNoSuchServer(target)
|
client.Send(nil, server.nameString, ERR_NOSUCHSERVER, client.nickString, target, "No such server")
|
||||||
client.Send("send")
|
return false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
client.RplTime()
|
client.Send(nil, server.nameString, RPL_TIME, client.nickString, server.nameString, time.Now().Format(time.RFC1123))
|
||||||
client.Send("send")
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// KILL <nickname> <comment>
|
// KILL <nickname> <comment>
|
||||||
func killHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
func killHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
nickname := NewName(msg.Params[0])
|
nickname := msg.Params[0]
|
||||||
comment := NewText(msg.Params[1])
|
comment := msg.Params[1]
|
||||||
|
|
||||||
if !client.flags[Operator] {
|
if !client.flags[Operator] {
|
||||||
client.ErrNoPrivileges()
|
client.Send(nil, server.nameString, ERR_NOPRIVILEGES, client.nickString, "Permission Denied - You're not an IRC operator")
|
||||||
client.Send("send")
|
return false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
target := server.clients.Get(nickname)
|
target := server.clients.Get(Name(nickname))
|
||||||
if target == nil {
|
if target == nil {
|
||||||
client.ErrNoSuchNick(nickname)
|
client.Send(nil, client.server.nameString, ERR_NOSUCHNICK, nickname, "No such nick")
|
||||||
client.Send("send")
|
return false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO(dan): make below format match that from other IRCds
|
quitMsg := fmt.Sprintf("Killed (%s (%s))", client.nickString, comment)
|
||||||
quitMsg := fmt.Sprintf("KILLed by %s: %s", client.Nick(), comment)
|
target.Quit(quitMsg)
|
||||||
target.Quit(NewText(quitMsg))
|
target.destroy()
|
||||||
return true
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// WHOWAS <nickname> [<count> [<server>]]
|
// WHOWAS <nickname> [<count> [<server>]]
|
||||||
func whowasHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
func whowasHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
nicknames := NewNames(strings.Split(msg.Params[0], ","))
|
nicknames := strings.Split(msg.Params[0], ",")
|
||||||
|
|
||||||
var count int
|
var count int64
|
||||||
if len(msg.Params) > 1 {
|
if len(msg.Params) > 1 {
|
||||||
count, _ = strconv.ParseInt(msg.Params[1], 10, 64)
|
count, _ = strconv.ParseInt(msg.Params[1], 10, 64)
|
||||||
}
|
}
|
||||||
var target Name
|
var target string
|
||||||
if len(msg.Params) > 2 {
|
if len(msg.Params) > 2 {
|
||||||
target = NewName(msg.Params[2])
|
target = msg.Params[2]
|
||||||
}
|
}
|
||||||
for _, nickname := range nicknames {
|
for _, nickname := range nicknames {
|
||||||
results := server.whoWas.Find(nickname, msg.count)
|
results := server.whoWas.Find(Name(nickname), count)
|
||||||
if len(results) == 0 {
|
if len(results) == 0 {
|
||||||
client.ErrWasNoSuchNick(nickname)
|
client.Send(nil, server.nameString, ERR_WASNOSUCHNICK, client.nickString, nickname, "There was no such nickname")
|
||||||
client.Send("send")
|
|
||||||
} else {
|
} else {
|
||||||
for _, whoWas := range results {
|
for _, whoWas := range results {
|
||||||
client.RplWhoWasUser(whoWas)
|
client.Send(nil, server.nameString, RPL_WHOWASUSER, client.nickString, whoWas.nickname.String(), whoWas.username.String(), whoWas.hostname.String(), "*", whoWas.realname)
|
||||||
client.Send("send")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
client.Send(nil, server.Name, RPL_ENDOFWHOWAS, nickname, "End of WHOWAS")
|
client.Send(nil, server.nameString, RPL_ENDOFWHOWAS, client.nickString, nickname, "End of WHOWAS")
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ type WhoWas struct {
|
|||||||
nickname Name
|
nickname Name
|
||||||
username Name
|
username Name
|
||||||
hostname Name
|
hostname Name
|
||||||
realname Text
|
realname string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWhoWasList(size uint) *WhoWasList {
|
func NewWhoWasList(size uint) *WhoWasList {
|
||||||
|
Loading…
Reference in New Issue
Block a user