跨服分组修改
parent
fb69e8de2e
commit
5c70df47db
|
@ -1,8 +1,5 @@
|
||||||
package com.ljsd.jieling.db.redis;
|
package com.ljsd.jieling.db.redis;
|
||||||
|
|
||||||
import com.ljsd.jieling.db.mongo.AreaManager;
|
|
||||||
import com.ljsd.jieling.logic.GlobleSystemLogic;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -356,7 +353,8 @@ public class RedisKey {
|
||||||
|
|
||||||
public static final String GUILD_LEADER_CACHE = "GUILD_LEADER_CACHE";
|
public static final String GUILD_LEADER_CACHE = "GUILD_LEADER_CACHE";
|
||||||
|
|
||||||
public static final String CROSS_RANK_UPDATE_VERSION = "CROSS_RANK_UPDATE_VERSION";
|
public static final String CROSS_RANK_UPDATE = "CROSS_RANK_UPDATE";
|
||||||
|
public static final String CROSS_RANK_DELETE = "CROSS_RANK_DELETE";
|
||||||
|
|
||||||
//玉虚论道
|
//玉虚论道
|
||||||
public static final String CROSS_YUXULUNDAO_RANK = "CROSS_YUXULUNDAO_RANK";//排行榜信息 废弃
|
public static final String CROSS_YUXULUNDAO_RANK = "CROSS_YUXULUNDAO_RANK";//排行榜信息 废弃
|
||||||
|
|
|
@ -1429,27 +1429,27 @@ public class RedisUtil {
|
||||||
if (result == null){
|
if (result == null){
|
||||||
result = AreaManager.areaId + RedisKey.Delimiter_colon + type + RedisKey.Delimiter_colon + key;
|
result = AreaManager.areaId + RedisKey.Delimiter_colon + type + RedisKey.Delimiter_colon + key;
|
||||||
}
|
}
|
||||||
deathPathKeyHandler(result);
|
// 保存需要清理的key
|
||||||
helpHeroKeyHandler(result);
|
saveRemoveKeyHandler(result);
|
||||||
|
|
||||||
return result;}
|
return result;}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 十绝阵rediskey处理
|
* 保存需要清理的key
|
||||||
*/
|
*/
|
||||||
private void deathPathKeyHandler(String key){
|
private void saveRemoveKeyHandler(String key){
|
||||||
|
// 十绝阵相关
|
||||||
if(key.contains("DEATH_PATH")){
|
if(key.contains("DEATH_PATH")){
|
||||||
RedisUtil.getInstence().sSet(RedisKey.DEATH_PATH_DELETE,key);
|
RedisUtil.getInstence().sSet(RedisKey.DEATH_PATH_DELETE,key);
|
||||||
}
|
}
|
||||||
}
|
// 助战相关
|
||||||
|
|
||||||
/**
|
|
||||||
* 助战rediskey处理
|
|
||||||
*/
|
|
||||||
private void helpHeroKeyHandler(String key){
|
|
||||||
if(key.contains("HELP_FIGHT")){
|
if(key.contains("HELP_FIGHT")){
|
||||||
RedisUtil.getInstence().sSet(RedisKey.HELP_FIGHT_DELETE,key);
|
RedisUtil.getInstence().sSet(RedisKey.HELP_FIGHT_DELETE,key);
|
||||||
}
|
}
|
||||||
|
// 跨服排行榜相关
|
||||||
|
if(key.contains("CROSS_RANK_UPDATE")){
|
||||||
|
RedisUtil.getInstence().sSet(RedisKey.CROSS_RANK_DELETE,key);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String LOCK_SUCCESS = "OK";
|
private static final String LOCK_SUCCESS = "OK";
|
||||||
|
|
|
@ -285,13 +285,20 @@ public class GlobleSystemLogic implements IEventHandler {
|
||||||
redisUtil.del(RedisKey.CHAT_CROSS_MSG_ID+i);
|
redisUtil.del(RedisKey.CHAT_CROSS_MSG_ID+i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 重新分组,需要删除旧排行榜数据,重新分组
|
||||||
|
redisUtil.delVague(RedisKey.CROSS_RANK_DELETE,"CROSS_RANK_UPDATE:.*");
|
||||||
|
|
||||||
//释放分布式锁
|
//释放分布式锁
|
||||||
redisUtil.del("SERVER_SPLIT_REDIS_LOCK");
|
redisUtil.del("SERVER_SPLIT_REDIS_LOCK");
|
||||||
|
|
||||||
LOGGER.info("跨服分组结束");
|
LOGGER.info("跨服分组结束");
|
||||||
// splitInfo = RedisUtil.getInstence().getMapValues(RedisKey.SERVER_SPLIT_INFO,"",String.class,Integer.class);
|
// splitInfo = RedisUtil.getInstence().getMapValues(RedisKey.SERVER_SPLIT_INFO,"",String.class,Integer.class);
|
||||||
}
|
}
|
||||||
//获取当前区服的跨服区组 -1为未在分组内
|
|
||||||
|
/**
|
||||||
|
* 获取当前区服的跨服区组 -1为未在分组内
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public int getCrossGroup(){
|
public int getCrossGroup(){
|
||||||
//测试服不参与分组和跨服
|
//测试服不参与分组和跨服
|
||||||
if(!GameApplication.serverProperties.isArenaCross()){
|
if(!GameApplication.serverProperties.isArenaCross()){
|
||||||
|
@ -299,8 +306,23 @@ public class GlobleSystemLogic implements IEventHandler {
|
||||||
}
|
}
|
||||||
Integer group = RedisUtil.getInstence().getMapValue(RedisKey.SERVER_SPLIT_INFO, "", String.valueOf(GameApplication.serverId), Integer.class);
|
Integer group = RedisUtil.getInstence().getMapValue(RedisKey.SERVER_SPLIT_INFO, "", String.valueOf(GameApplication.serverId), Integer.class);
|
||||||
crossGroup = group==null?-1:group;
|
crossGroup = group==null?-1:group;
|
||||||
|
return crossGroup;
|
||||||
|
}
|
||||||
|
|
||||||
return crossGroup;
|
/**
|
||||||
|
* 获取和当前分组同一分组的服务器id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<String> getCrossServersByGroup(){
|
||||||
|
int group = getCrossGroup();
|
||||||
|
Map<String, Integer> values = RedisUtil.getInstence().getMapValues(RedisKey.SERVER_SPLIT_INFO, "", String.class, Integer.class);
|
||||||
|
ArrayList<String> list = new ArrayList<>();
|
||||||
|
for (Map.Entry<String, Integer> entry : values.entrySet()) {
|
||||||
|
if (entry.getValue() == group){
|
||||||
|
list.add(entry.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.ljsd.jieling.logic.rank;
|
package com.ljsd.jieling.logic.rank;
|
||||||
|
|
||||||
|
import com.ljsd.jieling.db.redis.RedisKey;
|
||||||
import com.ljsd.jieling.db.redis.RedisUtil;
|
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||||
import com.ljsd.jieling.logic.GlobleSystemLogic;
|
import com.ljsd.jieling.logic.GlobleSystemLogic;
|
||||||
import com.ljsd.jieling.logic.dao.GuilidManager;
|
import com.ljsd.jieling.logic.dao.GuilidManager;
|
||||||
|
@ -11,6 +12,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.data.redis.core.ZSetOperations;
|
import org.springframework.data.redis.core.ZSetOperations;
|
||||||
import util.TimeUtils;
|
import util.TimeUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -45,7 +47,7 @@ public class CrossRankManager {
|
||||||
/**
|
/**
|
||||||
* 跨服排行处理
|
* 跨服排行处理
|
||||||
*/
|
*/
|
||||||
public void crossRankHandle(boolean choice){
|
public void crossRankHandle(){
|
||||||
// 时间验证
|
// 时间验证
|
||||||
if (isTime()){
|
if (isTime()){
|
||||||
// 全部排行遍历
|
// 全部排行遍历
|
||||||
|
@ -57,11 +59,20 @@ public class CrossRankManager {
|
||||||
int crossGroup = GlobleSystemLogic.getInstence().getCrossGroup();
|
int crossGroup = GlobleSystemLogic.getInstence().getCrossGroup();
|
||||||
if(crossGroup != -1){
|
if(crossGroup != -1){
|
||||||
AbstractRank rank = RankContext.getRankEnum(type);
|
AbstractRank rank = RankContext.getRankEnum(type);
|
||||||
// 获取本服排行榜数据
|
// 获取跨服key
|
||||||
Set<ZSetOperations.TypedTuple<String>> range = RedisUtil.getInstence().getZsetreverseRangeWithScores(rank.getRedisKey(), "", 0, 100, true);
|
|
||||||
// 批量放入跨服排行榜
|
|
||||||
String key = RedisUtil.getInstence().getKey(rank.getCrossRedisKey(),"",false);
|
String key = RedisUtil.getInstence().getKey(rank.getCrossRedisKey(),"",false);
|
||||||
RedisUtil.getInstence().zsetAddAall(key,range);
|
// 清理旧榜数据
|
||||||
|
RedisUtil.getInstence().del(key);
|
||||||
|
// 获取本组的服务器列表
|
||||||
|
List<String> servers = GlobleSystemLogic.getInstence().getCrossServersByGroup();
|
||||||
|
for (String server : servers) {
|
||||||
|
String localKey = RedisUtil.getInstence().getKey(server, rank.getRedisKey(), false);
|
||||||
|
// 获取本地服排行榜数据
|
||||||
|
Set<ZSetOperations.TypedTuple<String>> range =
|
||||||
|
RedisUtil.getInstence().getZsetreverseRangeWithScores(localKey,"",0,100, false);
|
||||||
|
// 批量放入跨服排行榜
|
||||||
|
RedisUtil.getInstence().zsetAddAall(key,range);
|
||||||
|
}
|
||||||
LOGGER.info("=====================跨服排行榜处理========,key:{}",key);
|
LOGGER.info("=====================跨服排行榜处理========,key:{}",key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,14 +85,17 @@ public class CrossRankManager {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private boolean isTime(){
|
private boolean isTime(){
|
||||||
long now = TimeUtils.now();
|
int group = GlobleSystemLogic.getInstence().getCrossGroup();
|
||||||
long twoHour = TimeUtils.HOUR * 2;
|
if (group == -1){
|
||||||
if (now >= twoHour+time){
|
|
||||||
time = now;
|
|
||||||
return true;
|
|
||||||
}else{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
String key = RedisUtil.getInstence().getKey(RedisKey.CROSS_RANK_UPDATE, String.valueOf(group), false);
|
||||||
|
Object object = RedisUtil.getInstence().get(key);
|
||||||
|
if (object != null){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
RedisUtil.getInstence().set(key,"1",TimeUtils.HOUR * 2);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -11,7 +11,6 @@ import com.ljsd.jieling.globals.Global;
|
||||||
import com.ljsd.jieling.ktbeans.ReportEventEnum;
|
import com.ljsd.jieling.ktbeans.ReportEventEnum;
|
||||||
import com.ljsd.jieling.ktbeans.ReportUtil;
|
import com.ljsd.jieling.ktbeans.ReportUtil;
|
||||||
import com.ljsd.jieling.logic.GlobleSystemLogic;
|
import com.ljsd.jieling.logic.GlobleSystemLogic;
|
||||||
import com.ljsd.jieling.logic.activity.crossService.CrossServiceLogic;
|
|
||||||
import com.ljsd.jieling.logic.dao.Hero;
|
import com.ljsd.jieling.logic.dao.Hero;
|
||||||
import com.ljsd.jieling.logic.dao.TeamEnum;
|
import com.ljsd.jieling.logic.dao.TeamEnum;
|
||||||
import com.ljsd.jieling.logic.dao.TeamPosHeroInfo;
|
import com.ljsd.jieling.logic.dao.TeamPosHeroInfo;
|
||||||
|
|
|
@ -163,10 +163,10 @@ public class MinuteTask extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CrossRankManager.getInstance().crossRankHandle(false);
|
CrossRankManager.getInstance().crossRankHandle();
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
LOGGER.error("跨服排行榜初始化一次,Exception::=>{}",e.toString());
|
LOGGER.error("跨服排行榜初始化异常,Exception::=>{}",e.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue