添加黑名单功能
This commit is contained in:
parent
a5d5af84db
commit
769e40f714
@ -48,6 +48,7 @@ const char* const EVENT_FRIEND_DELETE = "friend.delete";
|
||||
const int MAX_INSTANCE_ID = 1023;
|
||||
|
||||
const int MAX_FRIEND_NUM = 30;
|
||||
const int MAX_BLACKLIST_NUM = 10;
|
||||
const int DAILY_JOIN_FRIEND_TIMES = 100;
|
||||
const int DAILY_APPLY_FRIEND_TIMES = 100;
|
||||
|
||||
|
@ -76,6 +76,11 @@ void Player::Deserialize(const ss::MFUserDB& user_db)
|
||||
TypeConvert::Convert(friend_db.base_data(), friendobj->base_data);
|
||||
AddFriend(friendobj);
|
||||
}
|
||||
for (auto& friend_db : user_db.black_list()) {
|
||||
Friend* friendobj = new Friend;
|
||||
TypeConvert::Convert(friend_db.base_data(), friendobj->base_data);
|
||||
AddBlackList(friendobj);
|
||||
}
|
||||
role_data.today_apply_times = user_db.role_data().today_apply_times();
|
||||
role_data.save_count = user_db.role_data().save_count();
|
||||
role_data.last_save_time = user_db.role_data().last_save_time();
|
||||
@ -87,6 +92,10 @@ void Player::Serialize(ss::MFUserDB& user_db)
|
||||
auto p = user_db.add_friends();
|
||||
TypeConvert::Convert(pair.second->base_data, *(p->mutable_base_data()));
|
||||
}
|
||||
for (auto& pair : black_hash_) {
|
||||
auto p = user_db.add_black_list();
|
||||
TypeConvert::Convert(pair.second->base_data, *(p->mutable_base_data()));
|
||||
}
|
||||
user_db.mutable_role_data()->set_today_apply_times(role_data.today_apply_times);
|
||||
user_db.mutable_role_data()->set_save_count(role_data.save_count);
|
||||
user_db.mutable_role_data()->set_last_save_time(role_data.last_save_time);
|
||||
@ -345,16 +354,54 @@ void Player::_CMFriendDelete(f8::MsgHdr& hdr, const cs::CMFriendDelete& msg)
|
||||
|
||||
void Player::_CMFriendBlackList(f8::MsgHdr& hdr, const cs::CMFriendBlackList& msg)
|
||||
{
|
||||
PushBlackList();
|
||||
}
|
||||
|
||||
void Player::_CMFriendAddBlack(f8::MsgHdr& hdr, const cs::CMFriendAddBlack& msg)
|
||||
{
|
||||
|
||||
if (black_hash_.size() >= MAX_BLACKLIST_NUM) {
|
||||
ShowErrorMsg("添加失败,黑名单已满");
|
||||
return;
|
||||
}
|
||||
Friend* p = GetFriendById(msg.account_id());
|
||||
if (p) {
|
||||
if (!GetBlackListById(msg.account_id())) {
|
||||
{
|
||||
cs::SMDeleteFriendNotify notifymsg;
|
||||
notifymsg.add_user_list(msg.account_id());
|
||||
SendMsg(notifymsg);
|
||||
}
|
||||
{
|
||||
cs::SMAddBlackListNotify notifymsg;
|
||||
auto user_info = notifymsg.add_user_infos();
|
||||
TypeConvert::Convert(p->base_data, *user_info->mutable_base_data());
|
||||
TypeConvert::Convert(p->temp_custom_data, *user_info->mutable_temp_custom_data());
|
||||
SendMsg(notifymsg);
|
||||
}
|
||||
friend_hash_.erase(p->base_data.account_id);
|
||||
black_hash_[p->base_data.account_id] = p;
|
||||
MarkDirty();
|
||||
}
|
||||
ShowErrorMsg("成功添加到黑名单");
|
||||
} else {
|
||||
ShowErrorMsg("对方不是你的好友");
|
||||
}
|
||||
}
|
||||
|
||||
void Player::_CMFriendDeleteBlack(f8::MsgHdr& hdr, const cs::CMFriendDeleteBlack& msg)
|
||||
{
|
||||
|
||||
Friend* friend_data = GetBlackListById(msg.account_id());
|
||||
if (friend_data) {
|
||||
{
|
||||
cs::SMDeleteBlackListNotify notifymsg;
|
||||
notifymsg.add_user_list(msg.account_id());
|
||||
SendMsg(notifymsg);
|
||||
}
|
||||
PlayerMgr::Instance()->UnWatchPlayer(friend_data);
|
||||
black_hash_.erase(friend_data->base_data.account_id);
|
||||
A8_SAFE_DELETE(friend_data);
|
||||
MarkDirty();
|
||||
}
|
||||
}
|
||||
|
||||
void Player::_CMQueryUserStatus(f8::MsgHdr& hdr, const cs::CMQueryUserStatus& msg)
|
||||
@ -640,6 +687,15 @@ void Player::FillFriendList(::google::protobuf::RepeatedPtrField< ::cs::MFUserIn
|
||||
}
|
||||
}
|
||||
|
||||
void Player::FillBlackList(::google::protobuf::RepeatedPtrField< ::cs::MFUserInfo >* black_list)
|
||||
{
|
||||
for (auto& pair : black_hash_) {
|
||||
auto p = black_list->Add();
|
||||
TypeConvert::Convert(pair.second->base_data, *(p->mutable_base_data()));
|
||||
TypeConvert::Convert(pair.second->temp_custom_data, *(p->mutable_temp_custom_data()));
|
||||
}
|
||||
}
|
||||
|
||||
void Player::FillIMMsgConext(ss::MFIMMsgConext* context)
|
||||
{
|
||||
FillMFUserInfo(context->mutable_user_info());
|
||||
@ -728,6 +784,12 @@ Friend* Player::GetFriendById(const std::string& friend_id)
|
||||
return itr != friend_hash_.end() ? itr->second : nullptr;
|
||||
}
|
||||
|
||||
Friend* Player::GetBlackListById(const std::string& friend_id)
|
||||
{
|
||||
auto itr = black_hash_.find(friend_id);
|
||||
return itr != black_hash_.end() ? itr->second : nullptr;
|
||||
}
|
||||
|
||||
void Player::FillApplyList(const cs::MFPaging& paging, cs::SMFriendApplyList& respmsg)
|
||||
{
|
||||
RemoveHandledApply();
|
||||
@ -852,6 +914,24 @@ int Player::AddFriend(Friend* friendobj)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Player::AddBlackList(Friend* friendobj)
|
||||
{
|
||||
if (friendobj->base_data.account_id == AccountId()) {
|
||||
return;
|
||||
}
|
||||
if (!GetFriendById(friendobj->base_data.account_id)) {
|
||||
INIT_LIST_HEAD(&friendobj->watch_node);
|
||||
friendobj->crc32_code = a8::openssl::Crc32
|
||||
(
|
||||
(unsigned char*)friendobj->base_data.account_id.data(),
|
||||
friendobj->base_data.account_id.size()
|
||||
);
|
||||
friendobj->hum = this;
|
||||
black_hash_[friendobj->base_data.account_id] = friendobj;
|
||||
PlayerMgr::Instance()->WatchPlayer(friendobj);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::RemoveFriend(const std::string& account_id, bool need_sync)
|
||||
{
|
||||
Friend* friendobj = GetFriendById(account_id);
|
||||
@ -930,11 +1010,13 @@ void Player::InternalUpdateUserInfo()
|
||||
|
||||
void Player::NotifyUserInfoUpdate(Friend* friend_data)
|
||||
{
|
||||
cs::SMUserInfoUpdate msg;
|
||||
auto p = msg.add_user_infos();
|
||||
TypeConvert::Convert(friend_data->base_data, *p->mutable_base_data());
|
||||
TypeConvert::Convert(friend_data->temp_custom_data, *p->mutable_temp_custom_data());
|
||||
SendMsg(msg);
|
||||
if (GetFriendById(friend_data->base_data.account_id)) {
|
||||
cs::SMUserInfoUpdate msg;
|
||||
auto p = msg.add_user_infos();
|
||||
TypeConvert::Convert(friend_data->base_data, *p->mutable_base_data());
|
||||
TypeConvert::Convert(friend_data->temp_custom_data, *p->mutable_temp_custom_data());
|
||||
SendMsg(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::PushFriendList()
|
||||
@ -944,6 +1026,13 @@ void Player::PushFriendList()
|
||||
SendMsg(respmsg);
|
||||
}
|
||||
|
||||
void Player::PushBlackList()
|
||||
{
|
||||
cs::SMFriendBlackList respmsg;
|
||||
FillBlackList(respmsg.mutable_black_list());
|
||||
SendMsg(respmsg);
|
||||
}
|
||||
|
||||
void Player::SyncOtherFriend()
|
||||
{
|
||||
cs::SMUserInfoUpdate msg;
|
||||
@ -1339,3 +1428,10 @@ void Player::QueryUserFromDB()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Player::ShowErrorMsg(const std::string& msg)
|
||||
{
|
||||
cs::SMShowErrorMsg notifymsg;
|
||||
notifymsg.set_msg(msg);
|
||||
SendMsg(notifymsg);
|
||||
}
|
||||
|
@ -112,9 +112,11 @@ class Player
|
||||
|
||||
private:
|
||||
void FillFriendList(::google::protobuf::RepeatedPtrField< ::cs::MFUserInfo >* friend_list);
|
||||
void FillBlackList(::google::protobuf::RepeatedPtrField< ::cs::MFUserInfo >* black_list);
|
||||
void ForwardGroupCMMsg(f8::MsgHdr& hdr, long long hash_code);
|
||||
void SaveToDB(a8::XParams param, f8::AsyncDBOnOkFunc on_ok, f8::AsyncDBOnErrorFunc on_error);
|
||||
Friend* GetFriendById(const std::string& friend_id);
|
||||
Friend* GetBlackListById(const std::string& friend_id);
|
||||
void FillApplyList(const cs::MFPaging& paging, cs::SMFriendApplyList& respmsg);
|
||||
void MarkDirty();
|
||||
void OnDataVersion1Change();
|
||||
@ -124,8 +126,10 @@ private:
|
||||
::google::protobuf::Message& msg);
|
||||
void InternalUpdateUserInfo();
|
||||
int AddFriend(Friend* friendobj);
|
||||
void AddBlackList(Friend* friendobj);
|
||||
void RemoveFriend(const std::string& account_id, bool need_sync);
|
||||
void PushFriendList();
|
||||
void PushBlackList();
|
||||
void SyncOtherFriend();
|
||||
void ProcessEventTimerFunc();
|
||||
void OnFetchEvent(const f8::DataSet* data_set);
|
||||
@ -143,7 +147,7 @@ private:
|
||||
void CombineRepeatApply();
|
||||
void QueryUserOnline(std::vector<std::string> account_ids);
|
||||
void QueryUserFromDB();
|
||||
|
||||
void ShowErrorMsg(const std::string& msg);
|
||||
|
||||
private:
|
||||
bool dirty_ = false;
|
||||
|
@ -133,15 +133,9 @@ void PlayerMgr::_SS_IM_PushUserOnlineState(f8::MsgHdr& hdr, const ss::SS_IM_Push
|
||||
if (itr != watch_players_.end()) {
|
||||
struct Friend *node, *tmp;
|
||||
list_for_each_entry_safe(node, tmp, &itr->second, watch_node) {
|
||||
#if 0
|
||||
if (!node->base_data.online) {
|
||||
#endif
|
||||
TypeConvert::Convert(user_info.base_data(), node->base_data);
|
||||
TypeConvert::Convert(user_info.temp_custom_data(), node->temp_custom_data);
|
||||
node->hum->NotifyUserInfoUpdate(node);
|
||||
#if 0
|
||||
}
|
||||
#endif
|
||||
TypeConvert::Convert(user_info.base_data(), node->base_data);
|
||||
TypeConvert::Convert(user_info.temp_custom_data(), node->temp_custom_data);
|
||||
node->hum->NotifyUserInfoUpdate(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -204,16 +198,6 @@ void PlayerMgr::UnWatchPlayer(Friend* friend_data)
|
||||
if (!list_empty(&friend_data->watch_node)) {
|
||||
list_del_init(&friend_data->watch_node);
|
||||
}
|
||||
#if 0
|
||||
{
|
||||
auto itr = watch_players_.find(friend_data->base_data.account_id);
|
||||
if (itr != watch_players_.end()) {
|
||||
if (list_empty(&itr->second)) {
|
||||
watch_players_.erase(itr);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int PlayerMgr::OnlineNum()
|
||||
@ -529,3 +513,4 @@ void PlayerMgr::OnClientSocketDisconnect(int socket_handle)
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,7 @@ message MFUserDB
|
||||
{
|
||||
repeated MFFriendDB friends = 1;
|
||||
optional MFRole role_data = 2;
|
||||
repeated MFFriendDB black_list = 3;
|
||||
}
|
||||
|
||||
message SS_WSP_SocketDisconnect
|
||||
|
Loading…
x
Reference in New Issue
Block a user