From f3b6f9619bc834e4d52242b727d1d306cae43ce6 Mon Sep 17 00:00:00 2001 From: CPunch Date: Mon, 12 Oct 2020 02:08:10 -0500 Subject: [PATCH] added /help --- src/ChatManager.cpp | 17 ++++++++++++++--- src/ChatManager.hpp | 4 +++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/ChatManager.cpp b/src/ChatManager.cpp index 7642cd7..b81261a 100644 --- a/src/ChatManager.cpp +++ b/src/ChatManager.cpp @@ -42,6 +42,17 @@ bool runCmd(std::string full, CNSocket* sock) { return false; } +void helpCommand(std::string full, std::vector& args, CNSocket* sock) { + ChatManager::sendServerMessage(sock, "Commands available to you"); + Player *plr = PlayerManager::getPlayer(sock); + int i = 1; + + for (auto& cmd : ChatManager::commands) { + if (cmd.second.requiredAccLevel >= plr->accountId) + ChatManager::sendServerMessage(sock, "/" + cmd.first + (cmd.second.help.length() > 0 ? " - " + cmd.second.help : "")); + } +} + void testCommand(std::string full, std::vector& args, CNSocket* sock) { ChatManager::sendServerMessage(sock, "Test command is working! Here are your passed args:"); @@ -310,9 +321,9 @@ void ChatManager::init() { REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT, emoteHandler); REGISTER_SHARD_PACKET(P_CL2FE_REQ_SEND_MENUCHAT_MESSAGE, menuChatHandler); + registerCommand("help", 100, helpCommand, "lists all unlocked commands"); registerCommand("test", 1, testCommand); registerCommand("access", 100, accessCommand); - // TODO: add help command registerCommand("mss", 30, mssCommand); registerCommand("npcr", 30, npcRotateCommand); registerCommand("summonW", 30, summonWCommand); @@ -324,8 +335,8 @@ void ChatManager::init() { registerCommand("refresh", 100, refreshCommand); } -void ChatManager::registerCommand(std::string cmd, int requiredLevel, CommandHandler handlr) { - commands[cmd] = ChatCommand(requiredLevel, handlr); +void ChatManager::registerCommand(std::string cmd, int requiredLevel, CommandHandler handlr, std::string help) { + commands[cmd] = ChatCommand(requiredLevel, handlr, help); } void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) { diff --git a/src/ChatManager.hpp b/src/ChatManager.hpp index 9b5a821..10a169c 100644 --- a/src/ChatManager.hpp +++ b/src/ChatManager.hpp @@ -8,9 +8,11 @@ typedef void (*CommandHandler)(std::string fullString, std::vector& struct ChatCommand { int requiredAccLevel; + std::string help; CommandHandler handlr; ChatCommand(int r, CommandHandler h): requiredAccLevel(r), handlr(h) {} + ChatCommand(int r, CommandHandler h, std::string str): requiredAccLevel(r), help(str), handlr(h) {} ChatCommand(): ChatCommand(0, nullptr) {} }; @@ -18,7 +20,7 @@ namespace ChatManager { extern std::map commands; void init(); - void registerCommand(std::string cmd, int requiredLevel, CommandHandler handlr); + void registerCommand(std::string cmd, int requiredLevel, CommandHandler handlr, std::string help = ""); void chatHandler(CNSocket* sock, CNPacketData* data); void emoteHandler(CNSocket* sock, CNPacketData* data);