diff --git a/src/irc/channel.go b/src/irc/channel.go index 81c766a6..f921c19d 100644 --- a/src/irc/channel.go +++ b/src/irc/channel.go @@ -1,17 +1,13 @@ package irc type Channel struct { - server *Server - name string - key string - topic string - members ClientSet - invites map[string]bool - // modes - inviteOnly bool - noOutside bool - // modes with args - password string + server *Server + name string + key string + topic string + members ClientSet + noOutside bool + password string } type ChannelSet map[*Channel]bool @@ -22,7 +18,6 @@ func NewChannel(s *Server, name string) *Channel { return &Channel{ name: name, members: make(ClientSet), - invites: make(map[string]bool), server: s, } } @@ -57,11 +52,6 @@ func (ch *Channel) IsEmpty() bool { func (ch *Channel) Join(cl *Client, key string) { if ch.key != key { - cl.send <- ErrInviteOnlyChannel(ch) - return - } - - if ch.inviteOnly && !ch.invites[cl.nick] { cl.send <- ErrBadChannelKey(ch) return } @@ -122,20 +112,3 @@ func (ch *Channel) ChangeTopic(cl *Client, newTopic string) { ch.Send(RplNoTopic(ch), nil) } } - -func (ch *Channel) Invite(inviter *Client, invitee *Client) { - if !ch.members[inviter] { - inviter.send <- ErrNotOnChannel(ch) - return - } - - if ch.members[invitee] { - inviter.send <- ErrUserOnChannel(ch, invitee) - return - } - - ch.invites[invitee.nick] = true - - invitee.send <- RplInviteMsg(ch, inviter) - inviter.send <- RplInvitingMsg(ch, invitee) -} diff --git a/src/irc/client.go b/src/irc/client.go index 8d878cc7..81bca3e9 100644 --- a/src/irc/client.go +++ b/src/irc/client.go @@ -7,27 +7,19 @@ import ( ) type Client struct { - // communication - conn net.Conn - send chan<- Reply - recv <-chan string - // basic info + conn net.Conn + send chan<- Reply + recv <-chan string username string realname string hostname string nick string serverPass bool registered bool - // modes - away bool - invisible bool - wallOps bool - restricted bool - operator bool - localOperator bool - // relations - server *Server - channels ChannelSet + away bool + wallOps bool + server *Server + channels ChannelSet } type ClientSet map[*Client]bool @@ -77,14 +69,10 @@ func (c *Client) Nick() string { } func (c *Client) UModeString() string { - mode := "+" - if c.invisible { - mode += "i" - } if c.wallOps { - mode += "w" + return "+w" } - return mode + return "" } func (c *Client) HasNick() bool { diff --git a/src/irc/commands.go b/src/irc/commands.go index 908a27ee..2839ed77 100644 --- a/src/irc/commands.go +++ b/src/irc/commands.go @@ -226,6 +226,15 @@ func (m *ModeMessage) Handle(s *Server, c *Client) { s.ChangeUserMode(c, m.modes) } +func (m *ChannelModeMessage) Handle(s *Server, c *Client) { + channel := s.channels[m.channel] + if channel != nil { + c.send <- ErrNoChanModes(channel) + } else { + c.send <- ErrNoSuchChannel(s, m.channel) + } +} + // JOIN ( *( "," ) [ *( "," ) ] ) / "0" type JoinMessage struct { @@ -372,39 +381,6 @@ func (m *TopicMessage) Handle(s *Server, c *Client) { } } -// INVITE - -type InviteMessage struct { - nickname string - channel string -} - -func NewInviteMessage(args []string) (Message, error) { - if len(args) < 2 { - return nil, NotEnoughArgsError - } - return &InviteMessage{ - nickname: args[0], - channel: args[1], - }, nil -} - -func (m *InviteMessage) Handle(s *Server, c *Client) { - channel := s.channels[m.channel] - if channel == nil { - c.send <- ErrNoSuchNick(s, m.channel) - return - } - - invitee := s.nicks[m.nickname] - if invitee == nil { - c.send <- ErrNoSuchNick(s, m.nickname) - return - } - - channel.Invite(c, invitee) -} - // OPER type OperMessage struct { diff --git a/src/irc/parse.go b/src/irc/parse.go index b9bc6804..2bc74e82 100644 --- a/src/irc/parse.go +++ b/src/irc/parse.go @@ -10,7 +10,6 @@ type ParseFunc func([]string) (Message, error) var ( ErrParseMessage = errors.New("failed to parse message") parseCommandFuncs = map[string]ParseFunc{ - "INVITE": NewInviteMessage, "JOIN": NewJoinMessage, "MODE": NewModeMessage, "NICK": NewNickMessage, diff --git a/src/irc/reply.go b/src/irc/reply.go index e6344b65..53a96e0e 100644 --- a/src/irc/reply.go +++ b/src/irc/reply.go @@ -77,7 +77,7 @@ func RplCreated(server *Server) Reply { func RplMyInfo(server *Server) Reply { return NewReply(server, RPL_MYINFO, - fmt.Sprintf("%s %s w ikn", server.name, VERSION)) + fmt.Sprintf("%s %s w kn", server.name, VERSION)) } func RplUModeIs(server *Server, client *Client) Reply { @@ -187,3 +187,8 @@ func ErrNoSuchNick(source Identifier, nick string) Reply { func ErrPasswdMismatch(server *Server) Reply { return NewReply(server, ERR_PASSWDMISMATCH, ":Password incorrect") } + +func ErrNoChanModes(channel *Channel) Reply { + return NewReply(channel.server, ERR_NOCHANMODES, + channel.name+" :Channel doesn't support modes") +} diff --git a/src/irc/server.go b/src/irc/server.go index 082f2fcb..99c29451 100644 --- a/src/irc/server.go +++ b/src/irc/server.go @@ -142,16 +142,6 @@ func (s *Server) Quit(c *Client, message string) { func (s *Server) ChangeUserMode(c *Client, modes []string) { for _, mode := range modes { switch mode { - case "+i": - c.invisible = true - case "-i": - c.invisible = false - case "-o": - c.operator = false - case "-O": - c.localOperator = false - case "+r": - c.restricted = true case "+w": c.wallOps = true case "-w":