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_->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();
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,18 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include <google/protobuf/message.h>
|
||||
#include <a8/websocketsession.h>
|
||||
#include <a8/mixedsession.h>
|
||||
#include <a8/tcplistener.h>
|
||||
|
||||
#include "framework/cpp/netmsghandler.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "GCListener.h"
|
||||
#include "WSListener.h"
|
||||
#include "jsondatamgr.h"
|
||||
#include "ss_proto.pb.h"
|
||||
#include "handlermgr.h"
|
||||
|
||||
class GCClientSession: public a8::WebSocketSession
|
||||
class WSProxySession: public a8::MixedSession
|
||||
{
|
||||
public:
|
||||
|
||||
@ -27,7 +27,7 @@ public:
|
||||
if (buflen - offset < sizeof(f8::PackHead) + p->packlen) {
|
||||
break;
|
||||
}
|
||||
App::Instance()->AddSocketMsg(SF_Client,
|
||||
App::Instance()->AddSocketMsg(SF_WSProxy,
|
||||
socket_handle,
|
||||
saddr,
|
||||
p->msgid,
|
||||
@ -43,7 +43,7 @@ public:
|
||||
}
|
||||
|
||||
if (warning) {
|
||||
a8::UdpLog::Instance()->Warning("收到client非法数据包", {});
|
||||
a8::UdpLog::Instance()->Warning("收到wsproxy非法数据包", {});
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,39 +58,9 @@ public:
|
||||
.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
|
||||
{
|
||||
App::Instance()->AddIMMsg(IM_ClientSocketDisconnect,
|
||||
App::Instance()->AddIMMsg(IM_WSProxySocketDisconnect,
|
||||
a8::XParams()
|
||||
.SetSender(socket_handle)
|
||||
.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)
|
||||
{
|
||||
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_->on_create_client_socket = CreateGameClientSocket;
|
||||
tcp_listener_->on_create_client_socket = CreateWSProxySocket;
|
||||
tcp_listener_->on_error = GSListeneron_error;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void GCListener::UnInit()
|
||||
void WSListener::UnInit()
|
||||
{
|
||||
delete tcp_listener_;
|
||||
tcp_listener_ = nullptr;
|
||||
}
|
||||
|
||||
void GCListener::ForwardTargetConnMsg(f8::MsgHdr& hdr)
|
||||
void WSListener::ForwardTargetConnMsg(f8::MsgHdr& hdr)
|
||||
{
|
||||
char* buff = (char*)malloc(sizeof(f8::PackHead) + hdr.buflen);
|
||||
f8::PackHead* head = (f8::PackHead*)buff;
|
||||
@ -142,27 +112,17 @@ void GCListener::ForwardTargetConnMsg(f8::MsgHdr& hdr)
|
||||
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());
|
||||
}
|
||||
|
||||
void GCListener::ForceCloseClient(unsigned short sockhandle)
|
||||
void WSListener::ForceCloseClient(unsigned short 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);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
//game client listener
|
||||
//gate listener
|
||||
namespace a8
|
||||
{
|
||||
class TcpListener;
|
||||
}
|
||||
|
||||
class GCListener : public a8::Singleton<GCListener>
|
||||
class WSListener : public a8::Singleton<WSListener>
|
||||
{
|
||||
private:
|
||||
GCListener() {};
|
||||
friend class a8::Singleton<GCListener>;
|
||||
WSListener() {};
|
||||
friend class a8::Singleton<WSListener>;
|
||||
|
||||
public:
|
||||
enum { HID = HID_GCListener };
|
||||
enum { HID = HID_WSListener };
|
||||
|
||||
public:
|
||||
void Init();
|
||||
@ -31,8 +31,6 @@ class GCListener : public a8::Singleton<GCListener>
|
||||
|
||||
void ForceCloseClient(unsigned short sockhandle);
|
||||
void MarkClient(unsigned short sockhandle, bool is_active);
|
||||
long long GetSendNodeNum();
|
||||
long long GetSentBytesNum();
|
||||
|
||||
private:
|
||||
a8::TcpListener *tcp_listener_ = nullptr;
|
@ -14,7 +14,7 @@
|
||||
#include "framework/cpp/netmsghandler.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "GCListener.h"
|
||||
#include "WSListener.h"
|
||||
#include "jsondatamgr.h"
|
||||
#include "handlermgr.h"
|
||||
#include "gameclient.h"
|
||||
@ -81,15 +81,6 @@ static void SavePerfLog()
|
||||
(long long)a8::IoLoop::Instance()->error_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
|
||||
App::Instance()->perf.max_run_delay_time = 0;
|
||||
App::Instance()->perf.max_timer_idle = 0;
|
||||
@ -109,9 +100,9 @@ bool App::Init(int argc, char* argv[])
|
||||
if (!ParseOpt()) {
|
||||
terminated = true;
|
||||
if (instance_id <= 0) {
|
||||
a8::XPrintf("gameserver启动失败,缺少-i参数\n", {});
|
||||
a8::XPrintf("friend_imserver启动失败,缺少-i参数\n", {});
|
||||
} 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;
|
||||
}
|
||||
@ -136,7 +127,7 @@ bool App::Init(int argc, char* argv[])
|
||||
GameClientMgr::Instance()->Init();
|
||||
MasterSvrMgr::Instance()->Init();
|
||||
TargetConnMgr::Instance()->Init();
|
||||
GCListener::Instance()->Init();
|
||||
WSListener::Instance()->Init();
|
||||
|
||||
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()
|
||||
{
|
||||
a8::XPrintf("friend_imserver terminating instance_id:%d pid:%d\n", {instance_id, getpid()});
|
||||
GCListener::Instance()->UnInit();
|
||||
WSListener::Instance()->UnInit();
|
||||
MasterSvrMgr::Instance()->UnInit();
|
||||
TargetConnMgr::Instance()->UnInit();
|
||||
GameClientMgr::Instance()->UnInit();
|
||||
@ -361,11 +352,16 @@ void App::DispatchMsg()
|
||||
hdr.offset = 0;
|
||||
hdr.ip_saddr = pdelnode->ip_saddr;
|
||||
switch (pdelnode->sockfrom) {
|
||||
case SF_Client:
|
||||
case SF_WSProxy:
|
||||
{
|
||||
ProcessClientMsg(hdr);
|
||||
}
|
||||
break;
|
||||
case SF_IMServer:
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
case SF_TargetServer:
|
||||
{
|
||||
ProcessTargetServerMsg(hdr);
|
||||
@ -429,7 +425,7 @@ void App::ProcessMasterServerMsg(f8::MsgHdr& hdr)
|
||||
void App::ProcessTargetServerMsg(f8::MsgHdr& hdr)
|
||||
{
|
||||
if (hdr.msgid == ss::_SS_ForceCloseSocket) {
|
||||
GCListener::Instance()->ForceCloseClient(hdr.socket_handle);
|
||||
WSListener::Instance()->ForceCloseClient(hdr.socket_handle);
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
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()
|
||||
@ -454,7 +450,7 @@ void App::ProcessIMMsg()
|
||||
while (im_work_node_) {
|
||||
IMMsgNode *pdelnode = im_work_node_;
|
||||
switch (im_work_node_->msgid) {
|
||||
case IM_ClientSocketDisconnect:
|
||||
case IM_WSProxySocketDisconnect:
|
||||
{
|
||||
GameClientMgr::Instance()->OnClientDisconnect(pdelnode->params);
|
||||
MasterSvrMgr::Instance()->RemoveRequest(pdelnode->params.param1, pdelnode->params.sender, true);
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
enum SocketFrom_e
|
||||
{
|
||||
SF_Client,
|
||||
SF_WSProxy,
|
||||
SF_IMServer,
|
||||
SF_TargetServer,
|
||||
SF_MasterServer,
|
||||
@ -10,19 +10,19 @@ enum SocketFrom_e
|
||||
|
||||
enum InnerMesssage_e
|
||||
{
|
||||
IM_ClientSocketDisconnect = 100,
|
||||
IM_WSProxySocketDisconnect = 100,
|
||||
IM_PlayerOffline,
|
||||
IM_ExecGM,
|
||||
IM_MasterSvrDisconnect,
|
||||
IM_TargetConnConnect,
|
||||
IM_TargetConnDisconnect,
|
||||
IM_IMServerSocketDisConnect,
|
||||
IM_IMServerSocketDisconnect,
|
||||
};
|
||||
|
||||
//网络处理对象
|
||||
enum NetHandler_e
|
||||
{
|
||||
HID_GCListener,
|
||||
HID_WSListener,
|
||||
HID_MasterSvrMgr,
|
||||
HID_IMListener
|
||||
};
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "gameclient.h"
|
||||
#include "target_conn.h"
|
||||
#include "target_conn_mgr.h"
|
||||
#include "GCListener.h"
|
||||
#include "WSListener.h"
|
||||
#include "app.h"
|
||||
|
||||
void GameClientMgr::Init()
|
||||
@ -46,7 +46,7 @@ void GameClientMgr::OnTargetServerDisconnect(a8::XParams& param)
|
||||
}
|
||||
for (auto& client : delete_client) {
|
||||
RemovePendingAccount(client->socket_handle);
|
||||
GCListener::Instance()->ForceCloseClient(client->socket_handle);
|
||||
WSListener::Instance()->ForceCloseClient(client->socket_handle);
|
||||
socket_hash_.erase(client->socket_handle);
|
||||
delete client;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include "handlermgr.h"
|
||||
|
||||
#include "GCListener.h"
|
||||
#include "WSListener.h"
|
||||
#include "mastersvrmgr.h"
|
||||
#include "app.h"
|
||||
|
||||
@ -37,7 +37,7 @@ void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle,
|
||||
const std::string& url, const std::string& querystr)
|
||||
{
|
||||
if (url != "/webapp/index.php") {
|
||||
GCListener::Instance()->SendText(sockhandle, a8::HttpResponse(404, ""));
|
||||
WSListener::Instance()->SendText(sockhandle, a8::HttpResponse(404, ""));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -57,12 +57,12 @@ void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle,
|
||||
if (!request->pending){
|
||||
std::string response;
|
||||
request->resp_xobj->ToJsonStr(response);
|
||||
GCListener::Instance()->SendText(sockhandle, a8::HttpResponse(response));
|
||||
WSListener::Instance()->SendText(sockhandle, a8::HttpResponse(response));
|
||||
|
||||
delete request;
|
||||
}
|
||||
} else {
|
||||
GCListener::Instance()->SendText(sockhandle, a8::HttpResponse("{}"));
|
||||
WSListener::Instance()->SendText(sockhandle, a8::HttpResponse("{}"));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user