diff --git a/common/src/main/java/com/ljsd/common/mogodb/MongoUpdateCache.java b/common/src/main/java/com/ljsd/common/mogodb/MongoUpdateCache.java index 322d5b7e1..48f332c66 100644 --- a/common/src/main/java/com/ljsd/common/mogodb/MongoUpdateCache.java +++ b/common/src/main/java/com/ljsd/common/mogodb/MongoUpdateCache.java @@ -2,10 +2,10 @@ package com.ljsd.common.mogodb; import com.ljsd.common.mogodb.util.ConcurrentDataMessage; import com.ljsd.common.mogodb.util.MongoKeys; -import com.mongodb.BasicDBObject; -import org.springframework.data.mongodb.core.MongoTemplate; -import java.util.*; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; public class MongoUpdateCache { @@ -66,10 +66,7 @@ public class MongoUpdateCache { public boolean checkOverride(String key1,String key2){ String[] fullKeyArray = key1.split("\\."); String[] key1Array = key2.split("\\."); - if(fullKeyArray.length == key1Array.length && !fullKeyArray[fullKeyArray.length -1].equals(key1Array[key1Array.length -1])){ - return false; - } - return true; + return fullKeyArray.length != key1Array.length || fullKeyArray[fullKeyArray.length - 1].equals(key1Array[key1Array.length - 1]); } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/core/CoreLogic.java b/serverlogic/src/main/java/com/ljsd/jieling/core/CoreLogic.java index 4306652b9..7b6d886c2 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/core/CoreLogic.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/core/CoreLogic.java @@ -43,12 +43,12 @@ public class CoreLogic { return coreMongoTemplate.findOne(query, CHefuInfo.class); } - public boolean isHefu(int serverId) { + public boolean isNotHefu(int serverId) { CHefuInfo hefuInfo = findHefuInfo(); if (hefuInfo == null){ - return false; + return true; } - return hefuInfo.getSlaveServerIds().contains(serverId); + return !hefuInfo.getSlaveServerIds().contains(serverId); } public int findServerIdFromMongo(int uid) { diff --git a/serverlogic/src/main/java/com/ljsd/jieling/db/mongo/AreaManager.java b/serverlogic/src/main/java/com/ljsd/jieling/db/mongo/AreaManager.java index 71b977781..41a4ff747 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/db/mongo/AreaManager.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/db/mongo/AreaManager.java @@ -137,10 +137,7 @@ public class AreaManager { } else { //大区新建 int masterServerId = serverAreaInfoDb.getMasterServerId(); - if (masterServerId == GameApplication.serverId) { - needAddRobotInRank = true;//主服 - } - if (addServerOrAreaIds.keySet().contains(GameApplication.serverId)) { + if (addServerOrAreaIds.containsKey(GameApplication.serverId)) { mineServerAreaInfo = serverAreaInfoDb;//从服 } } @@ -415,22 +412,18 @@ public class AreaManager { return false; } - public int getServerIdByUid(int uid, int defaultServerId) { - if (defaultServerId == GameApplication.serverId){ - return defaultServerId; - } + public int getServerIdByUid(int uid) { + // redis绑定的serverid Integer serverIdByUid = RedisUtil.getInstence().getObject(RedisKey.CUser_ServerId_Key, Integer.toString(uid), Integer.class, GlobalsDef.REDIS_OVER_TIME_DAY * 10); - if (serverIdByUid != null && !CoreLogic.getInstance().isHefu(serverIdByUid)) { - LOGGER.info("uid=>{},defaultId =>{},getServerIdByUid1->{}",uid,defaultServerId,serverIdByUid); + if (serverIdByUid != null && CoreLogic.getInstance().isNotHefu(serverIdByUid)) { return serverIdByUid; } - LOGGER.info("uid=>{},defaultId =>{},getServerIdByUid2",uid,defaultServerId); + // 数据库里存储的serverid int serverIdFromMongo = CoreLogic.getInstance().findServerIdFromMongo(uid); - if (serverIdFromMongo != 0 && !CoreLogic.getInstance().isHefu(serverIdFromMongo)){ - LOGGER.info("uid=>{},defaultId =>{},serverIdFromMongo->{}",uid,defaultServerId,serverIdFromMongo); + if (serverIdFromMongo != 0 && CoreLogic.getInstance().isNotHefu(serverIdFromMongo)){ return serverIdFromMongo; } - LOGGER.info("uid=>{},defaultId =>{},serverIdFromMongo2",uid,defaultServerId); + // 本服的 return GameApplication.serverId; } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/db/mongo/LjsdMongoTemplate.java b/serverlogic/src/main/java/com/ljsd/jieling/db/mongo/LjsdMongoTemplate.java index 310853696..bdd7008db 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/db/mongo/LjsdMongoTemplate.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/db/mongo/LjsdMongoTemplate.java @@ -41,7 +41,7 @@ public class LjsdMongoTemplate implements MongoUpdateImp { // MongoRoot root = (MongoRoot)obj; // mongoTemplate.save(obj,root.getCollection()); // root.setBsave(true); - int serverIdByUid = AreaManager.getInstance().getServerIdByUid(uid, GameApplication.serverId); + int serverIdByUid = AreaManager.getInstance().getServerIdByUid(uid); MongoTemplate otherMonogTemplate = getMongoTemplate(serverIdByUid); if (otherMonogTemplate == null) { return; @@ -123,7 +123,7 @@ public class LjsdMongoTemplate implements MongoUpdateImp { } public T findById(String collectionName, String id, Class clazz) throws Exception { - int serverIdByUid = AreaManager.getInstance().getServerIdByUid(Integer.parseInt(id), GameApplication.serverId); + int serverIdByUid = AreaManager.getInstance().getServerIdByUid(Integer.parseInt(id)); MongoTemplate otherMonogTemplate = getMongoTemplate(serverIdByUid); if(otherMonogTemplate==null){ return null; @@ -141,7 +141,7 @@ public class LjsdMongoTemplate implements MongoUpdateImp { public T findById(String collectionName, int id, Class clazz) throws Exception { - int serverIdByUid = AreaManager.getInstance().getServerIdByUid(id, GameApplication.serverId); + int serverIdByUid = AreaManager.getInstance().getServerIdByUid(id); MongoTemplate otherMonogTemplate = getMongoTemplate(serverIdByUid); if(otherMonogTemplate==null){ return null; @@ -155,7 +155,7 @@ public class LjsdMongoTemplate implements MongoUpdateImp { if(clazz.equals(GlobalSystemControl.class)||clazz.equals(ServerConfig.class)){ serverIdByUid = GameApplication.serverId; }else { - serverIdByUid = AreaManager.getInstance().getServerIdByUid(id, GameApplication.serverId); + serverIdByUid = AreaManager.getInstance().getServerIdByUid(id); } MongoTemplate otherMonogTemplate = getMongoTemplate(serverIdByUid); @@ -215,7 +215,7 @@ public class LjsdMongoTemplate implements MongoUpdateImp { Integer guilderverId = MongoUtil.getInstence().findGuilderverId(Integer.parseInt(id)); otherMonogTemplate = MongoUtil.getInstence().getMonogTemplate(guilderverId); }else { - int serverIdByUid = AreaManager.getInstance().getServerIdByUid(Integer.parseInt(id), GameApplication.serverId); + int serverIdByUid = AreaManager.getInstance().getServerIdByUid(Integer.parseInt(id)); otherMonogTemplate = MongoUtil.getInstence().getMonogTemplate(serverIdByUid); } if (otherMonogTemplate == null) { diff --git a/serverlogic/src/main/java/com/ljsd/jieling/handler/family/GuildHelpHelpOtherRequestHandler.java b/serverlogic/src/main/java/com/ljsd/jieling/handler/family/GuildHelpHelpOtherRequestHandler.java index ad4849c04..2b5993c69 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/handler/family/GuildHelpHelpOtherRequestHandler.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/handler/family/GuildHelpHelpOtherRequestHandler.java @@ -111,7 +111,7 @@ public class GuildHelpHelpOtherRequestHandler extends BaseHandlertargetUser.getFriendManager().addBeLikedCount(1)); - int serverId = AreaManager.getInstance().getServerIdByUid(targetUid, GameApplication.serverId); + int serverId = AreaManager.getInstance().getServerIdByUid(targetUid); if (serverId == GameApplication.serverId) { ProtocolsManager.getInstance().updateAyncWorker(ayyncWorker); } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/player/PlayerLogic.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/player/PlayerLogic.java index e23e55c87..3739477e0 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/player/PlayerLogic.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/player/PlayerLogic.java @@ -1756,7 +1756,7 @@ public class PlayerLogic { * @throws Exception */ public User getUserByRpc(int uid) { - int serverId = AreaManager.getInstance().getServerIdByUid(uid, GameApplication.serverId); + int serverId = AreaManager.getInstance().getServerIdByUid(uid); if (serverId == 0) { LOGGER.info("serverId is Exception serverId={}", serverId); return null;