修改跨服取数据序列化方法

DESKTOP-C3M45P4\dengdan 2025-05-13 17:30:43 +08:00
parent e93fcdaf35
commit 8b87171a00
7 changed files with 60 additions and 3 deletions

View File

@ -355,6 +355,11 @@ public class CoreService implements RPCRequestIFace.Iface {
jsonObject.getJSONObject("playerManager").put("newRechargeInfo", null);
jsonObject.remove("mailManager");
jsonObject.remove("storeManager");
// jsonObject.remove("mainLevelManager");
jsonObject.remove("mailManager");
jsonObject.remove("userMissionManager");
jsonObject.remove("hardStageManager");
// jsonObject.remove("friendManager");
return jsonObject.toString();
}catch (Exception e){
e.printStackTrace();

View File

@ -0,0 +1,20 @@
package com.ljsd;
import com.google.gson.*;
import com.ljsd.jieling.logic.dao.Baubles;
import com.ljsd.jieling.logic.dao.PropertyItem;
import java.lang.reflect.Type;
public class PropertyItemDeserializer implements JsonDeserializer<PropertyItem> {
@Override
public PropertyItem deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObject = json.getAsJsonObject();
JsonPrimitive type = jsonObject.getAsJsonPrimitive("type");
if (type != null && type.getAsString().equals("baubles")) {
return context.deserialize(json, Baubles.class);
} else {
return null;
}
}
}

View File

@ -1,10 +1,13 @@
package com.ljsd.jieling.db.redis;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.ljsd.GameApplication;
import com.ljsd.PropertyItemDeserializer;
import com.ljsd.common.mogodb.util.GlobalData;
import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.db.mongo.AreaManager;
import com.ljsd.jieling.logic.dao.PropertyItem;
import com.ljsd.jieling.util.ConfigurableApplicationContextManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -30,6 +33,7 @@ public class RedisUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(RedisUtil.class);
private final Gson gson = new Gson();
private Gson specialGson = null;
private static final int MAX_TRY_TIMES = 3; //最大尝试次数,保障获取/存储成功
private static final int FAILED_SLEEP = 2; //每次失败最大停顿时间
@ -1495,4 +1499,13 @@ public class RedisUtil {
}
}
public Gson getSpecialGson(){
if(this.specialGson == null){
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(PropertyItem.class, new PropertyItemDeserializer());
specialGson = builder.create();
}
return specialGson;
}
}

View File

@ -8,6 +8,8 @@ import java.util.Set;
*/
public class Baubles extends PropertyItem{
private String type = "baubles";
private String masterId = "";//主法宝id用于庇佑
private Set<String> blessList = new HashSet<>();//庇佑
@ -48,4 +50,12 @@ public class Baubles extends PropertyItem{
this.blessList.add(baublesId);
updateString("blessList", blessList);
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = "baubles";
}
}

View File

@ -1,5 +1,7 @@
package com.ljsd.jieling.logic.dao;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.ljsd.common.mogodb.MongoBase;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.util.KeyGenUtils;
@ -7,6 +9,11 @@ import com.ljsd.jieling.util.UUIDEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
//@JsonSubTypes({
// @JsonSubTypes.Type(value = Baubles.class, name = "baubles")
//})
public class PropertyItem extends MongoBase {
private static final Logger LOGGER = LoggerFactory.getLogger(PropertyItem.class);

View File

@ -2338,7 +2338,7 @@ public class HeroLogic {
}
/**
* 使
*
*/
public List<Integer> getHeroSkillList(User user, Hero hero) {
HeroVo heroVo = HeroVo.createHeroVo(user, hero);

View File

@ -1,7 +1,10 @@
package com.ljsd.jieling.logic.player;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.ljsd.GameApplication;
import com.ljsd.PropertyItemDeserializer;
import com.ljsd.jieling.config.clazzStaticCfg.CommonStaticConfig;
import com.ljsd.jieling.config.clazzStaticCfg.TaskStaticConfig;
import com.ljsd.jieling.core.GlobalsDef;
@ -1385,7 +1388,7 @@ public class PlayerLogic {
String ip = rpcString.split(":")[0];
String port = rpcString.split(":")[3];
StringBuilder sb = new StringBuilder();
Gson gson = RedisUtil.getInstence().getGson();
Gson gson = RedisUtil.getInstence().getSpecialGson();
sb.append("RPCCORE").append("|").append(ip).append("|").append(port);
ClientAdapterPo<RPCRequestIFace.Client> rPCClient = null;
String userStr = null ;
@ -1401,7 +1404,6 @@ public class PlayerLogic {
LOGGER.info("callback=> rPCClient is null ");
}
}
if (userStr == null || userStr.isEmpty()) {
LOGGER.error("getUserByRpc userStr == null uid={}", uid);
return null;