package main

import (
	"mongo.games.com/game/proto"
	"mongo.games.com/game/protocol/login"
	"mongo.games.com/goserver/core/logger"
	"mongo.games.com/goserver/core/netlib"
	"time"
)

func init() {
	// 客户端心跳
	netlib.RegisterFactory(int(login.GatePacketID_PACKET_CS_PING), netlib.PacketFactoryWrapper(func() interface{} {
		return &login.CSPing{}
	}))

	netlib.RegisterHandler(int(login.GatePacketID_PACKET_CS_PING), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
		logger.Logger.Trace("receive gate load info==", pack)
		if _, ok := pack.(*login.CSPing); ok {
			pong := &login.SCPong{
				TimeStamp: time.Now().UnixMilli(),
			}
			proto.SetDefaults(pong)
			s.Send(int(login.GatePacketID_PACKET_SC_PONG), pong)
		}
		return nil
	}))
}
