mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
Move all errors into errors.go
This commit is contained in:
parent
3ef4c5f799
commit
2419f69879
@ -4,17 +4,11 @@
|
|||||||
package irc
|
package irc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/tidwall/buntdb"
|
"github.com/tidwall/buntdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
errAccountCreation = errors.New("Account could not be created")
|
|
||||||
errCertfpAlreadyExists = errors.New("An account already exists with your certificate")
|
|
||||||
)
|
|
||||||
|
|
||||||
// AccountRegistration manages the registration of accounts.
|
// AccountRegistration manages the registration of accounts.
|
||||||
type AccountRegistration struct {
|
type AccountRegistration struct {
|
||||||
Enabled bool
|
Enabled bool
|
||||||
|
@ -5,7 +5,6 @@ package irc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@ -37,9 +36,6 @@ var (
|
|||||||
NoAccount = ClientAccount{
|
NoAccount = ClientAccount{
|
||||||
Name: "*", // * is used until actual account name is set
|
Name: "*", // * is used until actual account name is set
|
||||||
}
|
}
|
||||||
|
|
||||||
// generic sasl fail error
|
|
||||||
errSaslFail = errors.New("SASL failed")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ClientAccount represents a user account.
|
// ClientAccount represents a user account.
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
package irc
|
package irc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@ -18,10 +17,6 @@ import (
|
|||||||
"github.com/oragono/oragono/irc/modes"
|
"github.com/oragono/oragono/irc/modes"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
ChannelAlreadyRegistered = errors.New("Channel is already registered")
|
|
||||||
)
|
|
||||||
|
|
||||||
// Channel represents a channel that clients can join.
|
// Channel represents a channel that clients can join.
|
||||||
type Channel struct {
|
type Channel struct {
|
||||||
flags modes.ModeSet
|
flags modes.ModeSet
|
||||||
@ -132,7 +127,7 @@ func (channel *Channel) SetRegistered(founder string) error {
|
|||||||
defer channel.stateMutex.Unlock()
|
defer channel.stateMutex.Unlock()
|
||||||
|
|
||||||
if channel.registeredFounder != "" {
|
if channel.registeredFounder != "" {
|
||||||
return ChannelAlreadyRegistered
|
return errChannelAlreadyRegistered
|
||||||
}
|
}
|
||||||
channel.registeredFounder = founder
|
channel.registeredFounder = founder
|
||||||
channel.registeredTime = time.Now()
|
channel.registeredTime = time.Now()
|
||||||
|
@ -4,16 +4,9 @@
|
|||||||
package irc
|
package irc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
InvalidChannelName = errors.New("Invalid channel name")
|
|
||||||
NoSuchChannel = errors.New("No such channel")
|
|
||||||
ChannelNameInUse = errors.New("Channel name in use")
|
|
||||||
)
|
|
||||||
|
|
||||||
type channelManagerEntry struct {
|
type channelManagerEntry struct {
|
||||||
channel *Channel
|
channel *Channel
|
||||||
// this is a refcount for joins, so we can avoid a race where we incorrectly
|
// this is a refcount for joins, so we can avoid a race where we incorrectly
|
||||||
@ -56,7 +49,7 @@ func (cm *ChannelManager) Join(client *Client, name string, key string) error {
|
|||||||
server := client.server
|
server := client.server
|
||||||
casefoldedName, err := CasefoldChannel(name)
|
casefoldedName, err := CasefoldChannel(name)
|
||||||
if err != nil || len(casefoldedName) > server.Limits().ChannelLen {
|
if err != nil || len(casefoldedName) > server.Limits().ChannelLen {
|
||||||
return NoSuchChannel
|
return errNoSuchChannel
|
||||||
}
|
}
|
||||||
|
|
||||||
cm.Lock()
|
cm.Lock()
|
||||||
@ -117,7 +110,7 @@ func (cm *ChannelManager) maybeCleanup(entry *channelManagerEntry, afterJoin boo
|
|||||||
func (cm *ChannelManager) Part(client *Client, name string, message string) error {
|
func (cm *ChannelManager) Part(client *Client, name string, message string) error {
|
||||||
casefoldedName, err := CasefoldChannel(name)
|
casefoldedName, err := CasefoldChannel(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return NoSuchChannel
|
return errNoSuchChannel
|
||||||
}
|
}
|
||||||
|
|
||||||
cm.RLock()
|
cm.RLock()
|
||||||
@ -125,7 +118,7 @@ func (cm *ChannelManager) Part(client *Client, name string, message string) erro
|
|||||||
cm.RUnlock()
|
cm.RUnlock()
|
||||||
|
|
||||||
if entry == nil {
|
if entry == nil {
|
||||||
return NoSuchChannel
|
return errNoSuchChannel
|
||||||
}
|
}
|
||||||
entry.channel.Part(client, message)
|
entry.channel.Part(client, message)
|
||||||
cm.maybeCleanup(entry, false)
|
cm.maybeCleanup(entry, false)
|
||||||
@ -136,23 +129,23 @@ func (cm *ChannelManager) Part(client *Client, name string, message string) erro
|
|||||||
func (cm *ChannelManager) Rename(name string, newname string) error {
|
func (cm *ChannelManager) Rename(name string, newname string) error {
|
||||||
cfname, err := CasefoldChannel(name)
|
cfname, err := CasefoldChannel(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return NoSuchChannel
|
return errNoSuchChannel
|
||||||
}
|
}
|
||||||
|
|
||||||
cfnewname, err := CasefoldChannel(newname)
|
cfnewname, err := CasefoldChannel(newname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return InvalidChannelName
|
return errInvalidChannelName
|
||||||
}
|
}
|
||||||
|
|
||||||
cm.Lock()
|
cm.Lock()
|
||||||
defer cm.Unlock()
|
defer cm.Unlock()
|
||||||
|
|
||||||
if cm.chans[cfnewname] != nil {
|
if cm.chans[cfnewname] != nil {
|
||||||
return ChannelNameInUse
|
return errChannelNameInUse
|
||||||
}
|
}
|
||||||
entry := cm.chans[cfname]
|
entry := cm.chans[cfname]
|
||||||
if entry == nil {
|
if entry == nil {
|
||||||
return NoSuchChannel
|
return errNoSuchChannel
|
||||||
}
|
}
|
||||||
delete(cm.chans, cfname)
|
delete(cm.chans, cfname)
|
||||||
cm.chans[cfnewname] = entry
|
cm.chans[cfnewname] = entry
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
package irc
|
package irc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
@ -32,8 +31,6 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// ErrNickAlreadySet is a weird error that's sent when the server's consistency has been compromised.
|
|
||||||
ErrNickAlreadySet = errors.New("Nickname is already set")
|
|
||||||
LoopbackIP = net.ParseIP("127.0.0.1")
|
LoopbackIP = net.ParseIP("127.0.0.1")
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -397,7 +394,7 @@ func (client *Client) TryResume() {
|
|||||||
var params []string
|
var params []string
|
||||||
if 0 < len(oldModes) {
|
if 0 < len(oldModes) {
|
||||||
params = []string{channel.name, "+" + oldModes}
|
params = []string{channel.name, "+" + oldModes}
|
||||||
for _ = range oldModes {
|
for range oldModes {
|
||||||
params = append(params, client.nick)
|
params = append(params, client.nick)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
package irc
|
package irc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -17,11 +16,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
ErrNickMissing = errors.New("nick missing")
|
|
||||||
ErrNicknameInUse = errors.New("nickname in use")
|
|
||||||
)
|
|
||||||
|
|
||||||
// ExpandUserHost takes a userhost, and returns an expanded version.
|
// ExpandUserHost takes a userhost, and returns an expanded version.
|
||||||
func ExpandUserHost(userhost string) (expanded string) {
|
func ExpandUserHost(userhost string) (expanded string) {
|
||||||
expanded = userhost
|
expanded = userhost
|
||||||
@ -91,7 +85,7 @@ func (clients *ClientManager) Remove(client *Client) error {
|
|||||||
defer clients.Unlock()
|
defer clients.Unlock()
|
||||||
|
|
||||||
if !client.HasNick() {
|
if !client.HasNick() {
|
||||||
return ErrNickMissing
|
return errNickMissing
|
||||||
}
|
}
|
||||||
clients.removeInternal(client)
|
clients.removeInternal(client)
|
||||||
return nil
|
return nil
|
||||||
@ -111,7 +105,7 @@ func (clients *ClientManager) SetNick(client *Client, newNick string) error {
|
|||||||
currentNewEntry := clients.byNick[newcfnick]
|
currentNewEntry := clients.byNick[newcfnick]
|
||||||
// the client may just be changing case
|
// the client may just be changing case
|
||||||
if currentNewEntry != nil && currentNewEntry != client {
|
if currentNewEntry != nil && currentNewEntry != client {
|
||||||
return ErrNicknameInUse
|
return errNicknameInUse
|
||||||
}
|
}
|
||||||
clients.byNick[newcfnick] = client
|
clients.byNick[newcfnick] = client
|
||||||
client.updateNickMask(newNick)
|
client.updateNickMask(newNick)
|
||||||
|
@ -8,7 +8,6 @@ package irc
|
|||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
@ -41,7 +40,7 @@ type TLSListenConfig struct {
|
|||||||
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 {
|
||||||
return nil, errors.New("tls cert+key: invalid pair")
|
return nil, ErrInvalidCertKeyPair
|
||||||
}
|
}
|
||||||
|
|
||||||
return &tls.Config{
|
return &tls.Config{
|
||||||
@ -232,7 +231,7 @@ func (conf *Config) OperatorClasses() (*map[string]OperClass, error) {
|
|||||||
lenOfLastOcs := -1
|
lenOfLastOcs := -1
|
||||||
for {
|
for {
|
||||||
if lenOfLastOcs == len(ocs) {
|
if lenOfLastOcs == len(ocs) {
|
||||||
return nil, errors.New("OperClasses contains a looping dependency, or a class extends from a class that doesn't exist")
|
return nil, ErrOperClassDependencies
|
||||||
}
|
}
|
||||||
lenOfLastOcs = len(ocs)
|
lenOfLastOcs = len(ocs)
|
||||||
|
|
||||||
@ -369,22 +368,22 @@ func LoadConfig(filename string) (config *Config, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if config.Network.Name == "" {
|
if config.Network.Name == "" {
|
||||||
return nil, errors.New("Network name missing")
|
return nil, ErrNetworkNameMissing
|
||||||
}
|
}
|
||||||
if config.Server.Name == "" {
|
if config.Server.Name == "" {
|
||||||
return nil, errors.New("Server name missing")
|
return nil, ErrServerNameMissing
|
||||||
}
|
}
|
||||||
if !utils.IsHostname(config.Server.Name) {
|
if !utils.IsHostname(config.Server.Name) {
|
||||||
return nil, errors.New("Server name must match the format of a hostname")
|
return nil, ErrServerNameNotHostname
|
||||||
}
|
}
|
||||||
if config.Datastore.Path == "" {
|
if config.Datastore.Path == "" {
|
||||||
return nil, errors.New("Datastore path missing")
|
return nil, ErrDatastorePathMissing
|
||||||
}
|
}
|
||||||
if len(config.Server.Listen) == 0 {
|
if len(config.Server.Listen) == 0 {
|
||||||
return nil, errors.New("Server listening addresses missing")
|
return nil, ErrNoListenersDefined
|
||||||
}
|
}
|
||||||
if config.Limits.NickLen < 1 || config.Limits.ChannelLen < 2 || config.Limits.AwayLen < 1 || config.Limits.KickLen < 1 || config.Limits.TopicLen < 1 {
|
if config.Limits.NickLen < 1 || config.Limits.ChannelLen < 2 || config.Limits.AwayLen < 1 || config.Limits.KickLen < 1 || config.Limits.TopicLen < 1 {
|
||||||
return nil, errors.New("Limits aren't setup properly, check them and make them sane")
|
return nil, ErrLimitsAreInsane
|
||||||
}
|
}
|
||||||
if config.Server.STS.Enabled {
|
if config.Server.STS.Enabled {
|
||||||
config.Server.STS.Duration, err = custime.ParseDuration(config.Server.STS.DurationString)
|
config.Server.STS.Duration, err = custime.ParseDuration(config.Server.STS.DurationString)
|
||||||
@ -422,7 +421,7 @@ func LoadConfig(filename string) (config *Config, err error) {
|
|||||||
config.Server.WebIRC = newWebIRC
|
config.Server.WebIRC = newWebIRC
|
||||||
// process limits
|
// process limits
|
||||||
if config.Limits.LineLen.Tags < 512 || config.Limits.LineLen.Rest < 512 {
|
if config.Limits.LineLen.Tags < 512 || config.Limits.LineLen.Rest < 512 {
|
||||||
return nil, errors.New("Line lengths must be 512 or greater (check the linelen section under server->limits)")
|
return nil, ErrLineLengthsTooSmall
|
||||||
}
|
}
|
||||||
var newLogConfigs []logger.LoggingConfig
|
var newLogConfigs []logger.LoggingConfig
|
||||||
for _, logConfig := range config.Logging {
|
for _, logConfig := range config.Logging {
|
||||||
@ -434,7 +433,7 @@ func LoadConfig(filename string) (config *Config, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if methods["file"] && logConfig.Filename == "" {
|
if methods["file"] && logConfig.Filename == "" {
|
||||||
return nil, errors.New("Logging configuration specifies 'file' method but 'filename' is empty")
|
return nil, ErrLoggerFilenameMissing
|
||||||
}
|
}
|
||||||
logConfig.MethodFile = methods["file"]
|
logConfig.MethodFile = methods["file"]
|
||||||
logConfig.MethodStdout = methods["stdout"]
|
logConfig.MethodStdout = methods["stdout"]
|
||||||
@ -453,7 +452,7 @@ func LoadConfig(filename string) (config *Config, err error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if typeStr == "-" {
|
if typeStr == "-" {
|
||||||
return nil, errors.New("Encountered logging type '-' with no type to exclude")
|
return nil, ErrLoggerExcludeEmpty
|
||||||
}
|
}
|
||||||
if typeStr[0] == '-' {
|
if typeStr[0] == '-' {
|
||||||
typeStr = typeStr[1:]
|
typeStr = typeStr[1:]
|
||||||
@ -463,7 +462,7 @@ func LoadConfig(filename string) (config *Config, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(logConfig.Types) < 1 {
|
if len(logConfig.Types) < 1 {
|
||||||
return nil, errors.New("Logger has no types to log")
|
return nil, ErrLoggerHasNoTypes
|
||||||
}
|
}
|
||||||
|
|
||||||
newLogConfigs = append(newLogConfigs, logConfig)
|
newLogConfigs = append(newLogConfigs, logConfig)
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
package irc
|
package irc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
@ -19,10 +18,6 @@ const (
|
|||||||
keyDlineEntry = "bans.dline %s"
|
keyDlineEntry = "bans.dline %s"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
errNoExistingBan = errors.New("Ban does not exist")
|
|
||||||
)
|
|
||||||
|
|
||||||
// IPRestrictTime contains the expiration info about the given IP.
|
// IPRestrictTime contains the expiration info about the given IP.
|
||||||
type IPRestrictTime struct {
|
type IPRestrictTime struct {
|
||||||
// Duration is how long this block lasts for.
|
// Duration is how long this block lasts for.
|
||||||
|
54
irc/errors.go
Normal file
54
irc/errors.go
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
// Copyright (c) 2012-2014 Jeremy Latt
|
||||||
|
// Copyright (c) 2014-2015 Edmund Huber
|
||||||
|
// Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
|
||||||
|
// released under the MIT license
|
||||||
|
|
||||||
|
package irc
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
// Runtime Errors
|
||||||
|
var (
|
||||||
|
errAccountCreation = errors.New("Account could not be created")
|
||||||
|
errCertfpAlreadyExists = errors.New("An account already exists with your certificate")
|
||||||
|
errChannelAlreadyRegistered = errors.New("Channel is already registered")
|
||||||
|
errChannelNameInUse = errors.New("Channel name in use")
|
||||||
|
errInvalidChannelName = errors.New("Invalid channel name")
|
||||||
|
errMonitorLimitExceeded = errors.New("Monitor limit exceeded")
|
||||||
|
errNickMissing = errors.New("nick missing")
|
||||||
|
errNicknameInUse = errors.New("nickname in use")
|
||||||
|
errNoExistingBan = errors.New("Ban does not exist")
|
||||||
|
errNoSuchChannel = errors.New("No such channel")
|
||||||
|
errRenamePrivsNeeded = errors.New("Only chanops can rename channels")
|
||||||
|
errSaslFail = errors.New("SASL failed")
|
||||||
|
)
|
||||||
|
|
||||||
|
// Socket Errors
|
||||||
|
var (
|
||||||
|
errNoPeerCerts = errors.New("Client did not provide a certificate")
|
||||||
|
errNotTLS = errors.New("Not a TLS connection")
|
||||||
|
)
|
||||||
|
|
||||||
|
// String Errors
|
||||||
|
var (
|
||||||
|
errCouldNotStabilize = errors.New("Could not stabilize string while casefolding")
|
||||||
|
errStringIsEmpty = errors.New("String is empty")
|
||||||
|
errInvalidCharacter = errors.New("Invalid character")
|
||||||
|
)
|
||||||
|
|
||||||
|
// Config Errors
|
||||||
|
var (
|
||||||
|
ErrDatastorePathMissing = errors.New("Datastore path missing")
|
||||||
|
ErrInvalidCertKeyPair = errors.New("tls cert+key: invalid pair")
|
||||||
|
ErrLimitsAreInsane = errors.New("Limits aren't setup properly, check them and make them sane")
|
||||||
|
ErrLineLengthsTooSmall = errors.New("Line lengths must be 512 or greater (check the linelen section under server->limits)")
|
||||||
|
ErrLoggerExcludeEmpty = errors.New("Encountered logging type '-' with no type to exclude")
|
||||||
|
ErrLoggerFilenameMissing = errors.New("Logging configuration specifies 'file' method but 'filename' is empty")
|
||||||
|
ErrLoggerHasNoTypes = errors.New("Logger has no types to log")
|
||||||
|
ErrNetworkNameMissing = errors.New("Network name missing")
|
||||||
|
ErrNoFingerprintOrPassword = errors.New("Fingerprint or password needs to be specified")
|
||||||
|
ErrNoListenersDefined = errors.New("Server listening addresses missing")
|
||||||
|
ErrOperClassDependencies = errors.New("OperClasses contains a looping dependency, or a class extends from a class that doesn't exist")
|
||||||
|
ErrServerNameMissing = errors.New("Server name missing")
|
||||||
|
ErrServerNameNotHostname = errors.New("Server name must match the format of a hostname")
|
||||||
|
)
|
@ -6,7 +6,6 @@
|
|||||||
package irc
|
package irc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
@ -25,7 +24,7 @@ type webircConfig struct {
|
|||||||
// Populate fills out our password or fingerprint.
|
// Populate fills out our password or fingerprint.
|
||||||
func (wc *webircConfig) Populate() (err error) {
|
func (wc *webircConfig) Populate() (err error) {
|
||||||
if wc.Fingerprint == "" && wc.PasswordString == "" {
|
if wc.Fingerprint == "" && wc.PasswordString == "" {
|
||||||
return errors.New("Fingerprint or password needs to be specified")
|
return ErrNoFingerprintOrPassword
|
||||||
}
|
}
|
||||||
|
|
||||||
if wc.PasswordString != "" {
|
if wc.PasswordString != "" {
|
||||||
|
@ -976,7 +976,7 @@ func joinHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
key = keys[i]
|
key = keys[i]
|
||||||
}
|
}
|
||||||
err := server.channels.Join(client, name, key)
|
err := server.channels.Join(client, name, key)
|
||||||
if err == NoSuchChannel {
|
if err == errNoSuchChannel {
|
||||||
client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.Nick(), name, client.t("No such channel"))
|
client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.Nick(), name, client.t("No such channel"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1571,7 +1571,7 @@ func monitorAddHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = server.monitorManager.Add(client, casefoldedTarget, limit)
|
err = server.monitorManager.Add(client, casefoldedTarget, limit)
|
||||||
if err == ErrMonitorLimitExceeded {
|
if err == errMonitorLimitExceeded {
|
||||||
client.Send(nil, server.name, ERR_MONLISTFULL, client.Nick(), strconv.Itoa(server.limits.MonitorEntries), strings.Join(targets, ","))
|
client.Send(nil, server.name, ERR_MONLISTFULL, client.Nick(), strconv.Itoa(server.limits.MonitorEntries), strings.Join(targets, ","))
|
||||||
break
|
break
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
@ -1855,7 +1855,7 @@ func partHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
|
|
||||||
for _, chname := range channels {
|
for _, chname := range channels {
|
||||||
err := server.channels.Part(client, chname, reason)
|
err := server.channels.Part(client, chname, reason)
|
||||||
if err == NoSuchChannel {
|
if err == errNoSuchChannel {
|
||||||
client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.nick, chname, client.t("No such channel"))
|
client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.nick, chname, client.t("No such channel"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2023,13 +2023,13 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage) (resul
|
|||||||
// TODO: send correct error codes, e.g., ERR_CANNOTRENAME, ERR_CHANNAMEINUSE
|
// TODO: send correct error codes, e.g., ERR_CANNOTRENAME, ERR_CHANNAMEINUSE
|
||||||
var code string
|
var code string
|
||||||
switch err {
|
switch err {
|
||||||
case NoSuchChannel:
|
case errNoSuchChannel:
|
||||||
code = ERR_NOSUCHCHANNEL
|
code = ERR_NOSUCHCHANNEL
|
||||||
case RenamePrivsNeeded:
|
case errRenamePrivsNeeded:
|
||||||
code = ERR_CHANOPRIVSNEEDED
|
code = ERR_CHANOPRIVSNEEDED
|
||||||
case InvalidChannelName:
|
case errInvalidChannelName:
|
||||||
code = ERR_UNKNOWNERROR
|
code = ERR_UNKNOWNERROR
|
||||||
case ChannelNameInUse:
|
case errChannelNameInUse:
|
||||||
code = ERR_UNKNOWNERROR
|
code = ERR_UNKNOWNERROR
|
||||||
default:
|
default:
|
||||||
code = ERR_UNKNOWNERROR
|
code = ERR_UNKNOWNERROR
|
||||||
@ -2040,12 +2040,12 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage) (resul
|
|||||||
oldName := strings.TrimSpace(msg.Params[0])
|
oldName := strings.TrimSpace(msg.Params[0])
|
||||||
newName := strings.TrimSpace(msg.Params[1])
|
newName := strings.TrimSpace(msg.Params[1])
|
||||||
if oldName == "" || newName == "" {
|
if oldName == "" || newName == "" {
|
||||||
errorResponse(InvalidChannelName, "<empty>")
|
errorResponse(errInvalidChannelName, "<empty>")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
casefoldedOldName, err := CasefoldChannel(oldName)
|
casefoldedOldName, err := CasefoldChannel(oldName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorResponse(InvalidChannelName, oldName)
|
errorResponse(errInvalidChannelName, oldName)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2056,12 +2056,12 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage) (resul
|
|||||||
|
|
||||||
channel := server.channels.Get(oldName)
|
channel := server.channels.Get(oldName)
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
errorResponse(NoSuchChannel, oldName)
|
errorResponse(errNoSuchChannel, oldName)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//TODO(dan): allow IRCops to do this?
|
//TODO(dan): allow IRCops to do this?
|
||||||
if !channel.ClientIsAtLeast(client, modes.Operator) {
|
if !channel.ClientIsAtLeast(client, modes.Operator) {
|
||||||
errorResponse(RenamePrivsNeeded, oldName)
|
errorResponse(errRenamePrivsNeeded, oldName)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
package irc
|
package irc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/goshuirc/irc-go/ircmsg"
|
"github.com/goshuirc/irc-go/ircmsg"
|
||||||
@ -29,9 +28,6 @@ func NewMonitorManager() *MonitorManager {
|
|||||||
return &mm
|
return &mm
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrMonitorLimitExceeded is used when the monitor list exceeds our limit.
|
|
||||||
var ErrMonitorLimitExceeded = errors.New("Monitor limit exceeded")
|
|
||||||
|
|
||||||
// AlertAbout alerts everyone monitoring `client`'s nick that `client` is now {on,off}line.
|
// AlertAbout alerts everyone monitoring `client`'s nick that `client` is now {on,off}line.
|
||||||
func (manager *MonitorManager) AlertAbout(client *Client, online bool) {
|
func (manager *MonitorManager) AlertAbout(client *Client, online bool) {
|
||||||
cfnick := client.NickCasefolded()
|
cfnick := client.NickCasefolded()
|
||||||
@ -67,7 +63,7 @@ func (manager *MonitorManager) Add(client *Client, nick string, limit int) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(manager.watching[client]) >= limit {
|
if len(manager.watching[client]) >= limit {
|
||||||
return ErrMonitorLimitExceeded
|
return errMonitorLimitExceeded
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.watching[client][nick] = true
|
manager.watching[client][nick] = true
|
||||||
|
@ -42,7 +42,7 @@ func performNickChange(server *Server, client *Client, target *Client, newnick s
|
|||||||
origNick := target.Nick()
|
origNick := target.Nick()
|
||||||
origNickMask := target.NickMaskString()
|
origNickMask := target.NickMaskString()
|
||||||
err = client.server.clients.SetNick(target, nickname)
|
err = client.server.clients.SetNick(target, nickname)
|
||||||
if err == ErrNicknameInUse {
|
if err == errNicknameInUse {
|
||||||
client.Send(nil, server.name, ERR_NICKNAMEINUSE, client.nick, nickname, client.t("Nickname is already in use"))
|
client.Send(nil, server.name, ERR_NICKNAMEINUSE, client.nick, nickname, client.t("Nickname is already in use"))
|
||||||
return false
|
return false
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
@ -195,5 +195,6 @@ const (
|
|||||||
ERR_NOLANGUAGE = "982"
|
ERR_NOLANGUAGE = "982"
|
||||||
|
|
||||||
// draft numerics
|
// draft numerics
|
||||||
|
|
||||||
ERR_CANNOT_RESUME = "999"
|
ERR_CANNOT_RESUME = "999"
|
||||||
)
|
)
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
@ -43,8 +42,6 @@ var (
|
|||||||
// common error responses
|
// common error responses
|
||||||
couldNotParseIPMsg, _ = (&[]ircmsg.IrcMessage{ircmsg.MakeMessage(nil, "", "ERROR", "Unable to parse your IP address")}[0]).Line()
|
couldNotParseIPMsg, _ = (&[]ircmsg.IrcMessage{ircmsg.MakeMessage(nil, "", "ERROR", "Unable to parse your IP address")}[0]).Line()
|
||||||
|
|
||||||
RenamePrivsNeeded = errors.New("Only chanops can rename channels")
|
|
||||||
|
|
||||||
// supportedUserModesString acts as a cache for when we introduce users
|
// supportedUserModesString acts as a cache for when we introduce users
|
||||||
supportedUserModesString = modes.SupportedUserModes.String()
|
supportedUserModesString = modes.SupportedUserModes.String()
|
||||||
// supportedChannelModesString acts as a cache for when we introduce users
|
// supportedChannelModesString acts as a cache for when we introduce users
|
||||||
@ -349,10 +346,10 @@ func (server *Server) createListener(addr string, tlsConfig *tls.Config) *Listen
|
|||||||
// make listener
|
// make listener
|
||||||
var listener net.Listener
|
var listener net.Listener
|
||||||
var err error
|
var err error
|
||||||
optional_unix_prefix := "unix:"
|
optionalUnixPrefix := "unix:"
|
||||||
optional_prefix_len := len(optional_unix_prefix)
|
optionalPrefixLen := len(optionalUnixPrefix)
|
||||||
if len(addr) >= optional_prefix_len && strings.ToLower(addr[0:optional_prefix_len]) == optional_unix_prefix {
|
if len(addr) >= optionalPrefixLen && strings.ToLower(addr[0:optionalPrefixLen]) == optionalUnixPrefix {
|
||||||
addr = addr[optional_prefix_len:]
|
addr = addr[optionalPrefixLen:]
|
||||||
if len(addr) == 0 || addr[0] != '/' {
|
if len(addr) == 0 || addr[0] != '/' {
|
||||||
log.Fatal("Bad unix socket address", addr)
|
log.Fatal("Bad unix socket address", addr)
|
||||||
}
|
}
|
||||||
@ -492,7 +489,7 @@ func (server *Server) tryRegister(c *Client) {
|
|||||||
oldModes := myModes.String()
|
oldModes := myModes.String()
|
||||||
if 0 < len(oldModes) {
|
if 0 < len(oldModes) {
|
||||||
params := []string{channel.name, "+" + oldModes}
|
params := []string{channel.name, "+" + oldModes}
|
||||||
for _ = range oldModes {
|
for range oldModes {
|
||||||
params = append(params, c.nick)
|
params = append(params, c.nick)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
@ -18,8 +17,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errNotTLS = errors.New("Not a TLS connection")
|
|
||||||
errNoPeerCerts = errors.New("Client did not provide a certificate")
|
|
||||||
handshakeTimeout, _ = time.ParseDuration("5s")
|
handshakeTimeout, _ = time.ParseDuration("5s")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
package irc
|
package irc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/text/secure/precis"
|
"golang.org/x/text/secure/precis"
|
||||||
@ -16,12 +15,6 @@ const (
|
|||||||
casemappingName = "rfc8265"
|
casemappingName = "rfc8265"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
errCouldNotStabilize = errors.New("Could not stabilize string while casefolding")
|
|
||||||
errInvalidCharacter = errors.New("Invalid character")
|
|
||||||
errEmpty = errors.New("String is empty")
|
|
||||||
)
|
|
||||||
|
|
||||||
// Casefold returns a casefolded string, without doing any name or channel character checks.
|
// Casefold returns a casefolded string, without doing any name or channel character checks.
|
||||||
func Casefold(str string) (string, error) {
|
func Casefold(str string) (string, error) {
|
||||||
var err error
|
var err error
|
||||||
@ -51,7 +44,7 @@ func CasefoldChannel(name string) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
} else if len(lowered) == 0 {
|
} else if len(lowered) == 0 {
|
||||||
return "", errEmpty
|
return "", errStringIsEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
if lowered[0] != '#' {
|
if lowered[0] != '#' {
|
||||||
@ -76,7 +69,7 @@ func CasefoldName(name string) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
} else if len(lowered) == 0 {
|
} else if len(lowered) == 0 {
|
||||||
return "", errEmpty
|
return "", errStringIsEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
// space can't be used
|
// space can't be used
|
||||||
|
Loading…
Reference in New Issue
Block a user