remove support for channel modes

--HG--
branch : nmdc-ircfrontend
This commit is contained in:
. 2016-05-03 18:00:40 +12:00
parent e866451b7a
commit cb736df27c
2 changed files with 12 additions and 53 deletions

View File

@ -22,7 +22,6 @@ func NewServer(name string) *Server {
name: BLESSED_CHANNEL, name: BLESSED_CHANNEL,
topic: name, topic: name,
clientMap: make(map[string]*Client), clientMap: make(map[string]*Client),
mode: ChannelMode{},
modeMap: make(map[string]*ClientMode), modeMap: make(map[string]*ClientMode),
}, },
} }
@ -157,30 +156,18 @@ func (s *Server) handleCommand(client *Client, command string, args []string) {
message := strings.Join(args[1:], " ") message := strings.Join(args[1:], " ")
if strings.ToLower(args[0]) == BLESSED_CHANNEL { if strings.ToLower(args[0]) == BLESSED_CHANNEL {
if s.channel.mode.noExternal {
if _, inChannel := s.channel.clientMap[client.key]; !inChannel {
//Not in channel, not allowed to send
client.reply(errCannotSend, args[0])
return
}
}
if s.channel.mode.moderated {
clientMode := s.channel.modeMap[client.key]
if !clientMode.operator && !clientMode.voice {
//It's moderated and we're not +v or +o, do nothing
client.reply(errCannotSend, args[0])
return
}
}
for _, c := range s.channel.clientMap { for _, c := range s.channel.clientMap {
if c != client { if c != client {
c.reply(rplMsg, client.nick, args[0], message) c.reply(rplMsg, client.nick, args[0], message)
} }
} }
} else if client2, clientExists := s.clientMap[strings.ToLower(args[0])]; clientExists { } else if client2, clientExists := s.clientMap[strings.ToLower(args[0])]; clientExists {
client2.reply(rplMsg, client.nick, client2.nick, message) client2.reply(rplMsg, client.nick, client2.nick, message)
} else { } else {
client.reply(errNoSuchNick, args[0]) client.reply(errNoSuchNick, args[0])
} }
case "QUIT": case "QUIT":
@ -300,23 +287,19 @@ func (s *Server) handleCommand(client *Client, command string, args []string) {
return return
} }
channelKey := strings.ToLower(args[0]) if strings.ToLower(args[0]) != BLESSED_CHANNEL {
channelExists := channelKey == BLESSED_CHANNEL
if !channelExists {
client.reply(errNoSuchNick, args[0]) client.reply(errNoSuchNick, args[0])
return return
} }
mode := s.channel.mode
if len(args) == 1 { if len(args) == 1 {
//No more args, they just want the mode //No more args, they just want the mode
client.reply(rplChannelModeIs, args[0], mode.String(), "") client.reply(rplChannelModeIs, args[0], BLESSED_CHANNEL_MODE, "")
return } else {
// Setting modes is disallowed
client.reply(errNoPriv)
} }
// Setting modes is disallowed
client.reply(errNoPriv)
return return
default: default:

View File

@ -3,9 +3,10 @@ package main
import "net" import "net"
const ( const (
VERSION = "1.0.0" VERSION = "1.0.0"
APP_DESCRIPTION = "nmdc-ircfrontend v" + VERSION APP_DESCRIPTION = "nmdc-ircfrontend v" + VERSION
BLESSED_CHANNEL = "#chat" BLESSED_CHANNEL = "#chat" // must be lowercase
BLESSED_CHANNEL_MODE = "n" // means that you have to be in the channel to chat, but that's it
) )
type Server struct { type Server struct {
@ -47,34 +48,9 @@ type Channel struct {
name string name string
topic string topic string
clientMap map[string]*Client clientMap map[string]*Client
mode ChannelMode
modeMap map[string]*ClientMode modeMap map[string]*ClientMode
} }
type ChannelMode struct {
secret bool //Channel is hidden from LIST
topicLocked bool //Only ops may change topic
moderated bool //Only ops and voiced may speak
noExternal bool //Only users in the channel may talk to it
}
func (m *ChannelMode) String() string {
modeStr := ""
if m.secret {
modeStr += "s"
}
if m.topicLocked {
modeStr += "t"
}
if m.moderated {
modeStr += "m"
}
if m.noExternal {
modeStr += "n"
}
return modeStr
}
type ClientMode struct { type ClientMode struct {
operator bool //Channel operator operator bool //Channel operator
voice bool //Has voice voice bool //Has voice