This commit is contained in:
wav3 2025-01-24 22:44:06 +01:00
commit eecd3fbdeb
5 changed files with 46 additions and 23 deletions

View File

@ -273,7 +273,7 @@ static struct ChatCommand SkinCommand = {
}; };
static void ClearDeniedCommand_Execute(const cc_string* args, int argsCount) { static void ClearDeniedCommand_Execute(const cc_string* args, int argsCount) {
int count = TextureCache_ClearDenied(); int count = TextureUrls_ClearDenied();
Chat_Add1("Removed &e%i &fdenied texture pack URLs.", &count); Chat_Add1("Removed &e%i &fdenied texture pack URLs.", &count);
} }

View File

@ -2738,7 +2738,7 @@ static cc_bool TexPackOverlay_IsAlways(void* screen, void* w) {
static void TexPackOverlay_YesClick(void* screen, void* widget) { static void TexPackOverlay_YesClick(void* screen, void* widget) {
struct TexPackOverlay* s = (struct TexPackOverlay*)screen; struct TexPackOverlay* s = (struct TexPackOverlay*)screen;
TexturePack_Extract(&s->url); TexturePack_Extract(&s->url);
if (TexPackOverlay_IsAlways(s, widget)) TextureCache_Accept(&s->url); if (TexPackOverlay_IsAlways(s, widget)) TextureUrls_Accept(&s->url);
Gui_Remove((struct Screen*)s); Gui_Remove((struct Screen*)s);
if (TexPackOverlay_IsAlways(s, widget)) CPE_SendNotifyAction(NOTIFY_ACTION_TEXTURE_PROMPT_RESPONDED, 3); if (TexPackOverlay_IsAlways(s, widget)) CPE_SendNotifyAction(NOTIFY_ACTION_TEXTURE_PROMPT_RESPONDED, 3);
@ -2754,7 +2754,7 @@ static void TexPackOverlay_NoClick(void* screen, void* widget) {
static void TexPackOverlay_ConfirmNoClick(void* screen, void* b) { static void TexPackOverlay_ConfirmNoClick(void* screen, void* b) {
struct TexPackOverlay* s = (struct TexPackOverlay*)screen; struct TexPackOverlay* s = (struct TexPackOverlay*)screen;
if (s->alwaysDeny) TextureCache_Deny(&s->url); if (s->alwaysDeny) TextureUrls_Deny(&s->url);
Gui_Remove((struct Screen*)s); Gui_Remove((struct Screen*)s);
if (s->alwaysDeny) CPE_SendNotifyAction(NOTIFY_ACTION_TEXTURE_PROMPT_RESPONDED, 0); if (s->alwaysDeny) CPE_SendNotifyAction(NOTIFY_ACTION_TEXTURE_PROMPT_RESPONDED, 0);

View File

@ -45,9 +45,9 @@ static void Server_ResetState(void) {
} }
void Server_RetrieveTexturePack(const cc_string* url) { void Server_RetrieveTexturePack(const cc_string* url) {
if (!Game_AllowServerTextures || TextureCache_HasDenied(url)) return; if (!Game_AllowServerTextures || TextureUrls_HasDenied(url)) return;
if (!url->length || TextureCache_HasAccepted(url)) { if (!url->length || TextureUrls_HasAccepted(url)) {
TexturePack_Extract(url); TexturePack_Extract(url);
} else { } else {
TexPackOverlay_Show(url); TexPackOverlay_Show(url);

View File

@ -255,40 +255,62 @@ cc_bool Atlas_TryChange(struct Bitmap* atlas) {
/*########################################################################################################################* /*########################################################################################################################*
*------------------------------------------------------TextureCache-------------------------------------------------------* *------------------------------------------------------TextureUrls--------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static struct StringsBuffer acceptedList, deniedList, etagCache, lastModCache; #ifdef CC_BUILD_NETWORKING
static struct StringsBuffer acceptedList, deniedList;
#define ACCEPTED_TXT "texturecache/acceptedurls.txt" #define ACCEPTED_TXT "texturecache/acceptedurls.txt"
#define DENIED_TXT "texturecache/deniedurls.txt" #define DENIED_TXT "texturecache/deniedurls.txt"
#define ETAGS_TXT "texturecache/etags.txt"
#define LASTMOD_TXT "texturecache/lastmodified.txt"
/* Initialises cache state (loading various lists) */ static void TextureUrls_Init(void) {
static void TextureCache_Init(void) {
EntryList_UNSAFE_Load(&acceptedList, ACCEPTED_TXT); EntryList_UNSAFE_Load(&acceptedList, ACCEPTED_TXT);
EntryList_UNSAFE_Load(&deniedList, DENIED_TXT); EntryList_UNSAFE_Load(&deniedList, DENIED_TXT);
EntryList_UNSAFE_Load(&etagCache, ETAGS_TXT);
EntryList_UNSAFE_Load(&lastModCache, LASTMOD_TXT);
} }
cc_bool TextureCache_HasAccepted(const cc_string* url) { return EntryList_Find(&acceptedList, url, ' ') >= 0; } cc_bool TextureUrls_HasAccepted(const cc_string* url) { return EntryList_Find(&acceptedList, url, ' ') >= 0; }
cc_bool TextureCache_HasDenied(const cc_string* url) { return EntryList_Find(&deniedList, url, ' ') >= 0; } cc_bool TextureUrls_HasDenied(const cc_string* url) { return EntryList_Find(&deniedList, url, ' ') >= 0; }
void TextureCache_Accept(const cc_string* url) { void TextureUrls_Accept(const cc_string* url) {
EntryList_Set(&acceptedList, url, &String_Empty, ' '); EntryList_Set(&acceptedList, url, &String_Empty, ' ');
EntryList_Save(&acceptedList, ACCEPTED_TXT); EntryList_Save(&acceptedList, ACCEPTED_TXT);
} }
void TextureCache_Deny(const cc_string* url) {
void TextureUrls_Deny(const cc_string* url) {
EntryList_Set(&deniedList, url, &String_Empty, ' '); EntryList_Set(&deniedList, url, &String_Empty, ' ');
EntryList_Save(&deniedList, DENIED_TXT); EntryList_Save(&deniedList, DENIED_TXT);
} }
int TextureCache_ClearDenied(void) { int TextureUrls_ClearDenied(void) {
int count = deniedList.count; int count = deniedList.count;
StringsBuffer_Clear(&deniedList); StringsBuffer_Clear(&deniedList);
EntryList_Save(&deniedList, DENIED_TXT); EntryList_Save(&deniedList, DENIED_TXT);
return count; return count;
} }
#else
static void TextureUrls_Init(void) { }
cc_bool TextureUrls_HasAccepted(const cc_string* url) { return false; }
cc_bool TextureUrls_HasDenied(const cc_string* url) { return false; }
void TextureUrls_Accept(const cc_string* url) { }
void TextureUrls_Deny(const cc_string* url) { }
int TextureUrls_ClearDenied(void) { return 0; }
#endif
/*########################################################################################################################*
*------------------------------------------------------TextureCache-------------------------------------------------------*
*#########################################################################################################################*/
static struct StringsBuffer etagCache, lastModCache;
#define ETAGS_TXT "texturecache/etags.txt"
#define LASTMOD_TXT "texturecache/lastmodified.txt"
static void TextureCache_Init(void) {
EntryList_UNSAFE_Load(&etagCache, ETAGS_TXT);
EntryList_UNSAFE_Load(&lastModCache, LASTMOD_TXT);
}
CC_INLINE static void HashUrl(cc_string* key, const cc_string* url) { CC_INLINE static void HashUrl(cc_string* key, const cc_string* url) {
String_AppendUInt32(key, Utils_CRC32((const cc_uint8*)url->buffer, url->length)); String_AppendUInt32(key, Utils_CRC32((const cc_uint8*)url->buffer, url->length));
@ -696,6 +718,7 @@ static void OnInit(void) {
Utils_EnsureDirectory("texpacks"); Utils_EnsureDirectory("texpacks");
Utils_EnsureDirectory("texturecache"); Utils_EnsureDirectory("texturecache");
TextureCache_Init(); TextureCache_Init();
TextureUrls_Init();
} }
static void OnReset(void) { static void OnReset(void) {

View File

@ -80,17 +80,17 @@ TextureRec Atlas1D_TexRec(TextureLoc texLoc, int uCount, int* index);
void Atlas1D_Bind(int index); void Atlas1D_Bind(int index);
/* Whether the given URL is in list of accepted URLs. */ /* Whether the given URL is in list of accepted URLs. */
cc_bool TextureCache_HasAccepted(const cc_string* url); cc_bool TextureUrls_HasAccepted(const cc_string* url);
/* Whether the given URL is in list of denied URLs. */ /* Whether the given URL is in list of denied URLs. */
cc_bool TextureCache_HasDenied(const cc_string* url); cc_bool TextureUrls_HasDenied(const cc_string* url);
/* Adds the given URL to list of accepted URLs, then saves it. */ /* Adds the given URL to list of accepted URLs, then saves it. */
/* Accepted URLs are loaded without prompting the user. */ /* Accepted URLs are loaded without prompting the user. */
void TextureCache_Accept(const cc_string* url); void TextureUrls_Accept(const cc_string* url);
/* Adds the given URL to list of denied URLs, then saves it. */ /* Adds the given URL to list of denied URLs, then saves it. */
/* Denied URLs are never loaded. */ /* Denied URLs are never loaded. */
void TextureCache_Deny(const cc_string* url); void TextureUrls_Deny(const cc_string* url);
/* Clears the list of denied URLs, returning number removed. */ /* Clears the list of denied URLs, returning number removed. */
int TextureCache_ClearDenied(void); int TextureUrls_ClearDenied(void);
/* Request ID of texture pack currently being downloaded */ /* Request ID of texture pack currently being downloaded */
extern int TexturePack_ReqID; extern int TexturePack_ReqID;