mirror of
https://github.com/EQEmu/Server.git
synced 2026-02-26 06:12:26 +00:00
Fix for quest stuff loading junk from a file. Also will properly memset the entire buffer
This commit is contained in:
parent
509babc2d1
commit
06f7f6b483
@ -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()) {
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#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<std::string, std::string> 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);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user