From 5269dc8776e66ad98340ebefcb28fb92981a5bab Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Mon, 5 Sep 2016 22:35:13 +1000 Subject: [PATCH] accounts: Very roughly introduce account type --- irc/accounts.go | 10 ++++++++-- irc/channel.go | 4 ++-- irc/client.go | 4 ++-- irc/registration.go | 13 +++++++++++++ irc/server.go | 4 ++-- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/irc/accounts.go b/irc/accounts.go index 76adf9c1..171832ec 100644 --- a/irc/accounts.go +++ b/irc/accounts.go @@ -5,8 +5,14 @@ package irc import "time" -// Account represents a user account. -type Account struct { +var ( + NoAccount = ClientAccount{ + Name: "*", // * is used until actual account name is set + } +) + +// ClientAccount represents a user account. +type ClientAccount struct { // Name of the account. Name string // RegisteredAt represents the time that the account was registered. diff --git a/irc/channel.go b/irc/channel.go index 6eb6cd6e..c624622d 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -209,7 +209,7 @@ func (channel *Channel) Join(client *Client, key string) { for member := range channel.members { if member.capabilities[ExtendedJoin] { - member.Send(nil, client.nickMaskString, "JOIN", channel.nameString, client.accountName, client.realname) + member.Send(nil, client.nickMaskString, "JOIN", channel.nameString, client.account.Name, client.realname) } else { member.Send(nil, client.nickMaskString, "JOIN", channel.nameString) } @@ -224,7 +224,7 @@ func (channel *Channel) Join(client *Client, key string) { } if client.capabilities[ExtendedJoin] { - client.Send(nil, client.nickMaskString, "JOIN", channel.nameString, client.accountName, client.realname) + client.Send(nil, client.nickMaskString, "JOIN", channel.nameString, client.account.Name, client.realname) } else { client.Send(nil, client.nickMaskString, "JOIN", channel.nameString) } diff --git a/irc/client.go b/irc/client.go index 66053df2..a10b5336 100644 --- a/irc/client.go +++ b/irc/client.go @@ -45,7 +45,7 @@ type Client struct { nickMaskString string // cache for nickmask string since it's used with lots of replies quitTimer *time.Timer realname string - accountName string + account *ClientAccount registered bool server *Server socket *Socket @@ -67,7 +67,7 @@ func NewClient(server *Server, conn net.Conn, isTLS bool) *Client { flags: make(map[UserMode]bool), server: server, socket: &socket, - accountName: "*", // * is used until actual account name is set + account: &NoAccount, nickString: "*", // * is used until actual nick is given } if isTLS { diff --git a/irc/registration.go b/irc/registration.go index e4a267fb..1fadfb3e 100644 --- a/irc/registration.go +++ b/irc/registration.go @@ -18,6 +18,7 @@ import ( const ( keyAccountExists = "account %s exists" + keyAccountVerified = "account %s verified" keyAccountRegTime = "account %s registered.time" keyAccountCredentials = "account %s credentials" ) @@ -221,11 +222,23 @@ func regCreateHandler(server *Server, client *Client, msg ircmsg.IrcMessage) boo if err != nil { client.Send(nil, server.nameString, ERR_UNKNOWNERROR, client.nickString, "REG", "CREATE", "Could not register") log.Println("Could not save registration creds:", err.Error()) + removeFailedRegCreateData(server.store, accountString) return false } // automatically complete registration if callbackNamespace == "*" { + err = server.store.Update(func(tx *buntdb.Tx) error { + tx.Set(keyAccountVerified, "1", nil) + return nil + }) + if err != nil { + client.Send(nil, server.nameString, ERR_UNKNOWNERROR, client.nickString, "REG", "CREATE", "Could not register") + log.Println("Could not save verification confirmation (*):", err.Error()) + removeFailedRegCreateData(server.store, accountString) + return false + } + client.Notice("Account creation was successful!") return false } diff --git a/irc/server.go b/irc/server.go index 2b9f0307..5bc78312 100644 --- a/irc/server.go +++ b/irc/server.go @@ -27,7 +27,7 @@ import ( ) type Server struct { - accounts map[string]Account + accounts map[string]ClientAccount channels ChannelNameMap clients *ClientLookupSet commands chan Command @@ -67,7 +67,7 @@ type clientConn struct { func NewServer(config *Config) *Server { server := &Server{ - accounts: make(map[string]Account), + accounts: make(map[string]ClientAccount), channels: make(ChannelNameMap), clients: NewClientLookupSet(), commands: make(chan Command),