正文
增加 13 行删除 13 行
14 行未改动15161718192021222397 行未改动1211221231241251261271281295 行未改动13513613713813914014114214398 行未改动2422432442452462472482492502 行未改动2532542552562572582592602613 行未改动26526626726826927027127227375 行未改动34935035135235335435535635723 行未改动38138238338438538638738838939039142 行未改动43443543643743843944044144284 行未改动5275285295305315325335345357 行未改动543544545546547548549550551125 行未改动全部展开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=gbkg++.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 -lcryptopause97 行未改动/// @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 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.// 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/84645586bool verify_subject_alternative_name(const char* hostname, X509* cert) {98 行未改动}// Invalid connection checkers.namespace checkerThreadFuncs {/// @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.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.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 hourif (!infile[userid].is_null( )) {int usrID = infile[userid];if ((int)time(0) - usrID < 3600) {return;}}23 行未改动}}/// @brief Actions when receiving a ping./// @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 APIsstd::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);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);DispatchMessage (&msg);}return msg.wParam;}125 行未改动全部展开14 行未改动15161718192021222397 行未改动1211221231241251261271281295 行未改动13513613713813914014114214398 行未改动2422432442452462472482492502 行未改动2532542552562572582592602613 行未改动26526626726826927027127227375 行未改动34935035135235335435535635723 行未改动38138238338438538638738838939039142 行未改动43443543643743843944044144284 行未改动5275285295305315325335345357 行未改动543544545546547548549550551125 行未改动全部展开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=gbkg++.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 -lcryptopause97 行未改动/// @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 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.// 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/84645586bool verify_subject_alternative_name(const char* hostname, X509* cert) {98 行未改动}// Invalid connection checkers.namespace checkerThreadFuncs {/// @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.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.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 hourif (!infile[userid].is_null( )) {int usrID = infile[userid];if ((int)time(0) - usrID < 3600) {return;}}23 行未改动}}/// @brief Actions when receiving a ping./// @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 APIsstd::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);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);DispatchMessage (&msg);}return msg.wParam;}125 行未改动全部展开