summaryrefslogtreecommitdiff
path: root/teleirc/matterbridge/vendor/layeh.com/gumble/gumble/reject.go
blob: f110982ed24d14a73721f8fd61b9418a2ab73e65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package gumble

import (
	"strconv"

	"layeh.com/gumble/gumble/MumbleProto"
)

// RejectType describes why a client connection was rejected by the server.
type RejectType int

// The possible reason why a client connection was rejected by the server.
const (
	RejectNone              RejectType = RejectType(MumbleProto.Reject_None)
	RejectVersion           RejectType = RejectType(MumbleProto.Reject_WrongVersion)
	RejectUserName          RejectType = RejectType(MumbleProto.Reject_InvalidUsername)
	RejectUserCredentials   RejectType = RejectType(MumbleProto.Reject_WrongUserPW)
	RejectServerPassword    RejectType = RejectType(MumbleProto.Reject_WrongServerPW)
	RejectUsernameInUse     RejectType = RejectType(MumbleProto.Reject_UsernameInUse)
	RejectServerFull        RejectType = RejectType(MumbleProto.Reject_ServerFull)
	RejectNoCertificate     RejectType = RejectType(MumbleProto.Reject_NoCertificate)
	RejectAuthenticatorFail RejectType = RejectType(MumbleProto.Reject_AuthenticatorFail)
)

// RejectError is returned by DialWithDialer when the server rejects the client
// connection.
type RejectError struct {
	Type   RejectType
	Reason string
}

// Error implements error.
func (e RejectError) Error() string {
	var msg string
	switch e.Type {
	case RejectNone:
		msg = "none"
	case RejectVersion:
		msg = "wrong client version"
	case RejectUserName:
		msg = "invalid username"
	case RejectUserCredentials:
		msg = "incorrect user credentials"
	case RejectServerPassword:
		msg = "incorrect server password"
	case RejectUsernameInUse:
		msg = "username in use"
	case RejectServerFull:
		msg = "server full"
	case RejectNoCertificate:
		msg = "no certificate"
	case RejectAuthenticatorFail:
		msg = "authenticator fail"
	default:
		msg = "unknown type " + strconv.Itoa(int(e.Type))
	}
	if e.Reason != "" {
		msg += ": " + e.Reason
	}
	return msg
}