Compare commits
3
Commits
ae5479b583
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
315fbebc03 | ||
|
|
3127665ecb | ||
|
|
dad2b61a50 |
@@ -1,6 +1,7 @@
|
||||
set(WTL_DIR $ENV{LIBRARIES_SDK_ROOT}/wtl)
|
||||
|
||||
set(CYCLONE_DIR $ENV{CYCLONE_SDK_ROOT})
|
||||
set(cyclone_DIR $ENV{CYCLONE_SDK_ROOT}/lib/cmake/cyclone)
|
||||
find_package(cyclone REQUIRED)
|
||||
|
||||
set(RapidJSON_DIR $ENV{LIBRARIES_SDK_ROOT}/rapidjson/cmake)
|
||||
find_package(RapidJSON REQUIRED)
|
||||
|
||||
@@ -21,6 +21,9 @@ bool AceClientInterface::init()
|
||||
if(ret!= ACE_SDK_RESULT_OK)
|
||||
{
|
||||
printf(">>ACE fail to init ace sdk client, ret : %d\n", ret);
|
||||
char szTemp[256];
|
||||
snprintf(szTemp, sizeof(szTemp), "Failed to init ACE SDK client! Error code: %x", ret);
|
||||
MessageBoxA(NULL, szTemp, "Error", MB_OK | MB_ICONERROR);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -52,20 +52,14 @@ target_include_directories(aClient
|
||||
PRIVATE
|
||||
${ACE_CLIENT_DIR}/include
|
||||
${WTL_DIR}/include
|
||||
${CYCLONE_DIR}/include
|
||||
${GAME_PROTO_DIR}
|
||||
${TENCENT_NETBAR_SDK}/include
|
||||
)
|
||||
|
||||
target_link_directories(aClient
|
||||
PRIVATE
|
||||
${CYCLONE_DIR}/lib
|
||||
)
|
||||
|
||||
target_link_libraries(aClient
|
||||
PRIVATE
|
||||
aGameProto
|
||||
cyclone.lib
|
||||
cyclone::cyclone
|
||||
ws2_32.lib
|
||||
shlwapi.lib
|
||||
winmm.lib
|
||||
|
||||
@@ -14,12 +14,10 @@ protobuf_generate(
|
||||
target_include_directories(aGameProto
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
|
||||
PRIVATE
|
||||
${CYCLONE_DIR}/include
|
||||
)
|
||||
|
||||
target_link_libraries(aGameProto
|
||||
PUBLIC
|
||||
protobuf::libprotobuf
|
||||
cyclone::cyclone
|
||||
)
|
||||
|
||||
@@ -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 "";
|
||||
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×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;
|
||||
}
|
||||
@@ -1,4 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
struct GameClient;
|
||||
namespace Game
|
||||
{
|
||||
class GameReportReq;
|
||||
}
|
||||
|
||||
std::string buildReportRequestUrl();
|
||||
class AceReportInterface
|
||||
{
|
||||
public:
|
||||
static bool onReceiveReportRequest(GameClient* client, Game::GameReportReq* request);
|
||||
};
|
||||
|
||||
@@ -41,22 +41,18 @@ add_executable(aServer
|
||||
|
||||
target_include_directories(aServer
|
||||
PRIVATE
|
||||
${CYCLONE_DIR}/include
|
||||
${ACE_SERVER_DIR}/include
|
||||
${RAPIDJSON_INCLUDE_DIRS}
|
||||
${GAME_PROTO_DIR}
|
||||
)
|
||||
|
||||
target_link_directories(aServer
|
||||
PRIVATE
|
||||
${CYCLONE_DIR}/lib
|
||||
../../libTinyEncrypt
|
||||
)
|
||||
|
||||
target_link_libraries(aServer
|
||||
PRIVATE
|
||||
aGameProto
|
||||
cyclone.lib
|
||||
cyclone::cyclone
|
||||
ws2_32.lib
|
||||
shlwapi.lib
|
||||
CURL::libcurl_static
|
||||
libTinyEncrypt
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
@@ -295,5 +297,5 @@ void GameServer::onNetbarRequest(cyclone::TcpConnectionPtr conn, Game::NetbaraSt
|
||||
GameClient* client = getClient(conn->get_id());
|
||||
assert(client);
|
||||
|
||||
NetbarInterface::onReceiveNetbarReportRequest(client, request);
|
||||
NetbarInterface::onReceiveNetbarStatusRequest(client, request);
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ std::string buildRequestUrl()
|
||||
return "http://api-test.netbar.itrpc.woa.com/netbar.cafe.rewards.rewards/Rewards";
|
||||
}
|
||||
|
||||
bool NetbarInterface::onReceiveNetbarReportRequest(GameClient* client, Game::NetbaraStatusReq* request)
|
||||
bool NetbarInterface::onReceiveNetbarStatusRequest(GameClient* client, Game::NetbaraStatusReq* request)
|
||||
{
|
||||
std::string requestBody = buildRequestJson(client, request);
|
||||
std::string requestUrl = buildRequestUrl();
|
||||
@@ -79,7 +79,7 @@ bool NetbarInterface::onReceiveNetbarReportRequest(GameClient* client, Game::Net
|
||||
|
||||
if(retCode != 0)
|
||||
{
|
||||
CY_LOG(cyclone::L_ERROR, "NetbarInterface::onReceiveNetbarReportRequest curlRequest failed, retCode=%d", retCode);
|
||||
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);
|
||||
|
||||
@@ -9,5 +9,5 @@ namespace Game
|
||||
class NetbarInterface
|
||||
{
|
||||
public:
|
||||
static bool onReceiveNetbarReportRequest(GameClient* client, Game::NetbaraStatusReq* request);
|
||||
static bool onReceiveNetbarStatusRequest(GameClient* client, Game::NetbaraStatusReq* request);
|
||||
};
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
srand(time(0));
|
||||
|
||||
//init ace interface
|
||||
if (!AceInterface::initAceInterface())
|
||||
{
|
||||
|
||||
@@ -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<uint8_t>(byte);
|
||||
|
||||
Reference in New Issue
Block a user