2016-06-15 13:50:56 +02:00
|
|
|
// Copyright (c) 2012-2014 Jeremy Latt
|
|
|
|
// Copyright (c) 2014-2015 Edmund Huber
|
|
|
|
// Copyright (c) 2016- Daniel Oaks <daniel@danieloaks.net>
|
|
|
|
// released under the MIT license
|
|
|
|
|
2012-04-18 03:16:57 +02:00
|
|
|
package irc
|
|
|
|
|
2016-06-17 14:17:42 +02:00
|
|
|
import "github.com/DanielOaks/girc-go/ircmsg"
|
2012-12-09 21:51:50 +01:00
|
|
|
|
2016-06-17 14:17:42 +02:00
|
|
|
// Command represents a command accepted on a listener.
|
|
|
|
type Command struct {
|
2016-06-19 02:01:30 +02:00
|
|
|
handler func(server *Server, client *Client, msg ircmsg.IrcMessage) bool
|
2016-06-17 14:17:42 +02:00
|
|
|
usablePreReg bool
|
|
|
|
minParams int
|
2014-03-13 01:52:25 +01:00
|
|
|
}
|
|
|
|
|
2016-06-17 14:17:42 +02:00
|
|
|
// Run runs this command with the given listener/message.
|
|
|
|
func (cmd *Command) Run(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
2016-06-19 02:01:30 +02:00
|
|
|
if !client.registered && !cmd.usablePreReg {
|
2016-06-17 14:17:42 +02:00
|
|
|
// command silently ignored
|
|
|
|
return false
|
2012-12-09 21:51:50 +01:00
|
|
|
}
|
2016-06-17 14:17:42 +02:00
|
|
|
if len(msg.Params) < cmd.minParams {
|
2016-06-19 02:01:30 +02:00
|
|
|
client.Send(nil, server.name, ERR_NEEDMOREPARAMS, client.nickString, msg.Command, "Not enough parameters")
|
2016-06-17 14:17:42 +02:00
|
|
|
return false
|
2014-02-24 18:41:09 +01:00
|
|
|
}
|
2016-06-17 14:17:42 +02:00
|
|
|
exiting := cmd.handler(server, client, msg)
|
2012-04-18 03:16:57 +02:00
|
|
|
|
2016-06-17 14:17:42 +02:00
|
|
|
// after each command, see if we can send registration to the client
|
2016-06-19 02:01:30 +02:00
|
|
|
if !client.registered {
|
|
|
|
server.tryRegister(client)
|
2014-03-01 04:21:33 +01:00
|
|
|
}
|
2014-03-17 20:11:35 +01:00
|
|
|
|
2016-06-17 14:17:42 +02:00
|
|
|
return exiting
|
|
|
|
}
|
|
|
|
|
|
|
|
// Commands holds all commands executable by a client connected to us.
|
|
|
|
var Commands = map[string]Command{
|
|
|
|
"AWAY": Command{
|
|
|
|
handler: awayHandler,
|
|
|
|
minParams: 0,
|
|
|
|
},
|
|
|
|
"CAP": Command{
|
|
|
|
handler: capHandler,
|
|
|
|
usablePreReg: true,
|
|
|
|
minParams: 1,
|
|
|
|
},
|
|
|
|
"DEBUG": Command{
|
|
|
|
handler: debugHandler,
|
|
|
|
minParams: 1,
|
|
|
|
},
|
|
|
|
"INVITE": Command{
|
|
|
|
handler: inviteHandler,
|
|
|
|
minParams: 2,
|
|
|
|
},
|
|
|
|
"ISON": Command{
|
|
|
|
handler: isonHandler,
|
|
|
|
minParams: 1,
|
|
|
|
},
|
|
|
|
"JOIN": Command{
|
|
|
|
handler: joinHandler,
|
|
|
|
minParams: 1,
|
|
|
|
},
|
|
|
|
"KICK": Command{
|
|
|
|
handler: kickHandler,
|
|
|
|
minParams: 2,
|
|
|
|
},
|
|
|
|
"KILL": Command{
|
|
|
|
handler: killHandler,
|
|
|
|
minParams: 2,
|
|
|
|
},
|
|
|
|
"LIST": Command{
|
|
|
|
handler: listHandler,
|
|
|
|
minParams: 0,
|
|
|
|
},
|
2016-06-19 02:01:30 +02:00
|
|
|
/*TODO(dan): ADD THIS BACK.
|
2016-06-17 14:17:42 +02:00
|
|
|
"MODE": Command{
|
|
|
|
handler: modeHandler,
|
|
|
|
minParams: 1,
|
2016-06-19 02:01:30 +02:00
|
|
|
},*/
|
2016-06-17 14:17:42 +02:00
|
|
|
"MOTD": Command{
|
|
|
|
handler: motdHandler,
|
|
|
|
minParams: 0,
|
|
|
|
},
|
|
|
|
"NAMES": Command{
|
|
|
|
handler: namesHandler,
|
|
|
|
minParams: 0,
|
|
|
|
},
|
|
|
|
"NICK": Command{
|
|
|
|
handler: nickHandler,
|
|
|
|
usablePreReg: true,
|
|
|
|
minParams: 1,
|
|
|
|
},
|
|
|
|
"NOTICE": Command{
|
|
|
|
handler: noticeHandler,
|
|
|
|
minParams: 2,
|
|
|
|
},
|
2016-06-19 02:01:30 +02:00
|
|
|
/*TODO(dan): ADD THIS BACK
|
2016-06-17 14:17:42 +02:00
|
|
|
"ONICK": Command{
|
|
|
|
handler: onickHandler,
|
|
|
|
minParams: 2,
|
2016-06-19 02:01:30 +02:00
|
|
|
},*/
|
2016-06-17 14:17:42 +02:00
|
|
|
"OPER": Command{
|
|
|
|
handler: operHandler,
|
|
|
|
minParams: 2,
|
|
|
|
},
|
|
|
|
"PART": Command{
|
|
|
|
handler: partHandler,
|
|
|
|
minParams: 1,
|
|
|
|
},
|
|
|
|
"PASS": Command{
|
|
|
|
handler: passHandler,
|
|
|
|
usablePreReg: true,
|
|
|
|
minParams: 1,
|
|
|
|
},
|
|
|
|
"PING": Command{
|
|
|
|
handler: pingHandler,
|
|
|
|
usablePreReg: true,
|
|
|
|
minParams: 1,
|
|
|
|
},
|
|
|
|
"PONG": Command{
|
|
|
|
handler: pongHandler,
|
|
|
|
usablePreReg: true,
|
|
|
|
minParams: 1,
|
|
|
|
},
|
|
|
|
"PRIVMSG": Command{
|
|
|
|
handler: privmsgHandler,
|
|
|
|
minParams: 2,
|
|
|
|
},
|
|
|
|
"PROXY": Command{
|
|
|
|
handler: proxyHandler,
|
|
|
|
usablePreReg: true,
|
|
|
|
minParams: 5,
|
|
|
|
},
|
|
|
|
"QUIT": Command{
|
|
|
|
handler: quitHandler,
|
|
|
|
usablePreReg: true,
|
|
|
|
minParams: 0,
|
|
|
|
},
|
2016-06-19 02:01:30 +02:00
|
|
|
/*TODO(dan): ADD THIS BACK IN
|
2016-06-17 14:17:42 +02:00
|
|
|
"THEATRE": Command{
|
|
|
|
handler: theatreHandler,
|
|
|
|
minParams: 1,
|
2016-06-19 02:01:30 +02:00
|
|
|
},*/
|
2016-06-17 14:17:42 +02:00
|
|
|
"TIME": Command{
|
|
|
|
handler: timeHandler,
|
|
|
|
minParams: 0,
|
|
|
|
},
|
|
|
|
"TOPIC": Command{
|
|
|
|
handler: topicHandler,
|
|
|
|
minParams: 1,
|
|
|
|
},
|
|
|
|
"USER": Command{
|
|
|
|
handler: userHandler,
|
|
|
|
usablePreReg: true,
|
|
|
|
minParams: 4,
|
|
|
|
},
|
|
|
|
"VERSION": Command{
|
|
|
|
handler: versionHandler,
|
|
|
|
minParams: 0,
|
|
|
|
},
|
|
|
|
"WHO": Command{
|
|
|
|
handler: whoHandler,
|
|
|
|
minParams: 0,
|
|
|
|
},
|
|
|
|
"WHOIS": Command{
|
|
|
|
handler: whoisHandler,
|
|
|
|
minParams: 1,
|
|
|
|
},
|
|
|
|
"WHOWAS": Command{
|
|
|
|
handler: whowasHandler,
|
|
|
|
minParams: 1,
|
|
|
|
},
|
2014-03-17 20:11:35 +01:00
|
|
|
}
|