This commit is contained in:
aozhiwei 2020-09-24 11:51:10 +08:00
parent 664807d95a
commit a181513c83
7 changed files with 24 additions and 7 deletions

View File

@ -27,12 +27,12 @@ class IMConn
bool Connected();
template <typename T>
void SendMsg(T& msg)
void SendMsg(const T& msg)
{
static int msgid = f8::Net_GetMessageId(msg);
SendMsg(msgid, msg);
}
void SendMsg(int msgid, ::google::protobuf::Message& msg)
void SendMsg(int msgid, const ::google::protobuf::Message& msg)
{
f8::Net_SendMsg(tcp_client_, 0, msgid, msg);
#ifdef DEBUG

View File

@ -82,3 +82,8 @@ bool JsonDataMgr::GetRankServerConf(std::string& ip, int& port)
port = conf->At("rankserver_ip")->AsXValue();
return true;
}
int JsonDataMgr::GetIMInstanceId(long long id)
{
return (id % imserver_cluster_json_.Size()) + 1;
}

View File

@ -15,6 +15,7 @@ class JsonDataMgr : public a8::Singleton<JsonDataMgr>
std::shared_ptr<a8::XObject> GetRankServerClusterConf();
std::shared_ptr<a8::XObject> GetMysqlClusterConf();
bool GetRankServerConf(std::string& ip, int& port);
int GetIMInstanceId(long long id);
private:
std::string work_path_ = "../config";

View File

@ -24,6 +24,7 @@
#include "MSConn.h"
#include "MSConnMgr.h"
#include "handlermgr.h"
#include "jsondatamgr.h"
void Player::Init()
{
@ -618,6 +619,8 @@ void Player::_CMGuildInfo(f8::MsgHdr& hdr, const cs::CMGuildInfo& msg)
SendMsg(respmsg);
return;
}
SyncHelper::Instance()->SendIMConnMsg(JsonDataMgr::Instance()->GetIMInstanceId(msg.guild_id()),
msg);
}
void Player::_CMGuildCreate(f8::MsgHdr& hdr, const cs::CMGuildCreate& msg)
@ -627,7 +630,15 @@ void Player::_CMGuildCreate(f8::MsgHdr& hdr, const cs::CMGuildCreate& msg)
void Player::_CMGuildJoin(f8::MsgHdr& hdr, const cs::CMGuildJoin& msg)
{
cs::SMGuildJoin respmsg;
if (msg.guild_id() == 0 && GuildId() == 0) {
respmsg.set_errcode(1);
respmsg.set_errmsg("你已经有公会");
SendMsg(respmsg);
return;
}
SyncHelper::Instance()->SendIMConnMsg(JsonDataMgr::Instance()->GetIMInstanceId(msg.guild_id()),
msg);
}
void Player::_CMGuildAgree(f8::MsgHdr& hdr, const cs::CMGuildAgree& msg)

View File

@ -175,7 +175,7 @@ void SyncHelper::SS_IM_FriendDeleteRequest_TimeOut(ss::SS_IM_FriendDeleteRequest
);
}
void SyncHelper::SendIMConnMsg(int instance_id, int msgid, ::google::protobuf::Message& msg)
void SyncHelper::SendIMConnMsg(int instance_id, int msgid, const ::google::protobuf::Message& msg)
{
if (instance_id == App::Instance()->instance_id) {
int packlen = msg.ByteSize();

View File

@ -48,13 +48,13 @@ public:
void BroadcastIMConnMsg(int msgid, ::google::protobuf::Message& msg);
template <typename T>
void SendIMConnMsg(int intance_id, T& msg)
void SendIMConnMsg(int intance_id, const T& msg)
{
static int msgid = f8::Net_GetMessageId(msg);
SendIMConnMsg(msgid, msg);
}
void SendIMConnMsg(int intance_id, int msgid, ::google::protobuf::Message& msg);
void SendIMConnMsg(int intance_id, int msgid, const ::google::protobuf::Message& msg);
std::map<long long, timer_list*> pending_request_hash_;
};

@ -1 +1 @@
Subproject commit ea69b96451e7004430e99b86db1cfd3ae4d76c6b
Subproject commit a1c591dd5f2bad2aba07134fa6b9c2415abff318