Merge branch 'bt/hefu' into dev_dh_bt

back_recharge
duhui 2023-05-19 16:35:56 +08:00
commit 0d19cccb45
7 changed files with 88 additions and 14 deletions

View File

@ -1,6 +1,8 @@
package com.ljsd.jieling.core; package com.ljsd.jieling.core;
import com.ljsd.GameApplication;
import com.ljsd.jieling.db.mongo.MongoUtil; import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.db.mongo.core.CHefuInfo;
import com.ljsd.jieling.db.mongo.core.ServerAreaInfoManager; import com.ljsd.jieling.db.mongo.core.ServerAreaInfoManager;
import com.ljsd.jieling.logic.dao.SCdkInfo; import com.ljsd.jieling.logic.dao.SCdkInfo;
import com.ljsd.jieling.logic.dao.root.UserInfo; import com.ljsd.jieling.logic.dao.root.UserInfo;
@ -30,13 +32,25 @@ public class CoreLogic {
public final static CoreLogic instance = new CoreLogic(); public final static CoreLogic instance = new CoreLogic();
} }
public ServerAreaInfoManager findServerArenaInfoManager() throws Exception{
MongoTemplate coreMongoTemplate = MongoUtil.getCoreMongoTemplate();
public ServerAreaInfoManager findServerArenaInfoManager() throws Exception{
MongoTemplate coreMongoTemplate =MongoUtil.getCoreMongoTemplate();
return coreMongoTemplate.findById(1,ServerAreaInfoManager.class); return coreMongoTemplate.findById(1,ServerAreaInfoManager.class);
} }
public CHefuInfo findHefuInfo() {
MongoTemplate coreMongoTemplate = MongoUtil.getCoreMongoTemplate();
Query query = new Query(Criteria.where("serverId").is(GameApplication.serverId));
return coreMongoTemplate.findOne(query, CHefuInfo.class);
}
public boolean isHefu(int serverId) {
CHefuInfo hefuInfo = findHefuInfo();
if (hefuInfo == null){
return false;
}
return hefuInfo.getSlaveServerIds().contains(serverId);
}
public int findServerIdFromMongo(int uid) { public int findServerIdFromMongo(int uid) {
MongoTemplate coreMongoTemplate = MongoUtil.getCoreMongoTemplate(); MongoTemplate coreMongoTemplate = MongoUtil.getCoreMongoTemplate();
Query query = new Query(Criteria.where("_id").is(uid)); Query query = new Query(Criteria.where("_id").is(uid));

View File

@ -416,19 +416,25 @@ public class AreaManager {
} }
public int getServerIdByUid(int uid, int defaultServerId) { public int getServerIdByUid(int uid, int defaultServerId) {
// Integer serverIdByUid = RedisUtil.getInstence().getMapEntry(RedisKey.CUser_ServerId_Key,"",Integer.toString(uid),Integer.class); if (defaultServerId == GameApplication.serverId){
if (serverIds.contains(uid)) { return defaultServerId;
return uid;
} }
Integer serverIdByUid = RedisUtil.getInstence().getObject(RedisKey.CUser_ServerId_Key, Integer.toString(uid), Integer.class, GlobalsDef.REDIS_OVER_TIME_DAY * 10); Integer serverIdByUid = RedisUtil.getInstence().getObject(RedisKey.CUser_ServerId_Key, Integer.toString(uid), Integer.class, GlobalsDef.REDIS_OVER_TIME_DAY * 10);
if (serverIdByUid != null) { if (serverIdByUid != null && !CoreLogic.getInstance().isHefu(serverIdByUid)) {
return serverIdByUid; return serverIdByUid;
} }
int serverIdFromMongo = CoreLogic.getInstance().findServerIdFromMongo(uid); int serverIdFromMongo = CoreLogic.getInstance().findServerIdFromMongo(uid);
if (serverIdFromMongo > 0) { if (serverIdFromMongo != 0 && !CoreLogic.getInstance().isHefu(serverIdFromMongo)){
String key = RedisKey.CUser_ServerId_Key + RedisKey.Delimiter_colon + uid; return serverIdFromMongo;
RedisUtil.getInstence().setObject(key, Integer.toString(serverIdFromMongo), GlobalsDef.REDIS_OVER_TIME_DAY * 10);
} }
return serverIdFromMongo;
return GameApplication.serverId;
}
public void putCUserServer(int uid, int serverId){
String key = RedisKey.CUser_ServerId_Key + RedisKey.Delimiter_colon + uid;
RedisUtil.getInstence().setObject(key, serverId, GlobalsDef.REDIS_OVER_TIME_DAY * 10);
} }
} }

View File

@ -0,0 +1,50 @@
package com.ljsd.jieling.db.mongo.core;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import java.util.List;
/**
* @Author hj
* @Date 2023/5/17 17:22:10
* @Description:
* @Version 1.0
*/
@Document(collection = "c_hefu_info")
public class CHefuInfo {
@Id
private int id;
@Field(value = "masterServerId")
private int masterServerId;
@Field(value = "slaveServerIds")
private List<Integer> slaveServerIds;
public int getMasterServerId() {
return masterServerId;
}
public void setMasterServerId(int masterServerId) {
this.masterServerId = masterServerId;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public List<Integer> getSlaveServerIds() {
return slaveServerIds;
}
public void setSlaveServerIds(List<Integer> slaveServerIds) {
this.slaveServerIds = slaveServerIds;
}
}

View File

@ -1589,7 +1589,7 @@ public class RedisUtil {
if (!RedisKey.newAreaCacChe.contains(type) && !RedisKey.rankCacChe.contains(type) && key.length() == 8) { if (!RedisKey.newAreaCacChe.contains(type) && !RedisKey.rankCacChe.contains(type) && key.length() == 8) {
Integer serverId = RedisUtil.getInstence().getObject(RedisKey.CUser_ServerId_Key, key, Integer.class, GlobalsDef.REDIS_OVER_TIME_DAY * 10); Integer serverId = RedisUtil.getInstence().getObject(RedisKey.CUser_ServerId_Key, key, Integer.class, GlobalsDef.REDIS_OVER_TIME_DAY * 10);
if (serverId != null){ if (serverId != null) {
return serverId + RedisKey.Delimiter_colon + type + RedisKey.Delimiter_colon + key; return serverId + RedisKey.Delimiter_colon + type + RedisKey.Delimiter_colon + key;
} }
} }

View File

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.ljsd.GameApplication; import com.ljsd.GameApplication;
import com.ljsd.jieling.config.clazzStaticCfg.HeroStaticConfig; import com.ljsd.jieling.config.clazzStaticCfg.HeroStaticConfig;
import com.ljsd.jieling.core.GlobalsDef; import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.db.mongo.AreaManager;
import com.ljsd.jieling.db.mongo.LjsdMongoTemplate; import com.ljsd.jieling.db.mongo.LjsdMongoTemplate;
import com.ljsd.jieling.db.mongo.MongoUtil; import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.db.mongo.gmActivity.ARBActivity; import com.ljsd.jieling.db.mongo.gmActivity.ARBActivity;
@ -83,6 +84,7 @@ public class GetPlayerInfoHandler extends BaseHandler{
int token = netData.getToken(); int token = netData.getToken();
int msgId = netData.getMsgId(); int msgId = netData.getMsgId();
int msgIndex = netData.getIndex(); int msgIndex = netData.getIndex();
AreaManager.getInstance().putCUserServer(userId,GameApplication.serverId);
PlayerInfoProto.GetPlayerInfoRequest getPlayerInfoRequest = PlayerInfoProto.GetPlayerInfoRequest.parseFrom(netData.parseClientProtoNetData()); PlayerInfoProto.GetPlayerInfoRequest getPlayerInfoRequest = PlayerInfoProto.GetPlayerInfoRequest.parseFrom(netData.parseClientProtoNetData());
LOGGER.info("processMessage->uid={},token={},msgId={},msgIndex={},messageNum={},messageStr={}", LOGGER.info("processMessage->uid={},token={},msgId={},msgIndex={},messageNum={},messageStr={}",
userId, token,msgId,msgIndex,getPlayerInfoRequest.getNum(),getPlayerInfoRequest.getStr()); userId, token,msgId,msgIndex,getPlayerInfoRequest.getNum(),getPlayerInfoRequest.getStr());

View File

@ -182,7 +182,7 @@ public class CSPlayer {
} }
public int getServerId() { public int getServerId() {
return AreaManager.getInstance().getServerIdByUid(userId, GameApplication.serverId); return AreaManager.getInstance().getServerIdByUid(userId, 0);
} }
public void setServerId(int serverId) { public void setServerId(int serverId) {

View File

@ -4,6 +4,7 @@ import com.google.gson.Gson;
import com.ljsd.GameApplication; import com.ljsd.GameApplication;
import com.ljsd.jieling.config.clazzStaticCfg.CommonStaticConfig; import com.ljsd.jieling.config.clazzStaticCfg.CommonStaticConfig;
import com.ljsd.jieling.config.clazzStaticCfg.TaskStaticConfig; import com.ljsd.jieling.config.clazzStaticCfg.TaskStaticConfig;
import com.ljsd.jieling.core.CoreLogic;
import com.ljsd.jieling.core.GlobalsDef; import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.core.VipPrivilegeType; import com.ljsd.jieling.core.VipPrivilegeType;
import com.ljsd.jieling.dataReport.reportBeans_37.ChatContentType; import com.ljsd.jieling.dataReport.reportBeans_37.ChatContentType;
@ -1777,6 +1778,7 @@ public class PlayerLogic {
if (rpcString == null) { if (rpcString == null) {
return null; return null;
} }
String[] split = rpcString.split(":"); String[] split = rpcString.split(":");
if (split.length < 4) { if (split.length < 4) {
LOGGER.error("获取玩家rpc地址,长度错误,rpc:{},玩家id:{},服务器id:{}", rpcString, uid, serverId); LOGGER.error("获取玩家rpc地址,长度错误,rpc:{},玩家id:{},服务器id:{}", rpcString, uid, serverId);