From da6d7538b093f3aca5bd82b24f4ab9308061a962 Mon Sep 17 00:00:00 2001 From: Chris M Date: Tue, 22 Jul 2014 23:14:44 -0500 Subject: [PATCH] Position updates with do_pos_update test call --- common/servertalk.h | 12 ++++++++++++ common/web_interface_utils.cpp | 12 ------------ common/web_interface_utils.h | 4 ---- web_interface/web_interface.cpp | 14 +++++++++++++- web_interface/worldserver.cpp | 18 ++++++++++++++++++ world/web_interface.cpp | 9 +++++++++ world/zoneserver.cpp | 1 + zone/mob.cpp | 15 +++++++++------ zone/net.cpp | 1 + zone/worldserver.cpp | 9 ++++++--- 10 files changed, 69 insertions(+), 26 deletions(-) diff --git a/common/servertalk.h b/common/servertalk.h index acb3aa701..d75641168 100644 --- a/common/servertalk.h +++ b/common/servertalk.h @@ -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 diff --git a/common/web_interface_utils.cpp b/common/web_interface_utils.cpp index ce0193b1d..bd666f375 100644 --- a/common/web_interface_utils.cpp +++ b/common/web_interface_utils.cpp @@ -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 explode(std::string const & s, char delim) { std::vector result; diff --git a/common/web_interface_utils.h b/common/web_interface_utils.h index 6f2eccb72..bea3016c6 100644 --- a/common/web_interface_utils.h +++ b/common/web_interface_utils.h @@ -26,11 +26,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include #include -std::string FloatToString(float number); -std::string IntegerToString(uint32_t number); -std::vector explode(std::string const & s, char delim); std::string MakeJSON(std::string json); - #endif diff --git a/web_interface/web_interface.cpp b/web_interface/web_interface.cpp index 55e72a4a2..32b802a6f 100644 --- a/web_interface/web_interface.cpp +++ b/web_interface/web_interface.cpp @@ -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(); 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: { diff --git a/web_interface/worldserver.cpp b/web_interface/worldserver.cpp index 4fc02a76c..f3052981c 100644 --- a/web_interface/worldserver.cpp +++ b/web_interface/worldserver.cpp @@ -23,17 +23,24 @@ #include #include #include +#include +#include #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 *send_queue; }; +extern std::map 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; } } diff --git a/world/web_interface.cpp b/world/web_interface.cpp index 981153a39..2aec5995e 100644 --- a/world/web_interface.cpp +++ b/world/web_interface.cpp @@ -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); diff --git a/world/zoneserver.cpp b/world/zoneserver.cpp index 119565fdc..8e4d4266e 100644 --- a/world/zoneserver.cpp +++ b/world/zoneserver.cpp @@ -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; } diff --git a/zone/mob.cpp b/zone/mob.cpp index 2b61a7eb2..dc1c3d269 100644 --- a/zone/mob.cpp +++ b/zone/mob.cpp @@ -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; } } diff --git a/zone/net.cpp b/zone/net.cpp index 15e108e42..eb8d75ae1 100644 --- a/zone/net.cpp +++ b/zone/net.cpp @@ -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); diff --git a/zone/worldserver.cpp b/zone/worldserver.cpp index 249bb9b41..6daec9cd5 100644 --- a/zone/worldserver.cpp +++ b/zone/worldserver.cpp @@ -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;