public class AntispamService {
static private class Keys {
static public String SECURITY_ANTISPAM_TIMES_USER_LIST = "py:sec:anti:tmlist:";
static public String SECURITY_ANTISPAM_TIMES_USER_STATUS = "py:sec:anti:tmstat:";
}
static private int allowtimes = 6;//条数
static private long checkmillidseconds = 3000;//3s
static private int banseconds = 1800;//1800s
static public boolean permitTimes(Session session, IRedis redis, long uid) {
boolean exi = redis.exists(Keys.SECURITY_ANTISPAM_TIMES_USER_STATUS
+ uid);
if (!exi) {
long nowtime = redis.currentTimeMillis();
redis.lpush(Keys.SECURITY_ANTISPAM_TIMES_USER_LIST + uid, nowtime
+ "");
String withtime = redis.lindex(
Keys.SECURITY_ANTISPAM_TIMES_USER_LIST + uid, allowtimes);
if (withtime != null) {
redis.ltrim(Keys.SECURITY_ANTISPAM_TIMES_USER_LIST + uid, 0,
allowtimes);
long with = Long.parseLong(withtime);
if ((nowtime - with) < checkmillidseconds) {
exi = redis.exists(Keys.SECURITY_ANTISPAM_TIMES_USER_STATUS
+ uid);
if (!exi) {
redis.set(Keys.SECURITY_ANTISPAM_TIMES_USER_STATUS
+ uid, nowtime + "");
redis.expire(Keys.SECURITY_ANTISPAM_TIMES_USER_STATUS
+ uid, banseconds);
sealUser(session, redis, uid);
}
return false;
}
}
return true;
}
return false;
}
}
反作弊
最新推荐文章于 2024-04-19 21:48:26 发布