1
This commit is contained in:
parent
a166d00686
commit
6de8c854a1
@ -1,5 +1,7 @@
|
|||||||
#include "precompile.h"
|
#include "precompile.h"
|
||||||
|
|
||||||
|
#include <a8/timer.h>
|
||||||
|
|
||||||
#include "chatmgr.h"
|
#include "chatmgr.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "playermgr.h"
|
#include "playermgr.h"
|
||||||
@ -15,6 +17,14 @@ struct ChatedUserRec
|
|||||||
std::map<std::string, ChatMsgRec> users;
|
std::map<std::string, ChatMsgRec> users;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ChatMsgRec::~ChatMsgRec()
|
||||||
|
{
|
||||||
|
for (cs::MFChatMsg* msg : msg_list) {
|
||||||
|
delete msg;
|
||||||
|
}
|
||||||
|
msg_list.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void ChatMsgRec::Pop(size_t max_num)
|
void ChatMsgRec::Pop(size_t max_num)
|
||||||
{
|
{
|
||||||
while (msg_list.size() > max_num) {
|
while (msg_list.size() > max_num) {
|
||||||
@ -307,7 +317,16 @@ void ChatMgr::OnPlayerOnline(Player* hum)
|
|||||||
|
|
||||||
void ChatMgr::OnPlayerOffline(Player* hum)
|
void ChatMgr::OnPlayerOffline(Player* hum)
|
||||||
{
|
{
|
||||||
|
a8::Timer::Instance()->AddDeadLineTimer
|
||||||
|
(1000 * 60 * 5,
|
||||||
|
a8::XParams()
|
||||||
|
.SetSender(hum->AccountId()),
|
||||||
|
[] (const a8::XParams& param)
|
||||||
|
{
|
||||||
|
if (!PlayerMgr::Instance()->GetPlayerByAccountId(param.sender)) {
|
||||||
|
ChatMgr::Instance()->RemoveChatedUser(param.sender);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatMgr::AddChatedUser(const std::string& sender_id, const std::string& receiver_id,
|
void ChatMgr::AddChatedUser(const std::string& sender_id, const std::string& receiver_id,
|
||||||
@ -349,3 +368,12 @@ void ChatMgr::FillMFChatMsg(cs::MFChatMsg* msg, Player* sender, long long msg_uu
|
|||||||
msg->set_msg_body(msg_body);
|
msg->set_msg_body(msg_body);
|
||||||
msg->set_send_time(time(nullptr));
|
msg->set_send_time(time(nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChatMgr::RemoveChatedUser(const std::string& account_id)
|
||||||
|
{
|
||||||
|
auto itr = private_chated_users_.find(account_id);
|
||||||
|
if (itr != private_chated_users_.end()) {
|
||||||
|
delete itr->second;
|
||||||
|
private_chated_users_.erase(account_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -4,11 +4,11 @@
|
|||||||
|
|
||||||
struct ChatMsgRec
|
struct ChatMsgRec
|
||||||
{
|
{
|
||||||
|
|
||||||
long long curr_id = 0;
|
long long curr_id = 0;
|
||||||
long long last_id = 0;
|
long long last_id = 0;
|
||||||
std::list<cs::MFChatMsg*> msg_list;
|
std::list<cs::MFChatMsg*> msg_list;
|
||||||
|
|
||||||
|
~ChatMsgRec();
|
||||||
void Pop(size_t max_num);
|
void Pop(size_t max_num);
|
||||||
void PopAndDelete(size_t max_num);
|
void PopAndDelete(size_t max_num);
|
||||||
};
|
};
|
||||||
@ -48,6 +48,7 @@ class ChatMgr : public a8::Singleton<ChatMgr>
|
|||||||
cs::MFChatMsg* chat_msg, long long last_id);
|
cs::MFChatMsg* chat_msg, long long last_id);
|
||||||
void FillMFChatMsg(cs::MFChatMsg* msg, Player* sender, long long msg_uuid,
|
void FillMFChatMsg(cs::MFChatMsg* msg, Player* sender, long long msg_uuid,
|
||||||
int chat_channel, int msg_type, const std::string& msg_body);
|
int chat_channel, int msg_type, const std::string& msg_body);
|
||||||
|
void RemoveChatedUser(const std::string& account_id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
long long world_msg_id_ = 1000;
|
long long world_msg_id_ = 1000;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user