aboutsummaryrefslogtreecommitdiff
path: root/server/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/client')
-rw-r--r--server/src/client/blacklist.h54
-rw-r--r--server/src/client/client.h11
2 files changed, 61 insertions, 4 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
diff --git a/server/src/client/client.h b/server/src/client/client.h
index 141ac67..a3d558d 100644
--- a/server/src/client/client.h
+++ b/server/src/client/client.h
@@ -24,8 +24,10 @@ class client {
void cleanup() {
close(m_socket);
- SSL_shutdown(m_ssl);
- SSL_free(m_ssl);
+ if (m_ssl) {
+ SSL_shutdown(m_ssl);
+ SSL_free(m_ssl);
+ }
m_socket = -1;
}
@@ -63,8 +65,9 @@ class client {
int& get_socket() { return m_socket; }
auto& get_ip() { return m_ip; }
- auto& get_session() { return m_session_id; }
- operator bool() const { return m_ssl && m_socket > 0; }
+ operator bool() const { return m_socket > 0; }
+ auto &operator()() { return m_session_id; }
+
};
}; // namespace tcp \ No newline at end of file