forked from Expensify/Bedrock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBedrockPlugin.cpp
More file actions
85 lines (72 loc) · 2.65 KB
/
BedrockPlugin.cpp
File metadata and controls
85 lines (72 loc) · 2.65 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
#include <libstuff/libstuff.h>
#include "BedrockPlugin.h"
#include "BedrockServer.h"
list<BedrockPlugin*>* BedrockPlugin::g_registeredPluginList = nullptr;
BedrockPlugin::BedrockPlugin() {
// Auto-register this instance into the global static list, initializing the list if that hasn't yet been done.
// This just makes it available for enabling via the command line: by default all plugins start out disabled.
//
// NOTE: This code runs *before* main(). This means that libstuff hasn't yet been initialized, so there is no
// logging.
if (!g_registeredPluginList) {
g_registeredPluginList = new list<BedrockPlugin*>;
}
g_registeredPluginList->push_back(this);
}
void BedrockPlugin::verifyAttributeInt64(const SData& request, const string& name, size_t minSize) {
if (request[name].size() < minSize) {
STHROW("402 Missing " + name);
}
if (!request[name].empty() && request[name] != SToStr(SToInt64(request[name]))) {
STHROW("402 Malformed " + name);
}
}
void BedrockPlugin::verifyAttributeSize(const SData& request, const string& name, size_t minSize, size_t maxSize) {
if (request[name].size() < minSize) {
STHROW("402 Missing " + name);
}
if (request[name].size() > maxSize) {
STHROW("402 Malformed " + name);
}
}
void BedrockPlugin::verifyAttributeBool(const SData& request, const string& name, bool require)
{
if (require && !request[name].size()) {
STHROW("402 Missing " + name);
}
if (!request[name].empty() && !SIEquals(request[name], "true") && !SIEquals(request[name], "false")) {
STHROW("402 Malformed " + name);
}
}
STable BedrockPlugin::getInfo() {
return STable();
}
string BedrockPlugin::getName() {
SERROR("No name defined by this plugin, aborting.");
}
void BedrockPlugin::initialize(const SData& args, BedrockServer& server) {}
bool BedrockPlugin::peekCommand(SQLite& db, BedrockCommand& command) {
return false;
}
bool BedrockPlugin::processCommand(SQLite& db, BedrockCommand& command) {
return false;
}
bool BedrockPlugin::shouldSuppressTimeoutWarnings() {
return false;
}
void BedrockPlugin::timerFired(SStopwatch* timer) {}
void BedrockPlugin::upgradeDatabase(SQLite& db) {}
BedrockPlugin* BedrockPlugin::getPluginByName(const string& name) {
// If our global list isn't set, there's no plugin to return.
if (!g_registeredPluginList) {
return nullptr;
}
// If we find our plugin in our list, we'll return it.
for (auto& plugin : *g_registeredPluginList) {
if (SIEquals(plugin->getName(), name)) {
return plugin;
}
}
// Didn't find it.
return nullptr;
}