This commit is contained in:
aozhiwei 2023-04-24 13:34:30 +08:00
parent caaf17bf26
commit 7ef9a15cc4
2 changed files with 34 additions and 22 deletions

View File

@ -72,28 +72,21 @@ public:
virtual bool HandleRedirect(const std::string& url, const std::string& querystr,
std::string& location) override
{
a8::HTTPRequest request;
a8::ParserUrlQueryString(querystr.c_str(), request);
if (a8::Get(request, "c").GetString() == "Ops" &&
a8::Get(request, "a").GetString() == "join") {
std::string team_uuid = a8::Get(request, "team_uuid").GetString();
std::vector<std::string> strings;
a8::Split(team_uuid, strings, '_');
if (strings.size() >= 2) {
int node_id = a8::XValue(strings[0]);
if (node_id != App::Instance()->node_id) {
std::string host;
if (JsonDataMgr::Instance()->GetNodeHost(node_id, host)) {
location = a8::Format("wss://%s/webapp/index.php?c=Ops&a=join&team_uuid=%s",
{
host,
team_uuid
});
return true;
}
}
}
}
#ifdef DEBUG
f8::MsgQueue::Instance()->PostMsg
(
IM_HandleRedirect,
a8::Args
(
{
(int)socket_handle,
(std::string)(url + ""),
(std::string)(querystr + ""),
(unsigned long)saddr
}
)
);
#endif
return false;
}
@ -132,6 +125,24 @@ void GCListener::Init()
tcp_listener_->bind_address = "0.0.0.0";
tcp_listener_->bind_port = JsonDataMgr::Instance()->GetConf()->At("listen_port")->AsXValue();
tcp_listener_->Open();
f8::MsgQueue::Instance()->RegisterCallBack
(
IM_HandleRedirect,
[this] (const a8::Args& args)
{
int socket_handle = args.Get<int>(0);
std::string url = args.Get<std::string>(1);
std::string query_str = args.Get<std::string>(2);
websocket_url_hash_[socket_handle] = std::make_tuple(url, query_str);
});
f8::MsgQueue::Instance()->RegisterCallBack
(
IM_ClientSocketDisconnect,
[this] (const a8::Args& args)
{
int socket_handle = args.Get<int>(0);
websocket_url_hash_.erase(socket_handle);
});
}
void GCListener::UnInit()

View File

@ -14,6 +14,7 @@ enum InnerMesssage_e
IM_ExecGM,
IM_UpStreamDisconnect,
IM_UpStreamConnect,
IM_HandleRedirect
};
//网络处理对象