C client: Fix texture pack downloading. Also log non-http errors to chat.

This commit is contained in:
UnknownShadow200 2018-09-02 20:32:28 +10:00
parent dd1e99d56b
commit 5fb1c1af89
5 changed files with 10 additions and 12 deletions

View File

@ -196,11 +196,12 @@ static void AsyncDownloader_ProcessRequest(struct AsyncRequest* request) {
struct Stopwatch stopwatch; struct Stopwatch stopwatch;
Stopwatch_Start(&stopwatch); Stopwatch_Start(&stopwatch);
ReturnCode res = Http_Do(request, &async_curProgress); request->Result = Http_Do(request, &async_curProgress);
UInt32 elapsed = Stopwatch_ElapsedMicroseconds(&stopwatch) / 1000; UInt32 elapsed = Stopwatch_ElapsedMicroseconds(&stopwatch) / 1000;
Int32 status = request->StatusCode; Int32 status = request->StatusCode;
Platform_Log3("HTTP: return code %i (http %i), in %i ms", &res, &status, &elapsed); Platform_Log3("HTTP: return code %i (http %i), in %i ms",
&request->Result, &status, &elapsed);
if (request->ResultData) { if (request->ResultData) {
UInt32 size = request->ResultSize; UInt32 size = request->ResultSize;

View File

@ -22,6 +22,7 @@ struct AsyncRequest {
UInt64 TimeAdded, TimeDownloaded; UInt64 TimeAdded, TimeDownloaded;
Int32 StatusCode; Int32 StatusCode;
ReturnCode Result;
void* ResultData; void* ResultData;
UInt32 ResultSize; UInt32 ResultSize;

View File

@ -926,7 +926,7 @@ static ReturnCode Http_GetHeaders(struct AsyncRequest* req, HINTERNET handle) {
if (!HttpQueryInfoA(handle, FLAG_STATUS, &req->StatusCode, &len, NULL)) return GetLastError(); if (!HttpQueryInfoA(handle, FLAG_STATUS, &req->StatusCode, &len, NULL)) return GetLastError();
len = sizeof(DWORD); len = sizeof(DWORD);
if (!HttpQueryInfoA(handle, FLAG_LENGTH, &req->ResultSize, &len, NULL)) return GetLastError(); HttpQueryInfoA(handle, FLAG_LENGTH, &req->ResultSize, &len, NULL);
SYSTEMTIME sysTime; SYSTEMTIME sysTime;
len = sizeof(SYSTEMTIME); len = sizeof(SYSTEMTIME);
@ -945,7 +945,7 @@ static ReturnCode Http_GetHeaders(struct AsyncRequest* req, HINTERNET handle) {
static ReturnCode Http_GetData(struct AsyncRequest* req, HINTERNET handle, volatile Int32* progress) { static ReturnCode Http_GetData(struct AsyncRequest* req, HINTERNET handle, volatile Int32* progress) {
UInt32 size = req->ResultSize; UInt32 size = req->ResultSize;
if (size) return ERROR_NOT_SUPPORTED; if (!size) return ERROR_NOT_SUPPORTED;
*progress = 0; *progress = 0;
UInt8* buffer = Mem_Alloc(size, sizeof(UInt8), "http get data"); UInt8* buffer = Mem_Alloc(size, sizeof(UInt8), "http get data");

View File

@ -2,15 +2,9 @@
#include "ErrorHandler.h" #include "ErrorHandler.h"
#include "Platform.h" #include "Platform.h"
#include "Window.h" #include "Window.h"
#include "GraphicsAPI.h"
#include "Deflate.h"
#include "Formats.h"
#include "TexturePack.h"
#include "Bitmap.h"
#include "Constants.h" #include "Constants.h"
#include "Game.h" #include "Game.h"
#include "Funcs.h" #include "Funcs.h"
#include "AsyncDownloader.h"
#include "ExtMath.h" #include "ExtMath.h"
#include "Utils.h" #include "Utils.h"
@ -70,7 +64,7 @@ int main(void) {
String title = String_FromConst(PROGRAM_APP_NAME); String title = String_FromConst(PROGRAM_APP_NAME);
String rawArgs = Platform_GetCommandLineArgs(); String rawArgs = Platform_GetCommandLineArgs();
/* NOTE: Make sure to comment this out before pushing a commit */ /* NOTE: Make sure to comment this out before pushing a commit */
//rawArgs = String_FromReadonly("UnknownShadow200 fff 127.0.1 25565"); rawArgs = String_FromReadonly("UnknownShadow200 fff 127.0.0.1 25566");
String args[5]; Int32 argsCount = Array_Elems(args); String args[5]; Int32 argsCount = Array_Elems(args);
String_UNSAFE_Split(&rawArgs, ' ', args, &argsCount); String_UNSAFE_Split(&rawArgs, ' ', args, &argsCount);

View File

@ -72,6 +72,8 @@ void ServerConnection_CheckAsyncResources(void) {
if (item.ResultData) { if (item.ResultData) {
TexturePack_Extract_Req(&item); TexturePack_Extract_Req(&item);
} else if (item.Result) {
Chat_Add1("&cError %i when trying to download texture pack", &item.Result);
} else { } else {
Int32 status = item.StatusCode; Int32 status = item.StatusCode;
if (status == 0 || status == 304) return; if (status == 0 || status == 304) return;