1
This commit is contained in:
parent
bf91b066fc
commit
d8128ddfdf
@ -1,5 +1,7 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <a8/openssl.h>
|
||||
#include <a8/timer.h>
|
||||
|
||||
@ -9,6 +11,7 @@
|
||||
#include "MSConnMgr.h"
|
||||
#include "dbengine.h"
|
||||
#include "app.h"
|
||||
#include "typeconvert.h"
|
||||
|
||||
void Player::Init()
|
||||
{
|
||||
@ -118,19 +121,54 @@ void Player::_CMFriendApplyList(f8::MsgHdr& hdr, const cs::CMFriendApplyList& ms
|
||||
{
|
||||
if (last_apply_idx_ > 0 &&
|
||||
last_apply_idx_ >= DBEngine::Instance()->GetFriendApplyCurrIdx(crc32_code)) {
|
||||
|
||||
cs::SMFriendApplyList respmsg;
|
||||
FillApplyList(msg.paging(), respmsg);
|
||||
SendMsg(respmsg);
|
||||
return;
|
||||
}
|
||||
|
||||
auto on_ok =
|
||||
[] (a8::XParams& param, const f8::DataSet* data_set)
|
||||
{
|
||||
|
||||
cs::MFPaging* paging = (cs::MFPaging*)param.param2.GetUserData();
|
||||
Player* hum = PlayerMgr::Instance()->GetPlayerByAccountId(param.sender.GetString());
|
||||
if (hum && hum->socket_handle == param.param1.GetInt()) {
|
||||
for (auto& row : *data_set) {
|
||||
FriendApply apply;
|
||||
apply.idx = a8::XValue(row[0]);
|
||||
apply.applyid = a8::XValue(row[1]);
|
||||
apply.target_id = row[2];
|
||||
apply.sender_id = row[3];
|
||||
apply.sender_nickname = row[4];
|
||||
apply.sender_avatar_url = row[5];
|
||||
apply.sender_sex = a8::XValue(row[6]);
|
||||
apply.sender_data_version1 = a8::XValue(row[7]);
|
||||
hum->apply_list_.push_back(apply);
|
||||
if (apply.idx > hum->last_apply_idx_) {
|
||||
hum->last_apply_idx_ = apply.idx;
|
||||
}
|
||||
}
|
||||
cs::SMFriendApplyList respmsg;
|
||||
hum->FillApplyList(*paging, respmsg);
|
||||
hum->SendMsg(respmsg);
|
||||
}
|
||||
delete paging;
|
||||
};
|
||||
auto on_error =
|
||||
[] (a8::XParams& param, int error_code, const std::string& error_msg)
|
||||
{
|
||||
|
||||
cs::MFPaging* paging = (cs::MFPaging*)param.param2.GetUserData();
|
||||
Player* hum = PlayerMgr::Instance()->GetPlayerByAccountId(param.sender.GetString());
|
||||
if (hum && hum->socket_handle == param.param1.GetInt()) {
|
||||
cs::SMFriendApplyList respmsg;
|
||||
hum->FillApplyList(*paging, respmsg);
|
||||
hum->SendMsg(respmsg);
|
||||
}
|
||||
delete paging;
|
||||
};
|
||||
|
||||
cs::MFPaging* paging_copy = nullptr;
|
||||
*paging_copy = msg.paging();
|
||||
a8::XObject conn_info = DBEngine::Instance()->GetConnInfo(crc32_code);
|
||||
DBEngine::Instance()->
|
||||
ExecAsyncScript(
|
||||
@ -142,13 +180,22 @@ void Player::_CMFriendApplyList(f8::MsgHdr& hdr, const cs::CMFriendApplyList& ms
|
||||
last_apply_idx_,
|
||||
account_id
|
||||
},
|
||||
a8::XParams(),
|
||||
a8::XParams()
|
||||
.SetSender(account_id)
|
||||
.SetParam1(hdr.socket_handle)
|
||||
.SetParam2(paging_copy),
|
||||
on_ok,
|
||||
on_error,
|
||||
crc32_code
|
||||
);
|
||||
}
|
||||
|
||||
void Player::_CMFriendAgree(f8::MsgHdr& hdr, const cs::CMFriendAgree& msg)
|
||||
{
|
||||
cs::SMFriendAgree respmsg;
|
||||
SendMsg(respmsg);
|
||||
}
|
||||
|
||||
void Player::_CMFriendIgnore(f8::MsgHdr& hdr, const cs::CMFriendIgnore& msg)
|
||||
{
|
||||
cs::SMFriendIgnore respmsg;
|
||||
@ -395,3 +442,17 @@ Friend* Player::GetFriendById(const std::string& friend_id)
|
||||
auto itr = friend_hash_.find(friend_id);
|
||||
return itr != friend_hash_.end() ? &itr->second : nullptr;
|
||||
}
|
||||
|
||||
void Player::FillApplyList(const cs::MFPaging& paging, cs::SMFriendApplyList& respmsg)
|
||||
{
|
||||
int i = 0;
|
||||
int start = paging.curr_page() * paging.page_size();
|
||||
for (const FriendApply& apply : apply_list_) {
|
||||
if (i >= start && i < start + paging.page_size()) {
|
||||
TypeConvert::Convert(apply, *respmsg.add_apply_list());
|
||||
}
|
||||
++i;
|
||||
}
|
||||
*respmsg.mutable_paging() = paging;
|
||||
respmsg.mutable_paging()->set_total_page(ceil(i / paging.page_size()));
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ class Player
|
||||
void _CMFriendList(f8::MsgHdr& hdr, const cs::CMFriendList& msg);
|
||||
void _CMFriendApply(f8::MsgHdr& hdr, const cs::CMFriendApply& msg);
|
||||
void _CMFriendApplyList(f8::MsgHdr& hdr, const cs::CMFriendApplyList& msg);
|
||||
void _CMFriendAgree(f8::MsgHdr& hdr, const cs::CMFriendAgree& msg);
|
||||
void _CMFriendIgnore(f8::MsgHdr& hdr, const cs::CMFriendIgnore& msg);
|
||||
void _CMFriendDelete(f8::MsgHdr& hdr, const cs::CMFriendDelete& msg);
|
||||
void _CMFriendBlackList(f8::MsgHdr& hdr, const cs::CMFriendBlackList& msg);
|
||||
@ -66,6 +67,7 @@ private:
|
||||
void ForwardGroupCMMsg(f8::MsgHdr& hdr, long long hash_code);
|
||||
void SaveToDB();
|
||||
Friend* GetFriendById(const std::string& friend_id);
|
||||
void FillApplyList(const cs::MFPaging& paging, cs::SMFriendApplyList& respmsg);
|
||||
|
||||
private:
|
||||
bool dirty_ = false;
|
||||
@ -73,4 +75,6 @@ private:
|
||||
long long last_apply_idx_ = 0;
|
||||
|
||||
std::map<std::string, Friend> friend_hash_;
|
||||
std::map<long long, FriendApply*> apply_hash_;
|
||||
std::list<FriendApply> apply_list_;
|
||||
};
|
||||
|
12
server/imserver/typeconvert.cc
Normal file
12
server/imserver/typeconvert.cc
Normal file
@ -0,0 +1,12 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include "typeconvert.h"
|
||||
|
||||
void TypeConvert::Convert(const cs::MFFriendApply& apply_pb, FriendApply& apply)
|
||||
{
|
||||
}
|
||||
|
||||
void TypeConvert::Convert(const FriendApply& apply, cs::MFFriendApply& apply_pb)
|
||||
{
|
||||
|
||||
}
|
13
server/imserver/typeconvert.h
Normal file
13
server/imserver/typeconvert.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
namespace cs
|
||||
{
|
||||
class MFFriendApply;
|
||||
}
|
||||
|
||||
class TypeConvert
|
||||
{
|
||||
public:
|
||||
static void Convert(const cs::MFFriendApply& apply_pb, FriendApply& apply);
|
||||
static void Convert(const FriendApply& apply, cs::MFFriendApply& apply_pb);
|
||||
};
|
@ -28,3 +28,15 @@ struct Friend
|
||||
int data_version1 = 0;
|
||||
unsigned int crc32_code = 0;
|
||||
};
|
||||
|
||||
struct FriendApply
|
||||
{
|
||||
long long idx = 0;
|
||||
long long applyid = 0;
|
||||
std::string target_id;
|
||||
std::string sender_id;
|
||||
std::string sender_nickname;
|
||||
std::string sender_avatar_url;
|
||||
int sender_sex = 0;
|
||||
int sender_data_version1 = 0;
|
||||
};
|
||||
|
@ -15,6 +15,14 @@ message SMPing
|
||||
optional int32 param1 = 1;
|
||||
}
|
||||
|
||||
//分页信息
|
||||
message MFPaging
|
||||
{
|
||||
optional int64 curr_page = 1; //当前页(第一页是0)
|
||||
optional int32 page_size = 2; //每页记录数
|
||||
optional int32 total_page = 3; //总页数(服务器填充该字段)
|
||||
}
|
||||
|
||||
message MFUserInfo
|
||||
{
|
||||
optional string account_id = 1;
|
||||
@ -54,6 +62,16 @@ message MFUserDB
|
||||
repeated MFGroupMemberDB friends = 1;
|
||||
}
|
||||
|
||||
message MFFriendApply
|
||||
{
|
||||
optional int64 idx = 1;
|
||||
optional int64 applyid = 2;
|
||||
optional string account_id = 3;
|
||||
optional string nickname = 4;
|
||||
optional string avatar_url = 5;
|
||||
optional int32 sex = 6;
|
||||
}
|
||||
|
||||
//
|
||||
message CMLogin
|
||||
{
|
||||
@ -97,18 +115,21 @@ message SMFriendApply
|
||||
//获取好友申请列表
|
||||
message CMFriendApplyList
|
||||
{
|
||||
optional MFPaging paging = 1; //分页信息
|
||||
}
|
||||
//获取好友申请列表回复
|
||||
message SMFriendApplyList
|
||||
{
|
||||
optional int32 error_code = 1; //
|
||||
optional string error_msg = 2; //错误消息
|
||||
optional MFPaging paging = 3; //分页信息回传
|
||||
repeated MFFriendApply apply_list = 4; //申请加好友列表
|
||||
}
|
||||
|
||||
//同意申请
|
||||
message CMFriendAgree
|
||||
{
|
||||
optional string friend_id = 1; //好友id
|
||||
optional string applyid = 1; //applyid
|
||||
}
|
||||
//同意申请回复
|
||||
message SMFriendAgree
|
||||
|
Loading…
x
Reference in New Issue
Block a user