Пример #1
0
func (u *User) GetServers() (servers []*common.IRCServer) {
	err := common.RedisSliceLoad(u.ServerListKey(), &servers)
	if err != nil {
		log.Println("GetServers: ", err)
	}
	return
}
Пример #2
0
func (u *User) GetChannels() (channels []*common.IRCChannel) {
	err := common.RedisSliceLoad(u.ChannelListKey(), &channels)
	if err != nil {
		log.Println("GetChannels: ", err)
		return nil
	}
	return
}
func LoadDb() {
	r := common.DefaultRedisPool().Get()
	defer r.Close()

	// 서버 목록들을 읽어와서 IRCClient를 생성하고 접속
	reply, err := redis.Values(r.Do("KEYS", "servers:*"))
	if err != nil {
		log.Println("LoadDb: ", err)
		os.Exit(1)
	}
	for _, key := range reply {
		key, _ := redis.String(key, nil)
		var servers []*common.IRCServer
		err = common.RedisSliceLoad(key, &servers)
		if err != nil {
			log.Println("LoadDb: ", err)
			os.Exit(1)
		}
		for _, server := range servers {
			server.Active = false
			ircMgr.register <- NewClient(server)
		}
	}

	// 채널 목록을 읽어와서 채널을 추가
	reply, err = redis.Values(r.Do("KEYS", "channels:*"))
	if err != nil {
		log.Println("LoadDb: ", err)
		os.Exit(1)
	}
	for _, key := range reply {
		key, _ := redis.String(key, nil)
		var channels []*common.IRCChannel
		err = common.RedisSliceLoad(key, &channels)
		if err != nil {
			log.Println("LoadDb: ", err)
			os.Exit(1)
		}
		for _, channel := range channels {
			c := ircMgr.GetClient(channel.UserId, channel.ServerId)
			channel.Joined = false
			c.AddChannel(channel.Name)
		}
	}
}
Пример #4
0
func (um *UserManager) SendPushMessage(userId string, packet *Packet) error {
	_tokens := make([]string, 0)
	tokenListKey := fmt.Sprintf("tokens:%s", userId)

	err := common.RedisSliceLoad(tokenListKey, &_tokens)
	if err != nil {
		return err
	}

	tokens := make(map[string]bool)
	for _, token := range _tokens {
		tokens[token] = true
	}

	user, _ := um.GetConnectedUser(userId)
	if user != nil {
		// websocket connection으로 푸시 전송 시도
		ignoreTokens := user.SendPushMessage(packet)
		for token, _ := range ignoreTokens {
			delete(tokens, token)
		}
	}

	if len(tokens) != 0 {
		// 푸시 Agent로 푸시 전송 시도
		pushMessage := &PushMessage{
			UserId:     userId,
			PushTokens: make([]string, len(tokens)),
			Payload:    packet,
		}
		i := 0
		for token, _ := range tokens {
			pushMessage.PushTokens[i] = token
			i++
		}
		manager.push.Send <- pushMessage
	}
	return nil
}