Position updates with do_pos_update test call

This commit is contained in:
Chris M 2014-07-22 23:14:44 -05:00
parent 69e90aac0a
commit da6d7538b0
10 changed files with 69 additions and 26 deletions

View File

@ -188,6 +188,7 @@
#define ServerOP_WIServGeneric 0x5001
#define ServerOP_WIWorldResponse 0x5002
#define ServerOP_WIClientRequest 0x5003
enum { QSG_LFGuild = 0 };
enum { QSG_LFGuild_PlayerMatches = 0, QSG_LFGuild_UpdatePlayerInfo, QSG_LFGuild_RequestPlayerInfo, QSG_LFGuild_UpdateGuildInfo, QSG_LFGuild_GuildMatches,
@ -1232,6 +1233,17 @@ struct ReloadWorld_Struct{
uint32 Option;
};
struct WI_Client_Request_Struct{
char Client_UUID[64];
char JSON_Data[0];
};
struct WI_Client_Response_Struct{
char Client_UUID[64];
char JSON_Data[0];
};
#pragma pack()
#endif

View File

@ -29,18 +29,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using namespace rapidjson;
using namespace std;
std::string FloatToString(float number){
std::ostringstream buff;
buff << number;
return buff.str();
}
std::string IntegerToString(uint32_t number){
std::ostringstream buff;
buff << number;
return buff.str();
}
std::vector<std::string> explode(std::string const & s, char delim)
{
std::vector<std::string> result;

View File

@ -26,11 +26,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include <vector>
#include <utility>
std::string FloatToString(float number);
std::string IntegerToString(uint32_t number);
std::vector<std::string> explode(std::string const & s, char delim);
std::string MakeJSON(std::string json);
#endif

View File

@ -7,6 +7,7 @@
#include "../common/crash.h"
#include "../common/EQEmuConfig.h"
#include "../common/web_interface_utils.h"
#include "../common/StringUtil.h"
#include "../common/uuid.h"
#include "worldserver.h"
#include "lib/libwebsockets.h"
@ -62,7 +63,7 @@ int callback_eqemu(libwebsocket_context *context, libwebsocket *wsi, libwebsocke
session->uuid = CreateUUID();
session->send_queue = new std::list<std::string>();
sessions[session->uuid] = session;
printf("Create session %s\n", session->uuid.c_str());
printf("Created session %s\n", session->uuid.c_str());
break;
case LWS_CALLBACK_RECEIVE: {
@ -76,6 +77,17 @@ int callback_eqemu(libwebsocket_context *context, libwebsocket *wsi, libwebsocke
if(command.compare("get_version") == 0) {
session->send_queue->push_back("0.8.0");
}
if (command.compare("do_pos_update") == 0){
printf("Sending ServerOP_WIClientRequest with session %s Command Str %s \n", session->uuid.c_str(), command.c_str());
/* Test Packet */
ServerPacket* pack = new ServerPacket(ServerOP_WIClientRequest, sizeof(WI_Client_Request_Struct) + command.length() + 1);
WI_Client_Request_Struct* WICR = (WI_Client_Request_Struct*)pack->pBuffer;
strn0cpy(WICR->Client_UUID, session->uuid.c_str(), 64);
strn0cpy(WICR->JSON_Data, command.c_str(), command.length() + 1);
worldserver->SendPacket(pack);
safe_delete(pack);
}
break;
}
case LWS_CALLBACK_SERVER_WRITEABLE: {

View File

@ -23,17 +23,24 @@
#include <time.h>
#include <stdlib.h>
#include <stdarg.h>
#include <list>
#include <map>
#include "../common/servertalk.h"
#include "../common/packet_functions.h"
#include "../common/md5.h"
#include "../common/packet_dump.h"
#include "../common/web_interface_utils.h"
#include "worldserver.h"
struct per_session_data_eqemu {
bool auth;
std::string uuid;
std::list<std::string> *send_queue;
};
extern std::map<std::string, per_session_data_eqemu*> sessions;
WorldServer::WorldServer(std::string shared_key)
: WorldConnection(EmuTCPConnection::packetModeWebInterface, shared_key.c_str()){
pTryReconnect = true;
@ -59,6 +66,17 @@ void WorldServer::Process(){
case 0: { break; }
case ServerOP_KeepAlive: { break; }
case ServerOP_WIWorldResponse: {
/* Generic Response routine: web_interface server recieves packet from World -
Relays data back to client
*/
_log(WEB_INTERFACE__ERROR, "WI Recieved packet from world 0x%04x, size %d", pack->opcode, pack->size);
WI_Client_Request_Struct* WICR = (WI_Client_Request_Struct*)pack->pBuffer;
std::string Data;
Data.assign(WICR->JSON_Data, pack->size - 64);
/* Check if Session is Valid before sending data back*/
if (sessions[WICR->Client_UUID]){
sessions[WICR->Client_UUID]->send_queue->push_back(Data.c_str());
}
break;
}
}

View File

@ -104,6 +104,15 @@ bool WebInterfaceConnection::Process()
zoneserver_list.SendPacket(pack); // Send to all zones to test
break;
}
case ServerOP_WIClientRequest:
{
std::string Data;
WI_Client_Request_Struct* WICR = (WI_Client_Request_Struct*)pack->pBuffer;
Data.assign(WICR->JSON_Data, pack->size - 64);
_log(WEB_INTERFACE__ERROR, "Recieved ServerOPcode from WebInterface 0x%04x \nSize %d\nData '%s' from client:\n%s\n", pack->opcode, pack->size, Data.c_str(), WICR->Client_UUID);
zoneserver_list.SendPacket(pack); // Send to all zones to test
break;
}
default:
{
_log(WEB_INTERFACE__ERROR, "Unknown ServerOPcode from WebInterface 0x%04x, size %d", pack->opcode, pack->size);

View File

@ -1320,6 +1320,7 @@ bool ZoneServer::Process() {
}
case ServerOP_WIWorldResponse:
{
_log(WEB_INTERFACE__ERROR, "ServerOP_WIWorldResponse for WebInterface 0x%04x, size %d", pack->opcode, pack->size);
WILink.SendPacket(pack);
break;
}

View File

@ -32,6 +32,7 @@ extern EntityList entity_list;
extern Zone* zone;
extern WorldServer worldserver;
extern std::string WS_Client_Connected;
Mob::Mob(const char* in_name,
const char* in_lastname,
@ -1218,14 +1219,16 @@ void Mob::MakeSpawnUpdateNoDelta(PlayerPositionUpdateServer_Struct *spu){
spu->padding0018 =0x5df27;
/* Testing */
if (IsNPC()){
std::string str = MakeJSON("ResponseType:PositionUpdate,entity:" + IntegerToString(GetID()) + ",x:" + FloatToString(x_pos) + ",y:" + FloatToString(y_pos) + ",z:" + FloatToString(z_pos) + ",h:" + FloatToString(heading));
if (IsNPC() && WS_Client_Connected.size() != 0){
std::string str = MakeJSON("ResponseType:PositionUpdate,entity:" + std::to_string(GetID()) + ",name:" + GetName() + ",x:" + std::to_string(x_pos) + ",y:" + std::to_string(y_pos) + ",z:" + std::to_string(z_pos) + ",h:" + std::to_string(heading));
char * writable = new char[str.size() + 1];
std::copy(str.begin(), str.end(), writable);
ServerPacket* wipack = new ServerPacket(ServerOP_WIWorldResponse, str.size() + 1);
wipack->WriteString(writable);
if (worldserver.Connected()) { worldserver.SendPacket(wipack); }
safe_delete(wipack);
ServerPacket* pack = new ServerPacket(ServerOP_WIWorldResponse, sizeof(WI_Client_Response_Struct)+str.length() + 1);
WI_Client_Response_Struct* WICR = (WI_Client_Response_Struct*)pack->pBuffer;
strn0cpy(WICR->Client_UUID, WS_Client_Connected.c_str(), 64);
strn0cpy(WICR->JSON_Data, str.c_str(), str.length() + 1);
if (worldserver.Connected()) { worldserver.SendPacket(pack); }
safe_delete(pack);
delete[] writable;
}
}

View File

@ -100,6 +100,7 @@ DBAsyncFinishedQueue MTdbafq;
DBAsync *dbasync = nullptr;
TaskManager *taskmanager = 0;
QuestParserCollection *parse = 0;
std::string WS_Client_Connected;
const SPDat_Spell_Struct* spells;
void LoadSpells(EQEmu::MemoryMappedFile **mmf);

View File

@ -62,6 +62,7 @@ extern NetConnection net;
extern PetitionList petition_list;
extern uint32 numclients;
extern volatile bool RunLoops;
extern std::string WS_Client_Connected;
WorldServer::WorldServer()
: WorldConnection(EmuTCPConnection::packetModeZone)
@ -1777,11 +1778,13 @@ void WorldServer::Process() {
break;
}
case ServerOP_WIServGeneric:
case ServerOP_WIClientRequest:
{
/* Do Nothing for now */
WI_Client_Request_Struct* WICR = (WI_Client_Request_Struct*)pack->pBuffer;
WS_Client_Connected = WICR->Client_UUID;
_log(WEB_INTERFACE__ERROR, "Recieved packet from World, setting Client Connected to %s", WICR->Client_UUID);
break;
}
}
case ServerOP_CZSignalClient:
{
CZClientSignal_Struct* CZCS = (CZClientSignal_Struct*) pack->pBuffer;