完成GM指令
This commit is contained in:
parent
b0b795a824
commit
ebe690a5d8
@ -54,7 +54,9 @@ public:
|
|||||||
a8::XParams()
|
a8::XParams()
|
||||||
.SetSender(socket_handle)
|
.SetSender(socket_handle)
|
||||||
.SetParam1(url)
|
.SetParam1(url)
|
||||||
.SetParam2(querystr));
|
.SetParam2(querystr)
|
||||||
|
.SetParam3(saddr)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnDisConnect() override
|
virtual void OnDisConnect() override
|
||||||
|
@ -336,7 +336,8 @@ void App::ProcessIMMsg()
|
|||||||
switch (im_work_node_->msgid) {
|
switch (im_work_node_->msgid) {
|
||||||
case IM_ExecGM:
|
case IM_ExecGM:
|
||||||
{
|
{
|
||||||
HandlerMgr::Instance()->ProcGMMsg(pdelnode->params.sender,
|
HandlerMgr::Instance()->ProcGMMsg(pdelnode->params.param3,
|
||||||
|
pdelnode->params.sender,
|
||||||
pdelnode->params.param1.GetString(),
|
pdelnode->params.param1.GetString(),
|
||||||
pdelnode->params.param2.GetString()
|
pdelnode->params.param2.GetString()
|
||||||
);
|
);
|
||||||
|
@ -7,17 +7,18 @@
|
|||||||
#include "dbpool.h"
|
#include "dbpool.h"
|
||||||
#include "ss_proto.pb.h"
|
#include "ss_proto.pb.h"
|
||||||
|
|
||||||
void _GMAppEcho(a8::HTTPRequest& request, a8::MutableXObject* xobj)
|
static void _GMOpsSelfChecking(f8::JsonHttpRequest* request)
|
||||||
{
|
{
|
||||||
xobj->SetVal("error_code", 1);
|
request->resp_xobj->SetVal("errcode", 1);
|
||||||
xobj->SetVal("error_msg", "");
|
request->resp_xobj->SetVal("errmsg", "");
|
||||||
xobj->SetVal("error_msg", a8::Get(request, "msg"));
|
request->resp_xobj->SetVal("healthy", 1);
|
||||||
|
request->resp_xobj->SetVal("max_rundelay", 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandlerMgr::Init()
|
void HandlerMgr::Init()
|
||||||
{
|
{
|
||||||
RegisterNetMsgHandlers();
|
RegisterNetMsgHandlers();
|
||||||
RegisterGMMsgHandler("app$echo", _GMAppEcho);
|
RegisterGMMsgHandler("Ops@selfChecking", _GMOpsSelfChecking);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandlerMgr::UnInit()
|
void HandlerMgr::UnInit()
|
||||||
@ -30,9 +31,10 @@ void HandlerMgr::RegisterNetMsgHandlers()
|
|||||||
RegisterNetMsgHandler(&gsmsghandler, &DBPool::_SS_GSM_ExecAsyncSql);
|
RegisterNetMsgHandler(&gsmsghandler, &DBPool::_SS_GSM_ExecAsyncSql);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandlerMgr::ProcGMMsg(int sockhandle, const std::string& url, const std::string& querystr)
|
void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle,
|
||||||
|
const std::string& url, const std::string& querystr)
|
||||||
{
|
{
|
||||||
if (url != "/index.php") {
|
if (url != "/webapp/index.php") {
|
||||||
GSListener::Instance()->SendText(sockhandle, a8::HttpResponse(404, ""));
|
GSListener::Instance()->SendText(sockhandle, a8::HttpResponse(404, ""));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -40,24 +42,32 @@ void HandlerMgr::ProcGMMsg(int sockhandle, const std::string& url, const std::st
|
|||||||
a8::HTTPRequest request;
|
a8::HTTPRequest request;
|
||||||
a8::ParserUrlQueryString(querystr.c_str(), request);
|
a8::ParserUrlQueryString(querystr.c_str(), request);
|
||||||
|
|
||||||
std::string msgname = a8::Get(request, "c").GetString() + "$" + a8::Get(request, "a").GetString();
|
std::string msgname = a8::Get(request, "c").GetString() + "@" + a8::Get(request, "a").GetString();
|
||||||
auto itr = gmhandlers_.find(msgname);
|
auto itr = gmhandlers_.find(msgname);
|
||||||
if (itr != gmhandlers_.end()) {
|
if (itr != gmhandlers_.end()) {
|
||||||
a8::MutableXObject* xobj = a8::MutableXObject::NewObject();
|
f8::JsonHttpRequest* request = new f8::JsonHttpRequest;
|
||||||
itr->second(request, xobj);
|
request->saddr = saddr;
|
||||||
|
request->socket_handle = sockhandle;
|
||||||
|
request->query_str = querystr;
|
||||||
|
request->request.ReadFromUrlQueryString(querystr);
|
||||||
|
request->resp_xobj->SetVal("errcode", 0);
|
||||||
|
request->resp_xobj->SetVal("errmsg", "");
|
||||||
|
itr->second(request);
|
||||||
|
|
||||||
|
if (!request->pending){
|
||||||
std::string response;
|
std::string response;
|
||||||
xobj->ToJsonStr(response);
|
request->resp_xobj->ToJsonStr(response);
|
||||||
GSListener::Instance()->SendText(sockhandle, a8::HttpResponse(response));
|
GSListener::Instance()->SendText(sockhandle, a8::HttpResponse(response));
|
||||||
|
|
||||||
delete xobj;
|
delete request;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
GSListener::Instance()->SendText(sockhandle, a8::HttpResponse("{}"));
|
GSListener::Instance()->SendText(sockhandle, a8::HttpResponse("{}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandlerMgr::RegisterGMMsgHandler(const std::string& msgname,
|
void HandlerMgr::RegisterGMMsgHandler(const std::string& msgname,
|
||||||
void (*handler)(a8::HTTPRequest&, a8::MutableXObject*))
|
void (*handler)(f8::JsonHttpRequest*))
|
||||||
{
|
{
|
||||||
gmhandlers_[msgname] = handler;
|
gmhandlers_[msgname] = handler;
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,13 @@ class HandlerMgr : public a8::Singleton<HandlerMgr>
|
|||||||
|
|
||||||
f8::NetMsgHandlerObject gsmsghandler;
|
f8::NetMsgHandlerObject gsmsghandler;
|
||||||
|
|
||||||
void ProcGMMsg(int sockhandle, const std::string& url, const std::string& quyerstr);
|
void ProcGMMsg(unsigned long saddr, int sockhandle,
|
||||||
|
const std::string& url, const std::string& quyerstr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void RegisterNetMsgHandlers();
|
void RegisterNetMsgHandlers();
|
||||||
void RegisterGMMsgHandler(const std::string& msgname,
|
void RegisterGMMsgHandler(const std::string& msgname,
|
||||||
void (*)(a8::HTTPRequest&, a8::MutableXObject*));
|
void (*)(f8::JsonHttpRequest*));
|
||||||
|
|
||||||
std::map<std::string, void (*)(a8::HTTPRequest&, a8::MutableXObject*)> gmhandlers_;
|
std::map<std::string, void (*)(f8::JsonHttpRequest*)> gmhandlers_;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user