完成群消息转发
This commit is contained in:
parent
60a1b6445a
commit
cc88f6de17
@ -169,7 +169,7 @@ void MSConn::CheckAlive()
|
||||
Open();
|
||||
} else {
|
||||
ss::SS_Ping msg;
|
||||
SendMsg(0, msg);
|
||||
SendMsg(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
namespace a8
|
||||
{
|
||||
class TcpClient;
|
||||
class AsyncTcpClient;
|
||||
}
|
||||
|
||||
@ -26,7 +25,7 @@ class MSConn
|
||||
bool Connected();
|
||||
|
||||
template <typename T>
|
||||
void SendMsg(int socket_handle, T& msg)
|
||||
void SendMsg(T& msg)
|
||||
{
|
||||
static int msgid = f8::Net_GetMessageId(msg);
|
||||
f8::Net_SendMsg(tcp_client_, 0, msgid, msg);
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
class MSConn;
|
||||
#include "MSConn.h"
|
||||
|
||||
class MSConnMgr : public a8::Singleton<MSConnMgr>
|
||||
{
|
||||
private:
|
||||
@ -12,8 +13,20 @@ class MSConnMgr : public a8::Singleton<MSConnMgr>
|
||||
void Init();
|
||||
void UnInit();
|
||||
|
||||
template <typename T>
|
||||
void SendMsg(T& msg, long long hash_code)
|
||||
{
|
||||
int instance_id = (hash_code % id_hash_.size()) + 1;
|
||||
MSConn* conn = GetConnById(instance_id);
|
||||
if (!conn) {
|
||||
abort();
|
||||
}
|
||||
conn->SendMsg(msg);
|
||||
}
|
||||
|
||||
private:
|
||||
MSConn* GetConnById(int instance_id);
|
||||
|
||||
private:
|
||||
private:
|
||||
std::map<int, MSConn*> id_hash_;
|
||||
};
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "ss_msgid.pb.h"
|
||||
#include "ss_proto.pb.h"
|
||||
#include "playermgr.h"
|
||||
#include "groupmgr.h"
|
||||
#include "dbengine.h"
|
||||
|
||||
#include "MSConnMgr.h"
|
||||
@ -128,6 +129,7 @@ bool App::Init(int argc, char* argv[])
|
||||
WSListener::Instance()->Init();
|
||||
IMListener::Instance()->Init();
|
||||
PlayerMgr::Instance()->Init();
|
||||
GroupMgr::Instance()->Init();
|
||||
DBEngine::Instance()->Init();
|
||||
|
||||
a8::UdpLog::Instance()->Info("friend_imserver starting instance_id:%d pid:%d ",
|
||||
@ -176,6 +178,7 @@ void App::UnInit()
|
||||
{
|
||||
a8::XPrintf("friend_imserver terminating instance_id:%d pid:%d\n", {instance_id, getpid()});
|
||||
DBEngine::Instance()->UnInit();
|
||||
GroupMgr::Instance()->UnInit();
|
||||
PlayerMgr::Instance()->UnInit();
|
||||
IMListener::Instance()->UnInit();
|
||||
WSListener::Instance()->UnInit();
|
||||
@ -472,6 +475,9 @@ void App::ProcessMSConnMsg(f8::MsgHdr& hdr)
|
||||
case HID_PlayerMgr:
|
||||
ProcessNetMsg(handler, PlayerMgr::Instance(), hdr);
|
||||
break;
|
||||
case HID_GroupMgr:
|
||||
ProcessNetMsg(handler, GroupMgr::Instance(), hdr);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
@ -646,3 +652,8 @@ void App::FreeIMMsgQueue()
|
||||
}
|
||||
im_msg_mutex_->unlock();
|
||||
}
|
||||
|
||||
long long App::NewUUID()
|
||||
{
|
||||
return uuid.Generate();
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ class App : public a8::Singleton<App>
|
||||
void DelContext(long long context_id);
|
||||
a8::XParams* GetContext(long long context_id);
|
||||
bool HasFlag(int flag);
|
||||
long long NewUUID();
|
||||
|
||||
private:
|
||||
void QuickExecute();
|
||||
|
@ -1,6 +1,9 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include "groupmgr.h"
|
||||
#include "cs_msgid.pb.h"
|
||||
#include "cs_proto.pb.h"
|
||||
#include "ss_proto.pb.h"
|
||||
|
||||
void GroupMgr::Init()
|
||||
{
|
||||
@ -11,3 +14,96 @@ void GroupMgr::UnInit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GroupMgr::_SS_MS_ForwardGroupMsg(f8::MsgHdr& hdr, const ss::SS_MS_ForwardGroupMsg& msg)
|
||||
{
|
||||
switch (hdr.msgid) {
|
||||
case cs::CMMessageId_e::_CMGroupCreate:
|
||||
{
|
||||
cs::CMGroupCreate cmmsg;
|
||||
cmmsg.ParseFromArray(msg.payload().data(), msg.payload().size());
|
||||
_CMGroupCreate(msg.context(), cmmsg);
|
||||
}
|
||||
break;
|
||||
case cs::CMMessageId_e::_CMGroupJoin:
|
||||
{
|
||||
cs::CMGroupJoin cmmsg;
|
||||
cmmsg.ParseFromArray(msg.payload().data(), msg.payload().size());
|
||||
_CMGroupJoin(msg.context(), cmmsg);
|
||||
}
|
||||
break;
|
||||
case cs::CMMessageId_e::_CMGroupAgree:
|
||||
{
|
||||
cs::CMGroupAgree cmmsg;
|
||||
cmmsg.ParseFromArray(msg.payload().data(), msg.payload().size());
|
||||
_CMGroupAgree(msg.context(), cmmsg);
|
||||
}
|
||||
break;
|
||||
case cs::CMMessageId_e::_CMGroupKick:
|
||||
{
|
||||
cs::CMGroupKick cmmsg;
|
||||
cmmsg.ParseFromArray(msg.payload().data(), msg.payload().size());
|
||||
_CMGroupKick(msg.context(), cmmsg);
|
||||
}
|
||||
break;
|
||||
case cs::CMMessageId_e::_CMGroupQuit:
|
||||
{
|
||||
cs::CMGroupQuit cmmsg;
|
||||
cmmsg.ParseFromArray(msg.payload().data(), msg.payload().size());
|
||||
_CMGroupQuit(msg.context(), cmmsg);
|
||||
}
|
||||
break;
|
||||
case cs::CMMessageId_e::_CMGroupDismiss:
|
||||
{
|
||||
cs::CMGroupDismiss cmmsg;
|
||||
cmmsg.ParseFromArray(msg.payload().data(), msg.payload().size());
|
||||
_CMGroupDismiss(msg.context(), cmmsg);
|
||||
}
|
||||
break;
|
||||
case cs::CMMessageId_e::_CMGroupRename:
|
||||
{
|
||||
cs::CMGroupRename cmmsg;
|
||||
cmmsg.ParseFromArray(msg.payload().data(), msg.payload().size());
|
||||
_CMGroupRename(msg.context(), cmmsg);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GroupMgr::_CMGroupCreate(const ss::MFIMMsgConext& context, const cs::CMGroupCreate& msg)
|
||||
{
|
||||
}
|
||||
|
||||
void GroupMgr::_CMGroupJoin(const ss::MFIMMsgConext& context, const cs::CMGroupJoin& msg)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GroupMgr::_CMGroupAgree(const ss::MFIMMsgConext& context, const cs::CMGroupAgree& msg)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GroupMgr::_CMGroupKick(const ss::MFIMMsgConext& context, const cs::CMGroupKick& msg)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GroupMgr::_CMGroupQuit(const ss::MFIMMsgConext& context, const cs::CMGroupQuit& msg)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GroupMgr::_CMGroupDismiss(const ss::MFIMMsgConext& context, const cs::CMGroupDismiss& msg)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GroupMgr::_CMGroupRename(const ss::MFIMMsgConext& context, const cs::CMGroupRename& msg)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -2,10 +2,19 @@
|
||||
|
||||
namespace cs
|
||||
{
|
||||
class CMGroupCreate;
|
||||
class CMGroupJoin;
|
||||
class CMGroupAgree;
|
||||
class CMGroupKick;
|
||||
class CMGroupQuit;
|
||||
class CMGroupDismiss;
|
||||
class CMGroupRename;
|
||||
}
|
||||
|
||||
namespace ss
|
||||
{
|
||||
class MFIMMsgConext;
|
||||
class SS_MS_ForwardGroupMsg;
|
||||
}
|
||||
|
||||
class Group;
|
||||
@ -22,7 +31,16 @@ class GroupMgr : public a8::Singleton<GroupMgr>
|
||||
void Init();
|
||||
void UnInit();
|
||||
|
||||
void _SS_MS_ForwardGroupMsg(f8::MsgHdr& hdr, const ss::SS_MS_ForwardGroupMsg& msg);
|
||||
|
||||
private:
|
||||
void _CMGroupCreate(const ss::MFIMMsgConext& context, const cs::CMGroupCreate& msg);
|
||||
void _CMGroupJoin(const ss::MFIMMsgConext& context, const cs::CMGroupJoin& msg);
|
||||
void _CMGroupAgree(const ss::MFIMMsgConext& context, const cs::CMGroupAgree& msg);
|
||||
void _CMGroupKick(const ss::MFIMMsgConext& context, const cs::CMGroupKick& msg);
|
||||
void _CMGroupQuit(const ss::MFIMMsgConext& context, const cs::CMGroupQuit& msg);
|
||||
void _CMGroupDismiss(const ss::MFIMMsgConext& context, const cs::CMGroupDismiss& msg);
|
||||
void _CMGroupRename(const ss::MFIMMsgConext& context, const cs::CMGroupRename& msg);
|
||||
|
||||
private:
|
||||
std::map<long long, Group*> id_hash_;
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "app.h"
|
||||
#include "player.h"
|
||||
#include "playermgr.h"
|
||||
#include "groupmgr.h"
|
||||
|
||||
#include "ss_proto.pb.h"
|
||||
#include "cs_proto.pb.h"
|
||||
@ -36,6 +37,7 @@ void HandlerMgr::RegisterNetMsgHandlers()
|
||||
RegisterNetMsgHandler(&immsghandler, &IMListener::_SS_Ping);
|
||||
|
||||
RegisterNetMsgHandler(&mscmsghandler, &PlayerMgr::_SS_MS_PushUserList);
|
||||
RegisterNetMsgHandler(&mscmsghandler, &GroupMgr::_SS_MS_ForwardGroupMsg);
|
||||
|
||||
RegisterNetMsgHandler(&imcmsghandler, &PlayerMgr::_SS_IM_SendChatMsg);
|
||||
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include "player.h"
|
||||
#include "playermgr.h"
|
||||
#include "dbengine.h"
|
||||
#include "app.h"
|
||||
#include "MSConnMgr.h"
|
||||
|
||||
void Player::Init()
|
||||
{
|
||||
@ -56,37 +58,86 @@ void Player::_CMFriendDelete(f8::MsgHdr& hdr, const cs::CMFriendDelete& msg)
|
||||
|
||||
void Player::_CMGroupCreate(f8::MsgHdr& hdr, const cs::CMGroupCreate& msg)
|
||||
{
|
||||
|
||||
if (group_id != 0) {
|
||||
cs::SMGroupCreate respmsg;
|
||||
respmsg.set_error_code(1);
|
||||
respmsg.set_error_msg("你已经有群");
|
||||
SendMsg(respmsg);
|
||||
return;
|
||||
}
|
||||
ForwardMsgToMasterServer(hdr, App::Instance()->NewUUID());
|
||||
}
|
||||
|
||||
void Player::_CMGroupJoin(f8::MsgHdr& hdr, const cs::CMGroupJoin& msg)
|
||||
{
|
||||
|
||||
if (group_id != 0) {
|
||||
cs::SMGroupJoin respmsg;
|
||||
respmsg.set_error_code(1);
|
||||
respmsg.set_error_msg("你已经有群");
|
||||
SendMsg(respmsg);
|
||||
return;
|
||||
}
|
||||
ForwardMsgToMasterServer(hdr, group_id);
|
||||
}
|
||||
|
||||
void Player::_CMGroupAgree(f8::MsgHdr& hdr, const cs::CMGroupAgree& msg)
|
||||
{
|
||||
|
||||
if (group_id == 0) {
|
||||
cs::SMGroupAgree respmsg;
|
||||
respmsg.set_error_code(2);
|
||||
respmsg.set_error_msg("你还没有群");
|
||||
SendMsg(respmsg);
|
||||
return;
|
||||
}
|
||||
ForwardMsgToMasterServer(hdr, group_id);
|
||||
}
|
||||
|
||||
void Player::_CMGroupKick(f8::MsgHdr& hdr, const cs::CMGroupKick& msg)
|
||||
{
|
||||
|
||||
if (group_id == 0) {
|
||||
cs::SMGroupKick respmsg;
|
||||
respmsg.set_error_code(2);
|
||||
respmsg.set_error_msg("你还没有群");
|
||||
SendMsg(respmsg);
|
||||
return;
|
||||
}
|
||||
ForwardMsgToMasterServer(hdr, group_id);
|
||||
}
|
||||
|
||||
void Player::_CMGroupQuit(f8::MsgHdr& hdr, const cs::CMGroupQuit& msg)
|
||||
{
|
||||
|
||||
if (group_id == 0) {
|
||||
cs::SMGroupQuit respmsg;
|
||||
respmsg.set_error_code(2);
|
||||
respmsg.set_error_msg("你还没有群");
|
||||
SendMsg(respmsg);
|
||||
return;
|
||||
}
|
||||
ForwardMsgToMasterServer(hdr, group_id);
|
||||
}
|
||||
|
||||
void Player::_CMGroupDismiss(f8::MsgHdr& hdr, const cs::CMGroupDismiss& msg)
|
||||
{
|
||||
|
||||
if (group_id == 0) {
|
||||
cs::SMGroupQuit respmsg;
|
||||
respmsg.set_error_code(2);
|
||||
respmsg.set_error_msg("你还没有群");
|
||||
SendMsg(respmsg);
|
||||
return;
|
||||
}
|
||||
ForwardMsgToMasterServer(hdr, group_id);
|
||||
}
|
||||
|
||||
void Player::_CMGroupRename(f8::MsgHdr& hdr, const cs::CMGroupRename& msg)
|
||||
{
|
||||
|
||||
if (group_id == 0) {
|
||||
cs::SMGroupRename respmsg;
|
||||
respmsg.set_error_code(2);
|
||||
respmsg.set_error_msg("你还没有群");
|
||||
SendMsg(respmsg);
|
||||
return;
|
||||
}
|
||||
ForwardMsgToMasterServer(hdr, group_id);
|
||||
}
|
||||
|
||||
void Player::ReLogin(f8::MsgHdr& hdr, const cs::CMLogin& msg)
|
||||
@ -127,3 +178,28 @@ void Player::FillFriendList(::google::protobuf::RepeatedPtrField< ::cs::MFUserIn
|
||||
p->set_online(pair.second.online);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::FillIMMsgConext(f8::MsgHdr& hdr, ss::MFIMMsgConext* conext)
|
||||
{
|
||||
conext->set_socket_handle(hdr.socket_handle);
|
||||
conext->set_account_id(account_id);
|
||||
conext->set_nickname(nickname);
|
||||
conext->set_avatar_url(avatar_url);
|
||||
conext->set_sex(sex);
|
||||
#if 1
|
||||
conext->set_online(true);
|
||||
#else
|
||||
conext->set_online(online);
|
||||
#endif
|
||||
conext->set_msgid(hdr.msgid);
|
||||
}
|
||||
|
||||
void Player::ForwardMsgToMasterServer(f8::MsgHdr& hdr, long long hash_code)
|
||||
{
|
||||
ss::SS_IM_ForwardMsg msg;
|
||||
FillIMMsgConext(hdr, msg.mutable_context());
|
||||
if (hdr.buflen > 0) {
|
||||
msg.mutable_payload()->assign(hdr.buf, hdr.buflen);
|
||||
}
|
||||
MSConnMgr::Instance()->SendMsg(msg, hash_code);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "cs_proto.pb.h"
|
||||
#include "ss_proto.pb.h"
|
||||
#include "WSListener.h"
|
||||
|
||||
class Player
|
||||
@ -53,6 +54,8 @@ class Player
|
||||
private:
|
||||
void AsyncGetFriendList();
|
||||
void FillFriendList(::google::protobuf::RepeatedPtrField< ::cs::MFUserInfo >* friend_list);
|
||||
void FillIMMsgConext(f8::MsgHdr& hdr, ss::MFIMMsgConext* conext);
|
||||
void ForwardMsgToMasterServer(f8::MsgHdr& hdr, long long hash_code);
|
||||
|
||||
private:
|
||||
std::map<std::string, Friend> friend_hash_;
|
||||
|
@ -92,6 +92,7 @@ message SMFriendDelete
|
||||
|
||||
message CMGroupCreate
|
||||
{
|
||||
optional string group_name = 1;
|
||||
}
|
||||
message SMGroupCreate
|
||||
{
|
||||
@ -101,6 +102,7 @@ message SMGroupCreate
|
||||
|
||||
message CMGroupJoin
|
||||
{
|
||||
optional int64 group_id = 1;
|
||||
}
|
||||
message SMGroupJoin
|
||||
{
|
||||
@ -146,6 +148,7 @@ message SMGroupDismiss
|
||||
|
||||
message CMGroupRename
|
||||
{
|
||||
optional string new_group_name = 1;
|
||||
}
|
||||
message SMGroupRename
|
||||
{
|
||||
|
@ -1,5 +1,16 @@
|
||||
package ss;
|
||||
|
||||
message MFIMMsgConext
|
||||
{
|
||||
optional int32 socket_handle = 1;
|
||||
optional string account_id = 2;
|
||||
optional string nickname = 3;
|
||||
optional string avatar_url = 4;
|
||||
optional int32 sex = 5;
|
||||
optional int32 online = 6;
|
||||
optional int32 msgid = 7;
|
||||
}
|
||||
|
||||
message SS_WSP_SocketDisconnect
|
||||
{
|
||||
}
|
||||
@ -58,6 +69,18 @@ message SS_ForceCloseSocket
|
||||
{
|
||||
}
|
||||
|
||||
message SS_IM_ForwardMsg
|
||||
{
|
||||
optional MFIMMsgConext context = 1;
|
||||
optional bytes payload = 2;
|
||||
}
|
||||
|
||||
message SS_MS_ForwardGroupMsg
|
||||
{
|
||||
optional MFIMMsgConext context = 1;
|
||||
optional bytes payload = 2;
|
||||
}
|
||||
|
||||
message SS_IM_UserOnline
|
||||
{
|
||||
optional string account_id = 1;
|
||||
@ -80,4 +103,4 @@ message SS_MS_PushUserList
|
||||
message SS_IM_SendChatMsg
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user