VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
PluginChat.cpp
Go to the documentation of this file.
4#include <VoltMod/Runtime.hpp>
5#include <string_view>
6
7namespace VoltMod::Internal
8{
9
10bool PluginModule::OnConsoleCommand(std::string_view name, std::string_view arguments, int slot)
11{
12 // A ballot for a plugin vote never reaches the engine's own vote controller.
13 if (name == "vote")
14 {
15 return _runtime->Vote.TryCastBallot(slot, arguments);
16 }
17 if (name == "callvote")
18 {
19 return _runtime->Vote.InProgress();
20 }
21
22 const bool teamChat = name == "say_team";
23 if (name != "say" && !teamChat)
24 {
25 return false;
26 }
27
28 std::string_view message = arguments;
29 if (message.size() >= 2 && message.front() == '"' && message.back() == '"')
30 {
31 message.remove_prefix(1);
32 message.remove_suffix(1);
33 }
34 if (message.empty() || !IsValidSlot(slot))
35 {
36 return false;
37 }
38
39 // A later plugin's command must reach it past this plugin's chat handling, such as admin-chat tagging.
40 if (_runtime->Commands.IsForeign(message))
41 {
42 return false;
43 }
44
45 Player* player = _runtime->Players.Get(slot);
46 if (!player)
47 {
48 return false;
49 }
50
51 // Menu input takes precedence over command parsing.
52 if (_runtime->ChatInput.TryConsume(slot, message) || _runtime->Commands.HandleChatMessage(player, message))
53 {
54 return true;
55 }
56
57 ChatMessage chat{.Sender = *player, .Text = message, .TeamOnly = teamChat};
58 _runtime->Players.Said.Raise(chat);
59 return chat.Blocked;
60}
61
62} // namespace VoltMod::Internal
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
constexpr bool IsValidSlot(int slot)
Definition Slot.hpp:13