From 4b88a60ba69c0b0d37b9da8e2ffdbe97324348fc Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Wed, 22 May 2019 19:07:12 -0400 Subject: [PATCH] clean up some old getters --- irc/channel.go | 4 ++-- irc/channelmanager.go | 2 +- irc/client.go | 2 +- irc/config.go | 10 ++++++---- irc/getters.go | 16 ---------------- irc/handlers.go | 6 +++--- irc/modes.go | 2 +- irc/nickname.go | 2 +- irc/server.go | 2 +- 9 files changed, 16 insertions(+), 30 deletions(-) diff --git a/irc/channel.go b/irc/channel.go index c3d355ee..9dac7fb1 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -908,7 +908,7 @@ func (channel *Channel) SetTopic(client *Client, topic string, rb *ResponseBuffe return } - topicLimit := client.server.Limits().TopicLen + topicLimit := client.server.Config().Limits.TopicLen if len(topic) > topicLimit { topic = topic[:topicLimit] } @@ -1137,7 +1137,7 @@ func (channel *Channel) Kick(client *Client, target *Client, comment string, rb return } - kicklimit := client.server.Limits().KickLen + kicklimit := client.server.Config().Limits.KickLen if len(comment) > kicklimit { comment = comment[:kicklimit] } diff --git a/irc/channelmanager.go b/irc/channelmanager.go index f520619e..ad07d1c6 100644 --- a/irc/channelmanager.go +++ b/irc/channelmanager.go @@ -61,7 +61,7 @@ func (cm *ChannelManager) Get(name string) (channel *Channel) { func (cm *ChannelManager) Join(client *Client, name string, key string, isSajoin bool, rb *ResponseBuffer) error { server := client.server casefoldedName, err := CasefoldChannel(name) - if err != nil || len(casefoldedName) > server.Limits().ChannelLen { + if err != nil || len(casefoldedName) > server.Config().Limits.ChannelLen { return errNoSuchChannel } diff --git a/irc/client.go b/irc/client.go index 59d06f3e..b75b822e 100644 --- a/irc/client.go +++ b/irc/client.go @@ -336,7 +336,7 @@ func (client *Client) run(session *Session) { if r := recover(); r != nil { client.server.logger.Error("internal", fmt.Sprintf("Client caused panic: %v\n%s", r, debug.Stack())) - if client.server.RecoverFromErrors() { + if client.server.Config().Debug.recoverFromErrors { client.server.logger.Error("internal", "Disconnecting client and attempting to recover") } else { panic(r) diff --git a/irc/config.go b/irc/config.go index 5750276f..a3ed6267 100644 --- a/irc/config.go +++ b/irc/config.go @@ -335,7 +335,8 @@ type Config struct { Logging []logger.LoggingConfig Debug struct { - RecoverFromErrors *bool `yaml:"recover-from-errors"` + RecoverFromErrors *bool `yaml:"recover-from-errors"` + recoverFromErrors bool PprofListener *string `yaml:"pprof-listener"` } @@ -669,9 +670,10 @@ func LoadConfig(filename string) (config *Config, err error) { } // RecoverFromErrors defaults to true - if config.Debug.RecoverFromErrors == nil { - config.Debug.RecoverFromErrors = new(bool) - *config.Debug.RecoverFromErrors = true + if config.Debug.RecoverFromErrors != nil { + config.Debug.recoverFromErrors = *config.Debug.RecoverFromErrors + } else { + config.Debug.recoverFromErrors = true } // casefold/validate server name diff --git a/irc/getters.go b/irc/getters.go index a0a4aef8..4d3ad7a8 100644 --- a/irc/getters.go +++ b/irc/getters.go @@ -21,22 +21,6 @@ func (server *Server) SetConfig(config *Config) { atomic.StorePointer(&server.config, unsafe.Pointer(config)) } -func (server *Server) Limits() Limits { - return server.Config().Limits -} - -func (server *Server) Password() []byte { - return server.Config().Server.passwordBytes -} - -func (server *Server) RecoverFromErrors() bool { - return *server.Config().Debug.RecoverFromErrors -} - -func (server *Server) DefaultChannelModes() modes.Modes { - return server.Config().Channels.defaultModes -} - func (server *Server) ChannelRegistrationEnabled() bool { return server.Config().Channels.Registration.Enabled } diff --git a/irc/handlers.go b/irc/handlers.go index 7ed920fd..784c4fa2 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -475,7 +475,7 @@ func awayHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp if len(msg.Params) > 0 { isAway = true awayMessage = msg.Params[0] - awayLen := server.Limits().AwayLen + awayLen := server.Config().Limits.AwayLen if len(awayMessage) > awayLen { awayMessage = awayMessage[:awayLen] } @@ -1827,7 +1827,7 @@ func monitorAddHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb var online []string var offline []string - limits := server.Limits() + limits := server.Config().Limits targets := strings.Split(msg.Params[1], ",") for _, target := range targets { @@ -2215,7 +2215,7 @@ func passHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp } // if no password exists, skip checking - serverPassword := server.Password() + serverPassword := server.Config().Server.passwordBytes if serverPassword == nil { return false } diff --git a/irc/modes.go b/irc/modes.go index 40b22875..026dd777 100644 --- a/irc/modes.go +++ b/irc/modes.go @@ -166,7 +166,7 @@ func (channel *Channel) ApplyChannelModeChanges(client *Client, isSamode bool, c switch change.Op { case modes.Add: - if channel.lists[change.Mode].Length() >= client.server.Limits().ChanListModes { + if channel.lists[change.Mode].Length() >= client.server.Config().Limits.ChanListModes { if !listFullWarned[change.Mode] { rb.Add(nil, client.server.name, ERR_BANLISTFULL, client.Nick(), channel.Name(), change.Mode.String(), client.t("Channel list is full")) listFullWarned[change.Mode] = true diff --git a/irc/nickname.go b/irc/nickname.go index 34917fb4..a1919e59 100644 --- a/irc/nickname.go +++ b/irc/nickname.go @@ -35,7 +35,7 @@ func performNickChange(server *Server, client *Client, target *Client, session * return false } - if err != nil || len(nickname) > server.Limits().NickLen || restrictedNicknames[cfnick] { + if err != nil || len(nickname) > server.Config().Limits.NickLen || restrictedNicknames[cfnick] { rb.Add(nil, server.name, ERR_ERRONEUSNICKNAME, currentNick, nickname, client.t("Erroneous nickname")) return false } diff --git a/irc/server.go b/irc/server.go index 2cde9519..9266ad7b 100644 --- a/irc/server.go +++ b/irc/server.go @@ -550,7 +550,7 @@ func (server *Server) applyConfig(config *Config, initial bool) (err error) { server.nameCasefolded = config.Server.nameCasefolded } else { // enforce configs that can't be changed after launch: - currentLimits := server.Limits() + currentLimits := server.Config().Limits if currentLimits.LineLen.Rest != config.Limits.LineLen.Rest { return fmt.Errorf("Maximum line length (linelen) cannot be changed after launching the server, rehash aborted") } else if server.name != config.Server.Name {