1
This commit is contained in:
parent
3e4db8e96a
commit
fe63c678f0
@ -28,6 +28,7 @@
|
||||
#include "asynctaskmgr.h"
|
||||
#include "guildmgr.h"
|
||||
#include "metamgr.h"
|
||||
#include "chatmgr.h"
|
||||
|
||||
#include "MSConnMgr.h"
|
||||
#include "IMConnMgr.h"
|
||||
@ -112,6 +113,7 @@ bool App::Init(int argc, char* argv[])
|
||||
SyncHelper::Instance()->Init();
|
||||
AsyncTaskMgr::Instance()->Init();
|
||||
GuildMgr::Instance()->Init();
|
||||
ChatMgr::Instance()->Init();
|
||||
|
||||
a8::UdpLog::Instance()->Info("friend_imserver starting instance_id:%d pid:%d 13423",
|
||||
{
|
||||
@ -146,6 +148,7 @@ bool App::Init(int argc, char* argv[])
|
||||
void App::UnInit()
|
||||
{
|
||||
a8::XPrintf("friend_imserver terminating instance_id:%d pid:%d\n", {instance_id, getpid()});
|
||||
ChatMgr::Instance()->UnInit();
|
||||
GuildMgr::Instance()->UnInit();
|
||||
AsyncTaskMgr::Instance()->UnInit();
|
||||
SyncHelper::Instance()->UnInit();
|
||||
|
72
server/imserver/chatmgr.cc
Normal file
72
server/imserver/chatmgr.cc
Normal file
@ -0,0 +1,72 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include "chatmgr.h"
|
||||
#include "player.h"
|
||||
|
||||
void ChatMgr::Init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ChatMgr::UnInit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ChatMgr::FillSMUpdateChatRedPointNotify(Player* hum, cs::SMUpdateChatRedPointNotify& msg)
|
||||
{
|
||||
if (world_msgrec_.curr_id > hum->world_channel_last_id) {
|
||||
msg.add_has_unread_msg_channels(kCCWorld);
|
||||
}
|
||||
if (hum->GuildId() != 0) {
|
||||
auto itr = guild_msgrec_.find(hum->GuildId());
|
||||
if (itr != guild_msgrec_.end()) {
|
||||
if (itr->second.curr_id > hum->guild_channel_last_id) {
|
||||
msg.add_has_unread_msg_channels(kCCGuild);
|
||||
}
|
||||
}
|
||||
}
|
||||
ChatedUserRec* chated_user = GetChatedUser(hum->AccountId());
|
||||
if (chated_user && chated_user->has_unread_msg) {
|
||||
msg.add_has_unread_msg_channels(kCCFriend);
|
||||
}
|
||||
}
|
||||
|
||||
void ChatMgr::FillSMUpdatePrivateChatRedPointNotify(Player* hum,
|
||||
cs::SMUpdatePrivateChatRedPointNotify& msg)
|
||||
{
|
||||
ChatedUserRec* chated_user = GetChatedUser(hum->AccountId());
|
||||
if (chated_user) {
|
||||
for (auto& pair : chated_user->users) {
|
||||
if (pair.second.curr_id < pair.second.last_id) {
|
||||
msg.add_has_unread_msg_accounts(pair.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ChatMgr::ProcWorldChat(Player* hum, const cs::CMSendChatMsg& msg)
|
||||
{
|
||||
++world_msg_id_;
|
||||
cs::MFChatMsg* p = new cs::MFChatMsg();
|
||||
p->set_msg_uuid(world_msg_id_);
|
||||
world_msgrec_.curr_id = world_msg_id_;
|
||||
world_msgrec_.msg_list.push_back(p);
|
||||
// hum->
|
||||
}
|
||||
|
||||
void ChatMgr::ProcPrivateChat(Player* hum, const cs::CMSendChatMsg& msg)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ChatMgr::ProcGuildChat(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;
|
||||
}
|
47
server/imserver/chatmgr.h
Normal file
47
server/imserver/chatmgr.h
Normal file
@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include "cs_proto.pb.h"
|
||||
|
||||
struct ChatMsgRec
|
||||
{
|
||||
|
||||
long long curr_id = 0;
|
||||
long long last_id = 0;
|
||||
std::list<cs::MFChatMsg*> msg_list;
|
||||
};
|
||||
|
||||
struct ChatedUserRec
|
||||
{
|
||||
bool has_unread_msg = false;
|
||||
std::map<std::string, ChatMsgRec> users;
|
||||
};
|
||||
|
||||
class Player;
|
||||
class ChatMgr : public a8::Singleton<ChatMgr>
|
||||
{
|
||||
private:
|
||||
ChatMgr() {};
|
||||
friend class a8::Singleton<ChatMgr>;
|
||||
|
||||
public:
|
||||
void Init();
|
||||
void UnInit();
|
||||
|
||||
void FillSMUpdateChatRedPointNotify(Player* hum, cs::SMUpdateChatRedPointNotify& msg);
|
||||
void FillSMUpdatePrivateChatRedPointNotify(Player* hum, cs::SMUpdatePrivateChatRedPointNotify& msg);
|
||||
|
||||
void ProcWorldChat(Player* hum, const cs::CMSendChatMsg& msg);
|
||||
void ProcPrivateChat(Player* hum, const cs::CMSendChatMsg& msg);
|
||||
void ProcGuildChat(Player* hum, const cs::CMSendChatMsg& msg);
|
||||
|
||||
private:
|
||||
ChatedUserRec* GetChatedUser(const std::string& account_id);
|
||||
|
||||
private:
|
||||
long long private_msg_id_ = 1000;
|
||||
long long world_msg_id_ = 1000;
|
||||
ChatMsgRec world_msgrec_;
|
||||
std::map<long long, ChatMsgRec> guild_msgrec_;
|
||||
std::map<long long, cs::MFChatMsg*> private_msg_hash_;
|
||||
std::map<std::string, ChatedUserRec> private_chated_users_;
|
||||
};
|
@ -77,9 +77,9 @@ enum GuildMemberUpdateReason
|
||||
|
||||
enum ChatChannel_e
|
||||
{
|
||||
kCCWorld = 0,
|
||||
kCCFriend = 1,
|
||||
kCCGuild = 2
|
||||
kCCWorld = 1,
|
||||
kCCFriend = 2,
|
||||
kCCGuild = 3
|
||||
};
|
||||
|
||||
const char* const PROJ_NAME_FMT = "friend_imserver";
|
||||
|
@ -103,6 +103,7 @@ void HandlerMgr::RegisterNetMsgHandlers()
|
||||
|
||||
RegisterNetMsgHandler(&wsmsghandler, &Player::_CMSendChatMsg);
|
||||
RegisterNetMsgHandler(&wsmsghandler, &Player::_CMReadMsgAndOpenChatNotify);
|
||||
RegisterNetMsgHandler(&wsmsghandler, &Player::_CMSetCurrPrivateChatTarget);
|
||||
RegisterNetMsgHandler(&wsmsghandler, &Player::_CMCloseChatNotify);
|
||||
RegisterNetMsgHandler(&wsmsghandler, &Player::_CMSendCustomMsg);
|
||||
RegisterNetMsgHandler(&wsmsghandler, &Player::_CMDirtyWordCheck);
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "MSConnMgr.h"
|
||||
#include "handlermgr.h"
|
||||
#include "jsondatamgr.h"
|
||||
#include "chatmgr.h"
|
||||
|
||||
#include "ss_msgid.pb.h"
|
||||
#include "framework/cpp/httpclientpool.h"
|
||||
@ -79,6 +80,20 @@ void Player::Init()
|
||||
},
|
||||
&timer_attacher.timer_list_
|
||||
);
|
||||
a8::Timer::Instance()->AddDeadLineTimerAndAttach
|
||||
(
|
||||
1000 * 2 + (rand() % 3000),
|
||||
a8::XParams()
|
||||
.SetSender(this),
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
Player* hum = (Player*)param.sender.GetUserData();
|
||||
cs::SMUpdateChatRedPointNotify msg;
|
||||
ChatMgr::Instance()->FillSMUpdateChatRedPointNotify(hum, msg);
|
||||
hum->SendMsg(msg);
|
||||
},
|
||||
&timer_attacher.timer_list_
|
||||
);
|
||||
}
|
||||
|
||||
void Player::UnInit()
|
||||
@ -548,6 +563,22 @@ void Player::_CMFriendIdList(f8::MsgHdr& hdr, const cs::CMFriendIdList& msg)
|
||||
|
||||
void Player::_CMSendChatMsg(f8::MsgHdr& hdr, const cs::CMSendChatMsg& msg)
|
||||
{
|
||||
if (!IsValidChatChannel(msg.chat_channel())) {
|
||||
return;
|
||||
}
|
||||
switch (msg.chat_channel()) {
|
||||
case kCCWorld:
|
||||
ChatMgr::Instance()->ProcWorldChat(this, msg);
|
||||
break;
|
||||
case kCCFriend:
|
||||
ChatMgr::Instance()->ProcPrivateChat(this, msg);
|
||||
break;
|
||||
case kCCGuild:
|
||||
ChatMgr::Instance()->ProcGuildChat(this, msg);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
ss::SS_IM_SendChatMsg ss_msg;
|
||||
FillIMMsgConext(ss_msg.mutable_context());
|
||||
ss_msg.set_chat_channel(msg.chat_channel());
|
||||
@ -563,18 +594,28 @@ void Player::_CMSendChatMsg(f8::MsgHdr& hdr, const cs::CMSendChatMsg& msg)
|
||||
void Player::_CMReadMsgAndOpenChatNotify(f8::MsgHdr& hdr, const cs::CMReadMsgAndOpenChatNotify& msg)
|
||||
{
|
||||
if (IsValidChatChannel(msg.curr_channel())) {
|
||||
chat_channel_ = msg.curr_channel();
|
||||
}
|
||||
for (auto& pair : msg.last_ids()) {
|
||||
if (IsValidChatChannel(pair.key())) {
|
||||
chat_last_ids_hash_[pair.key()] = pair.val();
|
||||
chat_channel = msg.curr_channel();
|
||||
if (chat_channel == kCCFriend) {
|
||||
SyncPrivateChatRedPoint();
|
||||
}
|
||||
|
||||
for (auto& pair : msg.last_ids()) {
|
||||
if (IsValidChatChannel(pair.key())) {
|
||||
chat_last_ids_hash[pair.key()] = pair.val();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Player::_CMSetCurrPrivateChatTarget(f8::MsgHdr& hdr, const cs::CMSetCurrPrivateChatTarget& msg)
|
||||
{
|
||||
private_target = msg.private_target();
|
||||
}
|
||||
|
||||
void Player::_CMCloseChatNotify(f8::MsgHdr& hdr, const cs::CMCloseChatNotify& msg)
|
||||
{
|
||||
chat_channel_ = -1;
|
||||
chat_channel = -1;
|
||||
private_target = "";
|
||||
}
|
||||
|
||||
void Player::_CMSendCustomMsg(f8::MsgHdr& hdr, const cs::CMSendCustomMsg& msg)
|
||||
@ -2272,9 +2313,15 @@ void Player::SyncGuildNewApply(long long guild_id)
|
||||
|
||||
bool Player::IsValidChatChannel(int chat_channel)
|
||||
{
|
||||
if (chat_channel >= 0 && chat_channel < 2) {
|
||||
if (chat_channel >= kCCWorld && chat_channel <= kCCGuild) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::SyncPrivateChatRedPoint()
|
||||
{
|
||||
cs::SMUpdatePrivateChatRedPointNotify msg;
|
||||
ChatMgr::Instance()->FillSMUpdatePrivateChatRedPointNotify(this, msg);
|
||||
}
|
||||
|
@ -24,6 +24,13 @@ class Player
|
||||
long ip_saddr = 0;
|
||||
int account_registertime = 0;
|
||||
|
||||
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;
|
||||
|
||||
public:
|
||||
void Init();
|
||||
void UnInit();
|
||||
@ -95,6 +102,7 @@ class Player
|
||||
|
||||
void _CMSendChatMsg(f8::MsgHdr& hdr, const cs::CMSendChatMsg& msg);
|
||||
void _CMReadMsgAndOpenChatNotify(f8::MsgHdr& hdr, const cs::CMReadMsgAndOpenChatNotify& msg);
|
||||
void _CMSetCurrPrivateChatTarget(f8::MsgHdr& hdr, const cs::CMSetCurrPrivateChatTarget& msg);
|
||||
void _CMCloseChatNotify(f8::MsgHdr& hdr, const cs::CMCloseChatNotify& msg);
|
||||
void _CMSendCustomMsg(f8::MsgHdr& hdr, const cs::CMSendCustomMsg& msg);
|
||||
void _CMDirtyWordCheck(f8::MsgHdr& hdr, const cs::CMDirtyWordCheck& msg);
|
||||
@ -200,6 +208,7 @@ private:
|
||||
void SyncGuildRedPoint();
|
||||
void SyncGuildNewApply(long long guild_id);
|
||||
bool IsValidChatChannel(int chat_channel);
|
||||
void SyncPrivateChatRedPoint();
|
||||
|
||||
private:
|
||||
bool dirty_ = false;
|
||||
@ -215,8 +224,6 @@ private:
|
||||
std::set<std::string> exclude_account_ids_;
|
||||
std::string user_sign_;
|
||||
int last_create_guild_time_ = 0;
|
||||
int chat_channel_ = -1;
|
||||
std::map<int, long long> chat_last_ids_hash_;
|
||||
|
||||
std::map<std::string, Friend*> friend_hash_;
|
||||
std::map<std::string, Friend*> black_hash_;
|
||||
|
@ -37,16 +37,16 @@ void PlayerMgr::_SS_MS_PushUserList(f8::MsgHdr& hdr, const ss::SS_MS_PushUserLis
|
||||
|
||||
void PlayerMgr::_SS_IM_SendChatMsg(f8::MsgHdr& hdr, const ss::SS_IM_SendChatMsg& msg)
|
||||
{
|
||||
#if 0
|
||||
Player* hum = GetPlayerByAccountId(msg.target());
|
||||
if (hum) {
|
||||
#if 0
|
||||
cs::SMChatMsgNotify notifymsg;
|
||||
notifymsg.set_sender(msg.context().user_info().base_data().account_id());
|
||||
notifymsg.set_chat_channel(msg.chat_channel());
|
||||
notifymsg.set_msg(msg.msg());
|
||||
hum->SendMsg(notifymsg);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void PlayerMgr::_SS_IM_SendCustomMsg(f8::MsgHdr& hdr, const ss::SS_IM_SendCustomMsg& msg)
|
||||
|
Loading…
x
Reference in New Issue
Block a user