mirror of
https://github.com/ergochat/ergo.git
synced 2025-10-09 20:17:27 +02:00
Allow multiple account registrations for testing
This commit is contained in:
parent
8e32098f1f
commit
c48d869f4d
@ -28,6 +28,7 @@ type AccountRegistration struct {
|
|||||||
Enabled bool
|
Enabled bool
|
||||||
EnabledCallbacks []string
|
EnabledCallbacks []string
|
||||||
EnabledCredentialTypes []string
|
EnabledCredentialTypes []string
|
||||||
|
AllowMultiplePerConnection bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// AccountCredentials stores the various methods for verifying accounts.
|
// AccountCredentials stores the various methods for verifying accounts.
|
||||||
@ -41,6 +42,7 @@ type AccountCredentials struct {
|
|||||||
func NewAccountRegistration(config AccountRegistrationConfig) (accountReg AccountRegistration) {
|
func NewAccountRegistration(config AccountRegistrationConfig) (accountReg AccountRegistration) {
|
||||||
if config.Enabled {
|
if config.Enabled {
|
||||||
accountReg.Enabled = true
|
accountReg.Enabled = true
|
||||||
|
accountReg.AllowMultiplePerConnection = config.AllowMultiplePerConnection
|
||||||
for _, name := range config.EnabledCallbacks {
|
for _, name := range config.EnabledCallbacks {
|
||||||
// we store "none" as "*" internally
|
// we store "none" as "*" internally
|
||||||
if name == "none" {
|
if name == "none" {
|
||||||
@ -94,9 +96,13 @@ func accRegisterHandler(server *Server, client *Client, msg ircmsg.IrcMessage) b
|
|||||||
|
|
||||||
// clients can't reg new accounts if they're already logged in
|
// clients can't reg new accounts if they're already logged in
|
||||||
if client.account != nil {
|
if client.account != nil {
|
||||||
|
if server.accountRegistration.AllowMultiplePerConnection {
|
||||||
|
client.LogoutOfAccount()
|
||||||
|
} else {
|
||||||
client.Send(nil, server.name, ERR_REG_UNSPECIFIED_ERROR, client.nick, "*", "You're already logged into an account")
|
client.Send(nil, server.name, ERR_REG_UNSPECIFIED_ERROR, client.nick, "*", "You're already logged into an account")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// get and sanitise account name
|
// get and sanitise account name
|
||||||
account := strings.TrimSpace(msg.Params[1])
|
account := strings.TrimSpace(msg.Params[1])
|
||||||
|
@ -262,6 +262,33 @@ func (client *Client) LoginToAccount(account *ClientAccount) {
|
|||||||
account.Clients = append(account.Clients, client)
|
account.Clients = append(account.Clients, client)
|
||||||
client.account = account
|
client.account = account
|
||||||
client.server.snomasks.Send(sno.LocalAccounts, fmt.Sprintf(ircfmt.Unescape("Client $c[grey][$r%s$c[grey]] logged into account $c[grey][$r%s$c[grey]]"), client.nickMaskString, account.Name))
|
client.server.snomasks.Send(sno.LocalAccounts, fmt.Sprintf(ircfmt.Unescape("Client $c[grey][$r%s$c[grey]] logged into account $c[grey][$r%s$c[grey]]"), client.nickMaskString, account.Name))
|
||||||
|
|
||||||
|
//TODO(dan): This should output the AccountNotify message instead of the sasl accepted function below.
|
||||||
|
}
|
||||||
|
|
||||||
|
// LogoutOfAccount logs the client out of their current account.
|
||||||
|
func (client *Client) LogoutOfAccount() {
|
||||||
|
account := client.account
|
||||||
|
if account == nil {
|
||||||
|
// already logged out
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// logout of existing acct
|
||||||
|
var newClientAccounts []*Client
|
||||||
|
for _, c := range account.Clients {
|
||||||
|
if c != client {
|
||||||
|
newClientAccounts = append(newClientAccounts, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
account.Clients = newClientAccounts
|
||||||
|
|
||||||
|
client.account = nil
|
||||||
|
|
||||||
|
// dispatch account-notify
|
||||||
|
for friend := range client.Friends(AccountNotify) {
|
||||||
|
friend.Send(nil, client.nickMaskString, "ACCOUNT", "*")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// authExternalHandler parses the SASL EXTERNAL mechanism.
|
// authExternalHandler parses the SASL EXTERNAL mechanism.
|
||||||
|
@ -74,6 +74,7 @@ type AccountRegistrationConfig struct {
|
|||||||
VerifyMessage string `yaml:"verify-message"`
|
VerifyMessage string `yaml:"verify-message"`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
AllowMultiplePerConnection bool `yaml:"allow-multiple-per-connection"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChannelRegistrationConfig controls channel registration.
|
// ChannelRegistrationConfig controls channel registration.
|
||||||
|
@ -132,6 +132,10 @@ accounts:
|
|||||||
enabled-callbacks:
|
enabled-callbacks:
|
||||||
- none # no verification needed, will instantly register successfully
|
- none # no verification needed, will instantly register successfully
|
||||||
|
|
||||||
|
# allow multiple account registrations per connection
|
||||||
|
# this is for testing purposes and shouldn't be allowed on real networks
|
||||||
|
allow-multiple-per-connection: false
|
||||||
|
|
||||||
# is account authentication enabled?
|
# is account authentication enabled?
|
||||||
authentication-enabled: true
|
authentication-enabled: true
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user