Split NS/CS commands into separate functions

This commit is contained in:
Daniel Oaks 2018-02-03 21:38:28 +10:00
parent 2ecec25d28
commit 3ef4c5f799
2 changed files with 296 additions and 283 deletions

View File

@ -45,12 +45,19 @@ func (server *Server) chanservPrivmsgHandler(client *Client, message string) {
return return
} }
server.chanservRegisterHandler(client, params[1])
} else {
client.ChanServNotice(client.t("Sorry, I don't know that command"))
}
}
// chanservRegisterHandler handles the ChanServ REGISTER subcommand.
func (server *Server) chanservRegisterHandler(client *Client, channelName string) {
if !server.channelRegistrationEnabled { if !server.channelRegistrationEnabled {
client.ChanServNotice(client.t("Channel registration is not enabled")) client.ChanServNotice(client.t("Channel registration is not enabled"))
return return
} }
channelName := params[1]
channelKey, err := CasefoldChannel(channelName) channelKey, err := CasefoldChannel(channelName)
if err != nil { if err != nil {
client.ChanServNotice(client.t("Channel name is not valid")) client.ChanServNotice(client.t("Channel name is not valid"))
@ -93,7 +100,4 @@ func (server *Server) chanservPrivmsgHandler(client *Client, message string) {
member.Send(nil, fmt.Sprintf("ChanServ!services@%s", client.server.name), "MODE", args...) member.Send(nil, fmt.Sprintf("ChanServ!services@%s", client.server.name), "MODE", args...)
} }
} }
} else {
client.ChanServNotice(client.t("Sorry, I don't know that command"))
}
} }

View File

@ -62,6 +62,18 @@ func (server *Server) nickservPrivmsgHandler(client *Client, message string) {
return return
} }
server.nickservRegisterHandler(client, username, passphrase)
} else if command == "identify" {
// get params
username, passphrase := extractParam(params)
server.nickservIdentifyHandler(client, username, passphrase)
} else {
client.Notice(client.t("Command not recognised. To see the available commands, run /NS HELP"))
}
}
func (server *Server) nickservRegisterHandler(client *Client, username, passphrase string) {
certfp := client.certfp certfp := client.certfp
if passphrase == "" && certfp == "" { if passphrase == "" && certfp == "" {
client.Notice(client.t("You need to either supply a passphrase or be connected via TLS with a client cert")) client.Notice(client.t("You need to either supply a passphrase or be connected via TLS with a client cert"))
@ -195,8 +207,9 @@ func (server *Server) nickservPrivmsgHandler(client *Client, message string) {
removeFailedAccRegisterData(server.store, casefoldedAccount) removeFailedAccRegisterData(server.store, casefoldedAccount)
return return
} }
}
} else if command == "identify" { func (server *Server) nickservIdentifyHandler(client *Client, username, passphrase string) {
// fail out if we need to // fail out if we need to
if !server.accountAuthenticationEnabled { if !server.accountAuthenticationEnabled {
client.Notice(client.t("Login has been disabled")) client.Notice(client.t("Login has been disabled"))
@ -204,7 +217,6 @@ func (server *Server) nickservPrivmsgHandler(client *Client, message string) {
} }
// try passphrase // try passphrase
username, passphrase := extractParam(params)
if username != "" && passphrase != "" { if username != "" && passphrase != "" {
// keep it the same as in the ACC CREATE stage // keep it the same as in the ACC CREATE stage
accountKey, err := CasefoldName(username) accountKey, err := CasefoldName(username)
@ -300,7 +312,4 @@ func (server *Server) nickservPrivmsgHandler(client *Client, message string) {
} }
client.Notice(client.t("Could not login with your TLS certificate or supplied username/password")) client.Notice(client.t("Could not login with your TLS certificate or supplied username/password"))
} else {
client.Notice(client.t("Command not recognised. To see the available commands, run /NS HELP"))
}
} }