From ece2b67aa689aee0b881bac17a62c16e0469bc56 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Sun, 21 Feb 2021 18:32:04 -0500 Subject: Proper support for favicons, rigid body intersections are no longer broken, palinko game --- backend/Header.h | 23 ---------------- backend/Server/Server/Server.vcxproj | 1 - backend/Server/Server/Server.vcxproj.filters | 3 --- backend/server.cpp | 39 ++++++++++++++++------------ 4 files changed, 22 insertions(+), 44 deletions(-) delete mode 100644 backend/Header.h (limited to 'backend') diff --git a/backend/Header.h b/backend/Header.h deleted file mode 100644 index 5282066..0000000 --- a/backend/Header.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#ifdef WIN32 - -#include - -#else -// TODO: Support Linux threads -#include -#endif - -struct ThreadInstance { - DWORD mThreadId; - HANDLE mThreadHandle; -}; - -bool initThreadInstance(ThreadInstance* instance) { - instance->mThreadHandle = CreateThread(NULL, 0,, NULL, 0, NULL); -} - -struct ThreadPool { - -}; \ No newline at end of file diff --git a/backend/Server/Server/Server.vcxproj b/backend/Server/Server/Server.vcxproj index 0e067f6..0e87860 100644 --- a/backend/Server/Server/Server.vcxproj +++ b/backend/Server/Server/Server.vcxproj @@ -142,7 +142,6 @@ - diff --git a/backend/Server/Server/Server.vcxproj.filters b/backend/Server/Server/Server.vcxproj.filters index b507bf5..5026929 100644 --- a/backend/Server/Server/Server.vcxproj.filters +++ b/backend/Server/Server/Server.vcxproj.filters @@ -23,8 +23,5 @@ Header Files - - Header Files - \ No newline at end of file diff --git a/backend/server.cpp b/backend/server.cpp index a58eed1..ac8f9fb 100644 --- a/backend/server.cpp +++ b/backend/server.cpp @@ -143,17 +143,6 @@ struct HeaderParseResult { HttpRequestError error = HttpRequestError_None; }; -int fixNewLines(char* str, int strSize) { - int removed = 0; - for(int i = 0; i < strSize; i++) { - if(str[i] == '\n') { - str[i] = '\r\n'; - removed++; - } - } - - return removed; -} struct HeaderParser { char buffer[4096]; @@ -275,15 +264,15 @@ void sendErrorMessage(SOCKET socket, HttpStatusCode status, const char* errorHtm #define MAXBUFLEN 1000000 -int readFileToMemory(char* filepath, char source[MAXBUFLEN + 1]) { +int readFileToMemory(char* filepath, char source[MAXBUFLEN + 1], bool isBinary) { FILE* file; - fopen_s(&file, filepath, "r+"); + fopen_s(&file, filepath, isBinary ? "rb" : "r+"); if(file == NULL) { printf("Failed to read the file\n"); return -1; - } + size_t newLen = fread(source, sizeof(char), MAXBUFLEN, file); if ( ferror( file ) != 0 ) { fputs("Error reading file", stderr); @@ -295,19 +284,35 @@ int readFileToMemory(char* filepath, char source[MAXBUFLEN + 1]) { } +int fixNewLines(char* str, int strSize) { + int removed = 0; + for(int i = 0; i < strSize; i++) { + if(str[i] == '\n') { + str[i] = '\r\n'; + removed++; + } + } + + return removed; +} + + bool trySendFile(SOCKET clientSocket, char* filename) { - FILE* file; char filePath[128]; sprintf(filePath, "../../frontend%s", filename); + bool isBinary = false; + if (endsWith(filename, ".ico")) { + isBinary = true; + } + char source[MAXBUFLEN + 1]; - int fileSizeBytes = readFileToMemory(filePath, source); + int fileSizeBytes = readFileToMemory(filePath, source, isBinary); if (fileSizeBytes <= 0) { return false; } - const char* contentType; if (endsWith(filename, ".html")) { contentType = "text/html"; -- cgit v1.2.1