summaryrefslogtreecommitdiff
path: root/backend/server.cpp
diff options
context:
space:
mode:
authorMatthew Kosarek <matthew.kosarek@vention.cc>2021-02-21 18:32:04 -0500
committerMatthew Kosarek <matthew.kosarek@vention.cc>2021-02-21 18:32:04 -0500
commitece2b67aa689aee0b881bac17a62c16e0469bc56 (patch)
treed99ac1bc32eea8687c06b28b90f15e08ba05d390 /backend/server.cpp
parentaee81cdf445c02032745f10a1904439e7eecaef7 (diff)
Proper support for favicons, rigid body intersections are no longer broken, palinko game
Diffstat (limited to 'backend/server.cpp')
-rw-r--r--backend/server.cpp39
1 files changed, 22 insertions, 17 deletions
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";