Exemple #1
0
func InvokeUserInit(componentList []string, user *User, p netfw.IPeer, param ...interface{}) error {

	// 防止重复注册
	user.Ev.Clear()

	var err error

	for _, cname := range componentList {

		// 在加载列表里没有的组件, 就不参与初始化了
		if !p.HasComponent(cname) {

			continue
		}

		ie, ok := p.GetComponent(cname).(IUserEvent)

		if !ok {
			continue
		}

		if err = ie.OnUserInit(user, param...); err != nil {
			return err
		}
	}

	return nil
}
Exemple #2
0
func (self *relayComponent) Start(p netfw.IPeer) {

	// 接收方
	p.RegisterMessage("coredef.RelayMessageACK", func(msg *coredef.RelayMessageACK, relaySession *netdef.Session) {

		userpkt := &netdef.Packet{
			MsgID: msg.GetUserMsgID(),
			Size:  uint16(len(msg.GetUserMsg())),
			Data:  msg.GetUserMsg(),
		}

		if self.callback == nil {
			return
		}

		self.callback(relaySession, msg.GetSessionID(), userpkt, msg.GetBroardCast())

	})
}
Exemple #3
0
func (self *rpcComponent) Start(p netfw.IPeer) {

	// 应答方
	p.RegisterMessage("coredef.RemoteCallREQ", func(msg *coredef.RemoteCallREQ, ses *netdef.Session) {

		userpkt := &netdef.Packet{
			MsgID: msg.GetUserMsgID(),
			Size:  uint16(len(msg.GetUserMsg())),
			Data:  msg.GetUserMsg(),
		}

		userc := netdef.NewPacketContext(userpkt, ses)

		injectResponseHandler(userc, p.GetCodec(), ses, msg)

		p.CallHandlers(int(userpkt.MsgID), userc)

	})

	p.RegisterMessage("coredef.RemoteCallACK", func(msg *coredef.RemoteCallACK) {

		// 获得callid对应的调用上下文
		rcd := self.getCallData(msg.GetCallID())

		defer self.removeCallData(msg.GetCallID())

		if rcd == nil {
			rcd.fail(lostCallDataError)
			return
		}

		err := proto.Unmarshal(msg.GetUserMsg(), rcd.Reply.(proto.Message))
		if err != nil {
			rcd.fail(replyUnmarshalingError)
			return
		}

		// 回应请求方, 请求方解除阻塞
		rcd.done()

	})
}