// net_probe — connect to a Metin2 auth server, run the libsodium handshake and // the CG_LOGIN3 exchange, print what happened. Purely diagnostic. // // net_probe (defaults: 192.168.21.203 11000 admin 123456789) #include "../src/net/auth_client.h" #include #include #include #include int main(int argc, char **argv) { std::string host = argc > 1 ? argv[1] : "192.168.21.203"; uint16_t port = argc > 2 ? static_cast(std::stoi(argv[2])) : 11000; std::string id = argc > 3 ? argv[3] : "admin"; std::string pw = argc > 4 ? argv[4] : "123456789"; std::printf("net_probe -> %s:%u id=%s\n", host.c_str(), port, id.c_str()); mtnet::AuthClient client(id, pw); if (!client.connect(host, port)) { std::printf("connect() failed: %s\n", client.last_error().c_str()); return 2; } using clock = std::chrono::steady_clock; auto start = clock::now(); auto last_state = mtnet::NetStream::State::Offline; bool reported_online = false, reported_cipher = false, reported_login = false; while (std::chrono::duration_cast(clock::now() - start).count() < 15) { client.process(); if (client.state() != last_state) { const char *s = client.state() == mtnet::NetStream::State::Connecting ? "Connecting" : client.state() == mtnet::NetStream::State::Online ? "Online" : "Offline"; std::printf("[state] %s\n", s); last_state = client.state(); } if (!reported_online && client.state() == mtnet::NetStream::State::Online) { std::printf("[tcp] connected\n"); reported_online = true; } if (!reported_cipher && client.handshaked()) { std::printf("[handshake] cipher activated (KX ok)\n"); reported_cipher = true; } if (!reported_login && client.sent_login()) { std::printf("[auth] PHASE_AUTH reached, CG_LOGIN3 sent\n"); reported_login = true; } if (client.done()) { break; } if (client.state() == mtnet::NetStream::State::Offline && reported_online) { std::printf("[net] disconnected: %s\n", client.last_error().c_str()); break; } std::this_thread::sleep_for(std::chrono::milliseconds(20)); } if (client.done() && client.success()) { std::printf("RESULT: auth OK, login_key=0x%08X\n", client.login_key()); return 0; } if (client.done()) { std::printf("RESULT: auth failed (%s)\n", client.fail_reason().empty() ? client.last_error().c_str() : client.fail_reason().c_str()); return 1; } std::printf("RESULT: timed out. last_error=%s online=%d cipher=%d login_sent=%d\n", client.last_error().c_str(), (int)reported_online, (int)reported_cipher, (int)reported_login); return 3; }