rename GCListener->WSListener
This commit is contained in:
parent
6d7d86f1ae
commit
106de8fcc1
@ -85,7 +85,7 @@ void IMListener::Init()
|
|||||||
tcp_listener_->on_error = GSListeneron_error;
|
tcp_listener_->on_error = GSListeneron_error;
|
||||||
|
|
||||||
tcp_listener_->bind_address = "0.0.0.0";
|
tcp_listener_->bind_address = "0.0.0.0";
|
||||||
tcp_listener_->bind_port = JsonDataMgr::Instance()->GetConf()->At("imserver_listen_port")->AsXValue();
|
tcp_listener_->bind_port = JsonDataMgr::Instance()->GetConf()->At("imserver_port")->AsXValue();
|
||||||
tcp_listener_->Open();
|
tcp_listener_->Open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
#include "precompile.h"
|
#include "precompile.h"
|
||||||
|
|
||||||
#include <google/protobuf/message.h>
|
#include <google/protobuf/message.h>
|
||||||
#include <a8/websocketsession.h>
|
#include <a8/mixedsession.h>
|
||||||
#include <a8/tcplistener.h>
|
#include <a8/tcplistener.h>
|
||||||
|
|
||||||
#include "framework/cpp/netmsghandler.h"
|
#include "framework/cpp/netmsghandler.h"
|
||||||
|
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "GCListener.h"
|
#include "WSListener.h"
|
||||||
#include "jsondatamgr.h"
|
#include "jsondatamgr.h"
|
||||||
#include "ss_proto.pb.h"
|
#include "ss_proto.pb.h"
|
||||||
#include "handlermgr.h"
|
#include "handlermgr.h"
|
||||||
|
|
||||||
class GCClientSession: public a8::WebSocketSession
|
class WSProxySession: public a8::MixedSession
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ public:
|
|||||||
if (buflen - offset < sizeof(f8::PackHead) + p->packlen) {
|
if (buflen - offset < sizeof(f8::PackHead) + p->packlen) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
App::Instance()->AddSocketMsg(SF_Client,
|
App::Instance()->AddSocketMsg(SF_WSProxy,
|
||||||
socket_handle,
|
socket_handle,
|
||||||
saddr,
|
saddr,
|
||||||
p->msgid,
|
p->msgid,
|
||||||
@ -43,7 +43,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (warning) {
|
if (warning) {
|
||||||
a8::UdpLog::Instance()->Warning("收到client非法数据包", {});
|
a8::UdpLog::Instance()->Warning("收到wsproxy非法数据包", {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,39 +58,9 @@ public:
|
|||||||
.SetParam3(saddr));
|
.SetParam3(saddr));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool HandleRedirect(const std::string& url, const std::string& querystr,
|
|
||||||
std::string& location) override
|
|
||||||
{
|
|
||||||
#if MASTER_MODE
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void OnDisConnect() override
|
virtual void OnDisConnect() override
|
||||||
{
|
{
|
||||||
App::Instance()->AddIMMsg(IM_ClientSocketDisconnect,
|
App::Instance()->AddIMMsg(IM_WSProxySocketDisconnect,
|
||||||
a8::XParams()
|
a8::XParams()
|
||||||
.SetSender(socket_handle)
|
.SetSender(socket_handle)
|
||||||
.SetParam1(1));
|
.SetParam1(1));
|
||||||
@ -98,34 +68,34 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void CreateGameClientSocket(a8::TcpSession **p)
|
static void CreateWSProxySocket(a8::TcpSession **p)
|
||||||
{
|
{
|
||||||
*p = new GCClientSession();
|
*p = new WSProxySession();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GSListeneron_error(a8::TcpListener*, int type, int errorid)
|
static void GSListeneron_error(a8::TcpListener*, int type, int errorid)
|
||||||
{
|
{
|
||||||
a8::UdpLog::Instance()->Debug("GCListeneron_error %d %d", {type, errorid});
|
a8::UdpLog::Instance()->Debug("WSListeneron_error %d %d", {type, errorid});
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCListener::Init()
|
void WSListener::Init()
|
||||||
{
|
{
|
||||||
tcp_listener_ = new a8::TcpListener();
|
tcp_listener_ = new a8::TcpListener();
|
||||||
tcp_listener_->on_create_client_socket = CreateGameClientSocket;
|
tcp_listener_->on_create_client_socket = CreateWSProxySocket;
|
||||||
tcp_listener_->on_error = GSListeneron_error;
|
tcp_listener_->on_error = GSListeneron_error;
|
||||||
|
|
||||||
tcp_listener_->bind_address = "0.0.0.0";
|
tcp_listener_->bind_address = "0.0.0.0";
|
||||||
tcp_listener_->bind_port = JsonDataMgr::Instance()->GetConf()->At("listen_port")->AsXValue();
|
tcp_listener_->bind_port = JsonDataMgr::Instance()->GetConf()->At("wsproxy_port")->AsXValue();
|
||||||
tcp_listener_->Open();
|
tcp_listener_->Open();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCListener::UnInit()
|
void WSListener::UnInit()
|
||||||
{
|
{
|
||||||
delete tcp_listener_;
|
delete tcp_listener_;
|
||||||
tcp_listener_ = nullptr;
|
tcp_listener_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCListener::ForwardTargetConnMsg(f8::MsgHdr& hdr)
|
void WSListener::ForwardTargetConnMsg(f8::MsgHdr& hdr)
|
||||||
{
|
{
|
||||||
char* buff = (char*)malloc(sizeof(f8::PackHead) + hdr.buflen);
|
char* buff = (char*)malloc(sizeof(f8::PackHead) + hdr.buflen);
|
||||||
f8::PackHead* head = (f8::PackHead*)buff;
|
f8::PackHead* head = (f8::PackHead*)buff;
|
||||||
@ -142,27 +112,17 @@ void GCListener::ForwardTargetConnMsg(f8::MsgHdr& hdr)
|
|||||||
free(buff);
|
free(buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCListener::SendText(unsigned short sockhandle, const std::string& text)
|
void WSListener::SendText(unsigned short sockhandle, const std::string& text)
|
||||||
{
|
{
|
||||||
tcp_listener_->SendClientMsg(sockhandle, text.data(), text.size());
|
tcp_listener_->SendClientMsg(sockhandle, text.data(), text.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCListener::ForceCloseClient(unsigned short sockhandle)
|
void WSListener::ForceCloseClient(unsigned short sockhandle)
|
||||||
{
|
{
|
||||||
tcp_listener_->ForceCloseClient(sockhandle);
|
tcp_listener_->ForceCloseClient(sockhandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCListener::MarkClient(unsigned short sockhandle, bool is_active)
|
void WSListener::MarkClient(unsigned short sockhandle, bool is_active)
|
||||||
{
|
{
|
||||||
tcp_listener_->MarkClient(sockhandle, is_active);
|
tcp_listener_->MarkClient(sockhandle, is_active);
|
||||||
}
|
}
|
||||||
|
|
||||||
long long GCListener::GetSendNodeNum()
|
|
||||||
{
|
|
||||||
return tcp_listener_->send_node_num;
|
|
||||||
}
|
|
||||||
|
|
||||||
long long GCListener::GetSentBytesNum()
|
|
||||||
{
|
|
||||||
return tcp_listener_->sent_bytes_num;
|
|
||||||
}
|
|
@ -1,19 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
//game client listener
|
//gate listener
|
||||||
namespace a8
|
namespace a8
|
||||||
{
|
{
|
||||||
class TcpListener;
|
class TcpListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
class GCListener : public a8::Singleton<GCListener>
|
class WSListener : public a8::Singleton<WSListener>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
GCListener() {};
|
WSListener() {};
|
||||||
friend class a8::Singleton<GCListener>;
|
friend class a8::Singleton<WSListener>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum { HID = HID_GCListener };
|
enum { HID = HID_WSListener };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void Init();
|
void Init();
|
||||||
@ -31,8 +31,6 @@ class GCListener : public a8::Singleton<GCListener>
|
|||||||
|
|
||||||
void ForceCloseClient(unsigned short sockhandle);
|
void ForceCloseClient(unsigned short sockhandle);
|
||||||
void MarkClient(unsigned short sockhandle, bool is_active);
|
void MarkClient(unsigned short sockhandle, bool is_active);
|
||||||
long long GetSendNodeNum();
|
|
||||||
long long GetSentBytesNum();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
a8::TcpListener *tcp_listener_ = nullptr;
|
a8::TcpListener *tcp_listener_ = nullptr;
|
@ -14,7 +14,7 @@
|
|||||||
#include "framework/cpp/netmsghandler.h"
|
#include "framework/cpp/netmsghandler.h"
|
||||||
|
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "GCListener.h"
|
#include "WSListener.h"
|
||||||
#include "jsondatamgr.h"
|
#include "jsondatamgr.h"
|
||||||
#include "handlermgr.h"
|
#include "handlermgr.h"
|
||||||
#include "gameclient.h"
|
#include "gameclient.h"
|
||||||
@ -81,15 +81,6 @@ static void SavePerfLog()
|
|||||||
(long long)a8::IoLoop::Instance()->error_times,
|
(long long)a8::IoLoop::Instance()->error_times,
|
||||||
(long long)a8::IoLoop::Instance()->immsg_times
|
(long long)a8::IoLoop::Instance()->immsg_times
|
||||||
});
|
});
|
||||||
if (App::Instance()->HasFlag(2)) {
|
|
||||||
a8::XPrintf("mainloop_time:%d netmsg_time:%d send_node_num:%d sent_bytes_num:%d\n",
|
|
||||||
{
|
|
||||||
App::Instance()->perf.max_run_delay_time,
|
|
||||||
App::Instance()->perf.max_dispatchmsg_time,
|
|
||||||
GCListener::Instance()->GetSendNodeNum(),
|
|
||||||
GCListener::Instance()->GetSentBytesNum()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
#if 1
|
#if 1
|
||||||
App::Instance()->perf.max_run_delay_time = 0;
|
App::Instance()->perf.max_run_delay_time = 0;
|
||||||
App::Instance()->perf.max_timer_idle = 0;
|
App::Instance()->perf.max_timer_idle = 0;
|
||||||
@ -109,9 +100,9 @@ bool App::Init(int argc, char* argv[])
|
|||||||
if (!ParseOpt()) {
|
if (!ParseOpt()) {
|
||||||
terminated = true;
|
terminated = true;
|
||||||
if (instance_id <= 0) {
|
if (instance_id <= 0) {
|
||||||
a8::XPrintf("gameserver启动失败,缺少-i参数\n", {});
|
a8::XPrintf("friend_imserver启动失败,缺少-i参数\n", {});
|
||||||
} else if (instance_id > MAX_INSTANCE_ID) {
|
} else if (instance_id > MAX_INSTANCE_ID) {
|
||||||
a8::XPrintf("gameserver启动失败,-i参数不能大于%d\n", {MAX_INSTANCE_ID});
|
a8::XPrintf("friend_imserver启动失败,-i参数不能大于%d\n", {MAX_INSTANCE_ID});
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -136,7 +127,7 @@ bool App::Init(int argc, char* argv[])
|
|||||||
GameClientMgr::Instance()->Init();
|
GameClientMgr::Instance()->Init();
|
||||||
MasterSvrMgr::Instance()->Init();
|
MasterSvrMgr::Instance()->Init();
|
||||||
TargetConnMgr::Instance()->Init();
|
TargetConnMgr::Instance()->Init();
|
||||||
GCListener::Instance()->Init();
|
WSListener::Instance()->Init();
|
||||||
|
|
||||||
a8::UdpLog::Instance()->Info("friend_imserver starting instance_id:%d pid:%d ",
|
a8::UdpLog::Instance()->Info("friend_imserver starting instance_id:%d pid:%d ",
|
||||||
{
|
{
|
||||||
@ -183,7 +174,7 @@ bool App::Init(int argc, char* argv[])
|
|||||||
void App::UnInit()
|
void App::UnInit()
|
||||||
{
|
{
|
||||||
a8::XPrintf("friend_imserver terminating instance_id:%d pid:%d\n", {instance_id, getpid()});
|
a8::XPrintf("friend_imserver terminating instance_id:%d pid:%d\n", {instance_id, getpid()});
|
||||||
GCListener::Instance()->UnInit();
|
WSListener::Instance()->UnInit();
|
||||||
MasterSvrMgr::Instance()->UnInit();
|
MasterSvrMgr::Instance()->UnInit();
|
||||||
TargetConnMgr::Instance()->UnInit();
|
TargetConnMgr::Instance()->UnInit();
|
||||||
GameClientMgr::Instance()->UnInit();
|
GameClientMgr::Instance()->UnInit();
|
||||||
@ -361,11 +352,16 @@ void App::DispatchMsg()
|
|||||||
hdr.offset = 0;
|
hdr.offset = 0;
|
||||||
hdr.ip_saddr = pdelnode->ip_saddr;
|
hdr.ip_saddr = pdelnode->ip_saddr;
|
||||||
switch (pdelnode->sockfrom) {
|
switch (pdelnode->sockfrom) {
|
||||||
case SF_Client:
|
case SF_WSProxy:
|
||||||
{
|
{
|
||||||
ProcessClientMsg(hdr);
|
ProcessClientMsg(hdr);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case SF_IMServer:
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
case SF_TargetServer:
|
case SF_TargetServer:
|
||||||
{
|
{
|
||||||
ProcessTargetServerMsg(hdr);
|
ProcessTargetServerMsg(hdr);
|
||||||
@ -429,7 +425,7 @@ void App::ProcessMasterServerMsg(f8::MsgHdr& hdr)
|
|||||||
void App::ProcessTargetServerMsg(f8::MsgHdr& hdr)
|
void App::ProcessTargetServerMsg(f8::MsgHdr& hdr)
|
||||||
{
|
{
|
||||||
if (hdr.msgid == ss::_SS_ForceCloseSocket) {
|
if (hdr.msgid == ss::_SS_ForceCloseSocket) {
|
||||||
GCListener::Instance()->ForceCloseClient(hdr.socket_handle);
|
WSListener::Instance()->ForceCloseClient(hdr.socket_handle);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (hdr.msgid < 100) {
|
if (hdr.msgid < 100) {
|
||||||
@ -437,9 +433,9 @@ void App::ProcessTargetServerMsg(f8::MsgHdr& hdr)
|
|||||||
}
|
}
|
||||||
if (hdr.msgid == ss::_SS_CMLogin || hdr.msgid == ss::_SS_CMReConnect) {
|
if (hdr.msgid == ss::_SS_CMLogin || hdr.msgid == ss::_SS_CMReConnect) {
|
||||||
GameClientMgr::Instance()->BindTargetConn(hdr.socket_handle, hdr.ip_saddr);
|
GameClientMgr::Instance()->BindTargetConn(hdr.socket_handle, hdr.ip_saddr);
|
||||||
GCListener::Instance()->MarkClient(hdr.socket_handle, true);
|
WSListener::Instance()->MarkClient(hdr.socket_handle, true);
|
||||||
}
|
}
|
||||||
GCListener::Instance()->ForwardTargetConnMsg(hdr);
|
WSListener::Instance()->ForwardTargetConnMsg(hdr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::ProcessIMMsg()
|
void App::ProcessIMMsg()
|
||||||
@ -454,7 +450,7 @@ void App::ProcessIMMsg()
|
|||||||
while (im_work_node_) {
|
while (im_work_node_) {
|
||||||
IMMsgNode *pdelnode = im_work_node_;
|
IMMsgNode *pdelnode = im_work_node_;
|
||||||
switch (im_work_node_->msgid) {
|
switch (im_work_node_->msgid) {
|
||||||
case IM_ClientSocketDisconnect:
|
case IM_WSProxySocketDisconnect:
|
||||||
{
|
{
|
||||||
GameClientMgr::Instance()->OnClientDisconnect(pdelnode->params);
|
GameClientMgr::Instance()->OnClientDisconnect(pdelnode->params);
|
||||||
MasterSvrMgr::Instance()->RemoveRequest(pdelnode->params.param1, pdelnode->params.sender, true);
|
MasterSvrMgr::Instance()->RemoveRequest(pdelnode->params.param1, pdelnode->params.sender, true);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
enum SocketFrom_e
|
enum SocketFrom_e
|
||||||
{
|
{
|
||||||
SF_Client,
|
SF_WSProxy,
|
||||||
SF_IMServer,
|
SF_IMServer,
|
||||||
SF_TargetServer,
|
SF_TargetServer,
|
||||||
SF_MasterServer,
|
SF_MasterServer,
|
||||||
@ -10,19 +10,19 @@ enum SocketFrom_e
|
|||||||
|
|
||||||
enum InnerMesssage_e
|
enum InnerMesssage_e
|
||||||
{
|
{
|
||||||
IM_ClientSocketDisconnect = 100,
|
IM_WSProxySocketDisconnect = 100,
|
||||||
IM_PlayerOffline,
|
IM_PlayerOffline,
|
||||||
IM_ExecGM,
|
IM_ExecGM,
|
||||||
IM_MasterSvrDisconnect,
|
IM_MasterSvrDisconnect,
|
||||||
IM_TargetConnConnect,
|
IM_TargetConnConnect,
|
||||||
IM_TargetConnDisconnect,
|
IM_TargetConnDisconnect,
|
||||||
IM_IMServerSocketDisConnect,
|
IM_IMServerSocketDisconnect,
|
||||||
};
|
};
|
||||||
|
|
||||||
//网络处理对象
|
//网络处理对象
|
||||||
enum NetHandler_e
|
enum NetHandler_e
|
||||||
{
|
{
|
||||||
HID_GCListener,
|
HID_WSListener,
|
||||||
HID_MasterSvrMgr,
|
HID_MasterSvrMgr,
|
||||||
HID_IMListener
|
HID_IMListener
|
||||||
};
|
};
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include "gameclient.h"
|
#include "gameclient.h"
|
||||||
#include "target_conn.h"
|
#include "target_conn.h"
|
||||||
#include "target_conn_mgr.h"
|
#include "target_conn_mgr.h"
|
||||||
#include "GCListener.h"
|
#include "WSListener.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
|
|
||||||
void GameClientMgr::Init()
|
void GameClientMgr::Init()
|
||||||
@ -46,7 +46,7 @@ void GameClientMgr::OnTargetServerDisconnect(a8::XParams& param)
|
|||||||
}
|
}
|
||||||
for (auto& client : delete_client) {
|
for (auto& client : delete_client) {
|
||||||
RemovePendingAccount(client->socket_handle);
|
RemovePendingAccount(client->socket_handle);
|
||||||
GCListener::Instance()->ForceCloseClient(client->socket_handle);
|
WSListener::Instance()->ForceCloseClient(client->socket_handle);
|
||||||
socket_hash_.erase(client->socket_handle);
|
socket_hash_.erase(client->socket_handle);
|
||||||
delete client;
|
delete client;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "handlermgr.h"
|
#include "handlermgr.h"
|
||||||
|
|
||||||
#include "GCListener.h"
|
#include "WSListener.h"
|
||||||
#include "mastersvrmgr.h"
|
#include "mastersvrmgr.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle,
|
|||||||
const std::string& url, const std::string& querystr)
|
const std::string& url, const std::string& querystr)
|
||||||
{
|
{
|
||||||
if (url != "/webapp/index.php") {
|
if (url != "/webapp/index.php") {
|
||||||
GCListener::Instance()->SendText(sockhandle, a8::HttpResponse(404, ""));
|
WSListener::Instance()->SendText(sockhandle, a8::HttpResponse(404, ""));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,12 +57,12 @@ void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle,
|
|||||||
if (!request->pending){
|
if (!request->pending){
|
||||||
std::string response;
|
std::string response;
|
||||||
request->resp_xobj->ToJsonStr(response);
|
request->resp_xobj->ToJsonStr(response);
|
||||||
GCListener::Instance()->SendText(sockhandle, a8::HttpResponse(response));
|
WSListener::Instance()->SendText(sockhandle, a8::HttpResponse(response));
|
||||||
|
|
||||||
delete request;
|
delete request;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
GCListener::Instance()->SendText(sockhandle, a8::HttpResponse("{}"));
|
WSListener::Instance()->SendText(sockhandle, a8::HttpResponse("{}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user