add proxy support for resource downloads
- Added ProxyPPC module to prepend proxy prefix to resource URLs
- Modified MusicAsset_Download in resources.c to use proxy
- Re-added legacy texture pack proxy code from ClassiCube-PPC1.3.7rev4
(Compiles ✅ on PowerMac G4 1.24GHz + ATI Radeon 9000 Pro)
This commit is contained in:
59
src/ProxyPPC.c
Normal file
59
src/ProxyPPC.c
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "ProxyPPC.h"
|
||||||
|
|
||||||
|
int HasProxyPrefix(const cc_string* url) {
|
||||||
|
const char* proxyPrefix = PROXY_PREFIX;
|
||||||
|
int prefixLen = strlen(proxyPrefix);
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (url->length < prefixLen) return 0;
|
||||||
|
|
||||||
|
for (i = 0; i < prefixLen; i++) {
|
||||||
|
if (url->buffer[i] != proxyPrefix[i]) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveProxyPrefix(cc_string* url) {
|
||||||
|
int prefixLen, newLength;
|
||||||
|
|
||||||
|
if (!url || url->length == 0) return;
|
||||||
|
|
||||||
|
if (HasProxyPrefix(url)) {
|
||||||
|
const char* proxyPrefix = PROXY_PREFIX;
|
||||||
|
prefixLen = strlen(proxyPrefix);
|
||||||
|
newLength = url->length - prefixLen;
|
||||||
|
|
||||||
|
if (newLength > 0) {
|
||||||
|
memmove(url->buffer, url->buffer + prefixLen, newLength);
|
||||||
|
}
|
||||||
|
url->buffer[newLength] = '\0';
|
||||||
|
url->length = newLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApplyProxyPPC(cc_string* url) {
|
||||||
|
int prefixLen, newLength;
|
||||||
|
|
||||||
|
if (!url || url->length == 0) return;
|
||||||
|
|
||||||
|
if (HasProxyPrefix(url)) return;
|
||||||
|
|
||||||
|
{
|
||||||
|
const char* proxyPrefix = PROXY_PREFIX;
|
||||||
|
prefixLen = strlen(proxyPrefix);
|
||||||
|
newLength = url->length + prefixLen;
|
||||||
|
|
||||||
|
if (newLength + 1 > url->capacity) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memmove(url->buffer + prefixLen, url->buffer, url->length + 1);
|
||||||
|
|
||||||
|
memcpy(url->buffer, proxyPrefix, prefixLen);
|
||||||
|
|
||||||
|
url->length = newLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/ProxyPPC.h
Normal file
11
src/ProxyPPC.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#ifndef PROXY_PPC_H
|
||||||
|
#define PROXY_PPC_H
|
||||||
|
#include "String.h"
|
||||||
|
|
||||||
|
#define PROXY_PREFIX "http://ppcproxy.andreiixe.website/?url="
|
||||||
|
|
||||||
|
void ApplyProxyPPC(cc_string* url);
|
||||||
|
int HasProxyPrefix(const cc_string* url);
|
||||||
|
void RemoveProxyPrefix(cc_string* url);
|
||||||
|
|
||||||
|
#endif // PROXY_PPC_H
|
||||||
@@ -333,12 +333,19 @@ static void MusicAssets_CountMissing(void) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-----------------------------------------------------Music asset fetching -----------------------------------------------*
|
*-----------------------------------------------------Music asset fetching -----------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
|
#include "ProxyPPC.h"
|
||||||
|
|
||||||
CC_NOINLINE static int MusicAsset_Download(const char* hash) {
|
CC_NOINLINE static int MusicAsset_Download(const char* hash) {
|
||||||
cc_string url; char urlBuffer[URL_MAX_SIZE];
|
cc_string url;
|
||||||
|
char urlBuffer[256];
|
||||||
|
|
||||||
String_InitArray(url, urlBuffer);
|
String_InitArray(url, urlBuffer);
|
||||||
|
|
||||||
String_Format3(&url, "https://resources.download.minecraft.net/%r%r/%c",
|
String_Format3(&url, "https://resources.download.minecraft.net/%r%r/%c",
|
||||||
&hash[0], &hash[1], hash);
|
&hash[0], &hash[1], hash);
|
||||||
|
|
||||||
|
ApplyProxyPPC(&url);
|
||||||
|
|
||||||
return Http_AsyncGetData(&url, 0);
|
return Http_AsyncGetData(&url, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -676,17 +676,19 @@ void TexturePack_CheckPending(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Asynchronously downloads the given texture pack */
|
/* Asynchronously downloads the given texture pack */
|
||||||
static void DownloadAsync(const cc_string* url) {
|
#include "ProxyPPC.h"
|
||||||
|
|
||||||
|
static void DownloadAsync(cc_string* url) {
|
||||||
cc_string etag = String_Empty;
|
cc_string etag = String_Empty;
|
||||||
cc_string time = String_Empty;
|
cc_string time = String_Empty;
|
||||||
|
/*Proxy From ProxyPPC.h*/
|
||||||
/* Only retrieve etag/last-modified headers if the file exists */
|
ApplyProxyPPC(url);
|
||||||
/* This inconsistency can occur if user deleted some cached files */
|
|
||||||
if (IsCached(url)) {
|
if (IsCached(url)) {
|
||||||
time = GetCachedLastModified(url);
|
time = GetCachedLastModified(url);
|
||||||
etag = GetCachedETag(url);
|
etag = GetCachedETag(url);
|
||||||
}
|
}
|
||||||
|
Http_TryCancel(TexturePack_ReqID);
|
||||||
|
TexturePack_ReqID = Http_AsyncGetDataEx(url, HTTP_FLAG_PRIORITY, &time, &etag, NULL);
|
||||||
Http_TryCancel(TexturePack_ReqID);
|
Http_TryCancel(TexturePack_ReqID);
|
||||||
TexturePack_ReqID = Http_AsyncGetDataEx(url, HTTP_FLAG_PRIORITY, &time, &etag, NULL);
|
TexturePack_ReqID = Http_AsyncGetDataEx(url, HTTP_FLAG_PRIORITY, &time, &etag, NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user