65 lines
1.6 KiB
C++
65 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include <a8/singleton.h>
|
|
|
|
#include <f8/types.h>
|
|
#include <f8/protoutils.h>
|
|
|
|
//game client listener
|
|
namespace a8
|
|
{
|
|
class TcpListener;
|
|
}
|
|
|
|
class GGListener : public a8::Singleton<GGListener>
|
|
{
|
|
private:
|
|
GGListener() {};
|
|
friend class a8::Singleton<GGListener>;
|
|
|
|
public:
|
|
enum { HID = HID_GGListener };
|
|
|
|
public:
|
|
void Init();
|
|
void UnInit();
|
|
|
|
int max_packet_size = 0;
|
|
int his_max_packet_size = 0;
|
|
|
|
template <typename T>
|
|
void SendProxyMsg(int sockhandle, T& msg)
|
|
{
|
|
static int msgid = f8::Net_GetMessageId(msg);
|
|
f8::Net_SendProxyMsg(tcp_listener_.get(), sockhandle, 0, 0, msgid, msg);
|
|
}
|
|
|
|
template <typename T>
|
|
void SendToClient(int sockhandle, unsigned int seqid, T& msg)
|
|
{
|
|
static int msgid = f8::Net_GetMessageId(msg);
|
|
int packet_size = f8::Net_SendProxyMsg(tcp_listener_.get(), sockhandle, seqid, 0, msgid, msg);
|
|
if (packet_size > max_packet_size) {
|
|
max_packet_size = packet_size;
|
|
}
|
|
}
|
|
void SendText(int sockhandle, const std::string& text);
|
|
|
|
void SendError(int sockhandle, unsigned int seqid,
|
|
int error_code, const std::string& error_msg,
|
|
const char* file = nullptr, int lineno = 0, int error_param = 0);
|
|
|
|
void ForceCloseClient(int sockhandle);
|
|
void ForceCloseChildSocket(int sockhandle);
|
|
void MarkClient(int sockhandle, bool is_active);
|
|
long long GetSendNodeNum();
|
|
long long GetSentNodeNum();
|
|
long long GetSentBytesNum();
|
|
|
|
private:
|
|
void OnListenError(int errorid);
|
|
|
|
private:
|
|
std::shared_ptr<a8::TcpListener> tcp_listener_;
|
|
};
|