This also lets us have a convenient adb.User() that returns the current
user; this only works though if we're already authenticated.
udp: newUDPWrap(),
}
}
+
+func (adb *AniDB) User() *User {
+ if adb != nil && adb.udp != nil {
+ return adb.udp.user
+ }
+ return nil
+}
decrypt(c.username),
decrypt(c.password),
decrypt(c.udpKey))
- runtime.GC() // any better way to clean the plaintexts?
logReply(r)
err := r.Error()
}
}
udp.connected = err == nil
+
+ if udp.connected {
+ ch := make(chan udpapi.APIReply, 1)
+ udp.sendQueueCh <- paramSet{
+ cmd: "USER",
+ params: paramMap{"user": decrypt(c.username)},
+ ch: ch,
+ }
+ reply := <-ch
+
+ if reply != nil {
+ uid, _ := parseUserReply(reply)
+ udp.user = uid.User()
+ }
+ }
+
+ runtime.GC()
return r
}
return &noauthAPIReply{}
adb.udp.sendLock.Lock()
defer adb.udp.sendLock.Unlock()
+ adb.udp.user = nil
+
if adb.udp.connected {
adb.udp.connected = false
logRequest(paramSet{cmd: "LOGOUT"})
credLock sync.Mutex
credentials *credentials
connected bool
+
+ user *User
}
func newUDPWrap() *udpWrap {
type UID int
+func (uid UID) User() *User {
+ var u User
+ if CacheGet(&u, "user", uid) == nil {
+ return &u
+ }
+ return nil
+}
+
func (adb *AniDB) GetCurrentUser() <-chan *User {
ch := make(chan *User, 1)