aboutsummaryrefslogtreecommitdiff
path: root/client/src/main.cpp
blob: 09db5cbe7810f40925b65d6757c62191d14db1ae (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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "include.h"
#include "util/io.h"
#include "client/client.h"
#include "assembler/shellcode.h"
#include "injection/mapper.h"

int main(int argc, char* argv[]) {
  io::init();

  /*assembler a;
  a.push({1, 2, 3, 7, 9});
  a.end();
  for(auto &b : a()) {
    io::logger->info("{:x}", b);
  }
  std::cin.get();*/

  tcp::client client;

  std::thread t{tcp::client::monitor, std::ref(client)};
  t.detach();

  client.start("127.0.0.1", 6666);

  client.connect_event.add([&]() { io::logger->info("connected."); });

  client.receive_event.add([&](tcp::packet_t& packet) {
    if (!packet) return;
    auto message = packet();
    auto id = packet.id;

    if (id == tcp::packet_id::session) {
      client.session_id = packet.session_id;

      tcp::version_t v{0, 1, 0};
      auto version = fmt::format("{}.{}.{}", v.major, v.minor, v.patch);
      io::logger->info("current server version {}", message);

      if (version != message) {
        io::logger->error("please update your client.");
        client.shutdown();
      }

      int ret =
          client.write(tcp::packet_t("hwid", tcp::packet_type::write,
                                     client.session_id, tcp::packet_id::hwid));
      if (ret <= 0) {
        io::logger->error("internal error.");
        client.shutdown();
        return;
      }
    }

    if (id == tcp::packet_id::login_resp) {
      auto j = nlohmann::json::parse(message);

      auto res = j["result"].get<int>();

      if (res == tcp::login_result::banned) {
        io::logger->error("your account is banned.");
        client.shutdown();
        return;
      }

      if (res == tcp::login_result::login_fail) {
        io::logger->error("please check your username or password.");
        client.shutdown();
        return;
      }

      if (res == tcp::login_result::hwid_mismatch) {
        io::logger->error("please reset your hwid on the forums.");
        client.shutdown();
        return;
      }

      if (res == tcp::login_result::server_error) {
        io::logger->error("internal server error, please contact a developer.");
        client.shutdown();
        return;
      }

      if (res == tcp::login_result::login_success) {
        client.state = tcp::client_state::logged_in;

        

        io::logger->info("logged in.");
      }
    }

    if (id == tcp::packet_id::ban) {
      io::logger->error(
          "your computer is blacklisted, please contact a developer.");
      client.shutdown();
      return;
    }

    io::logger->info("{}:{}->{} {}", packet.seq, packet.session_id, message,
                     id);
  });

  while (client) {
    std::string u;
    getline(std::cin, u);

    std::string p;
    getline(std::cin, p);

    auto l = fmt::format("{},{}", u, p);

    int ret = client.write(tcp::packet_t(l, tcp::packet_type::write,
                                         client.session_id,
                                         tcp::packet_id::login_req));

    if (ret <= 0) {
      break;
    }
  }

  std::cin.get();
}