diff options
author | Matthew Kosarek <matthew.kosarek@vention.cc> | 2021-02-21 18:32:04 -0500 |
---|---|---|
committer | Matthew Kosarek <matthew.kosarek@vention.cc> | 2021-02-21 18:32:04 -0500 |
commit | ece2b67aa689aee0b881bac17a62c16e0469bc56 (patch) | |
tree | d99ac1bc32eea8687c06b28b90f15e08ba05d390 /backend | |
parent | aee81cdf445c02032745f10a1904439e7eecaef7 (diff) |
Proper support for favicons, rigid body intersections are no longer broken, palinko game
Diffstat (limited to 'backend')
-rw-r--r-- | backend/Header.h | 23 | ||||
-rw-r--r-- | backend/Server/Server/Server.vcxproj | 1 | ||||
-rw-r--r-- | backend/Server/Server/Server.vcxproj.filters | 3 | ||||
-rw-r--r-- | backend/server.cpp | 39 |
4 files changed, 22 insertions, 44 deletions
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 <Windows.h> - -#else -// TODO: Support Linux threads -#include <pthread.h> -#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 @@ <ClCompile Include="..\..\server.cpp" /> </ItemGroup> <ItemGroup> - <ClInclude Include="..\..\Header.h" /> <ClInclude Include="..\..\stringmanip.h" /> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> 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 @@ <ClInclude Include="..\..\stringmanip.h"> <Filter>Header Files</Filter> </ClInclude> - <ClInclude Include="..\..\Header.h"> - <Filter>Header Files</Filter> - </ClInclude> </ItemGroup> </Project>
\ 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"; |