package org.tio.sitexxx.server.topic;

import cn.hutool.core.util.StrUtil;
import org.redisson.api.listener.MessageListener;
import org.tio.core.Tio;
import org.tio.sitexxx.service.vo.topic.PullIpToBlackVo;
import org.tio.sitexxx.server.init.WebApiInit;

import java.util.Objects;

/**
 * @author tanyaowu
 *
 */
public class TopicPullIpToBlackListener implements MessageListener<PullIpToBlackVo> {

	public static final TopicPullIpToBlackListener me = new TopicPullIpToBlackListener();

	@Override
	public void onMessage(CharSequence channel, PullIpToBlackVo pullIpToBlackVo) {
		String ip = pullIpToBlackVo.getIp();
		if (StrUtil.isNotBlank(ip)) {
			if (Objects.equals(pullIpToBlackVo.getType(), PullIpToBlackVo.Type.ADD_BLACK_IP)) {
				Tio.IpBlacklist.add(WebApiInit.tioServerConfig, ip);
			} else {
				Tio.IpBlacklist.remove(WebApiInit.tioServerConfig, ip);
			}
		}
	}

}
