UDP クライアントイベント - OnPush

OnPushは、クライアントが Diarkis サーバクラスタからPush(クライアントが要求していないパケット)としてパケットを受信したときに呼び出されます。UDPのOnPushは、Room, Group, Filed, MatchMakerに関係するPushイベントを受信したときも呼び出されます。

DiarkisUdpBase.h

class DIARKIS_API DiarkisUdpBase
{
protected:
 void OnConnect(bool isReconnect);
void OnConnect(bool isReconnect);
void OnDisconnect(bool isReconnect);
void OnResponse(const DiarkisResponseEventArgs& args, DiarkisTransportType tt);
void OnPush(const DiarkisPushEventArgs& args, DiarkisTransportType tt);
void OnEcho(const DiarkisUdpEchoEventArgs& args);
void OnPing(const DiarkisUdpPingEventArgs& args);

std::vector<std::function<void()>> eventUnsubscriptions;
}

DiarkisUdpBase.cpp

#define REG_EVENT(__EVENT__, __LAMBDA__) this->eventUnsubscriptions.push_back(__EVENT__->Register(__LAMBDA__))


void DiarkisUdpBase::Setup(std::shared_ptr<LoggerFactory> loggerFactory, std::shared_ptr<ILoggerBackend> loggerBackend)
{
if (this->udp == nullptr)
{
this->udp.reset(DiarkisCreateUdp(200, 5000));
}

this->udp->SetLoggerFactory(loggerFactory);
this->fileAndDebugLoggerBackend = loggerBackend;

REG_EVENT(this->udp->GetConnectedEvent(), [this](void*, bool reconnect) { this->OnConnect(reconnect); });
REG_EVENT(this->udp->GetDisconnectedEvent(), [this](void*, bool reconnect) { this->OnDisconnect(reconnect); });
REG_EVENT(this->udp->GetResponseEvent(), [this](void*, const DiarkisResponseEventArgs& args) { this->OnResponse(args, DiarkisTransportType::UDP); });
REG_EVENT(this->udp->GetPushEvent(), [this](void*, const DiarkisPushEventArgs& args) { this->OnPush(args, DiarkisTransportType::UDP); });
REG_EVENT(this->udp->GetEchoEvent(), [this](void*, const DiarkisUdpEchoEventArgs& args) { this->OnEcho(args); });
REG_EVENT(this->udp->GetPingEvent(), [this](void*, const DiarkisUdpPingEventArgs& args) { this->OnPing(args); });

}

void DiarkisUdpBase::OnPush(const DiarkisPushEventArgs& args, DiarkisTransportType tt)
{
uint8_t version = args.GetVersion();
uint16_t command = args.GetCommand();
const vector<uint8_t>& payload = args.GetPayload();


if (version == 2 && command == Commands::CustomCommand)
{
// CustomCommand Process
}
}