跨服修改
parent
06fb70ed2a
commit
c4d6ee097b
|
@ -5,19 +5,6 @@ public class RedisKey {
|
|||
public final static String Delimiter_colon = ":";
|
||||
|
||||
|
||||
/**
|
||||
* 服务器世界等级
|
||||
*/
|
||||
public static final String SERVER_WORLDLEVE_INFO = "SERVER_WORLDLEVE_INFO";
|
||||
|
||||
|
||||
public static final String MACH_SERVERINFO = "MACH_SERVERINFO";
|
||||
|
||||
public static final String MATCHED_SPLIT_KEY = "MATCHED_SPLIT_KEY";
|
||||
public static final String MATCHED_VERSION = "MATCHED_VERSION";
|
||||
|
||||
public static final String SERVER_LEVEL_RANK = "SERVER_LEVEL_RANK";
|
||||
|
||||
public static final String SERVER_SPLIT_INFO = "SERVER_SPLIT_INFO";
|
||||
|
||||
}
|
||||
|
|
|
@ -311,6 +311,14 @@ public class RedisKey {
|
|||
public final static String WORLD_ARE_JOIN = "WORLD_ARE_JOIN";//跨服参与人员
|
||||
public final static String WARLD_DIS_ARENA_RANK = "WARLD_DIS_ARENA_RANK";//跨服榜单
|
||||
|
||||
public static final String MACH_SERVERINFO = "MACH_SERVERINFO";
|
||||
|
||||
public static final String MATCHED_SPLIT_KEY = "MATCHED_SPLIT_KEY";
|
||||
public static final String MATCHED_VERSION = "MATCHED_VERSION";
|
||||
|
||||
public static final String SERVER_LEVEL_RANK = "SERVER_LEVEL_RANK";
|
||||
|
||||
public static final String SERVER_SPLIT_INFO = "SERVER_SPLIT_INFO";
|
||||
|
||||
|
||||
public static Set<String> familyKey = new HashSet<>();
|
||||
|
@ -359,25 +367,33 @@ public class RedisKey {
|
|||
static {
|
||||
familyKey.add(ADVENTRUEN_BOSS_CHALLENGE_LOCK_KEY);
|
||||
familyKey.add(OPERATE_FAMILY);
|
||||
familyKey.add(FAMILY_FIGHT);
|
||||
familyKey.add(FAMILY_FIGHT_RANK);
|
||||
familyKey.add(FAMILY_FIGHT_MATCHING_RANK);
|
||||
familyKey.add(FAMILY_ATTACK_BLOOD);
|
||||
familyKey.add(FAMILY_FIGHT_STAR_RANK);
|
||||
familyKey.add(FAMILY_FIGHT_EXTRA_STAR);
|
||||
familyKey.add(FAMILY_FIGHT_CAL_STAR);
|
||||
familyKey.add(FAMILY_FIGHT_BUFF);
|
||||
familyKey.add(FAMILY_FIGHT_ATTACK_COUNT);
|
||||
familyKey.add(FAMILY_FIGHT_TOTAL_STAR);
|
||||
familyKey.add(FAMILY_FIGHT_TOTAL_EXP);
|
||||
familyKey.add(FAMILY_FIGHT_FINISH_MATCHING);
|
||||
familyKey.add(MACH_SERVERINFO);
|
||||
familyKey.add(MATCHED_SPLIT_KEY);
|
||||
familyKey.add(MATCHED_VERSION);
|
||||
familyKey.add(SERVER_LEVEL_RANK);
|
||||
familyKey.add(SERVER_SPLIT_INFO);
|
||||
|
||||
|
||||
|
||||
// familyKey.add(FAMILY_FIGHT);
|
||||
// familyKey.add(FAMILY_FIGHT_RANK);
|
||||
// familyKey.add(FAMILY_FIGHT_MATCHING_RANK);
|
||||
// familyKey.add(FAMILY_ATTACK_BLOOD);
|
||||
// familyKey.add(FAMILY_FIGHT_STAR_RANK);
|
||||
// familyKey.add(FAMILY_FIGHT_EXTRA_STAR);
|
||||
// familyKey.add(FAMILY_FIGHT_CAL_STAR);
|
||||
// familyKey.add(FAMILY_FIGHT_BUFF);
|
||||
// familyKey.add(FAMILY_FIGHT_ATTACK_COUNT);
|
||||
// familyKey.add(FAMILY_FIGHT_TOTAL_STAR);
|
||||
// familyKey.add(FAMILY_FIGHT_TOTAL_EXP);
|
||||
// familyKey.add(FAMILY_FIGHT_FINISH_MATCHING);
|
||||
}
|
||||
public static String getKey(String type, String key, boolean withoutServerId){
|
||||
if(RedisKey.TOKEN.equals(type)||RedisKey.USER_SERVER_INFO.equals(type)||RedisKey.SERVER_WORLDLEVE_INFO.equals(type)){
|
||||
return type + RedisKey.Delimiter_colon + key;
|
||||
}
|
||||
if(familyKey.contains(type)){
|
||||
return GameApplication.serverProperties.getAreaId()+RedisKey.Delimiter_colon+ type+RedisKey.Delimiter_colon+key;
|
||||
return type + RedisKey.Delimiter_colon+key;
|
||||
}
|
||||
|
||||
if(!newAreaCacChe.contains(type)&&!rankCacChe.contains(type)){
|
||||
|
|
|
@ -207,7 +207,7 @@ public class GetPlayerInfoHandler extends BaseHandler{
|
|||
.setExpeditionLeve(user.getExpeditionManager().getExpeditionLeve())
|
||||
.setHadLuckTime( user.getPlayerInfoManager().getLuckWheelLimitTime())
|
||||
.setHadAdvanceLuckTime(user.getPlayerInfoManager().getLuckAdvanceWheelLimitTime())
|
||||
.setWorldLeve(GlobleSystemLogic.getGloableWorldLeveCache())
|
||||
.setWorldLeve(GlobleSystemLogic.getGlobalWorldLevelCache())
|
||||
.addAllDemonsTrialRewardInfo(user.getMapManager().getDemonsTrialRewardInfo())
|
||||
.addAllHeadFrameBag(CBean2Proto.getHeadFrameList(user))
|
||||
.addAllUserMountList(CBean2Proto.getUserMountList(user))
|
||||
|
@ -222,7 +222,7 @@ public class GetPlayerInfoHandler extends BaseHandler{
|
|||
try {
|
||||
//hotfix
|
||||
user.getUserMissionManager().onGameEvent(user,GameEvent.DAILY_TASK_TYPE,0,user);
|
||||
MessageUtil.sendIndicationMessage(iSession, 1, MessageTypeProto.MessageType.WorldLevelIndication_VALUE, PlayerInfoProto.WorldLevelIndication.newBuilder().setWorldLeve(GlobleSystemLogic.getGloableWorldLeveCache()).build(), true);
|
||||
MessageUtil.sendIndicationMessage(iSession, 1, MessageTypeProto.MessageType.WorldLevelIndication_VALUE, PlayerInfoProto.WorldLevelIndication.newBuilder().setWorldLeve(GlobleSystemLogic.getGlobalWorldLevelCache()).build(), true);
|
||||
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.GET_PLAYERINFO_RESPONSE_VALUE, getPlayerInfoResponse, true);
|
||||
|
||||
if(playerInfoManager.getIsdayFirst()==0){
|
||||
|
|
|
@ -6,10 +6,8 @@ import com.ljsd.jieling.db.redis.RedisKey;
|
|||
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||
import com.ljsd.jieling.exception.ErrorCode;
|
||||
import com.ljsd.jieling.exception.ErrorCodeException;
|
||||
import com.ljsd.jieling.kefu.GmRoleAbstract;
|
||||
import com.ljsd.jieling.logic.activity.ActivityLogic;
|
||||
import com.ljsd.jieling.logic.activity.ActivityType;
|
||||
import com.ljsd.jieling.logic.activity.ActivityTypeEnum;
|
||||
import com.ljsd.jieling.logic.activity.IEventHandler;
|
||||
import com.ljsd.jieling.logic.activity.event.*;
|
||||
import com.ljsd.jieling.logic.dao.root.GlobalSystemControl;
|
||||
|
@ -18,6 +16,7 @@ import com.ljsd.jieling.util.InnerMessageUtil;
|
|||
import com.ljsd.jieling.util.MessageUtil;
|
||||
import config.SGlobalActivity;
|
||||
import config.SGodSacrificeSetting;
|
||||
import config.SMServerArenaSetting;
|
||||
import manager.STableManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -28,7 +27,6 @@ import rpc.protocols.MessageTypeProto;
|
|||
import rpc.protocols.PlayerInfoProto;
|
||||
import util.TimeUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -114,14 +112,14 @@ public class GlobleSystemLogic implements IEventHandler {
|
|||
//开服 和 命中等级计算条件
|
||||
if (event instanceof UserLevelEvent || event instanceof ServerOpenEvent) {
|
||||
try {
|
||||
if (event instanceof UserLevelEvent) {
|
||||
if (((UserLevelEvent) event).getLevel() <= getGloableWorldLeveCacheLine()) {
|
||||
return;
|
||||
}
|
||||
String rankKey = RedisKey.getKey(RedisKey.WORLD_CALCUL_LEVE_RAND,"", false);
|
||||
RedisUtil.getInstence().zsetAddOne(rankKey, String.valueOf(((UserLevelEvent) event).getUid()), ((UserLevelEvent) event).getLevel());
|
||||
}
|
||||
calCulRank();
|
||||
// if (event instanceof UserLevelEvent) {
|
||||
// if (((UserLevelEvent) event).getLevel() <= getGloableWorldLeveCacheLine()) {
|
||||
// return;
|
||||
// }
|
||||
// String rankKey = RedisKey.getKey(RedisKey.WORLD_CALCUL_LEVE_RAND,"", false);
|
||||
// RedisUtil.getInstence().zsetAddOne(rankKey, String.valueOf(((UserLevelEvent) event).getUid()), ((UserLevelEvent) event).getLevel());
|
||||
// }
|
||||
getGlobalWorldLevelCache();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error("Exception::=>{}", e.toString());
|
||||
|
@ -137,43 +135,40 @@ public class GlobleSystemLogic implements IEventHandler {
|
|||
*
|
||||
* 2 高于50名
|
||||
*/
|
||||
private void calCulRank() {
|
||||
public void calCulRank() {
|
||||
//need cfg
|
||||
int rankEndLine = 50;
|
||||
Set<ZSetOperations.TypedTuple<String>> rankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.WORLD_CALCUL_LEVE_RAND, "", 0, rankEndLine - 1);
|
||||
RedisUtil.getInstence().del(GameApplication.serverId+":"+RedisKey.WORLD_CALCUL_LEVE_RAND+":");
|
||||
double sum=0;
|
||||
int i=1;
|
||||
//缓存为null 从库里查
|
||||
if(rankInfo.size()==0){
|
||||
Query query = new Query();
|
||||
query.with(new Sort(Sort.Direction.DESC,"playerManager.level"));
|
||||
query.fields().include("playerManager.level");
|
||||
query.limit(rankEndLine);
|
||||
List<User> users = new ArrayList<>();
|
||||
try {
|
||||
users = MongoUtil.getLjsdMongoTemplate().findAllByCondition(query, User.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for (int j = 0; j <users.size() ; j++) {
|
||||
String rankKey = RedisKey.getKey(RedisKey.WORLD_CALCUL_LEVE_RAND,"", false);
|
||||
RedisUtil.getInstence().zsetAddOne(rankKey, String.valueOf(users.get(j).getId()), users.get(j).getPlayerInfoManager().getLevel());
|
||||
}
|
||||
rankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.WORLD_CALCUL_LEVE_RAND, "", 0, rankEndLine - 1);
|
||||
Query query = new Query();
|
||||
query.with(new Sort(Sort.Direction.DESC,"playerManager.level"));
|
||||
query.fields().include("playerManager.level");
|
||||
query.limit(rankEndLine);
|
||||
List<User> users = new ArrayList<>();
|
||||
try {
|
||||
users = MongoUtil.getLjsdMongoTemplate().findAllByCondition(query, User.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for (int j = 0; j <users.size() ; j++) {
|
||||
String rankKey = RedisKey.getKey(RedisKey.WORLD_CALCUL_LEVE_RAND,"", false);
|
||||
RedisUtil.getInstence().zsetAddOne(rankKey, String.valueOf(users.get(j).getId()), users.get(j).getPlayerInfoManager().getLevel());
|
||||
}
|
||||
Set<ZSetOperations.TypedTuple<String>> rankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.WORLD_CALCUL_LEVE_RAND, "", 0, rankEndLine - 1);
|
||||
|
||||
|
||||
for (ZSetOperations.TypedTuple<String> item : rankInfo) {
|
||||
double score = item.getScore();
|
||||
sum+=score;
|
||||
if(i==rankEndLine){
|
||||
//更新line名分数缓存
|
||||
setGloableWorldLeveCacheLine((int)score);
|
||||
}
|
||||
i++;
|
||||
// if(i==rankEndLine){
|
||||
// //更新line名分数缓存
|
||||
// setGloableWorldLeveCacheLine((int)score);
|
||||
// }
|
||||
}
|
||||
|
||||
setGloableWorldLeveCache((int)Math.ceil(sum/ (double) Math.min(rankInfo.size(),rankEndLine)));
|
||||
setGlobalWorldLevelCache((int)Math.ceil(sum/ (double) Math.min(rankInfo.size(),rankEndLine)));
|
||||
|
||||
// if (rankInfo.size() > rankEndLine + 100) {
|
||||
// //删除多余数据 预留一些 长度maxSize
|
||||
|
@ -186,16 +181,23 @@ public class GlobleSystemLogic implements IEventHandler {
|
|||
|
||||
}
|
||||
|
||||
public static int getGloableWorldLeveCache() {
|
||||
return GLOABLE_WORLD_LEVE_CACHE;
|
||||
public static int getGlobalWorldLevelCache() {
|
||||
if (GLOABLE_WORLD_LEVE_CACHE!=0)
|
||||
return GLOABLE_WORLD_LEVE_CACHE;
|
||||
Integer level = RedisUtil.getInstence().getMapValue(RedisKey.SERVER_WORLDLEVE_INFO, "",String.valueOf(GameApplication.serverId),Integer.class);
|
||||
if(level!=null){
|
||||
GLOABLE_WORLD_LEVE_CACHE = level;
|
||||
return level;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static void setGloableWorldLeveCache(int gloableWorldLeveCache) {
|
||||
if(gloableWorldLeveCache!=GLOABLE_WORLD_LEVE_CACHE){
|
||||
GLOABLE_WORLD_LEVE_CACHE = gloableWorldLeveCache;
|
||||
RedisUtil.getInstence().putMapEntry(RedisKey.SERVER_WORLDLEVE_INFO,"",String.valueOf(GameApplication.serverId),gloableWorldLeveCache);
|
||||
private static void setGlobalWorldLevelCache(int globalWorldLevelCache) {
|
||||
if(globalWorldLevelCache>getGlobalWorldLevelCache()){
|
||||
GLOABLE_WORLD_LEVE_CACHE = globalWorldLevelCache;
|
||||
RedisUtil.getInstence().putMapEntry(RedisKey.SERVER_WORLDLEVE_INFO,"",String.valueOf(GameApplication.serverId),globalWorldLevelCache);
|
||||
InnerMessageUtil.broadcastWithRandom(user->{
|
||||
MessageUtil.sendIndicationMessage(OnlineUserManager.getSessionByUid(user.getId()), 1, MessageTypeProto.MessageType.WorldLevelIndication_VALUE, PlayerInfoProto.WorldLevelIndication.newBuilder().setWorldLeve(GlobleSystemLogic.getGloableWorldLeveCache()).build(), true);
|
||||
MessageUtil.sendIndicationMessage(OnlineUserManager.getSessionByUid(user.getId()), 1, MessageTypeProto.MessageType.WorldLevelIndication_VALUE, PlayerInfoProto.WorldLevelIndication.newBuilder().setWorldLeve(GlobleSystemLogic.getGlobalWorldLevelCache()).build(), true);
|
||||
}, new LinkedList<>(OnlineUserManager.sessionMap.keySet()),10);
|
||||
}
|
||||
|
||||
|
@ -209,4 +211,47 @@ public class GlobleSystemLogic implements IEventHandler {
|
|||
GLOABLE_WORLD_LEVE_CACHE_LINE = gloableWorldLeveCacheLine;
|
||||
|
||||
}
|
||||
public void doSplit(){
|
||||
SMServerArenaSetting setting = STableManager.getConfig(SMServerArenaSetting.class).get(1);
|
||||
RedisUtil redisUtil = RedisUtil.getInstence();
|
||||
//这里为所有服务器的世界等级
|
||||
Map<String,Integer> worldLevelMap = redisUtil.getMapValues(RedisKey.SERVER_WORLDLEVE_INFO+":","",String.class,Integer.class);
|
||||
Object matched = redisUtil.get(RedisKey.MATCHED_SPLIT_KEY);
|
||||
if(matched!=null){
|
||||
return;
|
||||
}
|
||||
LOGGER.info("Global开始分组");
|
||||
long lastHour = TimeUtils.getLastOrUnderHour(TimeUtils.now(), 1, 0, 0, true);
|
||||
lastHour+=(2*TimeUtils.WEEK);
|
||||
int expireTime =(int)((lastHour-TimeUtils.now())/1000);
|
||||
redisUtil.set(RedisKey.MATCHED_SPLIT_KEY,String.valueOf(1),expireTime-60);
|
||||
//提前两分钟结算
|
||||
redisUtil.set(RedisKey.MATCHED_VERSION,TimeUtils.getTimeStampYMD(System.currentTimeMillis()),expireTime-120);
|
||||
worldLevelMap.forEach((k,v)->redisUtil.zsetAddOne(RedisKey.SERVER_LEVEL_RANK,k,v));
|
||||
Set<ZSetOperations.TypedTuple<String>> zsetRevRangeWithScore = redisUtil.getZsetRangeWithScore(RedisKey.SERVER_LEVEL_RANK, setting.getWorldLevel(), 999);
|
||||
// int remain = zsetRevRangeWithScore.size() % 8;
|
||||
//如果只有一个服到达条件,则不进行分组
|
||||
if(zsetRevRangeWithScore.size()>1){
|
||||
int index = 0;
|
||||
int areaId = 1;
|
||||
Map<String,Integer> split = new HashMap<>(zsetRevRangeWithScore.size());
|
||||
for(ZSetOperations.TypedTuple<String> data:zsetRevRangeWithScore){
|
||||
if(index>=setting.getServerNum()){
|
||||
if((zsetRevRangeWithScore.size()-areaId*setting.getServerNum())>setting.getServerNum()/2){
|
||||
areaId++;
|
||||
}
|
||||
index=0;
|
||||
}
|
||||
split.put(data.getValue(),areaId);
|
||||
|
||||
index++;
|
||||
}
|
||||
redisUtil.putMapEntrys(RedisKey.SERVER_SPLIT_INFO,"",split);
|
||||
//todo 发分组邮件
|
||||
// sendMail(split.keySet());
|
||||
}
|
||||
LOGGER.info("Global分组结束");
|
||||
// splitInfo = RedisUtil.getInstence().getMapValues(RedisKey.SERVER_SPLIT_INFO,"",String.class,Integer.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -990,7 +990,7 @@ public class ChampionshipLogic {
|
|||
int attackUid = memberInfoAttack.getUid();
|
||||
int defUid = memberInfoDef.getUid();
|
||||
int type = memberInfoAttack.getType() + memberInfoDef.getType();
|
||||
ArenaRecord arenaRecord = new ArenaRecord();
|
||||
ArenaRecord arenaRecord = new ArenaRecord();
|
||||
arenaRecord.setId(KeyGenUtils.produceIdByModule(UUIDEnum.ARENARECORD, memberInfoAttack.getUid()));
|
||||
arenaRecord.setAttackId(attackUid);
|
||||
arenaRecord.setDefUid(defUid);
|
||||
|
|
|
@ -13,6 +13,7 @@ import com.ljsd.jieling.db.redis.RedisUtil;
|
|||
import com.ljsd.jieling.handler.map.MapLogic;
|
||||
import com.ljsd.jieling.hotfix.HotfixUtil;
|
||||
import com.ljsd.jieling.logic.GlobalDataManaager;
|
||||
import com.ljsd.jieling.logic.GlobleSystemLogic;
|
||||
import com.ljsd.jieling.logic.OnlineUserManager;
|
||||
import com.ljsd.jieling.logic.SituationLogic;
|
||||
import com.ljsd.jieling.logic.activity.ActivityLogic;
|
||||
|
@ -63,6 +64,7 @@ public class MinuteTask extends Thread {
|
|||
AreaManager.getInstance().processAddServerAreaIsChange();
|
||||
MessageUtil.checkAndSendMsg();
|
||||
STableManager.updateTablesWithTableNames(true);
|
||||
//计算世界等级
|
||||
ActivityLogic.getInstance().checkSecretBoxSeason();
|
||||
StoreLogic.checkGlobalStore(false);
|
||||
|
||||
|
@ -184,6 +186,7 @@ public class MinuteTask extends Thread {
|
|||
|
||||
//保证每分钟线程
|
||||
try {
|
||||
GlobleSystemLogic.getInstence().calCulRank();
|
||||
ArenaLogic.getInstance().sendReward(GlobalsDef.ARENA_DAILY_REWARD);
|
||||
Map<Integer, GuildInfo> guildInfoMap = GuilidManager.guildInfoMap;
|
||||
for(Map.Entry<Integer,GuildInfo> guildInfoEntry:guildInfoMap.entrySet()){
|
||||
|
@ -252,9 +255,10 @@ public class MinuteTask extends Thread {
|
|||
int minute = calendar.get(Calendar.MINUTE);
|
||||
int w = calendar.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
|
||||
if(w == 1 &&hour == 5 && minute ==0){
|
||||
if(w == 1 &&hour == 0 && minute ==0){
|
||||
LOGGER.info("everyMondyFiveClockTask start ...");
|
||||
CombatLogic.getInstance().sendReward();
|
||||
// CombatLogic.getInstance().sendReward();
|
||||
GlobleSystemLogic.getInstence().doSplit();
|
||||
LOGGER.info("everyMondyFiveClockTask end ...");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue