Example #1
0
//service self
func Start(service *cham.Service, args ...interface{}) cham.Dispatch {
	log.Infoln("New Service ", service.String())
	mul := new(Multicast)
	mul.channel = 0
	mul.groups = make(map[uint32]map[cham.Address]cham.NULL, DEFAULT_GROUP_SIZE)

	return func(session int32, source cham.Address, ptype uint8, args ...interface{}) []interface{} {
		cmd := args[0].(uint8)
		channel := args[1].(uint32)
		addr := args[2].(cham.Address)

		result := cham.NORET

		switch cmd {
		case NEW:
			result = cham.Ret(mul.new(addr))
		case SUB:
			mul.sub(addr, channel)
		case PUB:
			mul.pub(addr, channel, args[3:]...)
		case UNSUB:
			mul.unsub(addr, channel)
		case DEL:
			mul.del(channel)
		}
		return result
	}
}
Example #2
0
func brokerStart(service *cham.Service, args ...interface{}) cham.Dispatch {
	log.Infoln("New Service ", service.String())
	um := args[0].(*usermanager.UserManager)
	return func(session int32, source cham.Address, ptype uint8, args ...interface{}) []interface{} {
		cmd := args[0].(uint8)
		switch cmd {
		case user.DELETE_USER:
			openid := args[1].(string)
			um.Delete(openid)
		}
		return cham.NORET
	}
}
Example #3
0
File: gate.go Project: hefju/cham
func Start(service *cham.Service, args ...interface{}) cham.Dispatch {
	log.Infoln("New Service ", service.String())
	gate := New(0, service)
	return func(session int32, source cham.Address, ptype uint8, args ...interface{}) []interface{} {
		cmd := args[0].(uint8)
		result := cham.NORET
		switch cmd {
		case OPEN:
			gate.Source = source
			service.RegisterProtocol(cham.PTYPE_RESPONSE, ResponseStart, gate)
			gate.open(args[1].(*Conf))
		case KICK:
			gate.kick(args[1].(uint32))
		}

		return result
	}
}
Example #4
0
func Start(service *cham.Service, args ...interface{}) cham.Dispatch {
	log.Infoln("New Service ", service.String())
	openid, session := args[0].(string), args[1].(uint32)
	user, err := newUser(service, &model.UserModel{Openid: openid}, session)
	if err != nil {
		log.Errorln("Service ", service.String(), "init error,", err.Error())
		service.Stop()
	}
	return func(session int32, source cham.Address, ptype uint8, args ...interface{}) []interface{} {
		cmd := args[0].(uint8)
		switch cmd {
		case CHANGE_SESSION:
			user.session = args[1].(uint32)
		}

		return cham.NORET
	}
}