Npc Warp implementation (#29)

* Update CNShardServer.hpp

* Update ChatManager.cpp

* Update ChatManager.hpp

* Update NPCManager.cpp

* Update NPCManager.hpp

* Add files via upload

* Update NPCManager.cpp

* Update NPCManager.cpp

* Update ChatManager.cpp

* Update ChatManager.cpp

* Update NPCManager.cpp

* Update NPCManager.cpp

Co-authored-by: CPunch <sethtstubbs@gmail.com>
This commit is contained in:
Zenpock 2020-08-23 10:32:25 -05:00 committed by GitHub
parent d6b96389be
commit 1d792a21dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 4 deletions

View File

@ -27,7 +27,6 @@ void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) {
otherSock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC));
}
}
void ChatManager::menuChatHandler(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_SEND_MENUCHAT_MESSAGE))
return; // malformed packet
@ -37,7 +36,7 @@ void ChatManager::menuChatHandler(CNSocket* sock, CNPacketData* data) {
// send to client
INITSTRUCT(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, resp);
memcpy(resp.szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat));
resp.iPC_ID = plr.plr.iID;
resp.iPC_ID = PlayerManager::players[sock].plr.iID;
resp.iEmoteCode = chat->iEmoteCode;
sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC));

View File

@ -30,6 +30,7 @@ void NPCManager::init() {
catch (const std::exception& err) {
std::cerr << "[WARN] Malformed NPC.json file! Reason:" << std::endl << err.what() << std::endl;
}
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_WARP_USE_NPC, npcWarpManager);
}
#undef CHECKNPC
@ -82,3 +83,25 @@ void NPCManager::updatePlayerNPCS(CNSocket* sock, PlayerView& view) {
PlayerManager::players[sock].viewableNPCs = view.viewableNPCs;
}
void NPCManager::npcWarpManager(CNSocket* sock, CNPacketData* data)
{
std::ifstream warp_file("warps.json", std::ifstream::binary);
nlohmann::json warp;
warp_file >> warp;
if (data->size != sizeof(sP_CL2FE_REQ_PC_WARP_USE_NPC))
return; // malformed packet
sP_CL2FE_REQ_PC_WARP_USE_NPC* warpNpc = (sP_CL2FE_REQ_PC_WARP_USE_NPC*)data->buf;
//Send to Client
INITSTRUCT(sP_FE2CL_REP_PC_WARP_USE_NPC_SUCC, resp);
resp.iX = warp[std::to_string(warpNpc->iWarpID)]["m_iToX"];
resp.iY = warp[std::to_string(warpNpc->iWarpID)]["m_iToY"];
resp.iZ = warp[std::to_string(warpNpc->iWarpID)]["m_iToZ"];
//Add Instance Stuff Later
std::cerr << "OpenFusion: Warp using " << "Warp ID" <<warpNpc->iWarpID << "Warp to Z:"<< warp[std::to_string(warpNpc->iWarpID)]["m_iToZ"] << std::endl;
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_WARP_USE_NPC_SUCC, sizeof(sP_FE2CL_REP_PC_WARP_USE_NPC_SUCC));
}

View File

@ -12,6 +12,8 @@ namespace NPCManager {
void init();
void updatePlayerNPCS(CNSocket* sock, PlayerView& plr);
void npcWarpManager(CNSocket* sock, CNPacketData* data);
}
#endif

1
warps.JSON Normal file

File diff suppressed because one or more lines are too long