This commit is contained in:
aozhiwei 2020-12-09 11:36:03 +08:00
parent 497cbd5379
commit 0906499a4a
4 changed files with 76 additions and 7 deletions

View File

@ -54,6 +54,12 @@ void ChatMgr::ProcWorldChat(Player* hum, const cs::CMSendChatMsg& msg)
cs::MFChatMsg* p = new cs::MFChatMsg();
p->set_msg_uuid(world_msg_id_);
hum->FillMFUserInfo(p->mutable_sender());
//p->set_receiver(world_msg_id_);
p->set_chat_channel(msg.chat_channel());
p->set_msg_type(msg.msg_type());
p->set_msg_body(msg.msg_body());
p->set_send_time(time(nullptr));
world_msgrec_.curr_id = world_msg_id_;
world_msgrec_.msg_list.push_back(p);
@ -71,6 +77,10 @@ void ChatMgr::ProcPrivateChat(Player* hum, const cs::CMSendChatMsg& msg)
cs::MFChatMsg* p = new cs::MFChatMsg();
p->set_msg_uuid(private_msg_id_);
p->set_chat_channel(msg.chat_channel());
p->set_msg_type(msg.msg_type());
p->set_msg_body(msg.msg_body());
p->set_send_time(time(nullptr));
ChatMgr::Instance()->SyncPrivateChatMsg(hum);
Player* target_hum = PlayerMgr::Instance()->GetPlayerByAccountId(msg.target());
@ -81,11 +91,27 @@ void ChatMgr::ProcPrivateChat(Player* hum, const cs::CMSendChatMsg& msg)
void ChatMgr::ProcGuildChat(Player* hum, const cs::CMSendChatMsg& msg)
{
if (hum->GuildId() == 0) {
return;
}
++guild_msg_id_;
cs::MFChatMsg* p = new cs::MFChatMsg();
p->set_msg_uuid(guild_msg_id_);
p->set_chat_channel(msg.chat_channel());
p->set_msg_type(msg.msg_type());
p->set_msg_body(msg.msg_body());
p->set_send_time(time(nullptr));
auto itr = guild_msgrec_.find(hum->GuildId());
if (itr != guild_msgrec_.end()) {
itr->second.msg_list.push_back(p);
itr->second.PopAndDelete(50);
} else {
ChatMsgRec msgrec;
msgrec.curr_id = guild_msg_id_;
guild_msgrec_[hum->GuildId()] = msgrec;
}
Guild* guild = GuildMgr::Instance()->GetGuild(hum->GuildId());
if (guild) {
guild->TraverseMember
@ -123,12 +149,30 @@ void ChatMgr::SyncWorldChatMsg(Player* hum)
} else {
hum->MarkNewMsg();
}
}
void ChatMgr::SyncPrivateChatMsg(Player* hum)
{
if (hum->chat_channel == kCCPrivate) {
ChatedUserRec* chated_user = GetChatedUser(hum->AccountId());
if (chated_user) {
cs::SMChatMsgNotify notifymsg;
auto itr = chated_user->users.find(hum->private_target);
if (itr != chated_user->users.end()) {
for (cs::MFChatMsg* chat_msg : itr->second.msg_list) {
if (chat_msg->msg_uuid() > itr->second.curr_id) {
*notifymsg.add_msg_list() = *chat_msg;
itr->second.curr_id = chat_msg->msg_uuid();
}
}
}
if (!notifymsg.msg_list().size() > 0) {
hum->SendMsg(notifymsg);
}
}
} else {
hum->MarkNewMsg();
}
}
void ChatMgr::SyncGuildChatMsg(Player* hum)

View File

@ -11,12 +11,16 @@ struct ChatMsgRec
void Pop(int max_num)
{
while (msg_list.size() > max_num) {
msg_list.erase(msg_list.begin());
}
}
void PopAndDelete(int max_num)
{
while (msg_list.size() > max_num) {
msg_list.erase(msg_list.begin());
}
}
};

View File

@ -579,6 +579,7 @@ void Player::_CMSendChatMsg(f8::MsgHdr& hdr, const cs::CMSendChatMsg& msg)
default:
return;
}
#if 0
ss::SS_IM_SendChatMsg ss_msg;
FillIMMsgConext(ss_msg.mutable_context());
ss_msg.set_chat_channel(msg.chat_channel());
@ -589,6 +590,7 @@ void Player::_CMSendChatMsg(f8::MsgHdr& hdr, const cs::CMSendChatMsg& msg)
if (friend_data) {
SendSSMsg(*friend_data, ss_msg);
}
#endif
}
void Player::_CMReadMsgAndOpenChatNotify(f8::MsgHdr& hdr, const cs::CMReadMsgAndOpenChatNotify& msg)
@ -601,7 +603,25 @@ void Player::_CMReadMsgAndOpenChatNotify(f8::MsgHdr& hdr, const cs::CMReadMsgAnd
for (auto& pair : msg.last_ids()) {
if (IsValidChatChannel(pair.key())) {
chat_last_ids_hash[pair.key()] = pair.val();
switch (pair.key()) {
case kCCWorld:
{
world_channel_last_id = pair.val();
}
break;
case kCCPrivate:
{
}
break;
case kCCGuild:
{
guild_channel_last_id = pair.val();
}
break;
default:
break;
}
}
}
}
@ -1516,7 +1536,9 @@ void Player::SaveToDB(a8::XParams param, f8::AsyncDBOnOkFunc on_ok, f8::AsyncDBO
void Player::MarkNewMsg()
{
cs::SMUpdateChatRedPointNotify msg;
ChatMgr::Instance()->FillSMUpdateChatRedPointNotify(this, msg);
SendMsg(msg);
}
Friend* Player::GetFriendById(const std::string& friend_id)

View File

@ -26,7 +26,6 @@ class Player
int chat_channel = -1;
std::string private_target;
std::map<int, long long> chat_last_ids_hash;
long long world_channel_last_id = 0;
long long guild_channel_last_id = 0;