remove support for multiple channels

--HG--
branch : nmdc-ircfrontend
This commit is contained in:
. 2016-05-02 19:23:15 +12:00
parent 37d61b3193
commit e866451b7a
3 changed files with 32 additions and 32 deletions

View File

@ -18,8 +18,7 @@ func main() {
log.Println("Starting server...") log.Println("Starting server...")
server := NewServer() server := NewServer(*serverName)
server.name = *serverName
if len(server.name) == 0 { if len(server.name) == 0 {
log.Println("Please specify the -servername parameter.") log.Println("Please specify the -servername parameter.")

View File

@ -13,12 +13,18 @@ var (
channelRegexp = regexp.MustCompile(`^#[a-zA-Z0-9_\-]+$`) channelRegexp = regexp.MustCompile(`^#[a-zA-Z0-9_\-]+$`)
) )
func NewServer() *Server { func NewServer(name string) *Server {
return &Server{eventChan: make(chan Event), return &Server{eventChan: make(chan Event),
name: "", name: name,
clientMap: make(map[string]*Client), clientMap: make(map[string]*Client),
channelMap: make(map[string]*Channel), motd: "",
motd: "", channel: Channel{
name: BLESSED_CHANNEL,
topic: name,
clientMap: make(map[string]*Client),
mode: ChannelMode{},
modeMap: make(map[string]*ClientMode),
},
} }
} }
@ -33,7 +39,6 @@ func (s *Server) HandleConnection(conn net.Conn) {
connection: conn, connection: conn,
outputChan: make(chan string), outputChan: make(chan string),
signalChan: make(chan signalCode, 3), signalChan: make(chan signalCode, 3),
channelMap: make(map[string]*Channel),
connected: true, connected: true,
} }
@ -62,8 +67,10 @@ func (s *Server) handleEvent(e Event) {
e.client.reply(rplMOTD, motd) e.client.reply(rplMOTD, motd)
} }
e.client.reply(rplEndOfMOTD) e.client.reply(rplEndOfMOTD)
case disconnected: case disconnected:
//Client disconnected //Client disconnected
case command: case command:
//Client send a command //Client send a command
fields := strings.Fields(e.input) fields := strings.Fields(e.input)
@ -149,31 +156,28 @@ func (s *Server) handleCommand(client *Client, command string, args []string) {
message := strings.Join(args[1:], " ") message := strings.Join(args[1:], " ")
channel, chanExists := s.channelMap[strings.ToLower(args[0])] if strings.ToLower(args[0]) == BLESSED_CHANNEL {
client2, clientExists := s.clientMap[strings.ToLower(args[0])] if s.channel.mode.noExternal {
if _, inChannel := s.channel.clientMap[client.key]; !inChannel {
if chanExists {
if channel.mode.noExternal {
if _, inChannel := channel.clientMap[client.key]; !inChannel {
//Not in channel, not allowed to send //Not in channel, not allowed to send
client.reply(errCannotSend, args[0]) client.reply(errCannotSend, args[0])
return return
} }
} }
if channel.mode.moderated { if s.channel.mode.moderated {
clientMode := channel.modeMap[client.key] clientMode := s.channel.modeMap[client.key]
if !clientMode.operator && !clientMode.voice { if !clientMode.operator && !clientMode.voice {
//It's moderated and we're not +v or +o, do nothing //It's moderated and we're not +v or +o, do nothing
client.reply(errCannotSend, args[0]) client.reply(errCannotSend, args[0])
return return
} }
} }
for _, c := range 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 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])
@ -198,7 +202,7 @@ func (s *Server) handleCommand(client *Client, command string, args []string) {
return return
} }
channel, exists := s.channelMap[strings.ToLower(args[0])] exists := strings.ToLower(args[0]) == BLESSED_CHANNEL
if exists == false { if exists == false {
client.reply(errNoSuchNick, args[0]) client.reply(errNoSuchNick, args[0])
return return
@ -206,7 +210,7 @@ func (s *Server) handleCommand(client *Client, command string, args []string) {
// Valid topic get // Valid topic get
if len(args) == 1 { if len(args) == 1 {
client.reply(rplTopic, channel.name, s.name) client.reply(rplTopic, s.channel.name, s.name)
return return
} }
@ -220,9 +224,7 @@ func (s *Server) handleCommand(client *Client, command string, args []string) {
return return
} }
// FIXME listItem := fmt.Sprintf("%s %d :%s", s.channel.name, len(s.channel.clientMap), s.channel.topic)
channel := s.channelMap[BLESSED_CHANNEL]
listItem := fmt.Sprintf("%s %d :%s", channel.name, len(channel.clientMap), channel.topic)
client.reply(rplList, listItem) client.reply(rplList, listItem)
client.reply(rplListEnd) client.reply(rplListEnd)
@ -300,12 +302,12 @@ func (s *Server) handleCommand(client *Client, command string, args []string) {
channelKey := strings.ToLower(args[0]) channelKey := strings.ToLower(args[0])
channel, channelExists := s.channelMap[channelKey] channelExists := channelKey == BLESSED_CHANNEL
if !channelExists { if !channelExists {
client.reply(errNoSuchNick, args[0]) client.reply(errNoSuchNick, args[0])
return return
} }
mode := channel.mode 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

View File

@ -9,12 +9,12 @@ const (
) )
type Server struct { type Server struct {
eventChan chan Event eventChan chan Event
running bool running bool
name string name string
clientMap map[string]*Client //Map of nicks → clients clientMap map[string]*Client // Map of nicks -> clients
channelMap map[string]*Channel //Map of channel names → channels channel Channel // Single blessed channel
motd string motd string
} }
type Client struct { type Client struct {
@ -27,7 +27,6 @@ type Client struct {
registered bool registered bool
connected bool connected bool
operator bool operator bool
channelMap map[string]*Channel
} }
type eventType int type eventType int