|
|
|
@@ -26,37 +26,37 @@ var (
|
|
|
|
NotEnoughArgsError = errors.New("not enough arguments")
|
|
|
|
NotEnoughArgsError = errors.New("not enough arguments")
|
|
|
|
ErrParseCommand = errors.New("failed to parse message")
|
|
|
|
ErrParseCommand = errors.New("failed to parse message")
|
|
|
|
parseCommandFuncs = map[StringCode]parseCommandFunc{
|
|
|
|
parseCommandFuncs = map[StringCode]parseCommandFunc{
|
|
|
|
AWAY: NewAwayCommand,
|
|
|
|
AWAY: ParseAwayCommand,
|
|
|
|
CAP: NewCapCommand,
|
|
|
|
CAP: ParseCapCommand,
|
|
|
|
DEBUG: NewDebugCommand,
|
|
|
|
DEBUG: ParseDebugCommand,
|
|
|
|
INVITE: NewInviteCommand,
|
|
|
|
INVITE: ParseInviteCommand,
|
|
|
|
ISON: NewIsOnCommand,
|
|
|
|
ISON: ParseIsOnCommand,
|
|
|
|
JOIN: NewJoinCommand,
|
|
|
|
JOIN: ParseJoinCommand,
|
|
|
|
KICK: NewKickCommand,
|
|
|
|
KICK: ParseKickCommand,
|
|
|
|
KILL: NewKillCommand,
|
|
|
|
KILL: ParseKillCommand,
|
|
|
|
LIST: NewListCommand,
|
|
|
|
LIST: ParseListCommand,
|
|
|
|
MODE: NewModeCommand,
|
|
|
|
MODE: ParseModeCommand,
|
|
|
|
MOTD: NewMOTDCommand,
|
|
|
|
MOTD: ParseMOTDCommand,
|
|
|
|
NAMES: NewNamesCommand,
|
|
|
|
NAMES: ParseNamesCommand,
|
|
|
|
NICK: NewNickCommand,
|
|
|
|
NICK: ParseNickCommand,
|
|
|
|
NOTICE: NewNoticeCommand,
|
|
|
|
NOTICE: ParseNoticeCommand,
|
|
|
|
ONICK: NewOperNickCommand,
|
|
|
|
ONICK: ParseOperNickCommand,
|
|
|
|
OPER: NewOperCommand,
|
|
|
|
OPER: ParseOperCommand,
|
|
|
|
PART: NewPartCommand,
|
|
|
|
PART: ParsePartCommand,
|
|
|
|
PASS: NewPassCommand,
|
|
|
|
PASS: ParsePassCommand,
|
|
|
|
PING: NewPingCommand,
|
|
|
|
PING: ParsePingCommand,
|
|
|
|
PONG: NewPongCommand,
|
|
|
|
PONG: ParsePongCommand,
|
|
|
|
PRIVMSG: NewPrivMsgCommand,
|
|
|
|
PRIVMSG: ParsePrivMsgCommand,
|
|
|
|
PROXY: NewProxyCommand,
|
|
|
|
PROXY: ParseProxyCommand,
|
|
|
|
QUIT: NewQuitCommand,
|
|
|
|
QUIT: ParseQuitCommand,
|
|
|
|
THEATER: NewTheaterCommand, // nonstandard
|
|
|
|
THEATER: ParseTheaterCommand, // nonstandard
|
|
|
|
TIME: NewTimeCommand,
|
|
|
|
TIME: ParseTimeCommand,
|
|
|
|
TOPIC: NewTopicCommand,
|
|
|
|
TOPIC: ParseTopicCommand,
|
|
|
|
USER: NewUserCommand,
|
|
|
|
USER: ParseUserCommand,
|
|
|
|
VERSION: NewVersionCommand,
|
|
|
|
VERSION: ParseVersionCommand,
|
|
|
|
WHO: NewWhoCommand,
|
|
|
|
WHO: ParseWhoCommand,
|
|
|
|
WHOIS: NewWhoisCommand,
|
|
|
|
WHOIS: ParseWhoisCommand,
|
|
|
|
WHOWAS: NewWhoWasCommand,
|
|
|
|
WHOWAS: ParseWhoWasCommand,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -85,7 +85,7 @@ func ParseCommand(line string) (cmd Command, err error) {
|
|
|
|
code, args := ParseLine(line)
|
|
|
|
code, args := ParseLine(line)
|
|
|
|
constructor := parseCommandFuncs[code]
|
|
|
|
constructor := parseCommandFuncs[code]
|
|
|
|
if constructor == nil {
|
|
|
|
if constructor == nil {
|
|
|
|
cmd = NewUnknownCommand(args)
|
|
|
|
cmd = ParseUnknownCommand(args)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
cmd, err = constructor(args)
|
|
|
|
cmd, err = constructor(args)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -135,11 +135,7 @@ type UnknownCommand struct {
|
|
|
|
args []string
|
|
|
|
args []string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (cmd *UnknownCommand) String() string {
|
|
|
|
func ParseUnknownCommand(args []string) *UnknownCommand {
|
|
|
|
return fmt.Sprintf("UNKNOWN(command=%s, args=%s)", cmd.Code(), cmd.args)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func NewUnknownCommand(args []string) *UnknownCommand {
|
|
|
|
|
|
|
|
return &UnknownCommand{
|
|
|
|
return &UnknownCommand{
|
|
|
|
args: args,
|
|
|
|
args: args,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -153,11 +149,7 @@ type PingCommand struct {
|
|
|
|
server2 Name
|
|
|
|
server2 Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (cmd *PingCommand) String() string {
|
|
|
|
func ParsePingCommand(args []string) (Command, error) {
|
|
|
|
return fmt.Sprintf("PING(server=%s, server2=%s)", cmd.server, cmd.server2)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func NewPingCommand(args []string) (Command, error) {
|
|
|
|
|
|
|
|
if len(args) < 1 {
|
|
|
|
if len(args) < 1 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -178,11 +170,7 @@ type PongCommand struct {
|
|
|
|
server2 Name
|
|
|
|
server2 Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (cmd *PongCommand) String() string {
|
|
|
|
func ParsePongCommand(args []string) (Command, error) {
|
|
|
|
return fmt.Sprintf("PONG(server1=%s, server2=%s)", cmd.server1, cmd.server2)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func NewPongCommand(args []string) (Command, error) {
|
|
|
|
|
|
|
|
if len(args) < 1 {
|
|
|
|
if len(args) < 1 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -204,10 +192,6 @@ type PassCommand struct {
|
|
|
|
err error
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (cmd *PassCommand) String() string {
|
|
|
|
|
|
|
|
return fmt.Sprintf("PASS(password=%s)", cmd.password)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (cmd *PassCommand) LoadPassword(server *Server) {
|
|
|
|
func (cmd *PassCommand) LoadPassword(server *Server) {
|
|
|
|
cmd.hash = server.password
|
|
|
|
cmd.hash = server.password
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -219,7 +203,7 @@ func (cmd *PassCommand) CheckPassword() {
|
|
|
|
cmd.err = ComparePassword(cmd.hash, cmd.password)
|
|
|
|
cmd.err = ComparePassword(cmd.hash, cmd.password)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewPassCommand(args []string) (Command, error) {
|
|
|
|
func ParsePassCommand(args []string) (Command, error) {
|
|
|
|
if len(args) < 1 {
|
|
|
|
if len(args) < 1 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -230,7 +214,7 @@ func NewPassCommand(args []string) (Command, error) {
|
|
|
|
|
|
|
|
|
|
|
|
// NICK <nickname>
|
|
|
|
// NICK <nickname>
|
|
|
|
|
|
|
|
|
|
|
|
func NewNickCommand(args []string) (Command, error) {
|
|
|
|
func ParseNickCommand(args []string) (Command, error) {
|
|
|
|
if len(args) != 1 {
|
|
|
|
if len(args) != 1 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -252,11 +236,6 @@ type RFC1459UserCommand struct {
|
|
|
|
servername Name
|
|
|
|
servername Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (cmd *RFC1459UserCommand) String() string {
|
|
|
|
|
|
|
|
return fmt.Sprintf("USER(username=%s, hostname=%s, servername=%s, realname=%s)",
|
|
|
|
|
|
|
|
cmd.username, cmd.hostname, cmd.servername, cmd.realname)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// USER <user> <mode> <unused> <realname>
|
|
|
|
// USER <user> <mode> <unused> <realname>
|
|
|
|
type RFC2812UserCommand struct {
|
|
|
|
type RFC2812UserCommand struct {
|
|
|
|
UserCommand
|
|
|
|
UserCommand
|
|
|
|
@@ -264,11 +243,6 @@ type RFC2812UserCommand struct {
|
|
|
|
unused string
|
|
|
|
unused string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (cmd *RFC2812UserCommand) String() string {
|
|
|
|
|
|
|
|
return fmt.Sprintf("USER(username=%s, mode=%d, unused=%s, realname=%s)",
|
|
|
|
|
|
|
|
cmd.username, cmd.mode, cmd.unused, cmd.realname)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (cmd *RFC2812UserCommand) Flags() []UserMode {
|
|
|
|
func (cmd *RFC2812UserCommand) Flags() []UserMode {
|
|
|
|
flags := make([]UserMode, 0)
|
|
|
|
flags := make([]UserMode, 0)
|
|
|
|
if (cmd.mode & 4) == 4 {
|
|
|
|
if (cmd.mode & 4) == 4 {
|
|
|
|
@@ -280,7 +254,7 @@ func (cmd *RFC2812UserCommand) Flags() []UserMode {
|
|
|
|
return flags
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewUserCommand(args []string) (Command, error) {
|
|
|
|
func ParseUserCommand(args []string) (Command, error) {
|
|
|
|
if len(args) != 4 {
|
|
|
|
if len(args) != 4 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -311,11 +285,15 @@ type QuitCommand struct {
|
|
|
|
message Text
|
|
|
|
message Text
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (cmd *QuitCommand) String() string {
|
|
|
|
func NewQuitCommand(message Text) *QuitCommand {
|
|
|
|
return fmt.Sprintf("QUIT(message=%s)", cmd.message)
|
|
|
|
cmd := &QuitCommand{
|
|
|
|
|
|
|
|
message: message,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.code = QUIT
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewQuitCommand(args []string) (Command, error) {
|
|
|
|
func ParseQuitCommand(args []string) (Command, error) {
|
|
|
|
msg := &QuitCommand{}
|
|
|
|
msg := &QuitCommand{}
|
|
|
|
if len(args) > 0 {
|
|
|
|
if len(args) > 0 {
|
|
|
|
msg.message = NewText(args[0])
|
|
|
|
msg.message = NewText(args[0])
|
|
|
|
@@ -331,11 +309,7 @@ type JoinCommand struct {
|
|
|
|
zero bool
|
|
|
|
zero bool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (cmd *JoinCommand) String() string {
|
|
|
|
func ParseJoinCommand(args []string) (Command, error) {
|
|
|
|
return fmt.Sprintf("JOIN(channels=%s, zero=%t)", cmd.channels, cmd.zero)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func NewJoinCommand(args []string) (Command, error) {
|
|
|
|
|
|
|
|
msg := &JoinCommand{
|
|
|
|
msg := &JoinCommand{
|
|
|
|
channels: make(map[Name]Text),
|
|
|
|
channels: make(map[Name]Text),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -378,11 +352,7 @@ func (cmd *PartCommand) Message() Text {
|
|
|
|
return cmd.message
|
|
|
|
return cmd.message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (cmd *PartCommand) String() string {
|
|
|
|
func ParsePartCommand(args []string) (Command, error) {
|
|
|
|
return fmt.Sprintf("PART(channels=%s, message=%s)", cmd.channels, cmd.message)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func NewPartCommand(args []string) (Command, error) {
|
|
|
|
|
|
|
|
if len(args) < 1 {
|
|
|
|
if len(args) < 1 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -403,11 +373,7 @@ type PrivMsgCommand struct {
|
|
|
|
message Text
|
|
|
|
message Text
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (cmd *PrivMsgCommand) String() string {
|
|
|
|
func ParsePrivMsgCommand(args []string) (Command, error) {
|
|
|
|
return fmt.Sprintf("PRIVMSG(target=%s, message=%s)", cmd.target, cmd.message)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func NewPrivMsgCommand(args []string) (Command, error) {
|
|
|
|
|
|
|
|
if len(args) < 2 {
|
|
|
|
if len(args) < 2 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -426,11 +392,7 @@ type TopicCommand struct {
|
|
|
|
topic Text
|
|
|
|
topic Text
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (cmd *TopicCommand) String() string {
|
|
|
|
func ParseTopicCommand(args []string) (Command, error) {
|
|
|
|
return fmt.Sprintf("TOPIC(channel=%s, topic=%s)", cmd.channel, cmd.topic)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func NewTopicCommand(args []string) (Command, error) {
|
|
|
|
|
|
|
|
if len(args) < 1 {
|
|
|
|
if len(args) < 1 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -480,7 +442,7 @@ type ModeCommand struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MODE <nickname> *( ( "+" / "-" ) *( "i" / "w" / "o" / "O" / "r" ) )
|
|
|
|
// MODE <nickname> *( ( "+" / "-" ) *( "i" / "w" / "o" / "O" / "r" ) )
|
|
|
|
func NewUserModeCommand(nickname Name, args []string) (Command, error) {
|
|
|
|
func ParseUserModeCommand(nickname Name, args []string) (Command, error) {
|
|
|
|
cmd := &ModeCommand{
|
|
|
|
cmd := &ModeCommand{
|
|
|
|
nickname: nickname,
|
|
|
|
nickname: nickname,
|
|
|
|
changes: make(ModeChanges, 0),
|
|
|
|
changes: make(ModeChanges, 0),
|
|
|
|
@@ -506,10 +468,6 @@ func NewUserModeCommand(nickname Name, args []string) (Command, error) {
|
|
|
|
return cmd, nil
|
|
|
|
return cmd, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (cmd *ModeCommand) String() string {
|
|
|
|
|
|
|
|
return fmt.Sprintf("MODE(nickname=%s, changes=%s)", cmd.nickname, cmd.changes)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type ChannelModeChange struct {
|
|
|
|
type ChannelModeChange struct {
|
|
|
|
mode ChannelMode
|
|
|
|
mode ChannelMode
|
|
|
|
op ModeOp
|
|
|
|
op ModeOp
|
|
|
|
@@ -557,7 +515,7 @@ type ChannelModeCommand struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MODE <channel> *( ( "-" / "+" ) *<modes> *<modeparams> )
|
|
|
|
// MODE <channel> *( ( "-" / "+" ) *<modes> *<modeparams> )
|
|
|
|
func NewChannelModeCommand(channel Name, args []string) (Command, error) {
|
|
|
|
func ParseChannelModeCommand(channel Name, args []string) (Command, error) {
|
|
|
|
cmd := &ChannelModeCommand{
|
|
|
|
cmd := &ChannelModeCommand{
|
|
|
|
channel: channel,
|
|
|
|
channel: channel,
|
|
|
|
changes: make(ChannelModeChanges, 0),
|
|
|
|
changes: make(ChannelModeChanges, 0),
|
|
|
|
@@ -599,20 +557,16 @@ func NewChannelModeCommand(channel Name, args []string) (Command, error) {
|
|
|
|
return cmd, nil
|
|
|
|
return cmd, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (msg *ChannelModeCommand) String() string {
|
|
|
|
func ParseModeCommand(args []string) (Command, error) {
|
|
|
|
return fmt.Sprintf("MODE(channel=%s, changes=%s)", msg.channel, msg.changes)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func NewModeCommand(args []string) (Command, error) {
|
|
|
|
|
|
|
|
if len(args) == 0 {
|
|
|
|
if len(args) == 0 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
name := NewName(args[0])
|
|
|
|
name := NewName(args[0])
|
|
|
|
if name.IsChannel() {
|
|
|
|
if name.IsChannel() {
|
|
|
|
return NewChannelModeCommand(name, args[1:])
|
|
|
|
return ParseChannelModeCommand(name, args[1:])
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return NewUserModeCommand(name, args[1:])
|
|
|
|
return ParseUserModeCommand(name, args[1:])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -623,7 +577,7 @@ type WhoisCommand struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// WHOIS [ <target> ] <mask> *( "," <mask> )
|
|
|
|
// WHOIS [ <target> ] <mask> *( "," <mask> )
|
|
|
|
func NewWhoisCommand(args []string) (Command, error) {
|
|
|
|
func ParseWhoisCommand(args []string) (Command, error) {
|
|
|
|
if len(args) < 1 {
|
|
|
|
if len(args) < 1 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -644,10 +598,6 @@ func NewWhoisCommand(args []string) (Command, error) {
|
|
|
|
}, nil
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (msg *WhoisCommand) String() string {
|
|
|
|
|
|
|
|
return fmt.Sprintf("WHOIS(target=%s, masks=%s)", msg.target, msg.masks)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type WhoCommand struct {
|
|
|
|
type WhoCommand struct {
|
|
|
|
BaseCommand
|
|
|
|
BaseCommand
|
|
|
|
mask Name
|
|
|
|
mask Name
|
|
|
|
@@ -655,7 +605,7 @@ type WhoCommand struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// WHO [ <mask> [ "o" ] ]
|
|
|
|
// WHO [ <mask> [ "o" ] ]
|
|
|
|
func NewWhoCommand(args []string) (Command, error) {
|
|
|
|
func ParseWhoCommand(args []string) (Command, error) {
|
|
|
|
cmd := &WhoCommand{}
|
|
|
|
cmd := &WhoCommand{}
|
|
|
|
|
|
|
|
|
|
|
|
if len(args) > 0 {
|
|
|
|
if len(args) > 0 {
|
|
|
|
@@ -669,25 +619,17 @@ func NewWhoCommand(args []string) (Command, error) {
|
|
|
|
return cmd, nil
|
|
|
|
return cmd, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (msg *WhoCommand) String() string {
|
|
|
|
|
|
|
|
return fmt.Sprintf("WHO(mask=%s, operatorOnly=%t)", msg.mask, msg.operatorOnly)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type OperCommand struct {
|
|
|
|
type OperCommand struct {
|
|
|
|
PassCommand
|
|
|
|
PassCommand
|
|
|
|
name Name
|
|
|
|
name Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (msg *OperCommand) String() string {
|
|
|
|
|
|
|
|
return fmt.Sprintf("OPER(name=%s, password=%s)", msg.name, msg.password)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (msg *OperCommand) LoadPassword(server *Server) {
|
|
|
|
func (msg *OperCommand) LoadPassword(server *Server) {
|
|
|
|
msg.hash = server.operators[msg.name]
|
|
|
|
msg.hash = server.operators[msg.name]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// OPER <name> <password>
|
|
|
|
// OPER <name> <password>
|
|
|
|
func NewOperCommand(args []string) (Command, error) {
|
|
|
|
func ParseOperCommand(args []string) (Command, error) {
|
|
|
|
if len(args) < 2 {
|
|
|
|
if len(args) < 2 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -705,12 +647,7 @@ type CapCommand struct {
|
|
|
|
capabilities CapabilitySet
|
|
|
|
capabilities CapabilitySet
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (msg *CapCommand) String() string {
|
|
|
|
func ParseCapCommand(args []string) (Command, error) {
|
|
|
|
return fmt.Sprintf("CAP(subCommand=%s, capabilities=%s)",
|
|
|
|
|
|
|
|
msg.subCommand, msg.capabilities)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func NewCapCommand(args []string) (Command, error) {
|
|
|
|
|
|
|
|
if len(args) < 1 {
|
|
|
|
if len(args) < 1 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -740,11 +677,15 @@ type ProxyCommand struct {
|
|
|
|
hostname Name // looked up in socket thread
|
|
|
|
hostname Name // looked up in socket thread
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (msg *ProxyCommand) String() string {
|
|
|
|
func NewProxyCommand(hostname Name) *ProxyCommand {
|
|
|
|
return fmt.Sprintf("PROXY(sourceIP=%s, sourcePort=%s)", msg.sourceIP, msg.sourcePort)
|
|
|
|
cmd := &ProxyCommand{
|
|
|
|
|
|
|
|
hostname: hostname,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.code = PROXY
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewProxyCommand(args []string) (Command, error) {
|
|
|
|
func ParseProxyCommand(args []string) (Command, error) {
|
|
|
|
if len(args) < 5 {
|
|
|
|
if len(args) < 5 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -764,11 +705,7 @@ type AwayCommand struct {
|
|
|
|
away bool
|
|
|
|
away bool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (msg *AwayCommand) String() string {
|
|
|
|
func ParseAwayCommand(args []string) (Command, error) {
|
|
|
|
return fmt.Sprintf("AWAY(%s)", msg.text)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func NewAwayCommand(args []string) (Command, error) {
|
|
|
|
|
|
|
|
cmd := &AwayCommand{}
|
|
|
|
cmd := &AwayCommand{}
|
|
|
|
|
|
|
|
|
|
|
|
if len(args) > 0 {
|
|
|
|
if len(args) > 0 {
|
|
|
|
@@ -784,11 +721,7 @@ type IsOnCommand struct {
|
|
|
|
nicks []Name
|
|
|
|
nicks []Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (msg *IsOnCommand) String() string {
|
|
|
|
func ParseIsOnCommand(args []string) (Command, error) {
|
|
|
|
return fmt.Sprintf("ISON(nicks=%s)", msg.nicks)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func NewIsOnCommand(args []string) (Command, error) {
|
|
|
|
|
|
|
|
if len(args) == 0 {
|
|
|
|
if len(args) == 0 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -803,7 +736,7 @@ type MOTDCommand struct {
|
|
|
|
target Name
|
|
|
|
target Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewMOTDCommand(args []string) (Command, error) {
|
|
|
|
func ParseMOTDCommand(args []string) (Command, error) {
|
|
|
|
cmd := &MOTDCommand{}
|
|
|
|
cmd := &MOTDCommand{}
|
|
|
|
if len(args) > 0 {
|
|
|
|
if len(args) > 0 {
|
|
|
|
cmd.target = NewName(args[0])
|
|
|
|
cmd.target = NewName(args[0])
|
|
|
|
@@ -817,11 +750,7 @@ type NoticeCommand struct {
|
|
|
|
message Text
|
|
|
|
message Text
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (cmd *NoticeCommand) String() string {
|
|
|
|
func ParseNoticeCommand(args []string) (Command, error) {
|
|
|
|
return fmt.Sprintf("NOTICE(target=%s, message=%s)", cmd.target, cmd.message)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func NewNoticeCommand(args []string) (Command, error) {
|
|
|
|
|
|
|
|
if len(args) < 2 {
|
|
|
|
if len(args) < 2 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -844,7 +773,7 @@ func (msg *KickCommand) Comment() Text {
|
|
|
|
return msg.comment
|
|
|
|
return msg.comment
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewKickCommand(args []string) (Command, error) {
|
|
|
|
func ParseKickCommand(args []string) (Command, error) {
|
|
|
|
if len(args) < 2 {
|
|
|
|
if len(args) < 2 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -875,7 +804,7 @@ type ListCommand struct {
|
|
|
|
target Name
|
|
|
|
target Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewListCommand(args []string) (Command, error) {
|
|
|
|
func ParseListCommand(args []string) (Command, error) {
|
|
|
|
cmd := &ListCommand{}
|
|
|
|
cmd := &ListCommand{}
|
|
|
|
if len(args) > 0 {
|
|
|
|
if len(args) > 0 {
|
|
|
|
cmd.channels = NewNames(strings.Split(args[0], ","))
|
|
|
|
cmd.channels = NewNames(strings.Split(args[0], ","))
|
|
|
|
@@ -892,7 +821,7 @@ type NamesCommand struct {
|
|
|
|
target Name
|
|
|
|
target Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewNamesCommand(args []string) (Command, error) {
|
|
|
|
func ParseNamesCommand(args []string) (Command, error) {
|
|
|
|
cmd := &NamesCommand{}
|
|
|
|
cmd := &NamesCommand{}
|
|
|
|
if len(args) > 0 {
|
|
|
|
if len(args) > 0 {
|
|
|
|
cmd.channels = NewNames(strings.Split(args[0], ","))
|
|
|
|
cmd.channels = NewNames(strings.Split(args[0], ","))
|
|
|
|
@@ -908,7 +837,7 @@ type DebugCommand struct {
|
|
|
|
subCommand Name
|
|
|
|
subCommand Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewDebugCommand(args []string) (Command, error) {
|
|
|
|
func ParseDebugCommand(args []string) (Command, error) {
|
|
|
|
if len(args) == 0 {
|
|
|
|
if len(args) == 0 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -923,7 +852,7 @@ type VersionCommand struct {
|
|
|
|
target Name
|
|
|
|
target Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewVersionCommand(args []string) (Command, error) {
|
|
|
|
func ParseVersionCommand(args []string) (Command, error) {
|
|
|
|
cmd := &VersionCommand{}
|
|
|
|
cmd := &VersionCommand{}
|
|
|
|
if len(args) > 0 {
|
|
|
|
if len(args) > 0 {
|
|
|
|
cmd.target = NewName(args[0])
|
|
|
|
cmd.target = NewName(args[0])
|
|
|
|
@@ -937,7 +866,7 @@ type InviteCommand struct {
|
|
|
|
channel Name
|
|
|
|
channel Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewInviteCommand(args []string) (Command, error) {
|
|
|
|
func ParseInviteCommand(args []string) (Command, error) {
|
|
|
|
if len(args) < 2 {
|
|
|
|
if len(args) < 2 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -948,7 +877,7 @@ func NewInviteCommand(args []string) (Command, error) {
|
|
|
|
}, nil
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewTheaterCommand(args []string) (Command, error) {
|
|
|
|
func ParseTheaterCommand(args []string) (Command, error) {
|
|
|
|
if len(args) < 1 {
|
|
|
|
if len(args) < 1 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
} else if upperSubCmd := strings.ToUpper(args[0]); upperSubCmd == "IDENTIFY" && len(args) == 3 {
|
|
|
|
} else if upperSubCmd := strings.ToUpper(args[0]); upperSubCmd == "IDENTIFY" && len(args) == 3 {
|
|
|
|
@@ -978,7 +907,7 @@ type TimeCommand struct {
|
|
|
|
target Name
|
|
|
|
target Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewTimeCommand(args []string) (Command, error) {
|
|
|
|
func ParseTimeCommand(args []string) (Command, error) {
|
|
|
|
cmd := &TimeCommand{}
|
|
|
|
cmd := &TimeCommand{}
|
|
|
|
if len(args) > 0 {
|
|
|
|
if len(args) > 0 {
|
|
|
|
cmd.target = NewName(args[0])
|
|
|
|
cmd.target = NewName(args[0])
|
|
|
|
@@ -992,7 +921,7 @@ type KillCommand struct {
|
|
|
|
comment Text
|
|
|
|
comment Text
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewKillCommand(args []string) (Command, error) {
|
|
|
|
func ParseKillCommand(args []string) (Command, error) {
|
|
|
|
if len(args) < 2 {
|
|
|
|
if len(args) < 2 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -1009,7 +938,7 @@ type WhoWasCommand struct {
|
|
|
|
target Name
|
|
|
|
target Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewWhoWasCommand(args []string) (Command, error) {
|
|
|
|
func ParseWhoWasCommand(args []string) (Command, error) {
|
|
|
|
if len(args) < 1 {
|
|
|
|
if len(args) < 1 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -1025,7 +954,7 @@ func NewWhoWasCommand(args []string) (Command, error) {
|
|
|
|
return cmd, nil
|
|
|
|
return cmd, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewOperNickCommand(args []string) (Command, error) {
|
|
|
|
func ParseOperNickCommand(args []string) (Command, error) {
|
|
|
|
if len(args) < 2 {
|
|
|
|
if len(args) < 2 {
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
return nil, NotEnoughArgsError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|