This commit is contained in:
aozhiwei 2020-09-16 15:30:37 +08:00
parent 7f8433f1c0
commit d513ed2f3a
3 changed files with 107 additions and 215 deletions

View File

@ -8,6 +8,68 @@
#include "MSConnMgr.h"
#include "asynctaskmgr.h"
class AsyncGuildTask
{
public:
long long watch_guild_id = 0;
time_t time = 0;
ss::SS_IM_ForwardGuildCMMsg forward_msg;
};
class CMGuildInfoTask : public AsyncGuildTask
{
private:
cs::CMGuildInfo cmmsg;
};
class CMGuildJoinTask : public AsyncGuildTask
{
private:
cs::CMGuildJoin cmmsg;
};
class CMGuildAgreeTask : public AsyncGuildTask
{
private:
cs::CMGuildAgree cmmsg;
};
class CMGuildAgreeKick : public AsyncGuildTask
{
private:
cs::CMGuildKick cmmsg;
};
class CMGuildAgreeTak : public AsyncGuildTask
{
private:
cs::CMGuildQuit cmmsg;
};
class CMGuildDismissTask : public AsyncGuildTask
{
private:
cs::CMGuildDismiss cmmsg;
};
class CMGuildRenameTask : public AsyncGuildTask
{
private:
cs::CMGuildRename cmmsg;
};
class CMGuildMemberListTask : public AsyncGuildTask
{
private:
cs::CMGuildMemberList cmmsg;
};
class CMGuildLogTask : public AsyncGuildTask
{
private:
cs::CMGuildLog cmmsg;
};
void GuildMgr::Init()
{
@ -20,12 +82,24 @@ void GuildMgr::UnInit()
void GuildMgr::_SS_IM_ForwardGuildCMMsg(f8::MsgHdr& hdr, const ss::SS_IM_ForwardGuildCMMsg& msg)
{
switch (hdr.msgid) {
if (msg.msgid() < cs::CMMessageId_e::_CMGuildMsgBegin ||
msg.msgid() > cs::CMMessageId_e::_CMGuildMsgEnd) {
return;
}
if (!IsValidGuildId(msg.context().user_info().base_data().guild_id())) {
ss::SS_CommonError respmsg;
respmsg.set_errcode(SERVER_INTERNAL_ERROR);
respmsg.set_errmsg("服务器内部错误");
ForwardGuildSMMsg(msg.context(), msg.msgid(), respmsg);
return;
}
switch (msg.msgid()) {
case cs::CMMessageId_e::_CMGuildInfo:
{
cs::CMGuildInfo cmmsg;
cmmsg.ParseFromArray(msg.payload().data(), msg.payload().size());
_CMGuildInfo(msg.context(), cmmsg);
CMGuildInfoTask* task = new CMGuildInfoTask;
//AddAsyncTask(cmmsg.guild_id(), task);
}
break;
case cs::CMMessageId_e::_CMGuildCreate:
@ -39,42 +113,38 @@ void GuildMgr::_SS_IM_ForwardGuildCMMsg(f8::MsgHdr& hdr, const ss::SS_IM_Forward
{
cs::CMGuildJoin cmmsg;
cmmsg.ParseFromArray(msg.payload().data(), msg.payload().size());
_CMGuildJoin(msg.context(), cmmsg);
CMGuildJoinTask* task = new CMGuildJoinTask;
//AddAsyncTask(cmmsg.guild_id(), task);
}
break;
case cs::CMMessageId_e::_CMGuildAgree:
{
cs::CMGuildAgree cmmsg;
cmmsg.ParseFromArray(msg.payload().data(), msg.payload().size());
_CMGuildAgree(msg.context(), cmmsg);
}
break;
case cs::CMMessageId_e::_CMGuildKick:
{
cs::CMGuildKick cmmsg;
cmmsg.ParseFromArray(msg.payload().data(), msg.payload().size());
_CMGuildKick(msg.context(), cmmsg);
}
break;
case cs::CMMessageId_e::_CMGuildQuit:
{
cs::CMGuildQuit cmmsg;
cmmsg.ParseFromArray(msg.payload().data(), msg.payload().size());
_CMGuildQuit(msg.context(), cmmsg);
}
break;
case cs::CMMessageId_e::_CMGuildDismiss:
{
cs::CMGuildDismiss cmmsg;
cmmsg.ParseFromArray(msg.payload().data(), msg.payload().size());
_CMGuildDismiss(msg.context(), cmmsg);
}
break;
case cs::CMMessageId_e::_CMGuildRename:
{
cs::CMGuildRename cmmsg;
cmmsg.ParseFromArray(msg.payload().data(), msg.payload().size());
_CMGuildRename(msg.context(), cmmsg);
}
break;
case cs::CMMessageId_e::_CMGuildSearch:
@ -95,7 +165,12 @@ void GuildMgr::_SS_IM_ForwardGuildCMMsg(f8::MsgHdr& hdr, const ss::SS_IM_Forward
{
cs::CMGuildMemberList cmmsg;
cmmsg.ParseFromArray(msg.payload().data(), msg.payload().size());
_CMGuildMemberList(msg.context(), cmmsg);
}
break;
case cs::CMMessageId_e::_CMGuildLog:
{
cs::CMGuildLog cmmsg;
cmmsg.ParseFromArray(msg.payload().data(), msg.payload().size());
}
break;
default:
@ -105,20 +180,8 @@ void GuildMgr::_SS_IM_ForwardGuildCMMsg(f8::MsgHdr& hdr, const ss::SS_IM_Forward
}
}
void GuildMgr::_CMGuildInfo(const ss::MFIMMsgConext& context, const cs::CMGuildInfo& msg)
{
}
void GuildMgr::_CMGuildCreate(const ss::MFIMMsgConext& context, const cs::CMGuildCreate& msg)
{
if (!IsValidGuildId(context.user_info().base_data().guild_id())) {
cs::SMGuildCreate respmsg;
respmsg.set_errcode(SERVER_INTERNAL_ERROR);
respmsg.set_errmsg("服务器内部错误");
ForwardGuildSMMsg(context, respmsg);
return;
}
Guild* guild = GetGuild(context.user_info().base_data().guild_id());
if (guild) {
cs::SMGuildCreate respmsg;
@ -130,174 +193,6 @@ void GuildMgr::_CMGuildCreate(const ss::MFIMMsgConext& context, const cs::CMGuil
AsyncTaskMgr::Instance()->CreateNewGuildTask(context, msg);
}
void GuildMgr::_CMGuildJoin(const ss::MFIMMsgConext& context, const cs::CMGuildJoin& msg)
{
if (!IsValidGuildId(context.user_info().base_data().guild_id())) {
cs::SMGuildJoin respmsg;
respmsg.set_errcode(SERVER_INTERNAL_ERROR);
respmsg.set_errmsg("服务器内部错误");
ForwardGuildSMMsg(context, respmsg);
return;
}
#if 0
Guild* guild = GetGuild(msg.guild_id());
if (!guild) {
cs::SMGuildJoin respmsg;
respmsg.set_errcode(1);
respmsg.set_errmsg("群id已经存在");
ForwardGuildSMMsg(context, respmsg);
return;
}
GuildMember* member = guild->GetMember(context.account_id());
if (member) {
cs::SMGuildJoin respmsg;
ForwardGuildSMMsg(context, respmsg);
return;
}
if (guild->IsFull()) {
cs::SMGuildJoin respmsg;
respmsg.set_errcode(2);
respmsg.set_errmsg("群已满");
ForwardGuildSMMsg(context, respmsg);
return;
}
member = new GuildMember();
member->account_id = context.account_id();
member->nickname = context.nickname();
member->avatar_url = context.avatar_url();
member->sex = context.sex();
member->online = 1;
member->guild_id = guild->guild_id;
member->data_version1 = context.base_data_version();
guild->AddMember(member);
#endif
}
void GuildMgr::_CMGuildAgree(const ss::MFIMMsgConext& context, const cs::CMGuildAgree& msg)
{
if (!IsValidGuildId(context.user_info().base_data().guild_id())) {
cs::SMGuildAgree respmsg;
respmsg.set_errcode(SERVER_INTERNAL_ERROR);
respmsg.set_errmsg("服务器内部错误");
ForwardGuildSMMsg(context, respmsg);
return;
}
#if 0
Guild* guild = GetGuild(context.guild_id());
if (!guild) {
return;
}
#endif
}
void GuildMgr::_CMGuildKick(const ss::MFIMMsgConext& context, const cs::CMGuildKick& msg)
{
if (!IsValidGuildId(context.user_info().base_data().guild_id())) {
cs::SMGuildKick respmsg;
respmsg.set_errcode(SERVER_INTERNAL_ERROR);
respmsg.set_errmsg("服务器内部错误");
ForwardGuildSMMsg(context, respmsg);
return;
}
#if 0
Guild* guild = GetGuild(context.guild_id());
if (!guild) {
cs::SMGuildKick respmsg;
respmsg.set_errcode(1);
respmsg.set_errmsg("群id错误");
ForwardGuildSMMsg(context, respmsg);
return;
}
if (!guild->GetMember(msg.account_id())) {
cs::SMGuildKick respmsg;
ForwardGuildSMMsg(context, respmsg);
return;
}
guild->RemoveMember(msg.account_id());
cs::SMGuildKick respmsg;
ForwardGuildSMMsg(context, respmsg);
return;
#endif
}
void GuildMgr::_CMGuildQuit(const ss::MFIMMsgConext& context, const cs::CMGuildQuit& msg)
{
if (!IsValidGuildId(context.user_info().base_data().guild_id())) {
cs::SMGuildQuit respmsg;
respmsg.set_errcode(SERVER_INTERNAL_ERROR);
respmsg.set_errmsg("服务器内部错误");
ForwardGuildSMMsg(context, respmsg);
return;
}
#if 0
Guild* guild = GetGuild(context.guild_id());
if (!guild) {
cs::SMGuildQuit respmsg;
respmsg.set_errcode(1);
respmsg.set_errmsg("群id错误");
ForwardGuildSMMsg(context, respmsg);
return;
}
if (!guild->GetMember(context.account_id())) {
cs::SMGuildQuit respmsg;
ForwardGuildSMMsg(context, respmsg);
return;
}
guild->RemoveMember(context.account_id());
cs::SMGuildQuit respmsg;
ForwardGuildSMMsg(context, respmsg);
#endif
}
void GuildMgr::_CMGuildDismiss(const ss::MFIMMsgConext& context, const cs::CMGuildDismiss& msg)
{
if (!IsValidGuildId(context.user_info().base_data().guild_id())) {
cs::SMGuildDismiss respmsg;
respmsg.set_errcode(SERVER_INTERNAL_ERROR);
respmsg.set_errmsg("服务器内部错误");
ForwardGuildSMMsg(context, respmsg);
return;
}
#if 0
Guild* guild = GetGuild(context.guild_id());
if (!guild) {
return;
}
#endif
}
void GuildMgr::_CMGuildRename(const ss::MFIMMsgConext& context, const cs::CMGuildRename& msg)
{
if (!IsValidGuildId(context.user_info().base_data().guild_id())) {
cs::SMGuildRename respmsg;
respmsg.set_errcode(SERVER_INTERNAL_ERROR);
respmsg.set_errmsg("服务器内部错误");
ForwardGuildSMMsg(context, respmsg);
return;
}
#if 0
Guild* guild = GetGuild(context.guild_id());
if (!guild) {
cs::SMGuildRename respmsg;
respmsg.set_errcode(1);
respmsg.set_errmsg("群id错误");
ForwardGuildSMMsg(context, respmsg);
return;
}
GuildMember* member = guild->GetMember(context.account_id());
if (!member) {
cs::SMGuildRename respmsg;
respmsg.set_errcode(2);
respmsg.set_errmsg("没有权限");
ForwardGuildSMMsg(context, respmsg);
return;
}
guild->RemoveMember(msg.new_guild_name());
cs::SMGuildRename respmsg;
ForwardGuildSMMsg(context, respmsg);
#endif
}
void GuildMgr::_CMGuildSearch(const ss::MFIMMsgConext& context, const cs::CMGuildSearch& msg)
{
@ -308,12 +203,7 @@ void GuildMgr::_CMGuildRank(const ss::MFIMMsgConext& context, const cs::CMGuildR
}
void GuildMgr::_CMGuildMemberList(const ss::MFIMMsgConext& context, const cs::CMGuildMemberList& msg)
{
}
void GuildMgr::_CMGuildLog(const ss::MFIMMsgConext& context, const cs::CMGuildLog& msg)
void GuildMgr::AddAsyncTask(long long guild_id, AsyncGuildTask* task)
{
}
@ -330,10 +220,12 @@ Guild* GuildMgr::GetGuild(long long guild_id)
}
void GuildMgr::ForwardGuildSMMsg(const ss::MFIMMsgConext& context,
int msgid,
const ::google::protobuf::Message& smmsg)
{
ss::SS_IM_ForwardGuildSMMsg msg;
*msg.mutable_context() = context;
msg.set_msgid(msgid);
smmsg.SerializeToString(msg.mutable_payload());
MSConnMgr::Instance()->SendMsg(msg, 0);
}

View File

@ -2,18 +2,9 @@
namespace cs
{
class CMGuildInfo;
class CMGuildCreate;
class CMGuildJoin;
class CMGuildAgree;
class CMGuildKick;
class CMGuildQuit;
class CMGuildDismiss;
class CMGuildRename;
class CMGuildSearch;
class CMGuildRank;
class CMGuildMemberList;
class CMGuildLog;
}
namespace ss
@ -31,6 +22,7 @@ namespace google
}
class Guild;
class AsyncGuildTask;
class GuildMgr : public a8::Singleton<GuildMgr>
{
public:
@ -47,24 +39,24 @@ class GuildMgr : public a8::Singleton<GuildMgr>
void _SS_IM_ForwardGuildCMMsg(f8::MsgHdr& hdr, const ss::SS_IM_ForwardGuildCMMsg& msg);
private:
void _CMGuildInfo(const ss::MFIMMsgConext& context, const cs::CMGuildInfo& msg);
void _CMGuildCreate(const ss::MFIMMsgConext& context, const cs::CMGuildCreate& msg);
void _CMGuildJoin(const ss::MFIMMsgConext& context, const cs::CMGuildJoin& msg);
void _CMGuildAgree(const ss::MFIMMsgConext& context, const cs::CMGuildAgree& msg);
void _CMGuildKick(const ss::MFIMMsgConext& context, const cs::CMGuildKick& msg);
void _CMGuildQuit(const ss::MFIMMsgConext& context, const cs::CMGuildQuit& msg);
void _CMGuildDismiss(const ss::MFIMMsgConext& context, const cs::CMGuildDismiss& msg);
void _CMGuildRename(const ss::MFIMMsgConext& context, const cs::CMGuildRename& msg);
void _CMGuildSearch(const ss::MFIMMsgConext& context, const cs::CMGuildSearch& msg);
void _CMGuildRank(const ss::MFIMMsgConext& context, const cs::CMGuildRank& msg);
void _CMGuildMemberList(const ss::MFIMMsgConext& context, const cs::CMGuildMemberList& msg);
void _CMGuildLog(const ss::MFIMMsgConext& context, const cs::CMGuildLog& msg);
void AddAsyncTask(long long guild_id, AsyncGuildTask* task);
bool IsValidGuildId(long long guild_id);
Guild* GetGuild(long long group_id);
template <typename T>
void ForwardGuildSMMsg(const ss::MFIMMsgConext& context, T& smmsg)
{
static int msgid = f8::Net_GetMessageId(smmsg);
ForwardGuildSMMsg(context, msgid, smmsg);
}
void ForwardGuildSMMsg(const ss::MFIMMsgConext& context,
int msgid,
const ::google::protobuf::Message& smmsg);
private:
std::map<long long, Guild*> id_hash_;
std::map<long long, std::list<AsyncGuildTask*>> task_hash_;
};

View File

@ -78,6 +78,12 @@ message SS_CMPing
{
}
message SS_CommonError
{
optional int32 errcode = 1; //1:id错误
optional string errmsg = 2; //
}
message SS_CMLogin_CMReConnect_CommonHead
{
optional int32 server_id = 1;
@ -154,13 +160,15 @@ message SS_MS_LoadGroup
message SS_IM_ForwardGuildCMMsg
{
optional MFIMMsgConext context = 1;
optional bytes payload = 2;
optional int32 msgid = 2;
optional bytes payload = 3;
}
message SS_IM_ForwardGuildSMMsg
{
optional MFIMMsgConext context = 1;
optional bytes payload = 2;
optional int32 msgid = 2;
optional bytes payload = 3;
}
message SS_IM_ReportServerInfo