From 06f7f6b4838beacc6729dab3a935ea6300f6f52e Mon Sep 17 00:00:00 2001 From: KimLS Date: Sat, 11 Oct 2014 02:15:36 -0700 Subject: [PATCH] Fix for quest stuff loading junk from a file. Also will properly memset the entire buffer --- web_interface/web_interface.cpp | 3 +-- world/remote_call.cpp | 48 +++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/web_interface/web_interface.cpp b/web_interface/web_interface.cpp index 5805d2a42..c941e35a4 100644 --- a/web_interface/web_interface.cpp +++ b/web_interface/web_interface.cpp @@ -102,8 +102,7 @@ int callback_eqemu(libwebsocket_context *context, libwebsocket *wsi, libwebsocke for (auto iter = session->send_queue->begin(); iter != session->send_queue->end(); ++iter) { //out_message - size_t sz = LWS_SEND_BUFFER_PRE_PADDING + LWS_SEND_BUFFER_POST_PADDING + (*iter).size(); - memset(out_message, 0, sz); + memset(out_message, 0, MAX_MESSAGE_LENGTH + LWS_SEND_BUFFER_PRE_PADDING + LWS_SEND_BUFFER_POST_PADDING + 1); memcpy(&out_message[LWS_SEND_BUFFER_PRE_PADDING], &(*iter)[0], (*iter).size()); auto n = libwebsocket_write(wsi, (unsigned char*)&out_message[LWS_SEND_BUFFER_PRE_PADDING], (*iter).size(), LWS_WRITE_TEXT); if (n < (*iter).size()) { diff --git a/world/remote_call.cpp b/world/remote_call.cpp index 4f9ab9e30..200720aa5 100644 --- a/world/remote_call.cpp +++ b/world/remote_call.cpp @@ -1,5 +1,3 @@ -#include -#include #include #include "../common/debug.h" @@ -168,21 +166,43 @@ void handle_rc_quest_interface(const std::string &method, const std::string &con std::string error; std::map res; - /* - if (params.size() != 1) { - error = "Expected only one zone_id."; - RemoteCallResponse(connection_id, request_id, res, error); - return; + FILE *f = fopen("quests/global/Waypoint.pl", "r"); + if(!f) { + error = "File not found"; + RemoteCallResponse(connection_id, request_id, res, error); + return; } - */ - std::string str; - std::ifstream file("quests/global/Waypoint.pl", std::ios::in); - if (file) { - while (!file.eof()) str.push_back(file.get()); + fseek(f, 0, SEEK_END); + 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); + delete[] buffer; + return; } - // std::cout << str << '\n'; - res["quest_text"] = str.c_str(); + 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