Skip to content

Commit

Permalink
easier to use actions function
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeEndl committed Sep 7, 2024
1 parent 30a1528 commit 9a85afd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions include/action/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ void input(ENetEvent event, const std::string& header)
"`6>>`4Spam detected! ``Please wait a bit before typing anything else. Please note, any form of bot/macro/auto-paste will get all your accounts banned, so don't do it!");
else if (text.starts_with('/'))
{
packet(*event.peer, std::format("action|log\nmsg| `6{}``", text).c_str());
action(*event.peer, "log", std::format("msg| `6{}``", text).c_str());
if (cmd_pool.contains(text.substr(1, text.length())))
(static_cast<void>(std::async(std::launch::async, cmd_pool[text.substr(1, text.length())], std::ref(event), std::move(text.substr(1, text.length())))));
else packet(*event.peer, "action|log\nmsg|`4Unknown command.`` Enter `$/?`` for a list of valid commands.");
else action(*event.peer, "log", "msg|`4Unknown command.`` Enter `$/?`` for a list of valid commands.");
}
else if (text.back() == ' ' and text.length() > 1) text.pop_back(); // @note trim back spaces. "test "
else if (text.front() == ' ' and text.length() > 1) text = text.substr(1, text.length() - 1); // @note trim front spacing. " test"
Expand Down
2 changes: 1 addition & 1 deletion include/commands/commands
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ std::unordered_map<std::string, std::function<void(ENetEvent&, const std::string
{
{"help", [](ENetEvent& event, const std::string& text)
{
packet(*event.peer, "action|log\nmsg|>> Commands: /find /wave /dance /love /sleep /facepalm /fp /smh /yes /no /omg /idk /shrug /furious /rolleyes /foldarms /stubborn /fold /dab /sassy /dance2 /march /grumpy /shy");
action(*event.peer, "log", "msg|>> Commands: /find /wave /dance /love /sleep /facepalm /fp /smh /yes /no /omg /idk /shrug /furious /rolleyes /foldarms /stubborn /fold /dab /sassy /dance2 /march /grumpy /shy");
}},
{"wave", &Action}, {"dance", &Action}, {"love", &Action}, {"sleep", &Action}, {"facepalm", &Action}, {"fp", &Action}, {"smh", &Action}, {"yes", &Action},
{"no", &Action}, {"omg", &Action}, {"idk", &Action}, {"shrug", &Action}, {"furious", &Action}, {"rolleyes", &Action}, {"foldarms", &Action}, {"fa", &Action},
Expand Down
9 changes: 6 additions & 3 deletions include/network/packet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ void gt_packet(ENetPeer& p, bool netid, T... params) {
if (packet not_eq nullptr and packet->dataLength > 61) enet_peer_send(&p, 0, packet);
};

void packet(ENetPeer& p, const std::string& str)
void action(ENetPeer& p, const std::string& action, const std::string& str)
{
std::vector<std::byte> data(4 + str.length(), std::byte{0x0});
const std::string& _action = "action|" + action + "\n";
std::vector<std::byte> data(4 + _action.length() + str.length(), std::byte{0x0});
data[0] = static_cast<std::byte>(0x3);
for (std::size_t i = 0; i < _action.length(); ++i)
data[4 + i] = static_cast<std::byte>(_action[i]);
for (std::size_t i = 0; i < str.length(); ++i)
data[4 + i] = static_cast<std::byte>(str[i]);
data[4 + _action.length() + i] = static_cast<std::byte>(str[i]);
enet_peer_send(&p, 0, enet_packet_create(data.data(), data.size(), ENET_PACKET_FLAG_RELIABLE));
}

0 comments on commit 9a85afd

Please sign in to comment.