Ejemplo n.º 1
0
func (self *ProtoProc) procGetTopicProfile(cmd protocol.Cmd, session *libnet.Session) error {
	log.Info("procGetTopicProfile")
	var err error
	var topicCacheData *redis_store.TopicCacheData

	topicName := "<N/A>"
	resp := protocol.NewCmdSimple(protocol.RSP_GET_TOPIC_PROFILE_CMD)
	if len(cmd.GetArgs()) != 1 {
		err = common.SYNTAX_ERROR
	} else {
		topicName = cmd.GetArgs()[0]

		clientID := session.State.(*base.SessionState).ClientID
		//clientType := session.State.(*base.SessionState).ClientType

		// check whether the topic exist
		topicCacheData, err = self.msgServer.topicCache.Get(topicName)
		if topicCacheData == nil {
			log.Warningf("TOPIC %s not exist", topicName)
			err = common.TOPIC_NOT_EXIST
		} else if topicCacheData.MemberExist(clientID) == false {
			log.Warningf("%s not the member of topic %d", clientID, topicName)
			err = common.DENY_ACCESS
		}

	}

	if err != nil {
		resp.AddArg(err.Error())
		resp.AddArg(topicName)
	} else {
		resp.AddArg(protocol.RSP_SUCCESS)
		resp.AddArg(topicName)
		resp.AddArg(topicCacheData.CreaterID)
		for _, member := range topicCacheData.MemberList {
			resp.AddArg(member.ID)
			resp.AddArg(member.Name)
			resp.AddArg(member.Type)
		}
	}
	err = session.Send(libnet.Json(resp))
	if err != nil {
		log.Error(err.Error())
	}

	return err
}
Ejemplo n.º 2
0
func (self *MsgServer) procQuitTopic(clientID string, topicName string) error {
	log.Info("procQuitTopic")
	var err error
	var topicCacheData *redis_store.TopicCacheData
	var sessionCacheData *redis_store.SessionCacheData
	var sessionStoreData *mongo_store.SessionStoreData

	// check whether the topic exist
	topicCacheData, err = self.topicCache.Get(topicName)
	if topicCacheData == nil {
		log.Warningf("TOPIC %s not exist", topicName)
		return common.TOPIC_NOT_EXIST
	}

	if !topicCacheData.MemberExist(clientID) {
		log.Warningf("member %s is not in topic %s", clientID, topicName)
		return common.NOT_MEMBER
	}
	// update topic cache and store
	topicCacheData.RemoveMember(clientID)
	err = self.topicCache.Set(topicCacheData)
	if err != nil {
		log.Error(err.Error())
		return err
	}
	log.Infof("member %s removed from topic CACHE %s", clientID, topicName)

	err = self.mongoStore.Set(topicCacheData.TopicStoreData)
	if err != nil {
		log.Error(err.Error())
		return err
	}
	log.Infof("member %s removed from topic STORE %s", clientID, topicName)

	// update session cache and store
	sessionCacheData, err = self.sessionCache.Get(clientID)
	if sessionCacheData != nil {
		log.Infof("remove topic %s from Client CACHE %s", topicName, clientID)
		sessionCacheData.RemoveTopic(topicName)
		err = self.sessionCache.Set(sessionCacheData)
		if err != nil {
			log.Error(err.Error())
			return err
		}
		log.Infof("topic %s removed from Client CACHE %s", topicName, clientID)
		err = self.mongoStore.Set(sessionCacheData.SessionStoreData)
		if err != nil {
			log.Error(err.Error())
			return err
		}
		log.Infof("topic %s removed from Client STORE %s", topicName, clientID)
		if sessionCacheData.Alive {
			// update AliveMemberNumMap[server]
			if v, ok := topicCacheData.AliveMemberNumMap[sessionCacheData.MsgServerAddr]; ok {
				if v > 0 {
					topicCacheData.AliveMemberNumMap[sessionCacheData.MsgServerAddr] = v - 1
				} else {
					topicCacheData.AliveMemberNumMap[sessionCacheData.MsgServerAddr] = 0
				}
				self.topicCache.Set(topicCacheData)
			}
		}
	} else {
		sessionStoreData, err = self.mongoStore.GetSessionFromCid(clientID)
		if sessionStoreData == nil {
			log.Warningf("ID %s not registered in STORE", clientID)
		} else {
			log.Infof("remove topic %s from Client STORE %s", topicName, clientID)
			sessionStoreData.RemoveTopic(topicName)
			err = self.mongoStore.Set(sessionStoreData)
			if err != nil {
				log.Error(err.Error())
				return err
			}
			log.Infof("topic %s removed from Client STORE %s", topicName, clientID)

		}
	}
	return nil
}