diff --git a/src/ChatManager.cpp b/src/ChatManager.cpp index 6e98c2d..60e26c1 100644 --- a/src/ChatManager.cpp +++ b/src/ChatManager.cpp @@ -2,6 +2,7 @@ #include "CNStructs.hpp" #include "ChatManager.hpp" #include "PlayerManager.hpp" +#include "TableData.hpp" #include #include @@ -50,6 +51,114 @@ void accessCommand(std::string full, std::vector& args, CNSocket* s ChatManager::sendServerMessage(sock, "Your access level is " + std::to_string(PlayerManager::getPlayer(sock)->accountLevel)); } +void mssCommand(std::string full, std::vector& args, CNSocket* sock) { + if (args.size() < 2) { + ChatManager::sendServerMessage(sock, "[MSS] Too few arguments"); + ChatManager::sendServerMessage(sock, "[MSS] Usage: /mss <>"); + return; + } + + // Validate route number + char* routeNumC; + int routeNum = std::strtol(args[1].c_str(), &routeNumC, 10); + if (*routeNumC) { + // not an integer + ChatManager::sendServerMessage(sock, "[MSS] Invalid route number '" + args[1] + "'"); + return; + } + + if (args.size() < 3) { + ChatManager::sendServerMessage(sock, "[MSS] Too few arguments"); + ChatManager::sendServerMessage(sock, "[MSS] Usage: /mss <>"); + return; + } + + // get the route (if it doesn't exist yet, this will also make it) + std::stack* route = &TableData::RunningSkywayRoutes[routeNum]; + + // mss add + if (args[2] == "add") { + // make sure height token exists + if (args.size() < 4) { + ChatManager::sendServerMessage(sock, "[MSS] Point height must be specified"); + ChatManager::sendServerMessage(sock, "[MSS] Usage: /mss add "); + return; + } + // validate height token + char* heightC; + int height = std::strtol(args[3].c_str(), &heightC, 10); + if (*heightC) { + ChatManager::sendServerMessage(sock, "[MSS] Invalid height " + args[3]); + return; + } + + Player* plr = PlayerManager::getPlayer(sock); + route->push({ plr->x, plr->y, height }); // add point to stack + ChatManager::sendServerMessage(sock, "[MSS] Added point (" + std::to_string(plr->x) + ", " + std::to_string(plr->y) + ", " + std::to_string(height) + ") to route " + std::to_string(routeNum)); + return; + } + + // mss remove + if (args[2] == "remove") { + if (route->empty()) { + ChatManager::sendServerMessage(sock, "[MSS] Route " + std::to_string(routeNum) + " is empty"); + return; + } + + WarpLocation pulled = route->top(); + route->pop(); // remove point at top of stack + ChatManager::sendServerMessage(sock, "[MSS] Removed point (" + std::to_string(pulled.x) + ", " + std::to_string(pulled.y) + ", " + std::to_string(pulled.z) + ") from route " + std::to_string(routeNum)); + return; + } + + // mss goto + if (args[2] == "goto") { + if (route->empty()) { + ChatManager::sendServerMessage(sock, "[MSS] Route " + std::to_string(routeNum) + " is empty"); + return; + } + + WarpLocation pulled = route->top(); + // simulate goto + INITSTRUCT(sP_FE2CL_REP_PC_GOTO_SUCC, pkt); + Player* plr = PlayerManager::getPlayer(sock); + PlayerManager::updatePlayerPosition(sock, pulled.x, pulled.y, pulled.z); + pkt.iX = pulled.x; + pkt.iY = pulled.y; + pkt.iZ = pulled.z; + sock->sendPacket((void*)&pkt, P_FE2CL_REP_PC_GOTO_SUCC, sizeof(sP_FE2CL_REP_PC_GOTO_SUCC)); + return; + } + + // mss clear + if (args[2] == "clear") { + // clear the stack + while (!route->empty()) { + route->pop(); + } + ChatManager::sendServerMessage(sock, "[MSS] Cleared route " + std::to_string(routeNum)); + return; + } + + // mss reload + if (args[2] == "reload") { + ChatManager::sendServerMessage(sock, "[MSS] reload on " + std::to_string(routeNum)); + // TODO: inject route and reload + return; + } + + // mss export + if (args[2] == "export") { + ChatManager::sendServerMessage(sock, "[MSS] export on " + std::to_string(routeNum)); + // TODO: dump route to tdata + return; + } + + // mss ???? + ChatManager::sendServerMessage(sock, "[MSS] Unknown command '" + args[2] + "'"); + +} + void ChatManager::init() { REGISTER_SHARD_PACKET(P_CL2FE_REQ_SEND_FREECHAT_MESSAGE, chatHandler); REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT, emoteHandler); @@ -58,6 +167,7 @@ void ChatManager::init() { registerCommand("test", 1, testCommand); registerCommand("access", 100, accessCommand); // TODO: add help command + registerCommand("mss", 100, mssCommand); } void ChatManager::registerCommand(std::string cmd, int requiredLevel, CommandHandler handlr) { diff --git a/src/TableData.cpp b/src/TableData.cpp index d84e71d..288b1bc 100644 --- a/src/TableData.cpp +++ b/src/TableData.cpp @@ -12,6 +12,8 @@ #include +std::map> TableData::RunningSkywayRoutes; + void TableData::init() { int32_t nextId = 0; diff --git a/src/TableData.hpp b/src/TableData.hpp index 697339c..482072e 100644 --- a/src/TableData.hpp +++ b/src/TableData.hpp @@ -1,9 +1,13 @@ #pragma once #include +#include #include "contrib/JSON.hpp" +#include "NPCManager.hpp" namespace TableData { + extern std::map> RunningSkywayRoutes; + void init(); void cleanup();