版本比较
一坨更大的垃圾
正文
增加 13 行删除 13 行
14 行未改动1516171819192021222397 行未改动1211221231241251251261271281295 行未改动13513613713813913914014114214398 行未改动2422432442452462462472482492502 行未改动2532542552562572572582592602613 行未改动26526626726826926927027127227375 行未改动34935035135235335335435535635723 行未改动38138238338438538638738538638738838939039142 行未改动43443543643743843843944044144284 行未改动5275285295305315315325335345357 行未改动543544545546547547548549550551125 行未改动全部展开14 行未改动请安装所需的库和头文件(openssl, websocketpp, [boost](https://gist.github.com/zrsmithson/0b72e0cb58d0cb946fc48b5c88511da8), nlohmann/json.hpp, httplib)。
请对 C++ 代码使用编译 dos 脚本(compile.bat / compile.cmd):```dosg++.exe -c main.cpp -o main.o -I"c:/mingw64/include/c++/12.2.0" -I"c:/mingw64/include/c++/12.2.0/x86_64-w64-mingw32" -I"c:/mingw64/include/c++/12.2.0/backward" -I"c:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include" -I"c:/mingw64/include" -I"c:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include-fixed" -I"c:/mingw64/x86_64-w64-mingw32/include" -Wall -O2 -lws2_32 -lcrypt32 -lcryptui -lssl -lcrypto -finput-charset=utf-8 -fexec-charset=gbk g++.exe -c main.cpp -o main.o -I"c:/mingw64/include/c++/12.2.0" -I"c:/mingw64/include/c++/12.2.0/x86_64-w64-mingw32" -I"c:/mingw64/include/c++/12.2.0/backward" -I"c:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include" -I"c:/mingw64/include" -I"c:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include-fixed" -I"c:/mingw64/x86_64-w64-mingw32/include" -Wall -O2 -lws2_32 -lcrypt32 -lcryptui -lssl -lcrypto -finput-charset=utf-8 -fexec-charset=gbk
g++.exe main.o -o "main.exe" -L"c:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/" -L"c:/mingw64/lib/gcc/" -L"c:/mingw64/x86_64-w64-mingw32/lib/" -L"c:/mingw64/lib/" -L"C:/mingw64/lib" -L"C:/mingw64/x86_64-w64-mingw32/lib" -s -mwindows -lws2_32 -lcrypt32 -lcryptui -lssl -lcrypto
pause97 行未改动
/// @brief Check the existence of file, if file not exists then create one./// @param filePath Full (relative / absolute) path of the file./// @param initContent Initial content of the file (if need to create one)/// @return the ifstream of the existing/created file /// @return the ifstream of the existing/created filestd::ifstream initFile(const std::string& filePath, const std::string& initContent) {// json parser wil not work without a existed json file and the program will terminate. fs::path directory = fs::path(filePath).parent_path(); if (!fs::exists(directory)) {fs::create_directories(directory);} // creath directory5 行未改动 return std::ifstream(filePath);}
namespace TLS_INIT {// This namespace is derived from examples and documentations. // This namespace is derived from examples and documentations.// https://github.com/zaphoyd/websocketpp/issues/706// https://github.com/cotomonaga/websocketpp_tutorial/blob/master/utility_client/step7.cpp// https://blog.csdn.net/byxdaz/article/details/84645586 bool verify_subject_alternative_name(const char* hostname, X509* cert) {98 行未改动}
// Invalid connection checkers.namespace checkerThreadFuncs {/// @brief Check if the client is logged in. /// @brief Check if the client is logged in. void loginChecker ( ) { /* If the client have no "join_result" after the program start for 5 secs, the client may have a invalid cookie.*/ Sleep (1000 * 5);2 行未改动 "Please fill your cookies (_uid, __client_id) correctly. " + _uid + " " + __client_id); } }
/// @brief Check if the client is disconnected by ping. /// @brief Check if the client is disconnected by ping. void pingTimer ( ) { /* If the client received no ping after the time interval of 60 secs, the client may be automaticly disconnected, maybe for logged in on a different client. Normally, the ping interval is 54 secs, the range of checking is 60 secs.3 行未改动 "(normal: approx 54 seconds)."); } }
/// @brief Check if the client is disconnected by heartbeat. /// @brief Check if the client is disconnected by heartbeat. void heartbeatTimer ( ) { /* If the client received no heartbeat after the time interval of 96 secs, the client may be automaticly disconnected, maybe for logged in on a different client. Normally, the ping interval is 90 secs, the range of checking is 96 secs.75 行未改动 in.close( ); // Check if the avatar exists and is valid. Avatar cached for 1 hour if (!infile[userid].is_null( )) { int usrID = infile[userid]; if ((int)time(0) - usrID < 3600) { if ((int)time(0) - usrID < 3600) { return; } }
23 行未改动 }}
/// @brief Actions when receiving a ping./// @param hdl /// @param payload /// @return /// @param hdl/// @param payload/// @returnbool on_ping(websocketpp::connection_hdl hdl, std::string payload) { timePing_req = clock ( ); std::thread thrPing (pingTimer); thrPing.detach ( );42 行未改动 std::string uri = "wss://ws.luogu.com.cn/ws"; std::string tls_init_handlr = "ws.luogu.com.cn";
// Init cookies -> Luogu APIs
std::ifstream inCookie("cookie.txt"); inCookie >> _uid >> __client_id; inCookie.close ( ); int ulen = _uid.length ( );84 行未改动 wc.hCursor = LoadCursor (NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wc.lpszClassName = TEXT ("WindowClass"); wc.hIcon = LoadIcon (NULL, IDI_APPLICATION); wc.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wc.hIconSm = LoadIcon (NULL, IDI_APPLICATION); if (!RegisterClassEx (&wc)) { MessageBox (NULL, TEXT ("Window Registration Failed!"), TEXT ("Error"), MB_ICONEXCLAMATION | MB_OK); return 0; }7 行未改动 MessageBox(NULL, TEXT ("Window Creation Failed!"), TEXT ("Error"), MB_ICONEXCLAMATION | MB_OK); return 0; } while (GetMessage (&msg, NULL, 0, 0) > 0) { TranslateMessage (&msg); TranslateMessage (&msg); DispatchMessage (&msg); } return msg.wParam;}125 行未改动全部展开