74 lines
1.7 KiB
C++
74 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include "framework/cpp/netmsghandler.h"
|
|
#include "app.h"
|
|
|
|
//imserver listener
|
|
namespace a8
|
|
{
|
|
class TcpListener;
|
|
}
|
|
|
|
namespace ss
|
|
{
|
|
class SS_Ping;
|
|
}
|
|
|
|
class IMListener : public a8::Singleton<IMListener>
|
|
{
|
|
private:
|
|
IMListener() {};
|
|
friend class a8::Singleton<IMListener>;
|
|
|
|
public:
|
|
enum { HID = HID_IMListener };
|
|
|
|
public:
|
|
void Init();
|
|
void UnInit();
|
|
|
|
template <typename T>
|
|
void SendMsg(int socket_handle, T& msg)
|
|
{
|
|
static int msgid = f8::Net_GetMessageId(msg);
|
|
if (socket_handle != 0) {
|
|
f8::Net_SendMsg(tcp_listener_, socket_handle, 0, msgid, msg);
|
|
} else {
|
|
int packlen = msg.ByteSize();
|
|
char* buff = nullptr;
|
|
if (packlen > 0) {
|
|
buff = (char*)malloc(packlen);
|
|
msg.SerializeToArray(buff, packlen);
|
|
}
|
|
App::Instance()->AddSocketMsg
|
|
(
|
|
SF_IMServer,
|
|
0,
|
|
0,
|
|
msgid,
|
|
0,
|
|
buff,
|
|
packlen
|
|
);
|
|
if (buff) {
|
|
free(buff);
|
|
}
|
|
}
|
|
#ifdef DEBUG
|
|
f8::DumpMsgToLog(msg, "<<<<<<<IML ");
|
|
#endif
|
|
}
|
|
|
|
void ForwardTargetConnMsg(f8::MsgHdr& hdr);
|
|
void SendText(unsigned short sockhandle, const std::string& text);
|
|
|
|
void ForceCloseClient(unsigned short sockhandle);
|
|
void MarkClient(unsigned short sockhandle, bool is_active);
|
|
long long GetSendNodeNum();
|
|
long long GetSentBytesNum();
|
|
|
|
void _SS_Ping(f8::MsgHdr& hdr, const ss::SS_Ping& msg);
|
|
private:
|
|
a8::TcpListener *tcp_listener_ = nullptr;
|
|
};
|