增加ACE举报测试

This commit is contained in:
2025-12-31 12:02:58 +08:00
parent dad2b61a50
commit 3127665ecb
6 changed files with 215 additions and 7 deletions
+196 -3
View File
@@ -1,8 +1,201 @@
#include "stdafx.h" #include "stdafx.h"
#include "AceReportInterface.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, #include "rapidjson/document.h"
const std::string& token, uint32_t timeStamp, const std::string& body) #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 ""; 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<rapidjson::SizeType>(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<rapidjson::SizeType>(client->gameAccoundID.length()), allocator);
root.AddMember("informant_account_id", informantAccountID, allocator);
//informant_name
rapidjson::Value informantName(client->gameAccoundID.c_str(), static_cast<rapidjson::SizeType>(client->gameAccoundID.length()), allocator);
root.AddMember("informant_name", informantName, allocator);
//informant_roleid
rapidjson::Value informantRoleID(client->gameAccoundID.c_str(), static_cast<rapidjson::SizeType>(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<rapidjson::SizeType>(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<rapidjson::SizeType>(request->reported_name().length()), allocator);
root.AddMember("reported_name", reportedName, allocator);
//reported_roleid
rapidjson::Value reportedRoldID(request->reported_roleid().c_str(), static_cast<rapidjson::SizeType>(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<rapidjson::SizeType>(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<rapidjson::SizeType>(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<rapidjson::SizeType>(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<rapidjson::SizeType>(request->report_content().length()), allocator);
business_data.AddMember("report_content", reportContent, allocator);
root.AddMember("business_data", business_data, allocator);
rapidjson::StringBuffer sb;
rapidjson::Writer<rapidjson::StringBuffer> 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&timestamp=%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&timestamp=%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;
} }
+10 -1
View File
@@ -1,4 +1,13 @@
#pragma once #pragma once
struct GameClient;
namespace Game
{
class GameReportReq;
}
std::string buildReportRequestUrl(); class AceReportInterface
{
public:
static bool onReceiveReportRequest(GameClient* client, Game::GameReportReq* request);
};
+2
View File
@@ -45,6 +45,7 @@ PRIVATE
${ACE_SERVER_DIR}/include ${ACE_SERVER_DIR}/include
${RAPIDJSON_INCLUDE_DIRS} ${RAPIDJSON_INCLUDE_DIRS}
${GAME_PROTO_DIR} ${GAME_PROTO_DIR}
../../libTinyEncrypt
) )
target_link_directories(aServer target_link_directories(aServer
@@ -59,4 +60,5 @@ PRIVATE
ws2_32.lib ws2_32.lib
shlwapi.lib shlwapi.lib
CURL::libcurl_static CURL::libcurl_static
libTinyEncrypt
) )
+2
View File
@@ -3,6 +3,7 @@
#include "GameServer.h" #include "GameServer.h"
#include "AceInterface.h" #include "AceInterface.h"
#include "NetbarInterface.h" #include "NetbarInterface.h"
#include "AceReportInterface.h"
#include "GameProto.pb.h" #include "GameProto.pb.h"
GameServer* GameServer::getSingleton() GameServer* GameServer::getSingleton()
@@ -286,6 +287,7 @@ void GameServer::onReportRequest(cyclone::TcpConnectionPtr conn, Game::GameRepor
GameClient* client = getClient(conn->get_id()); GameClient* client = getClient(conn->get_id());
assert(client); assert(client);
AceReportInterface::onReceiveReportRequest(client, request);
} }
void GameServer::onNetbarRequest(cyclone::TcpConnectionPtr conn, Game::NetbaraStatusReq* request) void GameServer::onNetbarRequest(cyclone::TcpConnectionPtr conn, Game::NetbaraStatusReq* request)
+2
View File
@@ -4,6 +4,8 @@
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
srand(time(0));
//init ace interface //init ace interface
if (!AceInterface::initAceInterface()) if (!AceInterface::initAceInterface())
{ {
+2 -2
View File
@@ -199,7 +199,7 @@ std::string md5ToString(const MD5Digest& digest)
{ {
char buf[33] = { 0 }; char buf[33] = { 0 };
for (size_t i = 0; i < 16; ++i) { 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); return std::string(buf);
} }
@@ -211,7 +211,7 @@ bool string2MD5(const char* md5_string, MD5Digest& md5)
} }
for (size_t i = 0; i < 16; ++i) { for (size_t i = 0; i < 16; ++i) {
unsigned int byte; 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 return false; // Failed to parse byte
} }
md5[i] = static_cast<uint8_t>(byte); md5[i] = static_cast<uint8_t>(byte);