@@ -70,6 +70,31 @@ namespace LiveSteam
7070 return 1 ;
7171 }
7272
73+ //
74+ // Error handler lambda that automatically:
75+ // + frees the cache file handle
76+ // + deletes the cache file
77+ // + clears the memory cache
78+ //
79+ auto DeleteBadCache = [this , h](void )
80+ {
81+ // Close the file handle so we can actually delete the file
82+ fclose (h);
83+
84+ DeleteFileA (AUTHCACHE_FILEPATH);
85+ ClearCache ();
86+ };
87+
88+ //
89+ // Check the age of the cache file
90+ // If it's too old we need to delete it and clear the cache
91+ //
92+ if (FS_FileAge_Sec (AUTHCACHE_FILEPATH) > 60 )
93+ {
94+ DeleteBadCache ();
95+ return 5 ;
96+ }
97+
7398 // We only need to allocate a buffer for m_steamCookieKey if it doesn't already have one.
7499 // Since m_steamCookieKeySize is constant, we don't need to worry about resizing the buffer
75100 if (m_steamCookieKey == nullptr )
@@ -78,8 +103,7 @@ namespace LiveSteam
78103 if (fread (m_steamCookieKey, 1 , m_steamCookieKeySize, h) != m_steamCookieKeySize)
79104 {
80105 // Unable to read the correct number of bytes for the cookie key
81- fclose (h);
82- ClearCache ();
106+ DeleteBadCache ();
83107 return 2 ;
84108 }
85109
@@ -104,8 +128,7 @@ namespace LiveSteam
104128 if (fread (m_steamAppTicket, 1 , m_steamAppTicketSize, h) != m_steamAppTicketSize)
105129 {
106130 // Unable to read the correct number of bytes for the app ticket
107- fclose (h);
108- ClearCache ();
131+ DeleteBadCache ();
109132 return 3 ;
110133 }
111134
@@ -193,25 +216,36 @@ bool LiveSteamClient::GetRetrievedEncryptedAppTicket(void *ticketBuf, const unsi
193216 auto steamUser = (*(void *(__cdecl **)())0x009A356C )();
194217 auto getEncryptedAppTicket = *(bool (__thiscall **)(void *, void *, int , unsigned int *))(*(DWORD *)steamUser + 80 );
195218
196- // Use the real function if Steam had a good ticket
197- if (this ->rawTicketResult == k_EResultOK)
219+ bool useCache = dw_cacheTicket && dw_cacheTicket->current .enabled ;
220+
221+ //
222+ // Use the real function if one of the following conditions are met:
223+ // + Steam had a good ticket
224+ // + The caching subsystem is disabled
225+ //
226+ // Otherwise we fallback to using the cached ticket
227+ //
228+ if (this ->rawTicketResult == k_EResultOK || !useCache)
198229 {
199230 if (getEncryptedAppTicket (steamUser, ticketBuf, ticketBufSize, ticketSize))
200231 {
201- DBG_ASSERT (g_authService);
202- if (!g_authService)
232+ if (useCache)
203233 {
204- Com_DPrintf (1 , " STEAM: Couldn't cache recieved auth ticket - g_authService is NULL\n " );
205- return true ;
206- }
207-
208- // Update the cache with the generated ticket & DW cookie
209- g_authCache.UpdateCache (ticketBuf, *ticketSize, g_authService->m_steamCookieKey );
210-
211- // Commit the new cache contents to the disk
212- if (g_authCache.CommitCache () == 0 )
213- {
214- Com_DPrintf (1 , " STEAM: Wrote cached auth ticket\n " );
234+ DBG_ASSERT (g_authService);
235+ if (!g_authService)
236+ {
237+ Com_DPrintf (1 , " STEAM: Couldn't cache recieved auth ticket - g_authService is NULL\n " );
238+ return true ;
239+ }
240+
241+ // Update the cache with the generated ticket & DW cookie
242+ g_authCache.UpdateCache (ticketBuf, *ticketSize, g_authService->m_steamCookieKey );
243+
244+ // Commit the new cache contents to the disk
245+ if (g_authCache.CommitCache () == 0 )
246+ {
247+ Com_DPrintf (1 , " STEAM: Wrote cached auth ticket\n " );
248+ }
215249 }
216250
217251 Com_DPrintf (1 , " STEAM: Retrieved auth ticket from Steam, sending to DemonWare\n " );
@@ -266,15 +300,21 @@ void LiveSteamClient::OnRequestEncryptedAppTicket(EncryptedAppTicketResponse_t *
266300 break ;
267301 }
268302
269- // If the request was rate limited, check if there's a cached ticket
270- if (pEncryptedAppTicketResponse->m_eResult == k_EResultLimitExceeded)
303+ //
304+ // Only use the caching subsystem if we explicitly have it enabled
305+ //
306+ if (dw_cacheTicket && dw_cacheTicket->current .enabled )
271307 {
272- if (g_authCache.ValidateCache ())
308+ // If the request was rate limited, check if there's a cached ticket
309+ if (pEncryptedAppTicketResponse->m_eResult == k_EResultLimitExceeded)
273310 {
274- Com_DPrintf (1 , " STEAM: Attempting to use cached auth ticket...\n " );
311+ if (g_authCache.ValidateCache ())
312+ {
313+ Com_DPrintf (1 , " STEAM: Attempting to use cached auth ticket...\n " );
275314
276- pEncryptedAppTicketResponse->m_eResult = k_EResultOK;
277- dwLogonSeAcquiredSteamTicket ();
315+ pEncryptedAppTicketResponse->m_eResult = k_EResultOK;
316+ dwLogonSeAcquiredSteamTicket ();
317+ }
278318 }
279319 }
280320
0 commit comments