mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-22 03:58:27 +00:00
Added rapidjson library
Added web_interface_utils.cpp/.h to common to provide string based functions for outputting JSON Adjusted CMake to include rapidjson library and new web_interface_utils.h/cpp to common Currently, I have code set up hackishly for testing so do not think it is final. It is merely for demonstrating what I've done and played with.
This commit is contained in:
@@ -6,10 +6,13 @@
|
||||
#include "../common/platform.h"
|
||||
#include "../common/crash.h"
|
||||
#include "../common/EQEmuConfig.h"
|
||||
#include "../common/web_interface_utils.h"
|
||||
#include "worldserver.h"
|
||||
#include "lib/libwebsockets.h"
|
||||
#include <signal.h>
|
||||
#include <list>
|
||||
#include "rapidjson/writer.h"
|
||||
#include "rapidjson/stringbuffer.h"
|
||||
|
||||
volatile bool run = true;
|
||||
TimeoutManager timeout_manager;
|
||||
@@ -17,6 +20,13 @@ const EQEmuConfig *config = nullptr;
|
||||
WorldServer *worldserver = nullptr;
|
||||
libwebsocket_context *context = nullptr;
|
||||
|
||||
struct per_session_data_eqemu {
|
||||
bool auth;
|
||||
std::list<std::string> *send_queue;
|
||||
};
|
||||
|
||||
per_session_data_eqemu *globalsession = NULL;
|
||||
|
||||
void CatchSignal(int sig_num) {
|
||||
run = false;
|
||||
if(worldserver)
|
||||
@@ -40,11 +50,6 @@ int callback_http(libwebsocket_context *context, libwebsocket *wsi, libwebsocket
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct per_session_data_eqemu {
|
||||
bool auth;
|
||||
std::list<std::string> *send_queue;
|
||||
};
|
||||
|
||||
int callback_eqemu(libwebsocket_context *context, libwebsocket *wsi, libwebsocket_callback_reasons reason, void *user, void *in, size_t len) {
|
||||
per_session_data_eqemu *session = (per_session_data_eqemu*)user;
|
||||
switch (reason) {
|
||||
@@ -61,9 +66,20 @@ int callback_eqemu(libwebsocket_context *context, libwebsocket *wsi, libwebsocke
|
||||
std::string command;
|
||||
command.assign((const char*)in, len);
|
||||
|
||||
globalsession = session;
|
||||
if(command.compare("get_version") == 0) {
|
||||
session->send_queue->push_back("0.8.0");
|
||||
}
|
||||
if (command.compare("test_json") == 0) {
|
||||
session->send_queue->push_back(MakeJSON("niggers:tits"));
|
||||
}
|
||||
if (command.compare("stream_test") == 0) {
|
||||
ServerPacket* pack = new ServerPacket(ServerOP_WIServGeneric, len + 1);
|
||||
pack->WriteString(command.c_str());
|
||||
worldserver->SendPacket(pack);
|
||||
safe_delete(pack);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_SERVER_WRITEABLE:
|
||||
|
||||
@@ -29,7 +29,12 @@
|
||||
#include "../common/md5.h"
|
||||
#include "../common/packet_dump.h"
|
||||
#include "worldserver.h"
|
||||
struct per_session_data_eqemu {
|
||||
bool auth;
|
||||
std::list<std::string> *send_queue;
|
||||
};
|
||||
|
||||
extern per_session_data_eqemu *globalsession;
|
||||
WorldServer::WorldServer(std::string shared_key)
|
||||
: WorldConnection(EmuTCPConnection::packetModeWebInterface, shared_key.c_str()){
|
||||
pTryReconnect = true;
|
||||
@@ -54,6 +59,12 @@ void WorldServer::Process(){
|
||||
switch(pack->opcode) {
|
||||
case 0: { break; }
|
||||
case ServerOP_KeepAlive: { break; }
|
||||
case ServerOP_WIWorldResponse: {
|
||||
char pos_update[255];
|
||||
pack->ReadString(pos_update);
|
||||
globalsession->send_queue->push_back(pos_update);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user