3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

Fix lots of nits

This commit is contained in:
Daniel Oaks 2017-04-16 11:31:33 +10:00
parent 8ba0bf347d
commit 22216d4d60
7 changed files with 39 additions and 24 deletions

View File

@ -318,12 +318,12 @@ func authExternalHandler(server *Server, client *Client, mechanism string, value
} }
// successfulSaslAuth means that a SASL auth attempt completed successfully, and is used to dispatch messages. // successfulSaslAuth means that a SASL auth attempt completed successfully, and is used to dispatch messages.
func (c *Client) successfulSaslAuth() { func (client *Client) successfulSaslAuth() {
c.Send(nil, c.server.name, RPL_LOGGEDIN, c.nick, c.nickMaskString, c.account.Name, fmt.Sprintf("You are now logged in as %s", c.account.Name)) client.Send(nil, client.server.name, RPL_LOGGEDIN, client.nick, client.nickMaskString, client.account.Name, fmt.Sprintf("You are now logged in as %s", client.account.Name))
c.Send(nil, c.server.name, RPL_SASLSUCCESS, c.nick, "SASL authentication successful") client.Send(nil, client.server.name, RPL_SASLSUCCESS, client.nick, "SASL authentication successful")
// dispatch account-notify // dispatch account-notify
for friend := range c.Friends(AccountNotify) { for friend := range client.Friends(AccountNotify) {
friend.Send(nil, c.nickMaskString, "ACCOUNT", c.account.Name) friend.Send(nil, client.nickMaskString, "ACCOUNT", client.account.Name)
} }
} }

View File

@ -66,8 +66,11 @@ func (capability Capability) String() string {
type CapState uint type CapState uint
const ( const (
// CapNone means CAP hasn't been negotiated at all.
CapNone CapState = iota CapNone CapState = iota
// CapNegotiating means CAP is being negotiated and registration should be paused.
CapNegotiating CapState = iota CapNegotiating CapState = iota
// CapNegotiated means CAP negotiation has been successfully ended and reg should complete.
CapNegotiated CapState = iota CapNegotiated CapState = iota
) )
@ -101,16 +104,6 @@ func (set CapabilitySet) String(version CapVersion) string {
return strings.Join(strs, " ") return strings.Join(strs, " ")
} }
func (set CapabilitySet) DisableString() string {
parts := make([]string, len(set))
index := 0
for capability := range set {
parts[index] = "-" + capability.String()
index++
}
return strings.Join(parts, " ")
}
// CAP <subcmd> [<caps>] // CAP <subcmd> [<caps>]
func capHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool { func capHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
subCommand := strings.ToUpper(msg.Params[0]) subCommand := strings.ToUpper(msg.Params[0])

View File

@ -17,6 +17,7 @@ import (
"github.com/tidwall/buntdb" "github.com/tidwall/buntdb"
) )
// Channel represents a channel that clients can join.
type Channel struct { type Channel struct {
flags ModeSet flags ModeSet
lists map[Mode]*UserMaskSet lists map[Mode]*UserMaskSet

View File

@ -283,7 +283,7 @@ func (client *Client) HasNick() bool {
return client.nick != "" && client.nick != "*" return client.nick != "" && client.nick != "*"
} }
// HasNick returns true if the client's username is set (used in registration). // HasUsername returns true if the client's username is set (used in registration).
func (client *Client) HasUsername() bool { func (client *Client) HasUsername() bool {
return client.username != "" && client.username != "*" return client.username != "" && client.username != "*"
} }
@ -303,11 +303,11 @@ func (client *Client) HasCapabs(capabs ...string) bool {
return true return true
} }
// <mode> // ModeString returns the mode string for this client.
func (c *Client) ModeString() (str string) { func (client *Client) ModeString() (str string) {
str = "+" str = "+"
for flag := range c.flags { for flag := range client.flags {
str += flag.String() str += flag.String()
} }
@ -433,6 +433,7 @@ func (client *Client) ChangeNickname(nickname string) error {
return err return err
} }
// Quit sends the given quit message to the client (but does not destroy them).
func (client *Client) Quit(message string) { func (client *Client) Quit(message string) {
if !client.quitMessageSent { if !client.quitMessageSent {
client.Send(nil, client.nickMaskString, "QUIT", message) client.Send(nil, client.nickMaskString, "QUIT", message)

View File

@ -21,17 +21,18 @@ import (
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
// PassConfig holds the connection password.
type PassConfig struct { type PassConfig struct {
Password string Password string
} }
// TLSListenConfig defines configuration options for listening on TLS // TLSListenConfig defines configuration options for listening on TLS.
type TLSListenConfig struct { type TLSListenConfig struct {
Cert string Cert string
Key string Key string
} }
// Certificate returns the TLS certificate assicated with this TLSListenConfig // Config returns the TLS contiguration assicated with this TLSListenConfig.
func (conf *TLSListenConfig) Config() (*tls.Config, error) { func (conf *TLSListenConfig) Config() (*tls.Config, error) {
cert, err := tls.LoadX509KeyPair(conf.Cert, conf.Key) cert, err := tls.LoadX509KeyPair(conf.Cert, conf.Key)
if err != nil { if err != nil {
@ -43,6 +44,7 @@ func (conf *TLSListenConfig) Config() (*tls.Config, error) {
}, err }, err
} }
// PasswordBytes returns the bytes represented by the password hash.
func (conf *PassConfig) PasswordBytes() []byte { func (conf *PassConfig) PasswordBytes() []byte {
bytes, err := DecodePasswordHash(conf.Password) bytes, err := DecodePasswordHash(conf.Password)
if err != nil { if err != nil {
@ -51,6 +53,7 @@ func (conf *PassConfig) PasswordBytes() []byte {
return bytes return bytes
} }
// AccountRegistrationConfig controls account registration.
type AccountRegistrationConfig struct { type AccountRegistrationConfig struct {
Enabled bool Enabled bool
EnabledCallbacks []string `yaml:"enabled-callbacks"` EnabledCallbacks []string `yaml:"enabled-callbacks"`
@ -72,10 +75,12 @@ type AccountRegistrationConfig struct {
} }
} }
// ChannelRegistrationConfig controls channel registration.
type ChannelRegistrationConfig struct { type ChannelRegistrationConfig struct {
Enabled bool Enabled bool
} }
// OperClassConfig defines a specific operator class.
type OperClassConfig struct { type OperClassConfig struct {
Title string Title string
WhoisLine string WhoisLine string
@ -83,6 +88,7 @@ type OperClassConfig struct {
Capabilities []string Capabilities []string
} }
// OperConfig defines a specific operator's configuration.
type OperConfig struct { type OperConfig struct {
Class string Class string
Vhost string Vhost string
@ -98,11 +104,13 @@ func (conf *OperConfig) PasswordBytes() []byte {
return bytes return bytes
} }
// RestAPIConfig controls the integrated REST API.
type RestAPIConfig struct { type RestAPIConfig struct {
Enabled bool Enabled bool
Listen string Listen string
} }
// ConnectionLimitsConfig controls the automated connection limits.
type ConnectionLimitsConfig struct { type ConnectionLimitsConfig struct {
Enabled bool Enabled bool
CidrLenIPv4 int `yaml:"cidr-len-ipv4"` CidrLenIPv4 int `yaml:"cidr-len-ipv4"`
@ -111,6 +119,7 @@ type ConnectionLimitsConfig struct {
Exempted []string Exempted []string
} }
// ConnectionThrottleConfig controls the automated connection throttling.
type ConnectionThrottleConfig struct { type ConnectionThrottleConfig struct {
Enabled bool Enabled bool
CidrLenIPv4 int `yaml:"cidr-len-ipv4"` CidrLenIPv4 int `yaml:"cidr-len-ipv4"`
@ -124,6 +133,7 @@ type ConnectionThrottleConfig struct {
Exempted []string Exempted []string
} }
// LoggingConfig controls a single logging method.
type LoggingConfig struct { type LoggingConfig struct {
Method string Method string
MethodStderr bool MethodStderr bool
@ -136,11 +146,13 @@ type LoggingConfig struct {
Level logger.Level `yaml:"level-real"` Level logger.Level `yaml:"level-real"`
} }
// LineLenConfig controls line lengths.
type LineLenConfig struct { type LineLenConfig struct {
Tags int Tags int
Rest int Rest int
} }
// STSConfig controls the STS configuration/
type STSConfig struct { type STSConfig struct {
Enabled bool Enabled bool
Duration time.Duration `yaml:"duration-real"` Duration time.Duration `yaml:"duration-real"`
@ -161,6 +173,7 @@ func (sts *STSConfig) Value() string {
return val return val
} }
// Config defines the overall configuration.
type Config struct { type Config struct {
Network struct { Network struct {
Name string Name string
@ -215,12 +228,14 @@ type Config struct {
} }
} }
// OperClass defines an assembled operator class.
type OperClass struct { type OperClass struct {
Title string Title string
WhoisLine string `yaml:"whois-line"` WhoisLine string `yaml:"whois-line"`
Capabilities map[string]bool // map to make lookups much easier Capabilities map[string]bool // map to make lookups much easier
} }
// OperatorClasses returns a map of assembled operator classes from the given config.
func (conf *Config) OperatorClasses() (*map[string]OperClass, error) { func (conf *Config) OperatorClasses() (*map[string]OperClass, error) {
ocs := make(map[string]OperClass) ocs := make(map[string]OperClass)
@ -290,6 +305,7 @@ func (conf *Config) OperatorClasses() (*map[string]OperClass, error) {
return &ocs, nil return &ocs, nil
} }
// Oper represents a single assembled operator's config.
type Oper struct { type Oper struct {
Class *OperClass Class *OperClass
WhoisLine string WhoisLine string
@ -297,6 +313,7 @@ type Oper struct {
Pass []byte Pass []byte
} }
// Operators returns a map of operator configs from the given OperClass and config.
func (conf *Config) Operators(oc *map[string]OperClass) (map[string]Oper, error) { func (conf *Config) Operators(oc *map[string]OperClass) (map[string]Oper, error) {
operators := make(map[string]Oper) operators := make(map[string]Oper)
for name, opConf := range conf.Opers { for name, opConf := range conf.Opers {
@ -327,6 +344,7 @@ func (conf *Config) Operators(oc *map[string]OperClass) (map[string]Oper, error)
return operators, nil return operators, nil
} }
// TLSListeners returns a list of TLS listeners and their configs.
func (conf *Config) TLSListeners() map[string]*tls.Config { func (conf *Config) TLSListeners() map[string]*tls.Config {
tlsListeners := make(map[string]*tls.Config) tlsListeners := make(map[string]*tls.Config)
for s, tlsListenersConf := range conf.Server.TLSListeners { for s, tlsListenersConf := range conf.Server.TLSListeners {
@ -344,6 +362,7 @@ func (conf *Config) TLSListeners() map[string]*tls.Config {
return tlsListeners return tlsListeners
} }
// LoadConfig loads the given YAML configuration file.
func LoadConfig(filename string) (config *Config, err error) { func LoadConfig(filename string) (config *Config, err error) {
data, err := ioutil.ReadFile(filename) data, err := ioutil.ReadFile(filename)
if err != nil { if err != nil {

View File

@ -9,6 +9,7 @@ import (
"strings" "strings"
) )
// IPString returns a simple IP string from the given net.Addr.
func IPString(addr net.Addr) string { func IPString(addr net.Addr) string {
addrStr := addr.String() addrStr := addr.String()
ipaddr, _, err := net.SplitHostPort(addrStr) ipaddr, _, err := net.SplitHostPort(addrStr)

View File

@ -59,7 +59,7 @@ func (list *WhoWasList) Find(nickname string, limit int64) []*WhoWas {
} }
func (list *WhoWasList) prev(index int) int { func (list *WhoWasList) prev(index int) int {
index -= 1 index--
if index < 0 { if index < 0 {
index += len(list.buffer) index += len(list.buffer)
} }