-
-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathconsole.hpp
More file actions
90 lines (75 loc) · 2.51 KB
/
console.hpp
File metadata and controls
90 lines (75 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/.
*
* The original code is copyright (c) 2022, open.mp team and contributors.
*/
#pragma once
#include <core.hpp>
#include <types.hpp>
/// Used for custom handling of messages received by the console
struct ConsoleMessageHandler
{
virtual void handleConsoleMessage(StringView message) = 0;
};
/// The command sender types
enum class ConsoleCommandSender
{
Console,
Player,
Custom
};
/// Data attached to the command sender types
struct ConsoleCommandSenderData
{
ConsoleCommandSender sender;
union
{
IPlayer* player; ///< The player who sent the command, only available with ConsoleCommandSender::Player
ConsoleMessageHandler* handler; ///< The handler of the command sender, only available with ConsoleCommandSender::Custom
};
/// Console sender constructor
ConsoleCommandSenderData()
: sender(ConsoleCommandSender::Console)
, player(nullptr)
{
}
/// Player sender constructor
ConsoleCommandSenderData(IPlayer& player)
: sender(ConsoleCommandSender::Player)
, player(&player)
{
}
/// Custom sender constructor
ConsoleCommandSenderData(ConsoleMessageHandler& handler)
: sender(ConsoleCommandSender::Custom)
, handler(&handler)
{
}
};
struct ConsoleEventHandler
{
virtual bool onConsoleText(StringView command, StringView parameters, const ConsoleCommandSenderData& sender) { return false; }
virtual void onRconLoginAttempt(IPlayer& player, StringView password, bool success) { }
virtual void onConsoleCommandListRequest(FlatHashSet<StringView>& commands) { }
};
static const UID ConsoleComponent_UID = UID(0xbfa24e49d0c95ee4);
struct IConsoleComponent : public IComponent
{
PROVIDE_UID(ConsoleComponent_UID);
/// Get the ConsoleEventHandler event dispatcher
virtual IEventDispatcher<ConsoleEventHandler>& getEventDispatcher() = 0;
/// Send a console command
virtual void send(StringView command, const ConsoleCommandSenderData& sender = ConsoleCommandSenderData()) = 0;
virtual void sendMessage(const ConsoleCommandSenderData& recipient, StringView message) = 0;
};
static const UID PlayerConsoleData_UID = UID(0x9f8d20f2f471cbae);
struct IPlayerConsoleData : public IExtension
{
PROVIDE_EXT_UID(PlayerConsoleData_UID);
/// Check if player has console access
virtual bool hasConsoleAccess() const = 0;
/// Set player's console accessibility
virtual void setConsoleAccessibility(bool set) = 0;
};