This commit is contained in:
aozhiwei 2020-12-13 13:56:19 +08:00
parent c671cf1e78
commit c3613860be
2 changed files with 48 additions and 69 deletions

View File

@ -8,6 +8,13 @@
#include "typeconvert.h"
#include "metamgr.h"
struct ChatedUserRec
{
bool has_unread_msg = false;
bool dirty = false;
std::map<std::string, ChatMsgRec> users;
};
void ChatMsgRec::Pop(size_t max_num)
{
while (msg_list.size() > max_num) {
@ -77,12 +84,7 @@ void ChatMgr::FillSMUpdatePrivateChatRedPointNotify(Player* hum,
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_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));
FillMFChatMsg(p, hum, ++world_msg_id_, msg.chat_channel(), msg.msg_type(), msg.msg_body());
world_msgrec_.curr_id = world_msg_id_;
world_msgrec_.msg_list.push_back(p);
@ -104,15 +106,7 @@ void ChatMgr::ProcPrivateChat(Player* hum, const cs::CMSendChatMsg& msg)
return;
}
cs::MFChatMsg* p = new cs::MFChatMsg();
hum->FillMFUserInfo(p->mutable_sender());
{
TypeConvert::Convert(target->base_data, *p->mutable_receiver()->mutable_base_data());
TypeConvert::Convert(target->temp_custom_data, *p->mutable_receiver()->mutable_temp_custom_data());
}
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));
FillMFChatMsg(p, hum, 0, msg.chat_channel(), msg.msg_type(), msg.msg_body());
AddChatedUser(hum->AccountId(), msg.target(), p, hum->IncDBPrivateChatLastId());
ChatMgr::Instance()->SyncPrivateChatMsg(hum);
@ -133,12 +127,7 @@ void ChatMgr::ProcGuildChat(Player* hum, const cs::CMSendChatMsg& msg)
++guild_msg_id_;
cs::MFChatMsg* p = new cs::MFChatMsg();
p->set_msg_uuid(guild_msg_id_);
hum->FillMFUserInfo(p->mutable_sender());
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));
FillMFChatMsg(p, hum, ++guild_msg_id_, msg.chat_channel(), msg.msg_type(), msg.msg_body());
auto itr = guild_msgrec_.find(hum->GuildId());
if (itr != guild_msgrec_.end()) {
@ -166,16 +155,8 @@ void ChatMgr::ProcGuildChat(Player* hum, const cs::CMSendChatMsg& msg)
void ChatMgr::ProcTeamChat(Player* hum, const cs::CMSendChatMsg& msg)
{
++temp_msg_id_;
cs::MFChatMsg* p = new cs::MFChatMsg();
p->set_msg_uuid(temp_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));
FillMFChatMsg(p, hum, ++temp_msg_id_, msg.chat_channel(), msg.msg_type(), msg.msg_body());
cs::SMChatMsgNotify notifymsg;
*notifymsg.add_msg_list() = *p;
@ -190,15 +171,8 @@ void ChatMgr::ProcTeamChat(Player* hum, const cs::CMSendChatMsg& msg)
void ChatMgr::ProcBigHornChat(Player* hum, const cs::CMSendChatMsg& msg)
{
++temp_msg_id_;
cs::MFChatMsg* p = new cs::MFChatMsg();
p->set_msg_uuid(temp_msg_id_);
hum->FillMFUserInfo(p->mutable_sender());
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));
FillMFChatMsg(p, hum, ++temp_msg_id_, msg.chat_channel(), msg.msg_type(), msg.msg_body());
cs::SMChatMsgNotify notifymsg;
*notifymsg.add_msg_list() = *p;
@ -224,16 +198,8 @@ void ChatMgr::ProcBigHornChat(Player* hum, const cs::CMSendChatMsg& msg)
void ChatMgr::ProcLoopMsgChat(Player* hum, const cs::CMSendChatMsg& msg)
{
++temp_msg_id_;
cs::MFChatMsg* p = new cs::MFChatMsg();
p->set_msg_uuid(temp_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));
FillMFChatMsg(p, hum, ++temp_msg_id_, msg.chat_channel(), msg.msg_type(), msg.msg_body());
cs::SMChatMsgNotify notifymsg;
*notifymsg.add_msg_list() = *p;
@ -248,7 +214,7 @@ void ChatMgr::ProcLoopMsgChat(Player* hum, const cs::CMSendChatMsg& msg)
ChatedUserRec* ChatMgr::GetChatedUser(const std::string& account_id)
{
auto itr = private_chated_users_.find(account_id);
return itr != private_chated_users_.end() ? &itr->second : nullptr;
return itr != private_chated_users_.end() ? itr->second : nullptr;
}
void ChatMgr::SyncWorldChatMsg(Player* hum)
@ -352,19 +318,36 @@ void ChatMgr::AddChatedUser(const std::string& sender_id, const std::string& rec
cs::MFChatMsg* chat_msg_copy = new cs::MFChatMsg;
*chat_msg_copy = *chat_msg;
chat_msg_copy->set_msg_uuid(last_id);
auto itr = private_chated_users_.find(sender_id);
if (itr == private_chated_users_.end()) {
private_chated_users_[sender_id] = ChatedUserRec();
itr = private_chated_users_.find(sender_id);
ChatedUserRec* user = nullptr;
{
auto itr = private_chated_users_.find(sender_id);
if (itr == private_chated_users_.end()) {
private_chated_users_[sender_id] = new ChatedUserRec;
itr = private_chated_users_.find(sender_id);
}
user = itr->second;
}
itr->second.dirty = false;
itr->second.has_unread_msg = true;
auto itr2 = itr->second.users.find(receiver_id);
if (itr2 == itr->second.users.end()) {
itr->second.users[receiver_id] = ChatMsgRec();
itr2 = itr->second.users.find(receiver_id);
{
user->dirty = false;
user->has_unread_msg = true;
auto itr = user->users.find(receiver_id);
if (itr == user->users.end()) {
user->users[receiver_id] = ChatMsgRec();
itr = user->users.find(receiver_id);
}
itr->second.last_id = last_id;
itr->second.msg_list.push_back(chat_msg_copy);
itr->second.PopAndDelete(50);
}
itr2->second.last_id = last_id;
itr2->second.msg_list.push_back(chat_msg_copy);
itr2->second.PopAndDelete(50);
}
void ChatMgr::FillMFChatMsg(cs::MFChatMsg* msg, Player* sender, long long msg_uuid,
int chat_channel, int msg_type, const std::string& msg_body)
{
msg->set_msg_uuid(msg_uuid);
sender->FillMFUserInfo(msg->mutable_sender());
msg->set_chat_channel(chat_channel);
msg->set_msg_type(msg_type);
msg->set_msg_body(msg_body);
msg->set_send_time(time(nullptr));
}

View File

@ -13,14 +13,8 @@ struct ChatMsgRec
void PopAndDelete(size_t max_num);
};
struct ChatedUserRec
{
bool has_unread_msg = false;
bool dirty = false;
std::map<std::string, ChatMsgRec> users;
};
class Player;
struct ChatedUserRec;
class ChatMgr : public a8::Singleton<ChatMgr>
{
private:
@ -52,6 +46,8 @@ class ChatMgr : public a8::Singleton<ChatMgr>
ChatedUserRec* GetChatedUser(const std::string& account_id);
void AddChatedUser(const std::string& sender_id, const std::string& receiver_id,
cs::MFChatMsg* chat_msg, long long last_id);
void FillMFChatMsg(cs::MFChatMsg* msg, Player* sender, long long msg_uuid,
int chat_channel, int msg_type, const std::string& msg_body);
private:
long long world_msg_id_ = 1000;
@ -59,7 +55,7 @@ class ChatMgr : public a8::Singleton<ChatMgr>
long long temp_msg_id_ = 1000;
ChatMsgRec world_msgrec_;
std::map<long long, ChatMsgRec> guild_msgrec_;
std::map<std::string, ChatedUserRec> private_chated_users_;
std::map<std::string, ChatedUserRec*> private_chated_users_;
std::map<std::string, cs::MFChatMsg*> team_msg_hash_;
ChatMsgRec bighorn_msgrec_;
ChatMsgRec loop_msgrec_;