1
0
Fork 0
forked from External/grumble

Unbreak user registration after SuperUser changes.

This commit is contained in:
Mikkel Krautz 2011-05-20 21:35:42 +02:00
parent 4e95d40645
commit 7c46c9d140
3 changed files with 13 additions and 10 deletions

View file

@ -332,7 +332,7 @@ func NewServerFromFrozen(filename string) (s *Server, err os.Error) {
u.LastActive = fu.LastActive
s.Users[u.Id] = u
if u.Id > s.nextUserId {
if u.Id >= s.nextUserId {
s.nextUserId = u.Id + 1
}
s.UserNameMap[u.Name] = u

View file

@ -803,13 +803,14 @@ func (server *Server) handleUserStateMessage(client *Client, msg *Message) {
userRegistrationChanged := false
if userstate.UserId != nil {
uid := server.RegisterClient(client)
if uid > 0 {
uid, err := server.RegisterClient(client)
if err != nil {
client.Printf("Unable to register: %v", err)
userstate.UserId = nil
} else {
userstate.UserId = proto.Uint32(uid)
client.user = server.Users[uid]
userRegistrationChanged = true
} else {
userstate.UserId = nil
}
broadcast = true
}

View file

@ -155,6 +155,7 @@ func NewServer(id int64, addr string, port int) (s *Server, err os.Error) {
s.Users[0], err = NewUser(0, "SuperUser")
s.UserNameMap["SuperUser"] = s.Users[0]
s.nextUserId = 1
s.Channels = make(map[int]*Channel)
s.aclcache = NewACLCache()
@ -1053,22 +1054,22 @@ func (s *Server) FreezeServer() io.ReadCloser {
}
// Register a client on the server.
func (s *Server) RegisterClient(client *Client) (uid uint32) {
func (s *Server) RegisterClient(client *Client) (uid uint32, err os.Error) {
// Increment nextUserId only if registration succeeded.
defer func() {
if uid > 0 {
if err == nil {
s.nextUserId += 1
}
}()
user, err := NewUser(s.nextUserId, client.Username)
if err != nil {
return 0
return 0, err
}
// Grumble can only register users with certificates.
if len(client.CertHash) == 0 {
return 0
return 0, os.NewError("no cert hash")
}
user.Email = client.Email
@ -1078,7 +1079,8 @@ func (s *Server) RegisterClient(client *Client) (uid uint32) {
s.Users[uid] = user
s.UserCertMap[client.CertHash] = user
s.UserNameMap[client.Username] = user
return uid
return uid, nil
}
// Remove a registered user.