3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

Disable channel modes and remove some client modes.

This commit is contained in:
Jeremy Latt 2012-12-11 23:04:03 -08:00
parent c99bc6b453
commit dbaa73a319
6 changed files with 31 additions and 100 deletions

View File

@ -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)
}

View File

@ -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 {

View File

@ -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 ( <channel> *( "," <channel> ) [ <key> *( "," <key> ) ] ) / "0"
type JoinMessage struct {
@ -372,39 +381,6 @@ func (m *TopicMessage) Handle(s *Server, c *Client) {
}
}
// INVITE <nickname> <channel>
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 <name> <password>
type OperMessage struct {

View File

@ -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,

View File

@ -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")
}

View File

@ -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":