feat: refactor slash commands system into more scalable system (#1510)

* WIP, but working

* Scaffolding

* testing and making it compile again

* move all commands to functions

* renaming to compile

* fix failing tests

idk how these werent failing before.  Seems to have been magic.

* move commandss into their namespace
make help command useful
fix mac error

TODO: remove the multiple not founds/ rework the structure to split into help and handling

* Just need to fill out the fields, but it's all there templated

* Add all aliases, register missing commands

* All help text

* remove test logs

* improvements

pass through added code for optimizations and cleanup as well as reduce the amount of scoping for readability and maintainability

* Update SlashCommandHandler.cpp

* only save command if it is a GM command

* simplify if checks

* remove broken delimiter

* Update SlashCommandHandler.cpp

* Update SlashCommandHandler.cpp

---------

Co-authored-by: David Markowitz <EmosewaMC@gmail.com>
This commit is contained in:
Aaron Kimbrell 2024-04-08 15:11:59 -05:00 committed by GitHub
parent 18c27b14c8
commit feeac2e041
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 1793 additions and 674 deletions

View File

@ -790,9 +790,10 @@ enum class eGameMessageType : uint16_t {
GET_MISSION_TYPE_STATES = 853, GET_MISSION_TYPE_STATES = 853,
GET_TIME_PLAYED = 854, GET_TIME_PLAYED = 854,
SET_MISSION_VIEWED = 855, SET_MISSION_VIEWED = 855,
SLASH_COMMAND_TEXT_FEEDBACK = 856, HKX_VEHICLE_LOADED = 856,
HANDLE_SLASH_COMMAND_KORE_DEBUGGER = 857, SLASH_COMMAND_TEXT_FEEDBACK = 857,
BROADCAST_TEXT_TO_CHATBOX = 858, BROADCAST_TEXT_TO_CHATBOX = 858,
HANDLE_SLASH_COMMAND_KORE_DEBUGGER = 859,
OPEN_PROPERTY_MANAGEMENT = 860, OPEN_PROPERTY_MANAGEMENT = 860,
OPEN_PROPERTY_VENDOR = 861, OPEN_PROPERTY_VENDOR = 861,
VOTE_ON_PROPERTY = 862, VOTE_ON_PROPERTY = 862,

View File

@ -6197,3 +6197,15 @@ void GameMessages::HandleCancelDonationOnPlayer(RakNet::BitStream& inStream, Ent
if (!characterComponent) return; if (!characterComponent) return;
characterComponent->SetCurrentInteracting(LWOOBJID_EMPTY); characterComponent->SetCurrentInteracting(LWOOBJID_EMPTY);
} }
void GameMessages::SendSlashCommandFeedbackText(Entity* entity, std::u16string text) {
CBITSTREAM;
CMSGHEADER;
bitStream.Write(entity->GetObjectID());
bitStream.Write(eGameMessageType::SLASH_COMMAND_TEXT_FEEDBACK);
bitStream.Write<uint32_t>(text.size());
bitStream.Write(text);
auto sysAddr = entity->GetSystemAddress();
SEND_PACKET;
}

View File

@ -664,6 +664,8 @@ namespace GameMessages {
void HandleRemoveDonationItem(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr); void HandleRemoveDonationItem(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr);
void HandleConfirmDonationOnPlayer(RakNet::BitStream& inStream, Entity* entity); void HandleConfirmDonationOnPlayer(RakNet::BitStream& inStream, Entity* entity);
void HandleCancelDonationOnPlayer(RakNet::BitStream& inStream, Entity* entity); void HandleCancelDonationOnPlayer(RakNet::BitStream& inStream, Entity* entity);
void SendSlashCommandFeedbackText(Entity* entity, std::u16string text);
}; };
#endif // GAMEMESSAGES_H #endif // GAMEMESSAGES_H

File diff suppressed because it is too large Load Diff

View File

@ -7,13 +7,128 @@
#define SLASHCOMMANDHANDLER_H #define SLASHCOMMANDHANDLER_H
#include "RakNetTypes.h" #include "RakNetTypes.h"
#include "eGameMasterLevel.h"
#include <string> #include <string>
class Entity; class Entity;
namespace SlashCommandHandler { struct Command {
void HandleChatCommand(const std::u16string& command, Entity* entity, const SystemAddress& sysAddr); std::string help;
void SendAnnouncement(const std::string& title, const std::string& message); std::string info;
std::vector<std::string> aliases;
std::function<void(Entity*, const SystemAddress&,const std::string)> handle;
eGameMasterLevel requiredLevel = eGameMasterLevel::OPERATOR;
}; };
namespace SlashCommandHandler {
void Startup();
void HandleChatCommand(const std::u16string& command, Entity* entity, const SystemAddress& sysAddr);
void SendAnnouncement(const std::string& title, const std::string& message);
void RegisterCommand(Command info);
};
namespace DEVGMCommands {
void SetGMLevel(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ToggleNameplate(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ToggleSkipCinematics(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Kill(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Metrics(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Announce(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetAnnTitle(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetAnnMsg(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ShutdownUniverse(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetMinifig(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void TestMap(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ReportProxPhys(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SpawnPhysicsVerts(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Teleport(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ActivateSpawner(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void AddMission(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Boost(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Unboost(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Buff(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void BuffMe(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void BuffMed(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ClearFlag(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void CompleteMission(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void CreatePrivate(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void DebugUi(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Dismount(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ReloadConfig(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ForceSave(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Freecam(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void FreeMoney(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void GetNavmeshHeight(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void GiveUScore(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void GmAddItem(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Inspect(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ListSpawns(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void LocRow(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Lookup(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void PlayAnimation(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void PlayEffect(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void PlayLvlFx(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void PlayRebuildFx(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Pos(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void RefillStats(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Reforge(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ResetMission(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Rot(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void RunMacro(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetControlScheme(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetCurrency(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetFlag(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetInventorySize(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetUiState(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Spawn(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SpawnGroup(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SpeedBoost(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void StartCelebration(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void StopEffect(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Toggle(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void TpAll(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void TriggerSpawner(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void UnlockEmote(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetLevel(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetSkillSlot(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetFaction(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void AddFaction(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void GetFactions(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetRewardCode(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Crash(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void RollLoot(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void CastSkill(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void DeleteInven(Entity* entity, const SystemAddress& sysAddr, const std::string args);
}
namespace GMZeroCommands {
void Help(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Credits(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Info(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Die(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Ping(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Pvp(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void RequestMailCount(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Who(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void FixStats(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Join(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void LeaveZone(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Resurrect(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void InstanceInfo(Entity* entity, const SystemAddress& sysAddr, const std::string args);
}
namespace GMGreaterThanZeroCommands {
void Kick(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void MailItem(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Ban(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ApproveProperty(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Mute(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Fly(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void AttackImmune(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void GmImmune(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void GmInvis(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetName(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Title(Entity* entity, const SystemAddress& sysAddr, const std::string args);
}
#endif // SLASHCOMMANDHANDLER_H #endif // SLASHCOMMANDHANDLER_H

View File

@ -79,6 +79,7 @@
#include "PositionUpdate.h" #include "PositionUpdate.h"
#include "PlayerManager.h" #include "PlayerManager.h"
#include "eLoginResponse.h" #include "eLoginResponse.h"
#include "SlashCommandHandler.h"
namespace Game { namespace Game {
Logger* logger = nullptr; Logger* logger = nullptr;
@ -313,6 +314,9 @@ int main(int argc, char** argv) {
uint32_t sqlPingTime = 10 * 60 * currentFramerate; // 10 minutes in frames uint32_t sqlPingTime = 10 * 60 * currentFramerate; // 10 minutes in frames
uint32_t emptyShutdownTime = (cloneID == 0 ? 30 : 5) * 60 * currentFramerate; // 30 minutes for main worlds, 5 for all others. uint32_t emptyShutdownTime = (cloneID == 0 ? 30 : 5) * 60 * currentFramerate; // 30 minutes for main worlds, 5 for all others.
// Register slash commands
SlashCommandHandler::Startup();
Game::logger->Flush(); // once immediately before the main loop Game::logger->Flush(); // once immediately before the main loop
while (true) { while (true) {
Metrics::StartMeasurement(MetricVariable::Frame); Metrics::StartMeasurement(MetricVariable::Frame);

View File

@ -121,7 +121,7 @@ TEST(MagicEnumTest, eGameMessageTypeTest) {
namespace { namespace {
template <typename T> template <typename T>
void AssertEnumArraySorted(const T& eArray) { void AssertEnumArraySorted(const T& eArray) {
for (int i = 0; i < eArray->size(); ++i) { for (int i = 0; i < eArray->size() - 1; ++i) {
const auto entryCurr = eArray->at(i).first; const auto entryCurr = eArray->at(i).first;
LOG_EARRAY(eArray, i, entryCurr); LOG_EARRAY(eArray, i, entryCurr);
const auto entryNext = eArray->at(++i).first; const auto entryNext = eArray->at(++i).first;