コード例 #1
0
func (this *RegisterComponent) handleService(buffPool *buffpool.BuffPool, message *protocol.Message, conn *net.Conn) {
	if buffPool == nil || message == nil || conn == nil {
		err := errors.New("RegisterComponent handleService Error: the argument is nil")
		return err
	}
	err := buffPool.AddService(message.Number, message.UserUuid, conn)
	if err != nil {
		err = fmt.Errorf("RegisterCompoennt handleService Error: %v", err)
		return err
	}
	responseMessage, err := protocol.NewMessage(protocol.VERSION, protocol.MT_REGISTER, protocol.PT_PUSHSERVER, 0, message.Number, 0, P_UID,
		message.UserUuid, 0, nil)
	if err != nil {
		err = fmt.Errorf("RegisterComponent handleService Error:%v", err)
		return err
	}
	GetDispatcherOutComponent().NPushBack(responseMessage, false)

	if GetRunWithSnode().Flag {
		onlineInfo := structure.ClientOnlineInfo{
			PushID:   this.PushID,
			ParentID: this.PushID,
		}
		data, err := onlineInfo.Encode()
		if err != nil {
			err = fmt.Errorf("RegisterCompoennt handleService Error:%v", err)
			return err
		}
		snode_component.GetNodeComponent().Forward(stree_define.ONLINE, msg.UserId, 0, data) //added for QueryUser
	}

	go this.listenService(conn, buffPool, message.Number, message.UserUuid)
	return nil
}
コード例 #2
0
func (this *RegisterComponent) onlineBroadcast(buffPool *buffpool.BuffPool, dispatcherOut *DispatcherOutComponent, userUuid string, deviceID uint32) error {

	if GetRunWithSnode().Flag {
		onlineInfo := structure.ClientOnlineInfo{
			PushID:   this.PushID,
			ParentID: this.PushID,
		}
		data, err := onlineInfo.Encode()
		if err != nil {
			err = errors.New("RegisterComponent onlineBroadcast() Error: " + err.Error())
			return err
		}
		snode_component.GetNodeComponent().Forward(define.ONLINE, userUuid, deviceID, data)
		snode_component.GetNodeComponent().AddUsersNumber()
		snode_component.GetNodeComponent().AddConnNumber()
	}

	if buffPool == nil || dispatcherOut == nil {
		err := errors.New("RegisterComponent onlineBroadcast() Error: invalid argument")
		return err
	}

	brMsg := protocol.BRMsg{
		userUuid,
		deviceID,
	}
	brData, err := brMsg.Encode()
	if err != nil {
		err := errors.New("RegisterCompoent onlineBroadcast() Error: " + err.Error())
		return err
	}

	servNoUuidArr := buffPool.GetAllServices()
	for num, uuidArr := range servNoUuidArr {
		for _, uuid := range uuidArr {
			onlineMsg, err := protocol.NewMessage(protocol.VERSION, protocol.MT_BROADCAST_ONLINE, protocol.PT_PUSHSERVER, 0, num, uint16(len(brData)),
				P_UID, uuid, 0, brData)
			if err != nil {
				err = errors.New("RegisterComponent onlineBroadcast() Error: " + err.Error())
				return err
			}
			dispatcherOut.NPushBack(onlineMsg, false) //not need forward
		}
	}
	return nil
}