| 185 | } |
| 186 | |
| 187 | bool MinecraftAccount::shouldRefresh() const { |
| 188 | /* |
| 189 | * Never refresh accounts that are being used by the game, it breaks the game session. |
| 190 | * Always refresh accounts that have not been refreshed yet during this session. |
| 191 | * Don't refresh broken accounts. |
| 192 | * Refresh accounts that would expire in the next 12 hours (fresh token validity is 24 hours). |
| 193 | */ |
| 194 | if(isInUse()) { |
| 195 | return false; |
| 196 | } |
| 197 | switch(data.validity_) { |
| 198 | case Katabasis::Validity::Certain: { |
| 199 | break; |
| 200 | } |
| 201 | case Katabasis::Validity::None: { |
| 202 | return false; |
| 203 | } |
| 204 | case Katabasis::Validity::Assumed: { |
| 205 | return true; |
| 206 | } |
| 207 | } |
| 208 | auto now = QDateTime::currentDateTimeUtc(); |
| 209 | auto issuedTimestamp = data.yggdrasilToken.issueInstant; |
| 210 | auto expiresTimestamp = data.yggdrasilToken.notAfter; |
| 211 | |
| 212 | if(!expiresTimestamp.isValid()) { |
| 213 | expiresTimestamp = issuedTimestamp.addSecs(24 * 3600); |
| 214 | } |
| 215 | if (now.secsTo(expiresTimestamp) < (12 * 3600)) { |
| 216 | return true; |
| 217 | } |
| 218 | return false; |
| 219 | } |
| 220 | |
| 221 | void MinecraftAccount::fillSession(AuthSessionPtr session) |
| 222 | { |