aboutsummaryrefslogtreecommitdiff
path: root/server/src/client/blacklist.h
blob: f016f17b048a0882ecde82c6d6d1d37b6919a652 (plain) (blame)
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
#pragma once

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 uint32_t hwid) {
    m_data["hwids"].emplace_back(hwid);

    save();
  }

  void save() {
    std::ofstream o(m_name, std::ios::trunc);
    o << std::setw(4) << m_data;
    o.close();
  }

  bool find(const uint32_t key) {
    for (auto &item : m_data["hwids"]) {
      if (item.get<uint32_t>() == key) {
        return true;
      }
    }
    return false;
  }
};