From 9b7e7cb341ee5a65168d7b472e41c5b5c2ac8c49 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Wed, 27 Sep 2017 14:21:18 -0700 Subject: [PATCH] Cleanup and bugfix --- anonircd.go | 2 +- entity.go | 7 +++---- server.go | 18 +++++------------- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/anonircd.go b/anonircd.go index c6cb6d7..0131419 100644 --- a/anonircd.go +++ b/anonircd.go @@ -89,7 +89,7 @@ func main() { signal.Notify(sighup, syscall.SIGHUP) go func() { - _ = <-sighup + <-sighup server.reload() }() diff --git a/entity.go b/entity.go index a5bcce6..0b1a119 100644 --- a/entity.go +++ b/entity.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "strings" "sync" @@ -48,14 +47,14 @@ func (e *Entity) addMode(mode string, value string) { allowedmodes = CHANNEL_MODES } - if strings.Index(allowedmodes, mode) != -1 && !e.hasMode(mode) { + if strings.Contains(allowedmodes, mode) && !e.hasMode(mode) { e.modes.Set(mode, value) } } func (e *Entity) addModes(modes string) { for _, mode := range strings.Split(modes, "") { - e.addMode(fmt.Sprintf("%s", mode), "") + e.addMode(mode, "") } } @@ -67,7 +66,7 @@ func (e *Entity) removeMode(mode string) { func (e *Entity) removeModes(modes string) { for _, mode := range strings.Split(modes, "") { - e.removeMode(fmt.Sprintf("%s", mode)) + e.removeMode(mode) } } diff --git a/server.go b/server.go index ef542d0..3fba9cb 100644 --- a/server.go +++ b/server.go @@ -85,7 +85,7 @@ func (s *Server) getChannels(client string) map[string]*Channel { } func (s *Server) getClient(client string) *Client { - if cl, ok := s.channels.Load(client); ok { + if cl, ok := s.clients.Load(client); ok { return cl.(*Client) } @@ -109,14 +109,6 @@ func (s *Server) getClients(channel string) map[string]*Client { return clients } -func (s *Server) channelExists(channel string) bool { - if _, ok := s.channels.Load(channel); ok { - return true - } - - return false -} - func (s *Server) inChannel(channel string, client string) bool { ch := s.getChannel(channel) if ch != nil { @@ -143,7 +135,7 @@ func (s *Server) joinChannel(channel string, client string) { ch = &Channel{Entity{ENTITY_CHANNEL, channel, time.Now().Unix(), ENTITY_STATE_NORMAL, cmap.New(), new(sync.RWMutex)}, new(sync.Map), "", 0} s.channels.Store(channel, ch) } else if ch.hasMode("z") && !cl.ssl { - cl.sendNotice("Unable to join " + channel + ": SSL connections only (channel mode +z)")/// + cl.sendNotice("Unable to join " + channel + ": SSL connections only (channel mode +z)") return } @@ -476,7 +468,7 @@ func (s *Server) handleRead(c *Client) { return } if len(msg.Command) >= 4 && msg.Command[0:4] != irc.PING && msg.Command[0:4] != irc.PONG { - log.Println(c.identifier, "<-", fmt.Sprintf("%s", msg)) + log.Println(c.identifier, "<-", msg.String()) } if msg.Command == irc.CAP && len(msg.Params) > 0 && len(msg.Params[0]) > 0 && msg.Params[0] == irc.CAP_LS { c.write(&irc.Message{&anonirc, irc.CAP, []string{msg.Params[0], "userhost-in-names"}}) @@ -685,7 +677,7 @@ func (s *Server) listenPlain() { accept: for { select { - case _ = <-s.restartplain: + case <-s.restartplain: break accept default: conn, err := listen.Accept() @@ -725,7 +717,7 @@ func (s *Server) listenSSL() { accept: for { select { - case _ = <-s.restartssl: + case <-s.restartssl: break accept default: conn, err := listen.Accept()