1
This commit is contained in:
parent
a11a1ebf54
commit
0c57ca6934
79
server/textserver/GCListener.cc
Normal file
79
server/textserver/GCListener.cc
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "precompile.h"
|
||||||
|
|
||||||
|
#include <google/protobuf/message.h>
|
||||||
|
#include <a8/httpsession.h>
|
||||||
|
#include <a8/tcplistener.h>
|
||||||
|
|
||||||
|
#include "framework/cpp/netmsghandler.h"
|
||||||
|
|
||||||
|
#include "app.h"
|
||||||
|
#include "GCListener.h"
|
||||||
|
#include "jsondatamgr.h"
|
||||||
|
#include "handlermgr.h"
|
||||||
|
|
||||||
|
class GCClientSession: public a8::HttpSession
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual void OnRawHttpGet(const std::string& url, const std::string& querystr,
|
||||||
|
std::string& response) override
|
||||||
|
{
|
||||||
|
App::Instance()->AddIMMsg(IM_ExecGM,
|
||||||
|
a8::XParams()
|
||||||
|
.SetSender(socket_handle)
|
||||||
|
.SetParam1(url)
|
||||||
|
.SetParam2(querystr)
|
||||||
|
.SetParam3(saddr));
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void OnDisConnect() override
|
||||||
|
{
|
||||||
|
App::Instance()->AddIMMsg(IM_ClientSocketDisconnect,
|
||||||
|
a8::XParams()
|
||||||
|
.SetSender(socket_handle)
|
||||||
|
.SetParam1(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
static void CreateGameClientSocket(a8::TcpSession **p)
|
||||||
|
{
|
||||||
|
*p = new GCClientSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GSListeneron_error(a8::TcpListener*, int type, int errorid)
|
||||||
|
{
|
||||||
|
a8::UdpLog::Instance()->Debug("GCListeneron_error %d %d", {type, errorid});
|
||||||
|
}
|
||||||
|
|
||||||
|
void GCListener::Init()
|
||||||
|
{
|
||||||
|
tcp_listener_ = new a8::TcpListener();
|
||||||
|
tcp_listener_->on_create_client_socket = CreateGameClientSocket;
|
||||||
|
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_->Open();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GCListener::UnInit()
|
||||||
|
{
|
||||||
|
delete tcp_listener_;
|
||||||
|
tcp_listener_ = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GCListener::SendText(unsigned short sockhandle, const std::string& text)
|
||||||
|
{
|
||||||
|
tcp_listener_->SendClientMsg(sockhandle, text.data(), text.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GCListener::ForceCloseClient(unsigned short sockhandle)
|
||||||
|
{
|
||||||
|
tcp_listener_->ForceCloseClient(sockhandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GCListener::MarkClient(unsigned short sockhandle, bool is_active)
|
||||||
|
{
|
||||||
|
tcp_listener_->MarkClient(sockhandle, is_active);
|
||||||
|
}
|
36
server/textserver/GCListener.h
Normal file
36
server/textserver/GCListener.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
//game client listener
|
||||||
|
namespace a8
|
||||||
|
{
|
||||||
|
class TcpListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
class GCListener : public a8::Singleton<GCListener>
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
GCListener() {};
|
||||||
|
friend class a8::Singleton<GCListener>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum { HID = HID_GCListener };
|
||||||
|
|
||||||
|
public:
|
||||||
|
void Init();
|
||||||
|
void UnInit();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void SendMsg(unsigned short socket_handle, T& msg)
|
||||||
|
{
|
||||||
|
static int msgid = f8::Net_GetMessageId(msg);
|
||||||
|
f8::Net_SendMsg(tcp_listener_, socket_handle, 0, msgid, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SendText(unsigned short sockhandle, const std::string& text);
|
||||||
|
|
||||||
|
void ForceCloseClient(unsigned short sockhandle);
|
||||||
|
void MarkClient(unsigned short sockhandle, bool is_active);
|
||||||
|
|
||||||
|
private:
|
||||||
|
a8::TcpListener *tcp_listener_ = nullptr;
|
||||||
|
};
|
@ -16,7 +16,7 @@ enum InnerMesssage_e
|
|||||||
//网络处理对象
|
//网络处理对象
|
||||||
enum NetHandler_e
|
enum NetHandler_e
|
||||||
{
|
{
|
||||||
HID_IMSMgr,
|
HID_GCListener,
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* const PROJ_NAME_FMT = "textserver";
|
const char* const PROJ_NAME_FMT = "textserver";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user