Refactoring

This commit is contained in:
Changhua 2025-01-31 11:06:26 +08:00
parent 065db1d236
commit da4dcec8bc
3 changed files with 94 additions and 83 deletions

View File

@ -1,113 +1,109 @@
#include "framework.h"
#include <sstream>
#include <vector>
#pragma execution_character_set("utf-8")
#include "chatroom_mgmt.h"
#include "fill_response.h"
#include "log.hpp"
#include "pb_util.h"
#include "util.h"
using namespace std;
extern QWORD g_WeChatWinDllAddr;
namespace chatroom_mgmt
{
#define OS_GET_CHATROOM_MGR 0x1B83BD0
#define OS_ADD_MEMBERS 0x2155100
#define OS_DELETE_MEMBERS 0x2155740
#define OS_INVITE_MEMBERS 0x2154AE0
typedef QWORD (*GetChatRoomMgr_t)();
typedef QWORD (*AddMemberToChatRoom_t)(QWORD, QWORD, QWORD, QWORD);
typedef QWORD (*DelMemberFromChatRoom_t)(QWORD, QWORD, QWORD);
typedef QWORD (*InviteMemberToChatRoom_t)(QWORD, QWORD, QWORD, QWORD);
using get_chatroom_mgr_t = QWORD (*)();
using add_member_to_chatroom_t = QWORD (*)(QWORD, QWORD, QWORD, QWORD);
using del_member_from_chatroom_t = QWORD (*)(QWORD, QWORD, QWORD);
using invite_member_to_chatroom_t = QWORD (*)(QWORD, QWORD, QWORD, QWORD);
int AddChatroomMember(string roomid, string wxids)
static vector<WxString> parse_wxids(const string &wxids)
{
int status = -1;
vector<WxString> wx_members;
wstringstream wss(String2Wstring(wxids));
wstring wstr;
while (getline(wss, wstr, L',')) {
wx_members.emplace_back(wstr);
}
return wx_members;
}
int add_chatroom_member(const string &roomid, const string &wxids)
{
if (roomid.empty() || wxids.empty()) {
LOG_ERROR("Empty roomid or wxids.");
return status;
return -1;
}
GetChatRoomMgr_t GetChatRoomMgr = (GetChatRoomMgr_t)(g_WeChatWinDllAddr + OS_GET_CHATROOM_MGR);
AddMemberToChatRoom_t AddMembers = (AddMemberToChatRoom_t)(g_WeChatWinDllAddr + OS_ADD_MEMBERS);
get_chatroom_mgr_t get_chatroom_mgr
= reinterpret_cast<get_chatroom_mgr_t>(g_WeChatWinDllAddr + OS_GET_CHATROOM_MGR);
add_member_to_chatroom_t add_members
= reinterpret_cast<add_member_to_chatroom_t>(g_WeChatWinDllAddr + OS_ADD_MEMBERS);
vector<wstring> vMembers;
vector<WxString> vWxMembers;
wstringstream wss(String2Wstring(wxids));
while (wss.good()) {
wstring wstr;
getline(wss, wstr, L',');
vMembers.push_back(wstr);
WxString wxMember(vMembers.back());
vWxMembers.push_back(wxMember);
vector<WxString> wx_members = parse_wxids(wxids);
WxString *p_wx_roomid = NewWxStringFromStr(roomid);
QWORD p_members = reinterpret_cast<QWORD>(&wx_members.front());
return static_cast<int>(add_members(get_chatroom_mgr(), p_members, reinterpret_cast<QWORD>(p_wx_roomid), 0));
}
QWORD temp[2] = { 0 };
WxString *pWxRoomid = NewWxStringFromStr(roomid);
QWORD pMembers = (QWORD) & ((RawVector_t *)&vWxMembers)->start;
QWORD mgr = GetChatRoomMgr();
status = (int)AddMembers(mgr, pMembers, (QWORD)pWxRoomid, (QWORD)temp);
return status;
}
int DelChatroomMember(string roomid, string wxids)
int del_chatroom_member(const string &roomid, const string &wxids)
{
int status = -1;
if (roomid.empty() || wxids.empty()) {
LOG_ERROR("Empty roomid or wxids.");
return status;
return -1;
}
GetChatRoomMgr_t GetChatRoomMgr = (GetChatRoomMgr_t)(g_WeChatWinDllAddr + OS_GET_CHATROOM_MGR);
DelMemberFromChatRoom_t DelMembers = (DelMemberFromChatRoom_t)(g_WeChatWinDllAddr + OS_DELETE_MEMBERS);
get_chatroom_mgr_t get_chatroom_mgr
= reinterpret_cast<get_chatroom_mgr_t>(g_WeChatWinDllAddr + OS_GET_CHATROOM_MGR);
del_member_from_chatroom_t del_members
= reinterpret_cast<del_member_from_chatroom_t>(g_WeChatWinDllAddr + OS_DELETE_MEMBERS);
vector<wstring> vMembers;
vector<WxString> vWxMembers;
wstringstream wss(String2Wstring(wxids));
while (wss.good()) {
wstring wstr;
getline(wss, wstr, L',');
vMembers.push_back(wstr);
WxString wxMember(vMembers.back());
vWxMembers.push_back(wxMember);
vector<WxString> wx_members = parse_wxids(wxids);
WxString *p_wx_roomid = NewWxStringFromStr(roomid);
QWORD p_members = reinterpret_cast<QWORD>(&wx_members.front());
return static_cast<int>(del_members(get_chatroom_mgr(), p_members, reinterpret_cast<QWORD>(p_wx_roomid)));
}
WxString *pWxRoomid = NewWxStringFromStr(roomid);
QWORD pMembers = (QWORD) & ((RawVector_t *)&vWxMembers)->start;
QWORD mgr = GetChatRoomMgr();
status = (int)DelMembers(mgr, pMembers, (QWORD)pWxRoomid);
return status;
}
int InviteChatroomMember(string roomid, string wxids)
int invite_chatroom_member(const string &roomid, const string &wxids)
{
int status = -1;
if (roomid.empty() || wxids.empty()) {
LOG_ERROR("Empty roomid or wxids.");
return status;
return -1;
}
InviteMemberToChatRoom_t InviteMembers = (InviteMemberToChatRoom_t)(g_WeChatWinDllAddr + OS_INVITE_MEMBERS);
invite_member_to_chatroom_t invite_members
= reinterpret_cast<invite_member_to_chatroom_t>(g_WeChatWinDllAddr + OS_INVITE_MEMBERS);
vector<wstring> vMembers;
vector<WxString> vWxMembers;
wstringstream wss(String2Wstring(wxids));
while (wss.good()) {
wstring wstr;
getline(wss, wstr, L',');
vMembers.push_back(wstr);
WxString wxMember(vMembers.back());
vWxMembers.push_back(wxMember);
}
QWORD temp[2] = { 0 };
wstring wsRoomid = String2Wstring(roomid);
WxString *pWxRoomid = NewWxStringFromWstr(wsRoomid);
QWORD pMembers = (QWORD) & ((RawVector_t *)&vWxMembers)->start;
vector<WxString> wx_members = parse_wxids(wxids);
WxString *p_wx_roomid = NewWxStringFromStr(roomid);
QWORD p_members = reinterpret_cast<QWORD>(&wx_members.front());
status = (int)InviteMembers((QWORD)wsRoomid.c_str(), pMembers, (QWORD)pWxRoomid, (QWORD)temp);
return status;
return static_cast<int>(invite_members(reinterpret_cast<QWORD>(p_wx_roomid->c_str()), p_members,
reinterpret_cast<QWORD>(p_wx_roomid), 0));
}
bool rpc_add_chatroom_member(const string &roomid, const string &wxids, uint8_t *out, size_t *len)
{
return fill_response<Functions_FUNC_ADD_ROOM_MEMBERS>(
out, len, [&](Response &rsp) { rsp.msg.status = add_chatroom_member(roomid, wxids); });
}
bool rpc_del_chatroom_member(const string &roomid, const string &wxids, uint8_t *out, size_t *len)
{
return fill_response<Functions_FUNC_DEL_ROOM_MEMBERS>(
out, len, [&](Response &rsp) { rsp.msg.status = del_chatroom_member(roomid, wxids); });
}
bool rpc_invite_chatroom_member(const string &roomid, const string &wxids, uint8_t *out, size_t *len)
{
return fill_response<Functions_FUNC_INV_ROOM_MEMBERS>(
out, len, [&](Response &rsp) { rsp.msg.status = invite_chatroom_member(roomid, wxids); });
}
} // namespace chatroom_mgmt

View File

@ -2,6 +2,21 @@
#include <string>
int AddChatroomMember(std::string roomid, std::string wxids);
int DelChatroomMember(std::string roomid, std::string wxids);
int InviteChatroomMember(std::string roomid, std::string wxids);
namespace chatroom_mgmt
{
// 添加成员到群聊
int add_chatroom_member(const std::string &roomid, const std::string &wxids);
// 从群聊中移除成员
int del_chatroom_member(const std::string &roomid, const std::string &wxids);
// 邀请成员加入群聊
int invite_chatroom_member(const std::string &roomid, const std::string &wxids);
// RPC 方法
bool rpc_add_chatroom_member(const std::string &roomid, const std::string &wxids, uint8_t *out, size_t *len);
bool rpc_del_chatroom_member(const std::string &roomid, const std::string &wxids, uint8_t *out, size_t *len);
bool rpc_invite_chatroom_member(const std::string &roomid, const std::string &wxids, uint8_t *out, size_t *len);
} // namespace chatroom_mgmt

View File

@ -465,7 +465,7 @@ static bool func_add_room_members(char *roomid, char *wxids, uint8_t *out, size_
LOG_ERROR("Empty roomid or wxids.");
rsp.msg.status = -1;
} else {
rsp.msg.status = AddChatroomMember(roomid, wxids);
rsp.msg.status = chatroom_mgmt::add_chatroom_member(roomid, wxids);
}
});
}
@ -477,7 +477,7 @@ static bool func_del_room_members(char *roomid, char *wxids, uint8_t *out, size_
LOG_ERROR("Empty roomid or wxids.");
rsp.msg.status = -1;
} else {
rsp.msg.status = DelChatroomMember(roomid, wxids);
rsp.msg.status = chatroom_mgmt::del_chatroom_member(roomid, wxids);
}
});
}
@ -489,7 +489,7 @@ static bool func_invite_room_members(char *roomid, char *wxids, uint8_t *out, si
LOG_ERROR("Empty roomid or wxids.");
rsp.msg.status = -1;
} else {
rsp.msg.status = InviteChatroomMember(roomid, wxids);
rsp.msg.status = chatroom_mgmt::invite_chatroom_member(roomid, wxids);
}
});
}