aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorauth <[email protected]>2020-07-05 11:25:10 +0200
committerauth <[email protected]>2020-07-05 11:25:10 +0200
commite1ca40bf09255ea74602a6b31e0e17ae611e3e3b (patch)
treed163ae07461108a2667107153b72180f69981a9c /server
parentReplaced std::byte by uint8_t (diff)
downloadloader-e1ca40bf09255ea74602a6b31e0e17ae611e3e3b.tar.xz
loader-e1ca40bf09255ea74602a6b31e0e17ae611e3e3b.zip
Added support for packet actions.
Added support for client hwid handling. Removed timeout client message.
Diffstat (limited to 'server')
-rw-r--r--server/src/client/client.h11
-rw-r--r--server/src/main.cpp30
-rw-r--r--server/src/server/packet.h11
3 files changed, 26 insertions, 26 deletions
diff --git a/server/src/client/client.h b/server/src/client/client.h
index 52e0c42..4dad02e 100644
--- a/server/src/client/client.h
+++ b/server/src/client/client.h
@@ -13,6 +13,9 @@ class client {
std::string m_session_id;
public:
+ std::string hwid;
+
+
client() : m_socket{-1} {};
client(const int& socket, const std::string_view ip)
: m_socket{std::move(socket)}, m_ip{ip}, m_ssl{nullptr} {}
@@ -27,7 +30,7 @@ class client {
}
void reset() { std::time(&m_time); }
- bool timeout() { return std::difftime(std::time(nullptr), m_time) >= 30; }
+ bool timeout() { return std::difftime(std::time(nullptr), m_time) >= 300; }
int write(const packet_t& packet) {
if (!packet) return 0;
@@ -57,8 +60,8 @@ class client {
void gen_session();
- int get_socket() { return m_socket; }
- auto get_ip() { return m_ip; }
- auto get_session() { return m_session_id; }
+ int &get_socket() { return m_socket; }
+ auto &get_ip() { return m_ip; }
+ auto &get_session() { return m_session_id; }
};
}; // namespace tcp \ No newline at end of file
diff --git a/server/src/main.cpp b/server/src/main.cpp
index 138f733..77269a9 100644
--- a/server/src/main.cpp
+++ b/server/src/main.cpp
@@ -18,8 +18,9 @@ int main(int argc, char* argv[]) {
client_server.connect_event.add([&](tcp::client& client) {
auto ip = client.get_ip();
client.gen_session();
- client.write(tcp::packet_t(client_version,
- tcp::packet_type::write, client.get_session()));
+ client.write(tcp::packet_t(client_version, tcp::packet_type::write,
+ client.get_session(),
+ tcp::packet_action::session));
io::logger->info("{} connected", ip);
});
@@ -41,6 +42,7 @@ int main(int argc, char* argv[]) {
auto packet_session = packet.session_id;
auto ip = client.get_ip();
auto message = packet();
+ auto action = packet.act;
if (!packet) {
io::logger->info("{} sent invalid packet", ip);
@@ -54,29 +56,17 @@ int main(int argc, char* argv[]) {
io::logger->info("{} : {}", packet_session, message);
- client.write(tcp::packet_t(message, tcp::packet_type::write,
- client.get_session()));
+ if(action == tcp::packet_action::hwid) {
+ client.hwid = message;
- /*auto imports = image.get_json_imports();
- client.stream(imports);*/
-
- /*std::vector<char> t;
- io::read_file("test.dll", t);
- float tot;
- for(int i = 0; i < 100; i++) {
- float dur;
- client.stream(t, &dur);
- tot += dur;
+ io::logger->info("got hwid from {} : {}", ip, message);
}
- float avg = tot / 100.f;
- io::logger->info("average time {}", avg);*/
-
+
+ //client.write(tcp::packet_t(message, tcp::packet_type::write,
+ //client.get_session()));
});
client_server.timeout_event.add([&](tcp::client& client) {
- client.write(tcp::packet_t("timedout", tcp::packet_type::write,
- client.get_session()));
-
io::logger->info("{} timed out.", client.get_ip());
});
diff --git a/server/src/server/packet.h b/server/src/server/packet.h
index 661b0df..279d140 100644
--- a/server/src/server/packet.h
+++ b/server/src/server/packet.h
@@ -9,13 +9,17 @@ constexpr size_t message_len = 512;
enum packet_type : int { write = 0, read };
+enum packet_action : uint8_t { message = 0, hwid = 1, session };
+
struct packet_t {
std::string message;
std::string session_id;
+ uint8_t act;
packet_t() {}
- packet_t(const std::string_view msg, const packet_type& type,
- std::string_view session = "") {
+ packet_t(const std::string_view msg, const packet_type &type,
+ std::string_view session = "",
+ const packet_action &action = packet_action::message) {
if (type == read) {
message = msg;
enc::decrypt_message(message);
@@ -28,8 +32,10 @@ struct packet_t {
auto json = nlohmann::json::parse(message);
message = json["message"];
session_id = json["session_id"];
+ act = json["action"];
} else {
nlohmann::json json;
+ json["action"] = action;
json["session_id"] = session;
json["message"] = msg.data();
@@ -43,6 +49,7 @@ struct packet_t {
~packet_t() {
message.clear();
session_id.clear();
+ act = -1;
}
operator bool() const { return !message.empty() && !session_id.empty(); }