From 90d4fbac8ce653ab8244e55b2578652c5ed4a6da Mon Sep 17 00:00:00 2001 From: azw Date: Thu, 27 Apr 2023 09:16:09 +0000 Subject: [PATCH] 1 --- server/wsproxy/handlermgr.cc | 20 ++++++++++++++++++++ server/wsproxy/jsondatamgr.cc | 5 +++++ server/wsproxy/jsondatamgr.h | 1 + 3 files changed, 26 insertions(+) diff --git a/server/wsproxy/handlermgr.cc b/server/wsproxy/handlermgr.cc index fdf963c..2f562f5 100644 --- a/server/wsproxy/handlermgr.cc +++ b/server/wsproxy/handlermgr.cc @@ -9,6 +9,7 @@ #include "GCListener.h" #include "mastermgr.h" #include "app.h" +#include "jsondatamgr.h" #include "ss_proto.pb.h" @@ -27,11 +28,30 @@ static void _GMOpsGetNodeId(std::shared_ptr request) request->resp_xobj->SetVal("node_id", App::Instance()->GetNodeId()); } +static void _GMOpsSetKcpSwitch(std::shared_ptr request) +{ + request->resp_xobj->SetVal("errcode", 0); + request->resp_xobj->SetVal("errmsg", ""); + if (request->params->HasKey("open")) { + JsonDataMgr::Instance()->SetKcpSwitch(request->params->At("open")->AsXValue().GetInt()); + } + request->resp_xobj->SetVal("is_open", JsonDataMgr::Instance()->GetKcpConf().open); +} + +static void _GMOpsGetKcpSwitch(std::shared_ptr request) +{ + request->resp_xobj->SetVal("errcode", 0); + request->resp_xobj->SetVal("errmsg", ""); + request->resp_xobj->SetVal("is_open", JsonDataMgr::Instance()->GetKcpConf().open); +} + void HandlerMgr::Init() { RegisterNetMsgHandlers(); RegisterGMMsgHandler("Ops$selfChecking", _GMOpsSelfChecking); RegisterGMMsgHandler("Ops$getNodeId", _GMOpsGetNodeId); + RegisterGMMsgHandler("Ops$setKcpSwitch", _GMOpsSetKcpSwitch); + RegisterGMMsgHandler("Ops$getKcpSwitch", _GMOpsGetKcpSwitch); f8::MsgQueue::Instance()->RegisterCallBack ( IM_ExecGM, diff --git a/server/wsproxy/jsondatamgr.cc b/server/wsproxy/jsondatamgr.cc index 970e2b7..486e933 100644 --- a/server/wsproxy/jsondatamgr.cc +++ b/server/wsproxy/jsondatamgr.cc @@ -108,3 +108,8 @@ void JsonDataMgr::TraverseMaster(std::function cb) cb(instance_id, remote_ip, remote_port); } } + +void JsonDataMgr::SetKcpSwitch(int is_open) +{ + kcp_conf_.open = is_open ? 1 : 0; +} diff --git a/server/wsproxy/jsondatamgr.h b/server/wsproxy/jsondatamgr.h index 66bb92d..a2bc1b6 100644 --- a/server/wsproxy/jsondatamgr.h +++ b/server/wsproxy/jsondatamgr.h @@ -33,6 +33,7 @@ class JsonDataMgr : public a8::Singleton std::shared_ptr GetConf(); void TraverseMaster(std::function cb); const KcpConf& GetKcpConf() { return kcp_conf_; } + void SetKcpSwitch(int is_open); private: std::string work_path_ = "../config";