remove support for multiple channels
--HG-- branch : nmdc-ircfrontend
This commit is contained in:
parent
37d61b3193
commit
e866451b7a
3
main.go
3
main.go
@ -18,8 +18,7 @@ func main() {
|
||||
|
||||
log.Println("Starting server...")
|
||||
|
||||
server := NewServer()
|
||||
server.name = *serverName
|
||||
server := NewServer(*serverName)
|
||||
|
||||
if len(server.name) == 0 {
|
||||
log.Println("Please specify the -servername parameter.")
|
||||
|
48
server.go
48
server.go
@ -13,12 +13,18 @@ var (
|
||||
channelRegexp = regexp.MustCompile(`^#[a-zA-Z0-9_\-]+$`)
|
||||
)
|
||||
|
||||
func NewServer() *Server {
|
||||
func NewServer(name string) *Server {
|
||||
return &Server{eventChan: make(chan Event),
|
||||
name: "",
|
||||
clientMap: make(map[string]*Client),
|
||||
channelMap: make(map[string]*Channel),
|
||||
motd: "",
|
||||
name: name,
|
||||
clientMap: make(map[string]*Client),
|
||||
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,
|
||||
outputChan: make(chan string),
|
||||
signalChan: make(chan signalCode, 3),
|
||||
channelMap: make(map[string]*Channel),
|
||||
connected: true,
|
||||
}
|
||||
|
||||
@ -62,8 +67,10 @@ func (s *Server) handleEvent(e Event) {
|
||||
e.client.reply(rplMOTD, motd)
|
||||
}
|
||||
e.client.reply(rplEndOfMOTD)
|
||||
|
||||
case disconnected:
|
||||
//Client disconnected
|
||||
|
||||
case command:
|
||||
//Client send a command
|
||||
fields := strings.Fields(e.input)
|
||||
@ -149,31 +156,28 @@ func (s *Server) handleCommand(client *Client, command string, args []string) {
|
||||
|
||||
message := strings.Join(args[1:], " ")
|
||||
|
||||
channel, chanExists := s.channelMap[strings.ToLower(args[0])]
|
||||
client2, clientExists := s.clientMap[strings.ToLower(args[0])]
|
||||
|
||||
if chanExists {
|
||||
if channel.mode.noExternal {
|
||||
if _, inChannel := channel.clientMap[client.key]; !inChannel {
|
||||
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 channel.mode.moderated {
|
||||
clientMode := channel.modeMap[client.key]
|
||||
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 channel.clientMap {
|
||||
for _, c := range s.channel.clientMap {
|
||||
if c != client {
|
||||
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)
|
||||
} else {
|
||||
client.reply(errNoSuchNick, args[0])
|
||||
@ -198,7 +202,7 @@ func (s *Server) handleCommand(client *Client, command string, args []string) {
|
||||
return
|
||||
}
|
||||
|
||||
channel, exists := s.channelMap[strings.ToLower(args[0])]
|
||||
exists := strings.ToLower(args[0]) == BLESSED_CHANNEL
|
||||
if exists == false {
|
||||
client.reply(errNoSuchNick, args[0])
|
||||
return
|
||||
@ -206,7 +210,7 @@ func (s *Server) handleCommand(client *Client, command string, args []string) {
|
||||
|
||||
// Valid topic get
|
||||
if len(args) == 1 {
|
||||
client.reply(rplTopic, channel.name, s.name)
|
||||
client.reply(rplTopic, s.channel.name, s.name)
|
||||
return
|
||||
}
|
||||
|
||||
@ -220,9 +224,7 @@ func (s *Server) handleCommand(client *Client, command string, args []string) {
|
||||
return
|
||||
}
|
||||
|
||||
// FIXME
|
||||
channel := s.channelMap[BLESSED_CHANNEL]
|
||||
listItem := fmt.Sprintf("%s %d :%s", channel.name, len(channel.clientMap), channel.topic)
|
||||
listItem := fmt.Sprintf("%s %d :%s", s.channel.name, len(s.channel.clientMap), s.channel.topic)
|
||||
client.reply(rplList, listItem)
|
||||
client.reply(rplListEnd)
|
||||
|
||||
@ -300,12 +302,12 @@ func (s *Server) handleCommand(client *Client, command string, args []string) {
|
||||
|
||||
channelKey := strings.ToLower(args[0])
|
||||
|
||||
channel, channelExists := s.channelMap[channelKey]
|
||||
channelExists := channelKey == BLESSED_CHANNEL
|
||||
if !channelExists {
|
||||
client.reply(errNoSuchNick, args[0])
|
||||
return
|
||||
}
|
||||
mode := channel.mode
|
||||
mode := s.channel.mode
|
||||
|
||||
if len(args) == 1 {
|
||||
//No more args, they just want the mode
|
||||
|
13
typedefs.go
13
typedefs.go
@ -9,12 +9,12 @@ const (
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
eventChan chan Event
|
||||
running bool
|
||||
name string
|
||||
clientMap map[string]*Client //Map of nicks → clients
|
||||
channelMap map[string]*Channel //Map of channel names → channels
|
||||
motd string
|
||||
eventChan chan Event
|
||||
running bool
|
||||
name string
|
||||
clientMap map[string]*Client // Map of nicks -> clients
|
||||
channel Channel // Single blessed channel
|
||||
motd string
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
@ -27,7 +27,6 @@ type Client struct {
|
||||
registered bool
|
||||
connected bool
|
||||
operator bool
|
||||
channelMap map[string]*Channel
|
||||
}
|
||||
|
||||
type eventType int
|
||||
|
Loading…
Reference in New Issue
Block a user