Auto relogin when session expired.

This commit is contained in:
Otto Hollmann 2022-04-11 18:01:41 +02:00
parent 8e52729a7f
commit 4d5e43a039
No known key found for this signature in database
GPG Key ID: 101D022F467ECE22
1 changed files with 12 additions and 0 deletions

12
user.go
View File

@ -419,6 +419,18 @@ func (user *User) monitorSession(ce *CommandEvent) {
fmt.Println("monitorSession: ", x)
if x > 0 {
user.SetSession(user.Conn.LoginInfo)
} else if ce.User.Conn.LoginInfo != nil {
user.log.Debugln("Session expired for user " + ce.User.Conn.LoginInfo.Username + " trying to relogin.")
err := user.Login(ce, ce.User.Conn.LoginInfo.Username, ce.User.Conn.LoginInfo.Password)
if err == nil {
user.log.Debugln("User " + ce.User.Conn.LoginInfo.Username + " successfully reconnected.")
syncAll(user, false)
} else {
user.log.Debugln("Unable to relogin user %s", ce.User.Conn.LoginInfo.Username)
ce.Reply("Session expired and relogin failed.")
close(user.Conn.Refresh)
leavePortals(ce)
}
} else {
ce.Reply("Session expired\nStore your password into database with command `save-password` to resolve this issue.")
close(user.Conn.Refresh)