From d24a596f8421dc6cd0f42948ec43876e607dcf73 Mon Sep 17 00:00:00 2001 From: raven Date: Tue, 10 Feb 2026 17:30:34 -0600 Subject: refactor login handling --- server/object/object.go | 6 +++++- server/server/command.go | 23 +++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) (limited to 'server') diff --git a/server/object/object.go b/server/object/object.go index 70b84c2..82e8c59 100644 --- a/server/object/object.go +++ b/server/object/object.go @@ -76,6 +76,10 @@ func (w *World) setData(id string, o proto.Object) { } } +func (w *World) GetCachedObject(id string) Object { + return w.objects[id] +} + func (w *World) GetObject(id string) Object { if w.objects[id] == nil { o := w.getData(id) @@ -83,7 +87,7 @@ func (w *World) GetObject(id string) Object { w.objects[id] = w.kinds[o.Kind].Undata(o) } } - return w.objects[id] + return w.GetCachedObject(id) } func (w *World) PutObject(id string, o Object) { diff --git a/server/server/command.go b/server/server/command.go index 9c57fc1..f9386b1 100644 --- a/server/server/command.go +++ b/server/server/command.go @@ -15,6 +15,8 @@ func (s *server) SendRequest(r session.Request) { r.ReplyInvalid() return } + var theUser *user.User + auth := r.Cmd.Args[0] switch auth.Kind { @@ -33,8 +35,7 @@ func (s *server) SendRequest(r session.Request) { return } r.Reply(proto.NewCmd("you-are", "", u.InfoFor(u.Id()))) - r.From.UserId = u.Id() - r.From.Subscribe(&u.PrivateStream) + theUser = u case "password": var id, password string @@ -64,22 +65,28 @@ func (s *server) SendRequest(r session.Request) { r.Reply(proto.Fail{"bad-auth-id", "", nil}.Cmd()) return } - if u.CheckPassword(password) { - r.Reply(proto.NewCmd("you-are", "", u.InfoFor(u.Id()))) - r.From.UserId = u.Id() - r.From.PasswordAuthed = true - r.From.Subscribe(&u.PrivateStream) - } else { + if !u.CheckPassword(password) { r.Reply(proto.Fail{"incorrect-password", "", nil}.Cmd()) + return + } + r.Reply(proto.NewCmd("you-are", "", u.InfoFor(u.Id()))) + r.From.PasswordAuthed = true + if r.From.UserId != "" { + return } + theUser = u default: r.Reply(proto.Fail{"bad-auth-id", "", nil}.Cmd()) + return } default: r.ReplyInvalid() } + r.From.UserId = theUser.Id() + r.From.Subscribe(&theUser.PrivateStream) + case "lookup": var response []proto.Object for _, o := range r.Cmd.Args { -- cgit v1.2.3