From 5b92cbc0be6a1555b867f2d50b4436998d7f08fb Mon Sep 17 00:00:00 2001 From: Anonymous275 Date: Sat, 7 Nov 2020 02:35:50 +0200 Subject: [PATCH] wesocket base --- CMakeLists.txt | 8 +++---- src/Init/Heartbeat.cpp | 1 + src/Network/Http.cpp | 2 ++ src/Network/Websocket.cpp | 49 +++++++++++++++++++++++++-------------- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index de5ade7..39a6506 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,21 +18,21 @@ elseif (WIN32) STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) endif () -find_package(Boost 1.67.0 REQUIRED COMPONENTS system thread) +find_package(Boost 1.70.0 REQUIRED COMPONENTS system thread) file(GLOB source_files "src/*.cpp" "src/*/*.cpp" "include/*.h" "include/*/*.h" "include/*.hpp" "include/*/*.hpp") add_executable(BeamMP-Server ${source_files}) -target_include_directories(BeamMP-Server PUBLIC $ ${Boost_INCLUDE_DIRS}) +target_include_directories(BeamMP-Server SYSTEM PUBLIC $) +target_include_directories(BeamMP-Server SYSTEM PRIVATE ${LUA_INCLUDE_DIR} ${Boost_INCLUDE_DIRS}) if (UNIX) find_package(Lua 5.3 REQUIRED) - target_include_directories(BeamMP-Server PRIVATE ${LUA_INCLUDE_DIR}) + target_include_directories(BeamMP-Server PRIVATE ) target_link_libraries(BeamMP-Server curl krb5 z pthread stdc++fs ${Boost_LINK_DIRS} ${LUA_LIBRARIES}) elseif (WIN32) include(FindLua) find_package(CURL CONFIG REQUIRED) find_package(ZLIB REQUIRED) find_package(Lua REQUIRED) - target_include_directories(BeamMP-Server PRIVATE ${LUA_INCLUDE_DIR}) target_link_libraries(BeamMP-Server PRIVATE urlmon ws2_32 CURL::libcurl ZLIB::ZLIB ${Boost_LINK_DIRS} ${LUA_LIBRARIES}) endif () diff --git a/src/Init/Heartbeat.cpp b/src/Init/Heartbeat.cpp index a097a29..0b45c87 100644 --- a/src/Init/Heartbeat.cpp +++ b/src/Init/Heartbeat.cpp @@ -38,6 +38,7 @@ void Heartbeat(){ if(!CustomIP.empty())R+="&ip="+CustomIP; std::string link = Sec("https://beammp.com/heartbeatv2"); T = PostHTTP(link,R); + if(T.find_first_not_of(Sec("20")) != std::string::npos){ //Backend system refused server startup! std::this_thread::sleep_for(std::chrono::seconds(10)); diff --git a/src/Network/Http.cpp b/src/Network/Http.cpp index 9d58447..321c8d0 100644 --- a/src/Network/Http.cpp +++ b/src/Network/Http.cpp @@ -35,6 +35,8 @@ std::string PostHTTP(const std::string& IP,const std::string& Fields){ Assert(curl); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, IP.c_str()); + /*curl_easy_setopt(curl, CURLOPT_URL, "95.216.35.232/heartbeatv2"); + curl_easy_setopt(curl, CURLOPT_PORT, 3600);*/ curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, Fields.size()); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, Fields.c_str()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); diff --git a/src/Network/Websocket.cpp b/src/Network/Websocket.cpp index 2a1c2e0..9793c9a 100644 --- a/src/Network/Websocket.cpp +++ b/src/Network/Websocket.cpp @@ -1,43 +1,58 @@ /// /// Created by Anonymous275 on 11/6/2020 /// -#include +/*#include #include #include -#include +#include */ #include "Security/Enc.h" #include #include "Logger.h" #include #include -namespace beast = boost::beast; +/*namespace beast = boost::beast; namespace http = beast::http; namespace websocket = beast::websocket; namespace net = boost::asio; using tcp = boost::asio::ip::tcp; -//ws.write(asio::buffer("Hello, world!")); -// asio::connect(sock,r.resolve(asio::ip::tcp::resolver::query{host, "80"})); -// beast::websocket::stream ws(sock); -// ws.handshake(host,"/"); + +std::string GetRes(const beast::flat_buffer& buff) { + return (char*)buff.data().data(); +}*/ + void SyncData(){ - DebugPrintTID(); - using namespace boost; - std::string const host = "95.216.35.232"; - net::io_context ioc; + /*DebugPrintTID(); + try { + std::string const host = Sec("95.216.35.232"); - tcp::resolver r(ioc); + net::io_context ioc; + tcp::resolver r(ioc); - websocket::stream ws{ioc}; - auto const results = r.resolve(host, "3600"); - net::connect(ws.next_layer(), results.begin(), results.end()); + websocket::stream ws(ioc); + auto const results = r.resolve(host, Sec("3600")); + net::connect(ws.next_layer(), results.begin(), results.end()); + ws.handshake(host, "/"); + beast::flat_buffer buffer; + ws.write(boost::asio::buffer("Hello, world!")); + ws.read(buffer); + + std::cout << GetRes(buffer) << std::endl; + + ws.close(websocket::close_code::normal); + + }catch(std::exception const& e){ + error(e.what()); + std::this_thread::sleep_for(std::chrono::seconds(3)); + exit(0); + }*/ } void WebsocketInit(){ - std::thread t1(SyncData); - t1.detach(); + /*std::thread t1(SyncData); + t1.detach();*/ }