func init() { netlib.RegisterHandler(int(protocol.CoreBuiltinPacketID_PACKET_SS_SLICES), &PacketSlicesHandler{}) netlib.RegisterFactory(int(protocol.CoreBuiltinPacketID_PACKET_SS_SLICES), &PacketSlicesPacketFactory{}) netlib.DefaultBuiltinProtocolEncoder.PacketCutor = func(data []byte) (packs []interface{}) { var ( offset = 0 sendSize = 0 seqNo = 1 totalSize = len(data) restSize = len(data) ) for restSize > 0 { sendSize = restSize if sendSize > netlib.MaxPacketSize-128 { sendSize = netlib.MaxPacketSize - 128 } pack := &protocol.SSPacketSlices{ SeqNo: proto.Int32(int32(seqNo)), TotalSize: proto.Int32(int32(totalSize)), Offset: proto.Int32(int32(offset)), PacketData: data[offset : offset+sendSize], } proto.SetDefaults(pack) seqNo++ restSize -= sendSize offset += sendSize packs = append(packs, pack) } return } }
func init() { netlib.RegisterFactory(int(protocol.MmoPacketID_PACKET_SC_GATEINFO), netlib.PacketFactoryWrapper(func() interface{} { return &protocol.SCGateInfo{} })) netlib.RegisterHandler(int(protocol.MmoPacketID_PACKET_SC_GATEINFO), netlib.HandlerWrapper(func(s *netlib.Session, pack interface{}) error { logger.Trace("receive gateinfo==", pack) if sr, ok := pack.(*protocol.SCGateInfo); ok { sc := &netlib.SessionConfig{ Id: int(sr.GetSrvId()), Type: int(sr.GetSrvType()), Ip: sr.GetIp(), Port: int(sr.GetPort()), AuthKey: sr.GetAuthKey(), WriteTimeout: 30, ReadTimeout: 30, IdleTimeout: 30, MaxDone: 20, MaxPend: 20, MaxPacket: 1024, RcvBuff: 1024, SndBuff: 1024, IsClient: true, NoDelay: true, FilterChain: []string{"session-filter-trace", "session-filter-auth"}, } sc.Init() err := netlib.Connect(core.CoreObject(), sc) if err != nil { logger.Warn("connect server failed err:", err) } } return nil })) }
func init() { netlib.RegisterFactory(int(protocol.CoreBuiltinPacketID_PACKET_SS_AUTH), netlib.PacketFactoryWrapper(func() interface{} { return &protocol.SSPacketAuth{} })) netlib.RegisteSessionFilterCreator(AuthenticationFilterName, func() netlib.SessionFilter { return &AuthenticationFilter{} }) }
func init() { netlib.RegisteSessionHandlerCreator(SessionHandlerSrvRegisteName, func() netlib.SessionHandler { return &SessionHandlerSrvRegiste{} }) netlib.RegisterFactory(int(protocol.SrvlibPacketID_PACKET_SS_REGISTE), netlib.PacketFactoryWrapper(func() interface{} { return &protocol.SSSrvRegiste{} })) netlib.RegisterHandler(int(protocol.SrvlibPacketID_PACKET_SS_REGISTE), netlib.HandlerWrapper(func(s *netlib.Session, data interface{}) error { if registePacket, ok := data.(*protocol.SSSrvRegiste); ok { s.SetAttribute(srvlib.SessionAttributeServerInfo, registePacket) srvlib.ServerSessionMgrSington.RegisteSession(s) } return nil })) }
func init() { netlib.RegisterFactory(int(protocol.CoreBuiltinPacketID_PACKET_SS_KEEPALIVE), netlib.PacketFactoryWrapper(func() interface{} { return &protocol.SSPacketKeepAlive{} })) netlib.RegisteSessionFilterCreator(KeepAliveFilterName, func() netlib.SessionFilter { return &KeepAliveFilter{} }) netlib.RegisterHandler(int(protocol.CoreBuiltinPacketID_PACKET_SS_KEEPALIVE), netlib.HandlerWrapper(func(s *netlib.Session, data interface{}) error { if p, ok := data.(*protocol.SSPacketKeepAlive); ok { if p.GetFlag() == 0 { p.Flag = proto.Int32(1) s.Send(p) } } return nil })) }
func init() { netlib.RegisteSessionHandlerCreator(SessionHandlerClientBalanceName, func() netlib.SessionHandler { return SessionHandlerClientBalanceMgr }) netlib.RegisterFactory(int(protocol.MmoPacketID_PACKET_GB_CUR_LOAD), netlib.PacketFactoryWrapper(func() interface{} { return &protocol.ServerLoad{} })) netlib.RegisterHandler(int(protocol.MmoPacketID_PACKET_GB_CUR_LOAD), netlib.HandlerWrapper(func(s *netlib.Session, pack interface{}) error { logger.Trace("receive gate load info==", pack) if sr, ok := pack.(*protocol.ServerLoad); ok { srvid := sr.GetSrvId() if v, has := SessionHandlerClientBalanceMgr.gates[srvid]; has { v.load = int(sr.GetCurLoad()) } } return nil })) }
func init() { netlib.RegisterHandler(int(protocol.SrvlibPacketID_PACKET_SS_TRANSIT), &PacketTransitHandler{}) netlib.RegisterFactory(int(protocol.SrvlibPacketID_PACKET_SS_TRANSIT), &PacketTransitPacketFactory{}) }
func init() { netlib.RegisterHandler(int(protocol.CoreBuiltinPacketID_PACKET_SS_TX_RESULT), &TxResultHandler{}) netlib.RegisterFactory(int(protocol.CoreBuiltinPacketID_PACKET_SS_TX_RESULT), &TxResultPacketFactory{}) }
func init() { netlib.RegisterHandler(int(protocol.SrvlibPacketID_PACKET_SS_MULTICAST), &MulticastHandler{}) netlib.RegisterFactory(int(protocol.SrvlibPacketID_PACKET_SS_MULTICAST), MulticastMaker) }
func init() { netlib.RegisterHandler(int(protocol.SrvlibPacketID_PACKET_SS_BROADCAST), &BroadcastHandler{}) netlib.RegisterFactory(int(protocol.SrvlibPacketID_PACKET_SS_BROADCAST), BroadcastMaker) }
func init() { netlib.RegisterHandler(int(protocol.PacketID_PACKET_SC_PONG), &SCPacketPongHandler{}) netlib.RegisterFactory(int(protocol.PacketID_PACKET_SC_PONG), &SCPacketPongPacketFactory{}) }
func init() { netlib.RegisterHandler(int(protocol.CoreBuiltinPacketID_PACKET_SS_TX_START), &TxStartHandler{}) netlib.RegisterFactory(int(protocol.CoreBuiltinPacketID_PACKET_SS_TX_START), &TxStartPacketFactory{}) }
func init() { netlib.RegisterHandler(int(protocol.SrvlibPacketID_PACKET_SS_REDIRECT), &PacketRedirectHandler{}) netlib.RegisterFactory(int(protocol.SrvlibPacketID_PACKET_SS_REDIRECT), &PacketRedirectPacketFactory{}) }
func init() { // service registe netlib.RegisterFactory(int(protocol.SrvlibPacketID_PACKET_SS_SERVICE_REGISTE), netlib.PacketFactoryWrapper(func() interface{} { return &protocol.SSServiceRegiste{} })) netlib.RegisterHandler(int(protocol.SrvlibPacketID_PACKET_SS_SERVICE_REGISTE), netlib.HandlerWrapper(func(s *netlib.Session, pack interface{}) error { if sr, ok := pack.(*protocol.SSServiceRegiste); ok { ServiceMgr.RegisteService(s, sr.GetServices()) } return nil })) // service info netlib.RegisterFactory(int(protocol.SrvlibPacketID_PACKET_SS_SERVICE_INFO), netlib.PacketFactoryWrapper(func() interface{} { return &protocol.SSServiceInfo{} })) netlib.RegisterHandler(int(protocol.SrvlibPacketID_PACKET_SS_SERVICE_INFO), netlib.HandlerWrapper(func(s *netlib.Session, pack interface{}) error { if sr, ok := pack.(*protocol.SSServiceInfo); ok { service := sr.GetService() if service != nil { sc := &netlib.SessionConfig{ Id: int(service.GetSrvId()), Type: int(service.GetSrvType()), AreaId: int(service.GetAreaId()), Name: service.GetSrvName(), Ip: service.GetIp(), Port: int(service.GetPort()), WriteTimeout: time.Duration(service.GetWriteTimeOut()), ReadTimeout: time.Duration(service.GetReadTimeOut()), IdleTimeout: time.Duration(service.GetIdleTimeOut()), MaxDone: int(service.GetMaxDone()), MaxPend: int(service.GetMaxPend()), MaxPacket: int(service.GetMaxPacket()), RcvBuff: int(service.GetRcvBuff()), SndBuff: int(service.GetSndBuff()), IsClient: true, IsAutoReconn: true, AuthKey: service.GetAuthKey(), SoLinger: int(service.GetSoLinger()), KeepAlive: service.GetKeepAlive(), NoDelay: service.GetNoDelay(), IsInnerLink: service.GetIsInnerLink(), SupportFragment: service.GetSupportFragment(), AllowMultiConn: service.GetAllowMultiConn(), EncoderName: service.GetEncoderName(), DecoderName: service.GetDecoderName(), FilterChain: service.GetFilterChain(), HandlerChain: service.GetHandlerChain(), Protocol: service.GetProtocol(), Path: service.GetPath(), } sc.Init() err := netlib.Connect(sc) if err != nil { logger.Warn("connect server failed err:", err) } } } return nil })) // service shutdown netlib.RegisterFactory(int(protocol.SrvlibPacketID_PACKET_SS_SERVICE_SHUT), netlib.PacketFactoryWrapper(func() interface{} { return &protocol.SSServiceShut{} })) netlib.RegisterHandler(int(protocol.SrvlibPacketID_PACKET_SS_SERVICE_SHUT), netlib.HandlerWrapper(func(s *netlib.Session, pack interface{}) error { if sr, ok := pack.(*protocol.SSServiceShut); ok { service := sr.GetService() if service != nil { netlib.ShutConnector(service.GetIp(), int(service.GetPort())) } } return nil })) ServerSessionMgrSington.SetListener(ServiceMgr) }
func init() { netlib.RegisterHandler(int(protocol.PacketID_PACKET_CS_PING), &CSPacketPingHandler{}) netlib.RegisterFactory(int(protocol.PacketID_PACKET_CS_PING), &CSPacketPingPacketFactory{}) }
func init() { netlib.RegisterHandler(int(protocol.CoreBuiltinPacketID_PACKET_SS_TX_CMD), &TxCtrlCmdHandler{}) netlib.RegisterFactory(int(protocol.CoreBuiltinPacketID_PACKET_SS_TX_CMD), &TxCtrlCmdPacketFactory{}) }