From 45b83feb9927081cc8019b5f45ab93cdad863cd4 Mon Sep 17 00:00:00 2001 From: KimLS Date: Sun, 12 Oct 2014 14:41:53 -0700 Subject: [PATCH] Fix for file loading --- world/remote_call.cpp | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/world/remote_call.cpp b/world/remote_call.cpp index 200720aa5..c403d1c1c 100644 --- a/world/remote_call.cpp +++ b/world/remote_call.cpp @@ -166,7 +166,7 @@ void handle_rc_quest_interface(const std::string &method, const std::string &con std::string error; std::map res; - FILE *f = fopen("quests/global/Waypoint.pl", "r"); + FILE *f = fopen("quests/global/Waypoint.pl", "rb"); if(!f) { error = "File not found"; RemoteCallResponse(connection_id, request_id, res, error); @@ -177,32 +177,19 @@ void handle_rc_quest_interface(const std::string &method, const std::string &con size_t sz = ftell(f); rewind(f); - //todo: actually break the message apart or something so we don't destroy web_interface's poor buffer - //dunno where to do this yet, got some musing to do - //if(sz >= 1024) { - // error = "File too large... for now..."; - // RemoteCallResponse(connection_id, request_id, res, error); - // return; - //} - char *buffer = new char[sz + 1]; size_t r = fread(buffer, 1, sz, f); if(r != sz) { error = "Unable to read file"; RemoteCallResponse(connection_id, request_id, res, error); + fclose(f); delete[] buffer; return; } + fclose(f); buffer[sz] = '\0'; - //std::string str; - //std::ifstream file("quests/global/Waypoint.pl", std::ios::in); - //if (file) { - // while (!file.eof()) - // str.push_back(file.get()); - //} - res["quest_text"] = buffer; RemoteCallResponse(connection_id, request_id, res, error); } \ No newline at end of file