From 83c378c9c2918aecd6f92896084ab7c85b57d3b2 Mon Sep 17 00:00:00 2001 From: Jade Date: Sat, 31 Oct 2020 17:12:13 +0000 Subject: [PATCH] Added /notify and /players admin commands Co-authored-by: dongresource --- src/ChatManager.cpp | 20 ++++++++++++++++++++ src/Player.hpp | 2 ++ src/PlayerManager.cpp | 4 ++++ 3 files changed, 26 insertions(+) diff --git a/src/ChatManager.cpp b/src/ChatManager.cpp index 5731939..de6f540 100644 --- a/src/ChatManager.cpp +++ b/src/ChatManager.cpp @@ -436,6 +436,24 @@ void tasksCommand(std::string full, std::vector& args, CNSocket* so } } +void notifyCommand(std::string full, std::vector& args, CNSocket* sock) { + Player *plr = PlayerManager::getPlayer(sock); + + if (plr->notify) { + plr->notify = false; + ChatManager::sendServerMessage(sock, "[ADMIN] No longer receiving join notifications"); + } else { + plr->notify = true; + ChatManager::sendServerMessage(sock, "[ADMIN] Receiving join notifications"); + } +} + +void playersCommand(std::string full, std::vector& args, CNSocket* sock) { + ChatManager::sendServerMessage(sock, "[ADMIN] Players on the server:"); + for (auto pair : PlayerManager::players) + ChatManager::sendServerMessage(sock, PlayerManager::getPlayerName(pair.second.plr)); +} + void flushCommand(std::string full, std::vector& args, CNSocket* sock) { TableData::flush(); ChatManager::sendServerMessage(sock, "Wrote gruntwork to " + settings::GRUNTWORKJSON); @@ -461,6 +479,8 @@ void ChatManager::init() { registerCommand("refresh", 100, refreshCommand, "teleport yourself to your current location"); registerCommand("minfo", 30, minfoCommand, "show details of the current mission and task."); registerCommand("tasks", 30, tasksCommand, "list all active missions and their respective task ids."); + registerCommand("notify", 30, notifyCommand, "receive a message whenever a player joins the server"); + registerCommand("players", 30, playersCommand, "print all players on the server"); } void ChatManager::registerCommand(std::string cmd, int requiredLevel, CommandHandler handlr, std::string help) { diff --git a/src/Player.hpp b/src/Player.hpp index b60d73e..bd2d841 100644 --- a/src/Player.hpp +++ b/src/Player.hpp @@ -68,4 +68,6 @@ struct Player { int groupCnt; int32_t groupIDs[4]; int32_t iGroupConditionBitFlag; + + bool notify; }; diff --git a/src/PlayerManager.cpp b/src/PlayerManager.cpp index 46f6ccf..90c0d7a 100644 --- a/src/PlayerManager.cpp +++ b/src/PlayerManager.cpp @@ -402,6 +402,10 @@ void PlayerManager::enterPlayer(CNSocket* sock, CNPacketData* data) { ItemManager::setItemStats(getPlayer(sock)); MissionManager::failInstancedMissions(sock); + + for (auto& pair : PlayerManager::players) + if (pair.second.plr->notify) + ChatManager::sendServerMessage(pair.first, "[ADMIN]" + getPlayerName(&plr) + " has joined."); } void PlayerManager::sendToViewable(CNSocket* sock, void* buf, uint32_t type, size_t size) {