| 294 | } |
| 295 | |
| 296 | bool MinecraftAccount::shouldRefresh() const { |
| 297 | /* |
| 298 | * Never refresh accounts that are being used by the game, it breaks the game session. |
| 299 | * Always refresh accounts that have not been refreshed yet during this session. |
| 300 | * Don't refresh broken accounts. |
| 301 | * Refresh accounts that would expire in the next 12 hours (fresh token validity is 24 hours). |
| 302 | */ |
| 303 | if(isInUse()) { |
| 304 | return false; |
| 305 | } |
| 306 | switch(data.validity_) { |
| 307 | case Katabasis::Validity::Certain: { |
| 308 | break; |
| 309 | } |
| 310 | case Katabasis::Validity::None: { |
| 311 | return false; |
| 312 | } |
| 313 | case Katabasis::Validity::Assumed: { |
| 314 | return true; |
| 315 | } |
| 316 | } |
| 317 | auto now = QDateTime::currentDateTimeUtc(); |
| 318 | auto issuedTimestamp = data.yggdrasilToken.issueInstant; |
| 319 | auto expiresTimestamp = data.yggdrasilToken.notAfter; |
| 320 | |
| 321 | if(!expiresTimestamp.isValid()) { |
| 322 | expiresTimestamp = issuedTimestamp.addSecs(24 * 3600); |
| 323 | } |
| 324 | if (now.secsTo(expiresTimestamp) < (12 * 3600)) { |
| 325 | return true; |
| 326 | } |
| 327 | return false; |
| 328 | } |
| 329 | |
| 330 | void MinecraftAccount::fillSession(AuthSessionPtr session) |
| 331 | { |