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:
parent
8ba0bf347d
commit
22216d4d60
@ -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.
|
||||
func (c *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))
|
||||
c.Send(nil, c.server.name, RPL_SASLSUCCESS, c.nick, "SASL authentication successful")
|
||||
func (client *Client) successfulSaslAuth() {
|
||||
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))
|
||||
client.Send(nil, client.server.name, RPL_SASLSUCCESS, client.nick, "SASL authentication successful")
|
||||
|
||||
// dispatch account-notify
|
||||
for friend := range c.Friends(AccountNotify) {
|
||||
friend.Send(nil, c.nickMaskString, "ACCOUNT", c.account.Name)
|
||||
for friend := range client.Friends(AccountNotify) {
|
||||
friend.Send(nil, client.nickMaskString, "ACCOUNT", client.account.Name)
|
||||
}
|
||||
}
|
||||
|
@ -66,8 +66,11 @@ func (capability Capability) String() string {
|
||||
type CapState uint
|
||||
|
||||
const (
|
||||
// CapNone means CAP hasn't been negotiated at all.
|
||||
CapNone CapState = iota
|
||||
// CapNegotiating means CAP is being negotiated and registration should be paused.
|
||||
CapNegotiating CapState = iota
|
||||
// CapNegotiated means CAP negotiation has been successfully ended and reg should complete.
|
||||
CapNegotiated CapState = iota
|
||||
)
|
||||
|
||||
@ -101,16 +104,6 @@ func (set CapabilitySet) String(version CapVersion) string {
|
||||
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>]
|
||||
func capHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||
subCommand := strings.ToUpper(msg.Params[0])
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
"github.com/tidwall/buntdb"
|
||||
)
|
||||
|
||||
// Channel represents a channel that clients can join.
|
||||
type Channel struct {
|
||||
flags ModeSet
|
||||
lists map[Mode]*UserMaskSet
|
||||
|
@ -283,7 +283,7 @@ func (client *Client) HasNick() bool {
|
||||
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 {
|
||||
return client.username != "" && client.username != "*"
|
||||
}
|
||||
@ -303,11 +303,11 @@ func (client *Client) HasCapabs(capabs ...string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// <mode>
|
||||
func (c *Client) ModeString() (str string) {
|
||||
// ModeString returns the mode string for this client.
|
||||
func (client *Client) ModeString() (str string) {
|
||||
str = "+"
|
||||
|
||||
for flag := range c.flags {
|
||||
for flag := range client.flags {
|
||||
str += flag.String()
|
||||
}
|
||||
|
||||
@ -433,6 +433,7 @@ func (client *Client) ChangeNickname(nickname string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Quit sends the given quit message to the client (but does not destroy them).
|
||||
func (client *Client) Quit(message string) {
|
||||
if !client.quitMessageSent {
|
||||
client.Send(nil, client.nickMaskString, "QUIT", message)
|
||||
|
@ -21,17 +21,18 @@ import (
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// PassConfig holds the connection password.
|
||||
type PassConfig struct {
|
||||
Password string
|
||||
}
|
||||
|
||||
// TLSListenConfig defines configuration options for listening on TLS
|
||||
// TLSListenConfig defines configuration options for listening on TLS.
|
||||
type TLSListenConfig struct {
|
||||
Cert 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) {
|
||||
cert, err := tls.LoadX509KeyPair(conf.Cert, conf.Key)
|
||||
if err != nil {
|
||||
@ -43,6 +44,7 @@ func (conf *TLSListenConfig) Config() (*tls.Config, error) {
|
||||
}, err
|
||||
}
|
||||
|
||||
// PasswordBytes returns the bytes represented by the password hash.
|
||||
func (conf *PassConfig) PasswordBytes() []byte {
|
||||
bytes, err := DecodePasswordHash(conf.Password)
|
||||
if err != nil {
|
||||
@ -51,6 +53,7 @@ func (conf *PassConfig) PasswordBytes() []byte {
|
||||
return bytes
|
||||
}
|
||||
|
||||
// AccountRegistrationConfig controls account registration.
|
||||
type AccountRegistrationConfig struct {
|
||||
Enabled bool
|
||||
EnabledCallbacks []string `yaml:"enabled-callbacks"`
|
||||
@ -72,10 +75,12 @@ type AccountRegistrationConfig struct {
|
||||
}
|
||||
}
|
||||
|
||||
// ChannelRegistrationConfig controls channel registration.
|
||||
type ChannelRegistrationConfig struct {
|
||||
Enabled bool
|
||||
}
|
||||
|
||||
// OperClassConfig defines a specific operator class.
|
||||
type OperClassConfig struct {
|
||||
Title string
|
||||
WhoisLine string
|
||||
@ -83,6 +88,7 @@ type OperClassConfig struct {
|
||||
Capabilities []string
|
||||
}
|
||||
|
||||
// OperConfig defines a specific operator's configuration.
|
||||
type OperConfig struct {
|
||||
Class string
|
||||
Vhost string
|
||||
@ -98,11 +104,13 @@ func (conf *OperConfig) PasswordBytes() []byte {
|
||||
return bytes
|
||||
}
|
||||
|
||||
// RestAPIConfig controls the integrated REST API.
|
||||
type RestAPIConfig struct {
|
||||
Enabled bool
|
||||
Listen string
|
||||
}
|
||||
|
||||
// ConnectionLimitsConfig controls the automated connection limits.
|
||||
type ConnectionLimitsConfig struct {
|
||||
Enabled bool
|
||||
CidrLenIPv4 int `yaml:"cidr-len-ipv4"`
|
||||
@ -111,6 +119,7 @@ type ConnectionLimitsConfig struct {
|
||||
Exempted []string
|
||||
}
|
||||
|
||||
// ConnectionThrottleConfig controls the automated connection throttling.
|
||||
type ConnectionThrottleConfig struct {
|
||||
Enabled bool
|
||||
CidrLenIPv4 int `yaml:"cidr-len-ipv4"`
|
||||
@ -124,6 +133,7 @@ type ConnectionThrottleConfig struct {
|
||||
Exempted []string
|
||||
}
|
||||
|
||||
// LoggingConfig controls a single logging method.
|
||||
type LoggingConfig struct {
|
||||
Method string
|
||||
MethodStderr bool
|
||||
@ -136,11 +146,13 @@ type LoggingConfig struct {
|
||||
Level logger.Level `yaml:"level-real"`
|
||||
}
|
||||
|
||||
// LineLenConfig controls line lengths.
|
||||
type LineLenConfig struct {
|
||||
Tags int
|
||||
Rest int
|
||||
}
|
||||
|
||||
// STSConfig controls the STS configuration/
|
||||
type STSConfig struct {
|
||||
Enabled bool
|
||||
Duration time.Duration `yaml:"duration-real"`
|
||||
@ -161,6 +173,7 @@ func (sts *STSConfig) Value() string {
|
||||
return val
|
||||
}
|
||||
|
||||
// Config defines the overall configuration.
|
||||
type Config struct {
|
||||
Network struct {
|
||||
Name string
|
||||
@ -215,12 +228,14 @@ type Config struct {
|
||||
}
|
||||
}
|
||||
|
||||
// OperClass defines an assembled operator class.
|
||||
type OperClass struct {
|
||||
Title string
|
||||
WhoisLine string `yaml:"whois-line"`
|
||||
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) {
|
||||
ocs := make(map[string]OperClass)
|
||||
|
||||
@ -290,6 +305,7 @@ func (conf *Config) OperatorClasses() (*map[string]OperClass, error) {
|
||||
return &ocs, nil
|
||||
}
|
||||
|
||||
// Oper represents a single assembled operator's config.
|
||||
type Oper struct {
|
||||
Class *OperClass
|
||||
WhoisLine string
|
||||
@ -297,6 +313,7 @@ type Oper struct {
|
||||
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) {
|
||||
operators := make(map[string]Oper)
|
||||
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
|
||||
}
|
||||
|
||||
// TLSListeners returns a list of TLS listeners and their configs.
|
||||
func (conf *Config) TLSListeners() map[string]*tls.Config {
|
||||
tlsListeners := make(map[string]*tls.Config)
|
||||
for s, tlsListenersConf := range conf.Server.TLSListeners {
|
||||
@ -344,6 +362,7 @@ func (conf *Config) TLSListeners() map[string]*tls.Config {
|
||||
return tlsListeners
|
||||
}
|
||||
|
||||
// LoadConfig loads the given YAML configuration file.
|
||||
func LoadConfig(filename string) (config *Config, err error) {
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// IPString returns a simple IP string from the given net.Addr.
|
||||
func IPString(addr net.Addr) string {
|
||||
addrStr := addr.String()
|
||||
ipaddr, _, err := net.SplitHostPort(addrStr)
|
||||
|
@ -59,7 +59,7 @@ func (list *WhoWasList) Find(nickname string, limit int64) []*WhoWas {
|
||||
}
|
||||
|
||||
func (list *WhoWasList) prev(index int) int {
|
||||
index -= 1
|
||||
index--
|
||||
if index < 0 {
|
||||
index += len(list.buffer)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user