Fix for file loading

This commit is contained in:
KimLS 2014-10-12 14:41:53 -07:00
parent f4621bd5c0
commit 45b83feb99

View File

@ -166,7 +166,7 @@ void handle_rc_quest_interface(const std::string &method, const std::string &con
std::string error;
std::map<std::string, std::string> 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);
}