aboutsummaryrefslogtreecommitdiff
path: root/server/src/client/blacklist.h
diff options
context:
space:
mode:
authorauth <[email protected]>2020-07-11 17:09:27 +0200
committerauth <[email protected]>2020-07-11 17:09:27 +0200
commitf9b06df544c8134b5982b76f2d24aa93289f6d71 (patch)
tree052961cb2d76b7999a722745b120d4fcd0977860 /server/src/client/blacklist.h
parentMore assembler implementations. (diff)
downloadloader-f9b06df544c8134b5982b76f2d24aa93289f6d71.tar.xz
loader-f9b06df544c8134b5982b76f2d24aa93289f6d71.zip
Added blacklist implementation on server.
Overall code cleanup and optimization.
Diffstat (limited to 'server/src/client/blacklist.h')
-rw-r--r--server/src/client/blacklist.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/server/src/client/blacklist.h b/server/src/client/blacklist.h
new file mode 100644
index 0000000..ea9e261
--- /dev/null
+++ b/server/src/client/blacklist.h
@@ -0,0 +1,54 @@
+#pragma once
+
+namespace tcp {
+
+struct blacklist_data {
+ std::string ip;
+ std::string hwid;
+};
+
+class blacklist {
+
+nlohmann::json m_data;
+std::string m_name;
+
+public:
+ void init(const std::string_view file = "blacklist") {
+ m_name = file;
+
+ std::string data;
+ if(!io::read_file(file, data))
+ return;
+
+ if(!nlohmann::json::accept(data)) {
+ io::logger->error("blacklist file isnt valid json.");
+ return;
+ }
+
+ m_data = nlohmann::json::parse(data);
+ }
+
+ void add(const blacklist_data &data) {
+ m_data["ips"].emplace_back(data.ip);
+ m_data["hwids"].emplace_back(data.hwid);
+
+ save();
+ }
+
+ void save() {
+ std::ofstream o(m_name, std::ios::trunc);
+ o << std::setw(4) << m_data;
+ o.close();
+ }
+
+ bool find(const std::string &key) {
+ for(auto &item : m_data["ips"]) {
+ if(item.get<std::string>() == key) {
+ return true;
+ }
+ }
+ return false;
+ }
+};
+
+}; \ No newline at end of file