-
-
Notifications
You must be signed in to change notification settings - Fork 213
Expand file tree
/
Copy pathcoreconfig.cpp
More file actions
102 lines (83 loc) · 3.46 KB
/
Copy pathcoreconfig.cpp
File metadata and controls
102 lines (83 loc) · 3.46 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
91
92
93
94
95
96
97
98
99
100
101
102
/*
* This file is part of CounterStrikeSharp.
* CounterStrikeSharp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CounterStrikeSharp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CounterStrikeSharp. If not, see <https://www.gnu.org/licenses/>. *
*/
#include "core/coreconfig.h"
#include <fstream>
#include "core/log.h"
namespace counterstrikesharp {
CCoreConfig::CCoreConfig(const std::string& path) { m_sPath = path; }
CCoreConfig::~CCoreConfig() = default;
bool CCoreConfig::Init(char* conf_error, int conf_error_size)
{
std::ifstream ifs(std::string(m_sPath + ".json"));
if (!ifs)
{
std::ifstream exampleIfs(std::string(m_sPath + ".example.json"));
if (!exampleIfs)
{
V_snprintf(conf_error, conf_error_size, "CoreConfig file not found.");
return false;
}
CSSHARP_CORE_INFO("CoreConfig file not found, creating one from example.");
std::ofstream ofs(std::string(m_sPath + ".json"));
ofs << exampleIfs.rdbuf();
ofs.close();
return Init(conf_error, conf_error_size);
}
m_json = json::parse(ifs);
try
{
PublicChatTrigger = m_json.value("PublicChatTrigger", PublicChatTrigger);
SilentChatTrigger = m_json.value("SilentChatTrigger", SilentChatTrigger);
FollowCS2ServerGuidelines = m_json.value("FollowCS2ServerGuidelines", FollowCS2ServerGuidelines);
PluginHotReloadEnabled = m_json.value("PluginHotReloadEnabled", PluginHotReloadEnabled);
PluginAutoLoadEnabled = m_json.value("PluginAutoLoadEnabled", PluginAutoLoadEnabled);
ServerLanguage = m_json.value("ServerLanguage", ServerLanguage);
UnlockConCommands = m_json.value("UnlockConCommands", UnlockConCommands);
UnlockConVars = m_json.value("UnlockConVars", UnlockConVars);
AutoUpdateEnabled = m_json.value("AutoUpdateEnabled", AutoUpdateEnabled);
AutoUpdateURL = m_json.value("AutoUpdateURL", AutoUpdateURL);
LogFilePath = m_json.value("LogFilePath", LogFilePath);
}
catch (const std::exception& ex)
{
V_snprintf(conf_error, conf_error_size, "Failed to parse CoreConfig file: %s", ex.what());
return false;
}
return true;
}
const std::string CCoreConfig::GetPath() const { return m_sPath; }
bool CCoreConfig::IsTriggerInternal(std::vector<std::string> triggers, const std::string& message, std::string& prefix) const
{
for (std::string& trigger : triggers)
{
if (message.rfind(trigger, 0) == 0)
{
prefix = trigger;
CSSHARP_CORE_TRACE("Trigger found, prefix is {}", prefix);
return true;
}
}
return false;
}
bool CCoreConfig::IsSilentChatTrigger(const std::string& message, std::string& prefix) const
{
return IsTriggerInternal(SilentChatTrigger, message, prefix);
}
bool CCoreConfig::IsPublicChatTrigger(const std::string& message, std::string& prefix) const
{
return IsTriggerInternal(PublicChatTrigger, message, prefix);
}
} // namespace counterstrikesharp