From 3127665ecb1ce8dab84444ac43ed36a386eb765f Mon Sep 17 00:00:00 2001 From: thejinchao Date: Wed, 31 Dec 2025 12:02:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ACE=E4=B8=BE=E6=8A=A5?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ace_test/aServer/AceReportInterface.cpp | 201 +++++++++++++++++++++++- ace_test/aServer/AceReportInterface.h | 11 +- ace_test/aServer/CMakeLists.txt | 2 + ace_test/aServer/GameServer.cpp | 2 + ace_test/aServer/main.cpp | 2 + libTinyEncrypt/libEncrypt_MD5.cpp | 4 +- 6 files changed, 215 insertions(+), 7 deletions(-) diff --git a/ace_test/aServer/AceReportInterface.cpp b/ace_test/aServer/AceReportInterface.cpp index da486dd..0bf4132 100644 --- a/ace_test/aServer/AceReportInterface.cpp +++ b/ace_test/aServer/AceReportInterface.cpp @@ -1,8 +1,201 @@ #include "stdafx.h" #include "AceReportInterface.h" +#include "GameServer.h" +#include "GameProto.pb.h" +#include "CurlHelper.h" +#include "AceInterface.h" -std::string buildReportRequestUrl(const std::string& baseUrl, const std::string& user, - const std::string& token, uint32_t timeStamp, const std::string& body) +#include "rapidjson/document.h" +#include "rapidjson/stringbuffer.h" +#include "rapidjson/writer.h" +#include "rapidjson/prettywriter.h" + +#include "libEncrypt_MD5.h" + +const char* kReportProto = "http"; +const char* kReportHost = "service-exp.light.oa.com"; +const char* kReportUrl = "report/report_log_data"; +const char* kReportUser = "719_report"; +const char* kReportToken = "HaPjIyPBgVJSLsnZJGQjpAHKGLycsQSS"; + +std::string buildReportRequestJson(GameClient* client, Game::GameReportReq* request, uint32_t timeStamp) { - return ""; -} \ No newline at end of file + rapidjson::Document root; + root.SetObject(); + rapidjson::Document::AllocatorType& allocator = root.GetAllocator(); + + rapidjson::Value emptyString(""); + + + //informant_account_type + rapidjson::Value accountType(1);//ACE_SDK_ACCOUNT_TYPE_QQ=1 + root.AddMember("informant_account_type", accountType, allocator); + + //informant_account_id + rapidjson::Value openIDValue(client->gameAccoundID.c_str(), static_cast(client->gameAccoundID.length()), allocator); + root.AddMember("informant_account_id", openIDValue, allocator); + + //informant_app_id + rapidjson::Value appID(AceInterface::kGameID); + root.AddMember("informant_app_id", appID, allocator); + + //informant_plat_id + rapidjson::Value platID(2); + root.AddMember("informant_plat_id", platID, allocator); + + //informant_world_id + rapidjson::Value worldID(client->gameWorldID); + root.AddMember("informant_world_id", worldID, allocator); + + //informant_name + rapidjson::Value informantAccountID(client->gameAccoundID.c_str(), static_cast(client->gameAccoundID.length()), allocator); + root.AddMember("informant_account_id", informantAccountID, allocator); + + //informant_name + rapidjson::Value informantName(client->gameAccoundID.c_str(), static_cast(client->gameAccoundID.length()), allocator); + root.AddMember("informant_name", informantName, allocator); + + //informant_roleid + rapidjson::Value informantRoleID(client->gameAccoundID.c_str(), static_cast(client->gameAccoundID.length()), allocator); + root.AddMember("informant_roleid", informantRoleID, allocator); + + //informant_area + rapidjson::Value areaID(3); + root.AddMember("informant_area", areaID, allocator); + + //reported_account_type + rapidjson::Value reportedAccountType(1);//ACE_SDK_ACCOUNT_TYPE_QQ=1 + root.AddMember("reported_account_type", reportedAccountType, allocator); + + //reported_account_id + rapidjson::Value reportedIDValue(request->reported_account_id().c_str(), static_cast(request->reported_account_id().length()), allocator); + root.AddMember("reported_account_id", reportedIDValue, allocator); + + //reported_app_id + rapidjson::Value reportedAppID(AceInterface::kGameID); + root.AddMember("reported_app_id", reportedAppID, allocator); + + //reported_plat_id + rapidjson::Value reportedPlatID(2); + root.AddMember("reported_plat_id", reportedPlatID, allocator); + + //reported_world_id + rapidjson::Value reportedWorldIDValue(request->reported_world_id()); + root.AddMember("reported_world_id", reportedWorldIDValue, allocator); + + //reported_name + rapidjson::Value reportedName(request->reported_name().c_str(), static_cast(request->reported_name().length()), allocator); + root.AddMember("reported_name", reportedName, allocator); + + //reported_roleid + rapidjson::Value reportedRoldID(request->reported_roleid().c_str(), static_cast(request->reported_roleid().length()), allocator); + root.AddMember("reported_roleid", reportedRoldID, allocator); + + //reported_area + rapidjson::Value reportedAreaID(3); + root.AddMember("reported_area", reportedAreaID, allocator); + + //report_time + rapidjson::Value reportTime(timeStamp); + root.AddMember("report_time", reportTime, allocator); + + //business_data + rapidjson::Value business_data(rapidjson::kObjectType); + + //business_data:report_category + rapidjson::Value reportCategory(request->report_category()); + business_data.AddMember("report_category", reportCategory, allocator); + + //business_data:report_reason + rapidjson::Value reportReasonArray(rapidjson::kArrayType); + for (const auto& reason : request->report_reason()) + { + reportReasonArray.PushBack(reason, allocator); + } + business_data.AddMember("report_reason", reportReasonArray, allocator); + + //business_data::report_scene + rapidjson::Value reportScene(request->report_scene()); + business_data.AddMember("report_scene", reportScene, allocator); + + //business_data::reported_profile_url + rapidjson::Value reportedProfileUrl(request->reported_profile_url().c_str(), static_cast(request->reported_profile_url().length()), allocator); + business_data.AddMember("reported_profile_url", reportedProfileUrl, allocator); + + //business_data::report_battle_id + rapidjson::Value reportBattleID(request->report_battle_id().c_str(), static_cast(request->report_battle_id().length()), allocator); + business_data.AddMember("report_battle_id", reportBattleID, allocator); + + //business_data::report_battle_time + rapidjson::Value reportBattleTime(request->report_battle_time()); + business_data.AddMember("report_battle_time", reportBattleTime, allocator); + + //business_data::report_desc + rapidjson::Value reportDesc(request->report_desc().c_str(), static_cast(request->report_desc().length()), allocator); + business_data.AddMember("report_desc", reportDesc, allocator); + + //business_data::report_content + rapidjson::Value reportContent(request->report_content().c_str(), static_cast(request->report_content().length()), allocator); + business_data.AddMember("report_content", reportContent, allocator); + + root.AddMember("business_data", business_data, allocator); + + rapidjson::StringBuffer sb; + rapidjson::Writer writer(sb); + root.Accept(writer); + std::string outputJson = sb.GetString(); + + return outputJson; +} + +std::string buildReportRequestUrl(const std::string& requestBody, uint32_t timeStamp) +{ + uint32_t randomSerial = rand(); + + MD5Context md5Context; + md5Init(&md5Context); + md5Update(&md5Context, (uint8_t*)requestBody.c_str(), (uint32_t)requestBody.size()); + std::string requestBodyMD5 = md5ToString(md5Finalize(&md5Context)); + + char szStringC[1024] = { 0 }; + snprintf(szStringC, 1024, "serial=%u×tamp=%u&user=%s&body_md5=%s&token=%s", + randomSerial, timeStamp, kReportUser, requestBodyMD5.c_str(), kReportToken); + md5Init(&md5Context); + md5Update(&md5Context, (uint8_t*)szStringC, (uint32_t)strlen(szStringC)); + std::string signString = md5ToString(md5Finalize(&md5Context)); + + char szRequestURL[1024] = { 0 }; + snprintf(szRequestURL, 1024, "%s://%s/%s?serial=%u×tamp=%u&user=%s&sign=%s", + kReportProto, kReportHost, kReportUrl, + randomSerial, timeStamp, kReportUser, signString.c_str()); + + return szRequestURL; +} + +bool AceReportInterface::onReceiveReportRequest(GameClient* client, Game::GameReportReq* request) +{ + uint32_t timeStamp = (uint32_t)(time(0) & 0xFFFFFFFF); + + std::string requestBody = buildReportRequestJson(client, request, timeStamp); + std::string requestUrl = buildReportRequestUrl(requestBody, timeStamp); + + std::string result; + int32_t retCode = curlRequest(requestUrl, requestBody, result, true); + + int32_t errorCode = 0; + std::string errorInfo; + + if (retCode != 0) + { + CY_LOG(cyclone::L_ERROR, "NetbarInterface::onReceiveNetbarStatusRequest curlRequest failed, retCode=%d", retCode); + + char szTemp[256] = { 0 }; + snprintf(szTemp, 256, "Curl request failed, retCode=%d", retCode); + errorInfo = szTemp; + } + else + { + } + + return true; +} diff --git a/ace_test/aServer/AceReportInterface.h b/ace_test/aServer/AceReportInterface.h index c041a38..af61bc2 100644 --- a/ace_test/aServer/AceReportInterface.h +++ b/ace_test/aServer/AceReportInterface.h @@ -1,4 +1,13 @@ #pragma once +struct GameClient; +namespace Game +{ + class GameReportReq; +} -std::string buildReportRequestUrl(); \ No newline at end of file +class AceReportInterface +{ +public: + static bool onReceiveReportRequest(GameClient* client, Game::GameReportReq* request); +}; diff --git a/ace_test/aServer/CMakeLists.txt b/ace_test/aServer/CMakeLists.txt index 488e67b..bc02b81 100644 --- a/ace_test/aServer/CMakeLists.txt +++ b/ace_test/aServer/CMakeLists.txt @@ -45,6 +45,7 @@ PRIVATE ${ACE_SERVER_DIR}/include ${RAPIDJSON_INCLUDE_DIRS} ${GAME_PROTO_DIR} + ../../libTinyEncrypt ) target_link_directories(aServer @@ -59,4 +60,5 @@ PRIVATE ws2_32.lib shlwapi.lib CURL::libcurl_static + libTinyEncrypt ) diff --git a/ace_test/aServer/GameServer.cpp b/ace_test/aServer/GameServer.cpp index 2480005..b14edec 100644 --- a/ace_test/aServer/GameServer.cpp +++ b/ace_test/aServer/GameServer.cpp @@ -3,6 +3,7 @@ #include "GameServer.h" #include "AceInterface.h" #include "NetbarInterface.h" +#include "AceReportInterface.h" #include "GameProto.pb.h" GameServer* GameServer::getSingleton() @@ -286,6 +287,7 @@ void GameServer::onReportRequest(cyclone::TcpConnectionPtr conn, Game::GameRepor GameClient* client = getClient(conn->get_id()); assert(client); + AceReportInterface::onReceiveReportRequest(client, request); } void GameServer::onNetbarRequest(cyclone::TcpConnectionPtr conn, Game::NetbaraStatusReq* request) diff --git a/ace_test/aServer/main.cpp b/ace_test/aServer/main.cpp index c029cb9..bd3056c 100644 --- a/ace_test/aServer/main.cpp +++ b/ace_test/aServer/main.cpp @@ -4,6 +4,8 @@ int main(int argc, char* argv[]) { + srand(time(0)); + //init ace interface if (!AceInterface::initAceInterface()) { diff --git a/libTinyEncrypt/libEncrypt_MD5.cpp b/libTinyEncrypt/libEncrypt_MD5.cpp index fe095e9..f41a755 100644 --- a/libTinyEncrypt/libEncrypt_MD5.cpp +++ b/libTinyEncrypt/libEncrypt_MD5.cpp @@ -199,7 +199,7 @@ std::string md5ToString(const MD5Digest& digest) { char buf[33] = { 0 }; for (size_t i = 0; i < 16; ++i) { - sprintf_s(buf + i * 2, 3, "%02x", digest[i]); + sprintf_s(buf + i * 2, 3, "%02X", digest[i]); } return std::string(buf); } @@ -211,7 +211,7 @@ bool string2MD5(const char* md5_string, MD5Digest& md5) } for (size_t i = 0; i < 16; ++i) { unsigned int byte; - if (sscanf_s(md5_string + i * 2, "%02x", &byte) != 1) { + if (sscanf_s(md5_string + i * 2, "%02X", &byte) != 1) { return false; // Failed to parse byte } md5[i] = static_cast(byte);