Merge branch 'master' of http://60.1.1.230/backend/jieling_server
commit
11af6398d3
|
@ -33,6 +33,9 @@ public class MongoConfig {
|
|||
@Value("${spring.data.mongodb.uri}")
|
||||
private String MONGO_URI;
|
||||
|
||||
@Value("${spring.data.mongodbcore.uri}")
|
||||
private String MONGO_CORE_URI;
|
||||
|
||||
|
||||
// 覆盖默认的MongoDbFactory
|
||||
@Bean
|
||||
|
@ -72,8 +75,23 @@ public class MongoConfig {
|
|||
return new MongoTemplate(this.mongoDbFactory(), this.mappingMongoConverter1());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Bean(name = "LjsdMongoTemplate")
|
||||
public LjsdMongoTemplate ljsdMongoTemplate() throws Exception {
|
||||
return new LjsdMongoTemplate(this.mongoTemplate());
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认简单配置 查询core配置
|
||||
* @return
|
||||
* @throws UnknownHostException
|
||||
*/
|
||||
@Bean
|
||||
public MongoDbFactory dbFactory2() throws UnknownHostException {
|
||||
return new SimpleMongoDbFactory(new MongoClientURI(MONGO_CORE_URI));
|
||||
}
|
||||
|
||||
@Bean(name = "coreMongoTemplate")
|
||||
public MongoTemplate coreMongoTemplate() throws Exception {
|
||||
return new MongoTemplate(dbFactory2());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.ljsd.jieling.config.ServerConfig;
|
|||
import com.ljsd.jieling.config.json.CoreSettings;
|
||||
import com.ljsd.jieling.config.json.ServerConfiguration;
|
||||
import com.ljsd.jieling.config.json.ServerProperties;
|
||||
import com.ljsd.jieling.core.CoreLogic;
|
||||
import com.ljsd.jieling.db.mongo.MongoUtil;
|
||||
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||
import com.ljsd.jieling.handler.BaseHandler;
|
||||
|
@ -114,6 +115,8 @@ public class GameApplication {
|
|||
|
||||
KeyGenUtils.setMachineNum(serverConfiguration.getServerProperties().getNum());
|
||||
ActivityLogic.getInstance().checkActiviyStatus();
|
||||
//初始化cdk
|
||||
CoreLogic.getInstance().checkCoreCdk();
|
||||
ThriftPoolUtils.getInstance().initContext(configurableApplicationContext);
|
||||
GlobalDataManaager.getInstance().whenServerStart(configurableApplicationContext);
|
||||
HeroLogic.getInstance().afterSet();
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package com.ljsd.jieling.core;
|
||||
|
||||
import com.ljsd.jieling.db.mongo.MongoUtil;
|
||||
import com.ljsd.jieling.logic.dao.SCdkInfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CoreLogic {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CoreLogic.class);
|
||||
|
||||
private Map<Integer, SCdkInfo> sCdkInfosCacheMap = new HashMap<>();
|
||||
|
||||
private CoreLogic() {}
|
||||
|
||||
public static CoreLogic getInstance() {
|
||||
return Instance.instance;
|
||||
}
|
||||
|
||||
public static class Instance {
|
||||
public final static CoreLogic instance = new CoreLogic();
|
||||
}
|
||||
|
||||
|
||||
public void checkCoreCdk() throws Exception{
|
||||
try {
|
||||
List<SCdkInfo> all = MongoUtil.getCoreMongoTemplate().findAll(SCdkInfo.class);
|
||||
if(!all.isEmpty()){
|
||||
Map<Integer,SCdkInfo> sCdkInfosMap = new HashMap<>(all.size());
|
||||
for(SCdkInfo sCdkInfo: all){
|
||||
sCdkInfosMap.put(sCdkInfo.getId(),sCdkInfo);
|
||||
}
|
||||
sCdkInfosCacheMap = sCdkInfosMap;
|
||||
}
|
||||
}catch (Exception e){
|
||||
LOGGER.error("cdkErr:"+e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Map<Integer, SCdkInfo> getsCdkInfosCacheMap() {
|
||||
return sCdkInfosCacheMap;
|
||||
}
|
||||
|
||||
public void setsCdkInfosCacheMap(Map<Integer, SCdkInfo> sCdkInfosCacheMap) {
|
||||
this.sCdkInfosCacheMap = sCdkInfosCacheMap;
|
||||
}
|
||||
}
|
|
@ -2,24 +2,17 @@ package com.ljsd.jieling.db.mongo;
|
|||
|
||||
import com.google.gson.Gson;
|
||||
import com.ljsd.common.mogodb.LjsdMongoTemplate;
|
||||
import com.ljsd.common.mogodb.test.pojo.PlayerForTest;
|
||||
import com.ljsd.jieling.logic.dao.PlayerManager;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.util.MathUtils;
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.MongoClientURI;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
|
||||
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
|
||||
import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper;
|
||||
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
|
||||
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Field;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
|
@ -47,9 +40,12 @@ public class MongoUtil {
|
|||
|
||||
private LjsdMongoTemplate myMongoTemplate;
|
||||
|
||||
private MongoTemplate coreMongoTemplate;
|
||||
|
||||
|
||||
public void init(ConfigurableApplicationContext configurableApplicationContext){
|
||||
myMongoTemplate =configurableApplicationContext.getBean(LjsdMongoTemplate.class);
|
||||
coreMongoTemplate = (MongoTemplate)configurableApplicationContext.getBean("coreMongoTemplate");
|
||||
}
|
||||
|
||||
public LjsdMongoTemplate getMyMongoTemplate() {
|
||||
|
@ -82,6 +78,11 @@ public class MongoUtil {
|
|||
return this.myMongoTemplate.findAllByCondition(query, User.class) ;
|
||||
}
|
||||
|
||||
public static MongoTemplate getCoreMongoTemplate() throws UnknownHostException {
|
||||
|
||||
return MongoUtil.getInstence().coreMongoTemplate;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
LjsdMongoTemplate ljsdMongoTemplate = getLjsdMongoTemplate();
|
||||
|
@ -109,4 +110,5 @@ public class MongoUtil {
|
|||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -173,6 +173,8 @@ public class RedisKey {
|
|||
public static final String BLOODY_PERSON_BATTLE_INFO = "BLOODY_PERSON_BATTLE_INFO";
|
||||
public static final String MATCH_SERVER_INFO = "MATCH_SERVER_INFO";
|
||||
|
||||
public final static String CDKEY = "CDKEY";
|
||||
|
||||
public static String getKey(String type, String key, boolean withoutServerId) {
|
||||
if(RedisKey.TOKEN.equals(type)||RedisKey.USER_SERVER_INFO.equals(type)){
|
||||
return type + RedisKey.Delimiter_colon + key;
|
||||
|
|
|
@ -996,7 +996,8 @@ public class RedisUtil {
|
|||
if(RedisKey.BLOODY_RANK.equals(type) || RedisKey.BLOODY_TEAM.equals(type) || RedisKey.PLAYER_INFO_CACHE.equals(type) || RedisKey.BLOODY_PERSON_BATTLE_INFO.equals(type)) {
|
||||
return type + RedisKey.Delimiter_colon + key;
|
||||
}
|
||||
if(RedisKey.TOKEN.equals(type)||RedisKey.USER_SERVER_INFO.equals(type)){
|
||||
if(RedisKey.TOKEN.equals(type)||RedisKey.USER_SERVER_INFO.equals(type)||
|
||||
RedisKey.CDKEY.equals(type)){
|
||||
return type + RedisKey.Delimiter_colon + key;
|
||||
}
|
||||
return GameApplication.serverId + RedisKey.Delimiter_colon + type + RedisKey.Delimiter_colon + key;
|
||||
|
|
|
@ -76,6 +76,7 @@ public class LoginRequestHandler extends BaseHandler<PlayerInfoProto.LoginReques
|
|||
KTEnvironmentUtil.addUserSimpleEnviromentInfo(userId,paramEnvironmentSimpleBean);
|
||||
KTEnvironmentUtil.addUserEnviromentInfo(userId,paramEnvironmentBean);
|
||||
|
||||
int pid = Integer.valueOf(loginRequest.getChannelS());
|
||||
|
||||
//登陆注册入内存
|
||||
String openIdFront = loginRequest.getOpenId();
|
||||
|
@ -84,9 +85,9 @@ public class LoginRequestHandler extends BaseHandler<PlayerInfoProto.LoginReques
|
|||
if(split.length>=2){
|
||||
String openId = split[0];
|
||||
String chanel = split[1];
|
||||
user = UserManager.userLogin(userId,openId,chanel);
|
||||
user = UserManager.userLogin(userId,openId,chanel,pid);
|
||||
}else{
|
||||
user = UserManager.userLogin(userId,openIdFront,"");
|
||||
user = UserManager.userLogin(userId,openIdFront,"",pid);
|
||||
}
|
||||
|
||||
// String newToken = UserManager.getNewToken(userId);
|
||||
|
|
|
@ -0,0 +1,124 @@
|
|||
package com.ljsd.jieling.handler.core;
|
||||
|
||||
import com.ljsd.GameApplication;
|
||||
import com.ljsd.jieling.config.SErrorCodeEerverConfig;
|
||||
import com.ljsd.jieling.core.CoreLogic;
|
||||
import com.ljsd.jieling.core.GlobalsDef;
|
||||
import com.ljsd.jieling.db.mongo.MongoUtil;
|
||||
import com.ljsd.jieling.db.redis.RedisKey;
|
||||
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||
import com.ljsd.jieling.globals.Global;
|
||||
import com.ljsd.jieling.handler.BaseHandler;
|
||||
import com.ljsd.jieling.logic.dao.CdkInfo;
|
||||
import com.ljsd.jieling.logic.dao.CdkUseInfo;
|
||||
import com.ljsd.jieling.logic.dao.SCdkInfo;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.logic.mail.MailLogic;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||
import com.ljsd.jieling.protocols.PlayerInfoProto;
|
||||
import com.ljsd.jieling.util.*;
|
||||
import com.mongodb.BasicDBObject;
|
||||
import org.springframework.data.mongodb.core.query.BasicQuery;
|
||||
import org.springframework.data.mongodb.core.query.BasicUpdate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import sun.misc.MessageUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class ExchangeCdkHandler extends BaseHandler<PlayerInfoProto.ExchangeCdkRequest> {
|
||||
|
||||
|
||||
@Override
|
||||
public MessageTypeProto.MessageType getMessageCode() {
|
||||
return MessageTypeProto.MessageType.EXCHANGE_CDK_REQUEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processWithProto(ISession session, PlayerInfoProto.ExchangeCdkRequest proto) throws Exception {
|
||||
|
||||
String cdk = proto.getKey();
|
||||
int uid = session.getUid();
|
||||
User user = UserManager.getUser(session.getUid());
|
||||
Map<Integer, SCdkInfo> sCdkInfosCacheMap = CoreLogic.getInstance().getsCdkInfosCacheMap();
|
||||
if (cdk.length() != 18 || sCdkInfosCacheMap == null || sCdkInfosCacheMap.isEmpty()) {
|
||||
MessageUtil.sendErrorResponse(session, 0, MessageTypeProto.MessageType.EXCHANGE_CDK_RESPONSE_VALUE, "cdk.wrong");
|
||||
return;
|
||||
}
|
||||
boolean distributedLock = RedisUtil.getInstence().tryGetDistributedLock(RedisKey.CDKEY,cdk , Integer.toString(uid),500);
|
||||
if (!distributedLock) {
|
||||
MessageUtil.sendErrorResponse(session, 0, MessageTypeProto.MessageType.EXCHANGE_CDK_RESPONSE_VALUE, "兑换失败,请重试");
|
||||
return;
|
||||
}
|
||||
//兑换码信息
|
||||
CdkInfo cdkInfo;
|
||||
int goodsId;
|
||||
try {
|
||||
cdkInfo = MongoUtil.getCoreMongoTemplate().findById(cdk, CdkInfo.class);
|
||||
if (cdkInfo == null) {
|
||||
MessageUtil.sendErrorResponse(session, 0, MessageTypeProto.MessageType.EXCHANGE_CDK_RESPONSE_VALUE, "cdk.wrong");
|
||||
return;
|
||||
}
|
||||
goodsId = cdkInfo.getGoodsId();
|
||||
//礼包信息
|
||||
SCdkInfo scdkInfo = sCdkInfosCacheMap.get(goodsId);
|
||||
if (scdkInfo == null) {
|
||||
MessageUtil.sendErrorResponse(session, 0, MessageTypeProto.MessageType.EXCHANGE_CDK_RESPONSE_VALUE, "cdk.wrong");
|
||||
return;
|
||||
}
|
||||
|
||||
//pid
|
||||
if(user.getPlayerInfoManager().getPid()!=scdkInfo.getPid())
|
||||
{
|
||||
MessageUtil.sendErrorResponse(session,0, MessageTypeProto.MessageType.EXCHANGE_CDK_REQUEST_VALUE,"cdk wrong");
|
||||
return;
|
||||
}
|
||||
int usetype = scdkInfo.getUsetype();
|
||||
if (usetype == 0) {//只能兑换一次
|
||||
if (cdkInfo.getStatus() == 1) {
|
||||
MessageUtil.sendErrorResponse(session, 0, MessageTypeProto.MessageType.EXCHANGE_CDK_RESPONSE_VALUE, "cdk.used");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
boolean exists = MongoUtil.getCoreMongoTemplate().exists(new BasicQuery(new BasicDBObject("uid", uid).append("cdk_num", cdk)), CdkUseInfo.class);
|
||||
if(exists){
|
||||
MessageUtil.sendErrorResponse(session, 0, MessageTypeProto.MessageType.EXCHANGE_CDK_RESPONSE_VALUE, "cdk.role used");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
long size = MongoUtil.getCoreMongoTemplate().count(new BasicQuery(new BasicDBObject("uid", uid).append("goodsId", goodsId)), CdkUseInfo.class);
|
||||
if (size >= scdkInfo.getRoleUseNum()) {
|
||||
MessageUtil.sendErrorResponse(session, 0, MessageTypeProto.MessageType.EXCHANGE_CDK_RESPONSE_VALUE, "已达角色兑换上线");
|
||||
return;
|
||||
}
|
||||
|
||||
BasicDBObject basicDBObject = new BasicDBObject();
|
||||
basicDBObject.put("$set", new BasicDBObject("status", 1));
|
||||
BasicUpdate basicUpdate = new BasicUpdate(basicDBObject);
|
||||
MongoUtil.getCoreMongoTemplate().updateFirst(new BasicQuery(new BasicDBObject("_id", cdk)), basicUpdate, CdkInfo.class);
|
||||
updataCdkUseInfo(uid, cdk, goodsId);
|
||||
MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.EXCHANGE_CDK_RESPONSE_VALUE, null, true);
|
||||
|
||||
String title = SErrorCodeEerverConfig.getI18NMessage("Conversion_title");
|
||||
String content = SErrorCodeEerverConfig.getI18NMessage("Conversion_txt");
|
||||
|
||||
MailLogic.getInstance().sendMail(uid, title, content, scdkInfo.getReward(), (int) (TimeUtils.now() / 1000), Global.MAIL_EFFECTIVE_TIME);
|
||||
} finally {
|
||||
RedisUtil.getInstence().releaseDistributedLock(RedisKey.CDKEY, cdk, Integer.toString(uid));
|
||||
}
|
||||
}
|
||||
|
||||
private void updataCdkUseInfo(int uid, String cdk, int goodsId) throws Exception {
|
||||
CdkUseInfo cdkUseInfo = new CdkUseInfo();
|
||||
cdkUseInfo.setId(KeyGenUtils.produceIdByModule(UUIDEnum.CDK, uid));
|
||||
cdkUseInfo.setCdk(cdk);
|
||||
cdkUseInfo.setUid(uid);
|
||||
cdkUseInfo.setGoodsId(goodsId);
|
||||
cdkUseInfo.setServerId(GameApplication.serverId);
|
||||
cdkUseInfo.setCreateTime(System.currentTimeMillis());
|
||||
MongoUtil.getCoreMongoTemplate().insert(cdkUseInfo);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package com.ljsd.jieling.logic.dao;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
import org.springframework.data.mongodb.core.mapping.Field;
|
||||
|
||||
@Document(collection = "cdk_info")
|
||||
public class CdkInfo {
|
||||
@Id
|
||||
private String id; // 生成的序列号id
|
||||
|
||||
@Field(value = "goodsId")
|
||||
private int goodsId; //所属的商品id
|
||||
|
||||
@Field(value = "status")
|
||||
private int status; // 是否兑换 0:未兑换 1:已兑换
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getGoodsId() {
|
||||
return goodsId;
|
||||
}
|
||||
|
||||
public void setGoodsId(int goodsId) {
|
||||
this.goodsId = goodsId;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
package com.ljsd.jieling.logic.dao;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
import org.springframework.data.mongodb.core.mapping.Field;
|
||||
|
||||
@Document(collection = "cdk_use_info")
|
||||
public class CdkUseInfo {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@Field(value = "cdk_num")
|
||||
private String cdk;
|
||||
|
||||
@Field(value = "uid")
|
||||
private int uid;
|
||||
|
||||
@Field(value = "create_time")
|
||||
private long createTime;
|
||||
|
||||
@Field(value = "serverId")
|
||||
private int serverId;
|
||||
|
||||
|
||||
@Field(value = "goodsId")
|
||||
private int goodsId;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getCdk() {
|
||||
return cdk;
|
||||
}
|
||||
|
||||
public int getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public long getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public int getServerId() {
|
||||
return serverId;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setCdk(String cdk) {
|
||||
this.cdk = cdk;
|
||||
}
|
||||
|
||||
public void setUid(int uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public void setCreateTime(long createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public void setServerId(int serverId) {
|
||||
this.serverId = serverId;
|
||||
}
|
||||
|
||||
public int getGoodsId() {
|
||||
return goodsId;
|
||||
}
|
||||
|
||||
public void setGoodsId(int goodsId) {
|
||||
this.goodsId = goodsId;
|
||||
}
|
||||
}
|
|
@ -22,6 +22,8 @@ public class PlayerManager extends MongoBase {
|
|||
|
||||
private String openId;
|
||||
|
||||
private int pid;
|
||||
|
||||
private String nickName;
|
||||
|
||||
private int level;
|
||||
|
@ -490,4 +492,13 @@ public class PlayerManager extends MongoBase {
|
|||
updateString("phoneBindInfo",phoneBindInfo);
|
||||
this.phoneBindInfo = phoneBindInfo;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
updateString("pid",pid);
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
package com.ljsd.jieling.logic.dao;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
import org.springframework.data.mongodb.core.mapping.Field;
|
||||
|
||||
@Document(collection = "cdk_add_info")
|
||||
public class SCdkInfo {
|
||||
@Id
|
||||
private int id; //所属的商品id
|
||||
/**
|
||||
* 0:兌換一次。
|
||||
* 1:兌換多次。
|
||||
*/
|
||||
@Field(value = "usetype")
|
||||
private int usetype;
|
||||
|
||||
@Field(value = "pid")
|
||||
private int pid;
|
||||
|
||||
@Field(value = "role_use_num")
|
||||
private int roleUseNum;
|
||||
|
||||
@Field(value = "start_time")
|
||||
private long startTime;
|
||||
|
||||
@Field(value = "end_time")
|
||||
private long endTime;
|
||||
|
||||
@Field(value = "reward")
|
||||
private String reward;
|
||||
|
||||
@Field(value = "goods_name")
|
||||
private String goodsName;
|
||||
|
||||
@Field(value = "goods_info")
|
||||
private String goodsInfo;
|
||||
|
||||
@Field(value = "goods_sum")
|
||||
private int goodsSum;
|
||||
|
||||
@Field(value = "isAdd")
|
||||
private int isAdd; // 1: 已生成过 ,0: 未生成过
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getUsetype() {
|
||||
return usetype;
|
||||
}
|
||||
|
||||
public void setUsetype(int usetype) {
|
||||
this.usetype = usetype;
|
||||
}
|
||||
|
||||
public long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(long startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public long getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(long endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public String getReward() {
|
||||
return reward;
|
||||
}
|
||||
|
||||
public void setReward(String reward) {
|
||||
this.reward = reward;
|
||||
}
|
||||
|
||||
public String getGoodsName() {
|
||||
return goodsName;
|
||||
}
|
||||
|
||||
public void setGoodsName(String goodsName) {
|
||||
this.goodsName = goodsName;
|
||||
}
|
||||
|
||||
public String getGoodsInfo() {
|
||||
return goodsInfo;
|
||||
}
|
||||
|
||||
public void setGoodsInfo(String goodsInfo) {
|
||||
this.goodsInfo = goodsInfo;
|
||||
}
|
||||
|
||||
public int getGoodsSum() {
|
||||
return goodsSum;
|
||||
}
|
||||
|
||||
public void setGoodsSum(int goodsSum) {
|
||||
this.goodsSum = goodsSum;
|
||||
}
|
||||
|
||||
public int getIsAdd() {
|
||||
return isAdd;
|
||||
}
|
||||
|
||||
public void setIsAdd(int isAdd) {
|
||||
this.isAdd = isAdd;
|
||||
}
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public int getRoleUseNum() {
|
||||
return roleUseNum;
|
||||
}
|
||||
|
||||
public void setRoleUseNum(int roleUseNum) {
|
||||
this.roleUseNum = roleUseNum;
|
||||
}
|
||||
}
|
||||
|
|
@ -31,12 +31,12 @@ public class UserManager {
|
|||
return userMap.containsKey(uid);
|
||||
}
|
||||
|
||||
public static User userLogin(int uid,String openId,String channel) throws Exception {
|
||||
public static User userLogin(int uid,String openId,String channel,int pid) throws Exception {
|
||||
User user = null;
|
||||
if (!UserManager.isUserExist(uid)){
|
||||
user = MongoUtil.getInstence().getMyMongoTemplate().findById(User.getCollectionName(), uid, User.class);
|
||||
if (user == null) {
|
||||
user = registerUser(uid,openId,channel);
|
||||
user = registerUser(uid,openId,channel,pid);
|
||||
}
|
||||
UserManager.addUser(user);
|
||||
}else{
|
||||
|
@ -46,16 +46,16 @@ public class UserManager {
|
|||
}
|
||||
|
||||
|
||||
private static User registerUser(int uid,String openId,String channel) throws Exception {
|
||||
private static User registerUser(int uid,String openId,String channel,int pid) throws Exception {
|
||||
User user = new User(uid);
|
||||
initPlayer(user,openId,channel);
|
||||
initPlayer(user,openId,channel,pid);
|
||||
UserManager.addUser(user);
|
||||
MongoUtil.getInstence().getMyMongoTemplate().save(user);
|
||||
PlayerLogic.getInstance().sendTestWelfareMail(user,1,1);
|
||||
return user;
|
||||
}
|
||||
|
||||
private static void initPlayer(User user,String openId,String channel) throws Exception {
|
||||
private static void initPlayer(User user,String openId,String channel,int pid) throws Exception {
|
||||
SGameSetting gameSetting = SGameSetting.getGameSetting();
|
||||
PlayerManager playerManager = user.getPlayerInfoManager();
|
||||
long now = TimeUtils.now();
|
||||
|
@ -72,6 +72,7 @@ public class UserManager {
|
|||
playerManager.setRechargeInfo(new RechargeInfo());
|
||||
playerManager.setPhoneBindInfo(new PhoneBindInfo(""));
|
||||
playerManager.setChannel(channel);
|
||||
playerManager.setPid(pid);
|
||||
playerManager.setHeadFrame(SGameSetting.getGameSetting().getDefaultPicture());
|
||||
SPlayerLevelConfig sPlayerLevelConfig = SPlayerLevelConfig.getsPlayerLevelConfigMap().get(1);
|
||||
playerManager.setMaxStamina(sPlayerLevelConfig.getMaxEnergy());
|
||||
|
|
|
@ -297,6 +297,8 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
|||
ISession iSession = OnlineUserManager.getSessionByUid(uid);
|
||||
MessageUtil.sendErrorCode(iSession, ErrorCode.reloginCode,"您的账号已经在其他设备上登陆,请确认账号安全!");
|
||||
iSession.setOfflineType(ErrorCode.reloginCode);
|
||||
backUpMsgToRedis(iSession);
|
||||
offLine(iSession);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -311,7 +313,7 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
|||
byte[] message = iSession.getCacheMessage(index);
|
||||
if (message==null){
|
||||
//TODO error
|
||||
LOGGER.info("the uid={},the msg={} is processing",iSession.getUid(), MessageTypeProto.MessageType.valueOf(packetNetData.getMsgId()));
|
||||
LOGGER.info("the uid={},the msg={} is processing,the index={},the sessionIndex={}",iSession.getUid(), MessageTypeProto.MessageType.valueOf(packetNetData.getMsgId()),index,iSession.getIndex());
|
||||
return 1;
|
||||
}else {
|
||||
LOGGER.info("the uid={},the msg={} reback",iSession.getUid(), MessageTypeProto.MessageType.valueOf(packetNetData.getMsgId()));
|
||||
|
@ -349,7 +351,6 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
|||
LOGGER.info("player offLine ...");
|
||||
ISession session = (ISession) gameSession;
|
||||
synchronized (session) {
|
||||
OnlineUserManager.userOffline(session.getUid());
|
||||
User user = UserManager.getUserInMem(session.getUid());
|
||||
if(user == null){
|
||||
return;
|
||||
|
@ -360,6 +361,7 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
|||
if(session.getOfflineType() == ErrorCode.reloginCode){
|
||||
return;
|
||||
}
|
||||
OnlineUserManager.userOffline(session.getUid());
|
||||
if (session.getCtx() != null) {
|
||||
GameMessageHandler.allChannels.remove(session.getCtx().channel());
|
||||
}
|
||||
|
@ -380,14 +382,7 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
|||
ActivityLogic.getInstance().updateActivityMissionProgress(user, ActivityType.OnlineReward,(int)(onlineTime/TimeUtils.ONE_SECOND));
|
||||
GuildLogic.updateMyPos(user);
|
||||
MongoUtil.getInstence().lastUpdate();
|
||||
ConcurrentHashMap<Integer, ISession.IndicationMsg> indexToIndication = session.getIndexToIndication();
|
||||
if(!indexToIndication.isEmpty() ){
|
||||
String key = RedisUtil.getInstence().getKey(RedisKey.INDICATION_OFFLINE, Integer.toString(session.getUid()));
|
||||
RedisUtil.getInstence().set(key,gson.toJson(indexToIndication));
|
||||
}
|
||||
|
||||
String key = RedisUtil.getInstence().getKey(RedisKey.RESPONSE_OFFLINE, Integer.toString(session.getUid()));
|
||||
RedisUtil.getInstence().set(key,gson.toJson(session.getIndexToMessage()));
|
||||
backUpMsgToRedis(session);
|
||||
// 下线处理的逻辑需要添加在这里
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -397,6 +392,18 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
|||
}
|
||||
}
|
||||
|
||||
private void backUpMsgToRedis(ISession session){
|
||||
ConcurrentHashMap<Integer, ISession.IndicationMsg> indexToIndication = session.getIndexToIndication();
|
||||
if(!indexToIndication.isEmpty() ){
|
||||
String key = RedisUtil.getInstence().getKey(RedisKey.INDICATION_OFFLINE, Integer.toString(session.getUid()));
|
||||
RedisUtil.getInstence().set(key,gson.toJson(indexToIndication));
|
||||
}
|
||||
|
||||
String key = RedisUtil.getInstence().getKey(RedisKey.RESPONSE_OFFLINE, Integer.toString(session.getUid()));
|
||||
LOGGER.info("the uid={},the offlineIndex={},",session.getUid(),session.getIndexToMessage().keySet().iterator().next());
|
||||
RedisUtil.getInstence().set(key,gson.toJson(session.getIndexToMessage()));
|
||||
}
|
||||
|
||||
|
||||
public boolean kickOldUser(int uid, String uToken, int errorCode, String errorMsg, long requestTime) {
|
||||
if (GameMessageHandler.currentSessions.size() != 0 && GameMessageHandler.currentSessions.keySet().contains(uid)) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.ljsd.jieling.thread.task;
|
|||
|
||||
import com.ljsd.GameApplication;
|
||||
import com.ljsd.jieling.config.reportData.DataMessageUtils;
|
||||
import com.ljsd.jieling.core.CoreLogic;
|
||||
import com.ljsd.jieling.core.GlobalsDef;
|
||||
import com.ljsd.jieling.db.mongo.MongoUtil;
|
||||
import com.ljsd.jieling.db.redis.RedisKey;
|
||||
|
@ -60,6 +61,7 @@ public class MinuteTask extends Thread {
|
|||
QuestionLogic.getInstence().checkQuestion();
|
||||
MailLogic.getInstance().checkReadyToMail();
|
||||
ProtocolsManager.getInstance().minuteCheckForbidUser();
|
||||
CoreLogic.getInstance().checkCoreCdk();
|
||||
RedisUtil.getInstence().set(RedisKey.ONLINE_NUM+RedisKey.Delimiter_colon+GameApplication.serverId, String.valueOf(OnlineUserManager.sessionMap.entrySet().size()));
|
||||
LOGGER.info("MinuteTask end...");
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -8,7 +8,8 @@ public enum UUIDEnum {
|
|||
ADVENTUREBOSS(4),
|
||||
GUILDLOG(5),
|
||||
ESPECIAL_EQUIP(6),
|
||||
SOUL_EQUIP(7)//魂印
|
||||
SOUL_EQUIP(7),//魂印
|
||||
CDK(8)//cdk
|
||||
;
|
||||
|
||||
private int value;
|
||||
|
|
Loading…
Reference in New Issue