Пример #1
0
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
	}))
}
Пример #2
0
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{}
	})
}
Пример #3
0
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
	}))
}
Пример #4
0
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
	}))
}
Пример #5
0
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
	}))
}
Пример #6
0
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)
}