Merge branch 'project0.92'

# Conflicts:
#	serverlogic/src/main/java/com/ljsd/jieling/network/session/ISession.java
back_recharge
wangyuan 2019-08-26 15:31:15 +08:00
commit 08447fdb97
14 changed files with 246 additions and 38 deletions

View File

@ -2,7 +2,7 @@ package com.ljsd.jieling.core;
import com.ljsd.GameApplication;
import com.ljsd.jieling.config.SChallengeConfig;
import com.ljsd.jieling.config.SChallengeMapConfig;
import com.ljsd.jieling.config.SErrorCodeEerverConfig;
import com.ljsd.jieling.config.SGlobalSystemConfig;
import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.globals.Global;
@ -31,6 +31,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
public class HandlerLogicThread extends Thread{
private static final Logger LOGGER = LoggerFactory.getLogger(HandlerLogicThread.class);
private static Set<Integer> whiteMsg = new HashSet<>();
private static ThreadLocal<SimpleTransaction> threadlocal = new ThreadLocal();
static {
whiteMsg.add(MessageTypeProto.MessageType.MAP_ENTER_REQUEST_VALUE);
whiteMsg.add(MessageTypeProto.MessageType.MAP_START_EXPLORE_REQUEST_VALUE);
@ -85,6 +86,8 @@ public class HandlerLogicThread extends Thread{
whiteMsg.add(MessageTypeProto.MessageType.FAMILY_GET_APPLY_REQUEST_VALUE);
whiteMsg.add(MessageTypeProto.MessageType.ADVENTURE_BOSSHURT_REQEUST_VALUE);
@ -113,11 +116,14 @@ public class HandlerLogicThread extends Thread{
}
int userId = packetNetData.getUserId();
int msgId = packetNetData.getMsgId();
ISession session = OnlineUserManager.getSessionByUid(userId);
if(session == null){
LOGGER.info("request uid=>{} , msgId=>{}, session is null",userId,msgId);
return;
}
session.setLastMsgId(msgId);
setTransaction(session);
BaseHandler baseHandler = ProtocolsManager.getInstance().getHandler(msgId);
if(baseHandler == null){
LOGGER.info("request uid=>{} , msgId=>{}, not find the baseHandler",userId,msgId);
@ -143,7 +149,7 @@ public class HandlerLogicThread extends Thread{
MissionEventDistributor.requestStart();
baseHandler.execute(session, packetNetData);
MissionEventDistributor.requestEnd(session,true);
current().commit();
MongoUtil.getInstence().lastUpdate();
if(msgId != MessageTypeProto.MessageType.GET_CHAT_MESSAGE_REQUEST_VALUE){
long useTime = System.currentTimeMillis() - curTimeMillis;
@ -151,13 +157,35 @@ public class HandlerLogicThread extends Thread{
}
}catch (Exception e){
LOGGER.error("",e);
SimpleTransaction transaction = current();
if(null!=transaction){
ISession session = transaction.getSession();
try {
current().callback();
LOGGER.error("\nuser:"+ session.getUid(),e);
User user = UserManager.getUserInMem(session.getUid());
if (null != user) {
UserManager.removeUser(session.getUid());
}
user = MongoUtil.getInstence().getMyMongoTemplate().findById(User.getCollectionName(), session.getUid(), User.class);
if (user == null) {
return;
}
UserManager.addUser(user);
MessageUtil.sendErrorCode(session,session.getLastMsgId()+1, SErrorCodeEerverConfig.getI18NMessage("bug_unify_txt"));
}catch (Exception e1){}
}else {
LOGGER.error("",e);
}
}finally {
destroyISession();
}
}
private boolean checkIsPermit(int msgId,ISession session) throws Exception {
private boolean checkIsPermit(int msgId, ISession session) throws Exception {
int uid = session.getUid();
User user = UserManager.getUser(uid);
int curMapId = user.getMapManager().getCurMapId();
@ -175,7 +203,7 @@ public class HandlerLogicThread extends Thread{
}
private boolean checkFunctionIsOpen(int msgId,ISession session ) {
private boolean checkFunctionIsOpen(int msgId, ISession session ) {
int uid = session.getUid();
try {
User user = UserManager.getUser(uid);
@ -284,4 +312,22 @@ public class HandlerLogicThread extends Thread{
public void addAyyncWorker(AyyncWorker ayyncWorker){
ayyncWorkerConcurrentLinkedQueue.offer(ayyncWorker);
}
public static SimpleTransaction current() {
return threadlocal.get();
}
private static void destroyISession() {
threadlocal.set(null);
}
private static SimpleTransaction setTransaction(ISession session) {
SimpleTransaction var0 = threadlocal.get();
if (var0 != null && var0.getSession() != null && var0.getSession().getId().equals(session.getId())) {
var0.reset();
return var0;
} else {
threadlocal.set(new SimpleTransaction(session));
}
return threadlocal.get();
}
}

View File

@ -0,0 +1,68 @@
package com.ljsd.jieling.core;
import com.google.protobuf.GeneratedMessage;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.util.MessageUtil;
import java.util.ArrayList;
/**
*
*/
public class SimpleTransaction {
//当前过程的session
private ISession session;
private ArrayList<TransTask> tasks = new ArrayList();
public SimpleTransaction(ISession session) {
this.session = session;
}
public ISession getSession() {
return session;
}
public void dealWhileCommit(TransTask transTask) {
tasks.add(transTask);
}
public void dealWhileCallback(TransTask transTask) {
transTask.setCallback(true);
tasks.add(transTask);
}
public void commit() {
for (TransTask transTask : tasks) {
if (!transTask.isCallback())
transTask.run();
}
}
public void callback() {
for (TransTask transTask : tasks) {
if (transTask.isCallback())
transTask.run();
}
}
public static class SendTask extends TransTask {
private GeneratedMessage proto;
private int msgId;
public SendTask(GeneratedMessage proto, int msgId) {
this.proto = proto;
this.msgId = msgId;
}
@Override
public void run() {
if (null != HandlerLogicThread.current() && null != HandlerLogicThread.current().getSession())
MessageUtil.sendIndicationMessage(HandlerLogicThread.current().getSession(), 1, msgId, proto, true);
}
}
public void reset(){
tasks.clear();
}
}

View File

@ -0,0 +1,16 @@
package com.ljsd.jieling.core;
/**
*
*/
public abstract class TransTask implements Runnable{
boolean callback = false; //是否失败处理
public boolean isCallback() {
return callback;
}
public void setCallback(boolean callback) {
this.callback = callback;
}
}

View File

@ -0,0 +1,17 @@
package com.ljsd.jieling.exception;
public class LogicException extends Exception {
public LogicException(String s) {
super(s);
}
public LogicException(String s, Throwable throwable) {
super(s, throwable);
}
public String getMessage() {
return "" + super.getMessage();
}
}

View File

@ -1,12 +1,13 @@
package com.ljsd.jieling.handler;
import com.google.protobuf.*;
import com.google.protobuf.GeneratedMessage;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Parser;
import com.ljsd.jieling.exception.LogicException;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.protocols.PlayerInfoProto;
import javax.swing.plaf.basic.BasicEditorPaneUI;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
@ -31,14 +32,18 @@ public abstract class BaseHandler<T extends GeneratedMessage> {
}
@SuppressWarnings("unchecked")
private void processWithProto(ISession iSession, PacketNetData netData) {
private void processWithProto(ISession iSession, PacketNetData netData)throws Exception {
T proto = null;
try {
Field field = protoClazz.getField("PARSER");
Parser<T> parser = (Parser) field.get(protoClazz);
processWithProto(iSession, parser.parseFrom(netData.parseClientProtoNetData()));
} catch (Exception var4) {
System.out.print("解析协议失败" + var4);
var4.printStackTrace();
proto=parser.parseFrom(netData.parseClientProtoNetData());
processWithProto(iSession,proto);
} catch(NoSuchFieldException|SecurityException|IllegalAccessException|IllegalArgumentException|ExceptionInInitializerError|InvalidProtocolBufferException var5){
throw new LogicException("解析协议失败",var5);
}catch (Exception var4) {
if(null !=proto)
throw new LogicException("processWithProtoException\r\nprotoID:"+netData.getMsgId()+"\r\n"+proto.toString(),var4);
}
}

View File

@ -7,23 +7,53 @@ import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.FightInfoProto;
import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.MessageUtil;
import org.springframework.stereotype.Component;
@Component
public class StartFightRequestHandler extends BaseHandler{
public class StartFightRequestHandler extends BaseHandler<FightInfoProto.FightStartRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.FIGHT_START_REQUEST;
}
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
byte[] message = netData.parseClientProtoNetData();
// FightInfoProto.FightStartRequest fightEndRequest = FightInfoProto.FightStartRequest.parseFrom(message);
FightInfoProto.FightStartRequest fightStartRequest = FightInfoProto.FightStartRequest.parseFrom(message);
// byte[] message = netData.parseClientProtoNetData();
//// FightInfoProto.FightStartRequest fightEndRequest = FightInfoProto.FightStartRequest.parseFrom(message);
// FightInfoProto.FightStartRequest fightStartRequest = FightInfoProto.FightStartRequest.parseFrom(message);
// int type = fightStartRequest.getType();
// int fightId = fightStartRequest.getFightId();
// int teamId = fightStartRequest.getTeamId();
//
//
// if (type ==1){
// User user = UserManager.getUser(iSession.getUid());
// int curMapId = user.getMapManager().getCurMapId();
// if(curMapId>0){
// MessageUtil.sendErrorResponse(iSession, 0, MessageTypeProto.MessageType.FIGHT_START_RESPONSE.getNumber(),"在地图探索中,不可以操作");
// return;
// }
// MapLogic.getInstance().startLevelDifficultyFight(iSession,fightId,teamId,type,MessageTypeProto.MessageType.FIGHT_START_RESPONSE);
// }else if(type == 2){
// MapLogic.getInstance().startFight(iSession, MessageTypeProto.MessageType.FIGHT_START_RESPONSE);
//
// }else if(type == 3){
// MapLogic.getInstance().startSuddlenlyFight(iSession,teamId, MessageTypeProto.MessageType.FIGHT_START_RESPONSE);
// }else if(type == 5){
// MapLogic.getInstance().startMonsterAttackFight(iSession,fightId,teamId, MessageTypeProto.MessageType.FIGHT_START_RESPONSE);
// } else {
//// MapLogic.getInstance().startLevelDifficultyFight(iSession,fightId,teamId,type,MessageTypeProto.MessageType.FIGHT_START_RESPONSE);
//
// MessageUtil.sendErrorResponse(iSession, 0, MessageTypeProto.MessageType.FIGHT_START_RESPONSE.getNumber(),"type is wrong:" + type);
// }
}
@Override
public void processWithProto(ISession iSession, FightInfoProto.FightStartRequest fightStartRequest) throws Exception {
int type = fightStartRequest.getType();
int fightId = fightStartRequest.getFightId();
int teamId = fightStartRequest.getTeamId();
@ -36,7 +66,7 @@ public class StartFightRequestHandler extends BaseHandler{
MessageUtil.sendErrorResponse(iSession, 0, MessageTypeProto.MessageType.FIGHT_START_RESPONSE.getNumber(),"在地图探索中,不可以操作");
return;
}
MapLogic.getInstance().startLevelDifficultyFight(iSession,fightId,teamId,type,MessageTypeProto.MessageType.FIGHT_START_RESPONSE);
MapLogic.getInstance().startLevelDifficultyFight(iSession,fightId,teamId,type, MessageTypeProto.MessageType.FIGHT_START_RESPONSE);
}else if(type == 2){
MapLogic.getInstance().startFight(iSession, MessageTypeProto.MessageType.FIGHT_START_RESPONSE);

View File

@ -9,7 +9,7 @@ import com.ljsd.jieling.protocols.PlayerInfoProto;
import org.springframework.stereotype.Component;
@Component
public class TakeMissionRewardHandler extends BaseHandler {
public class TakeMissionRewardHandler extends BaseHandler<PlayerInfoProto.TakeMissionRewardRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.TAKE_MISSION_REWARD_REQUEST;
@ -17,8 +17,13 @@ public class TakeMissionRewardHandler extends BaseHandler {
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
byte[] bytes = netData.parseClientProtoNetData();
PlayerInfoProto.TakeMissionRewardRequest takeMissionRewardRequest = PlayerInfoProto.TakeMissionRewardRequest.parseFrom(bytes);
MissionLoigc.takeMissionReward(iSession,takeMissionRewardRequest.getType(),takeMissionRewardRequest.getMissionId());
// byte[] bytes = netData.parseClientProtoNetData();
// PlayerInfoProto.TakeMissionRewardRequest takeMissionRewardRequest = PlayerInfoProto.TakeMissionRewardRequest.parseFrom(bytes);
// MissionLoigc.takeMissionReward(iSession,takeMissionRewardRequest.getType(),takeMissionRewardRequest.getMissionId());
}
@Override
public void processWithProto(ISession iSession, PlayerInfoProto.TakeMissionRewardRequest proto) throws Exception {
MissionLoigc.takeMissionReward(iSession,proto.getType(),proto.getMissionId());
}
}

View File

@ -53,8 +53,7 @@ public class GetMonsterAttackRankHandler extends BaseHandler<PlayerInfoProto.Get
if (rankInfo.size() > 800) {
//删除多余数据 预留一些 长度maxSize
String key = RedisKey.getKey(RedisKey.MONSTER_ATTACK_RANK, "", false);
int size = RedisUtil.getInstence().getZsetSize(key);
RedisUtil.getInstence().removeZSetRangeByRank(key, 300, size);
RedisUtil.getInstence().removeZSetRangeByRank(key, 0, 500);
}
int uid = iSession.getUid();

View File

@ -108,7 +108,7 @@ public class CombatLogic {
SFoodsConfig sFoodsConfig = SFoodsConfig.getsFoodsConfigByFoodId(foodIdOrEventId);
int typeTmp = sFoodsConfig.getType();
int targetTmp = sFoodsConfig.getTarget();
if( typeTmp== GlobalsDef.FOOD_ADDITION_BATTLE_TYPE && targetTmp==GlobalsDef.FOOD_EAT_AFFECT_TEAM ){
if( typeTmp== GlobalsDef.FOOD_ADDITION_BATTLE_TYPE && targetTmp==GlobalsDef.FOOD_EAT_AFFECT_PERSON ){
for(Map.Entry<String,Map<Integer,Integer>> item : heroAllAttributeMap.entrySet()){
bufferOneHeroAttrAfterEat(item.getValue(),foodIdOrEventId);
}

View File

@ -1108,6 +1108,11 @@ public class HeroLogic {
Integer propertyValue = heroAllAttribute.get(propertyId);
heroAllAttribute.put(propertyId,(int)(propertyValue/10000f*item.getValue()));
}
Integer maxHp = heroAllAttribute.get(HeroAttributeEnum.Hp.getPropertyId());
Integer curHp = heroAllAttribute.get(HeroAttributeEnum.CurHP.getPropertyId());
if(maxHp!=null && curHp!=null && curHp > maxHp){
heroAllAttribute.put(HeroAttributeEnum.CurHP.getPropertyId(),maxHp);
}
}

View File

@ -1,6 +1,9 @@
package com.ljsd.jieling.logic.item;
import com.ljsd.jieling.config.*;
import com.ljsd.jieling.config.SCHeroRankUpConfig;
import com.ljsd.jieling.config.SGameSetting;
import com.ljsd.jieling.config.SHeroLevlConfig;
import com.ljsd.jieling.config.SItem;
import com.ljsd.jieling.globals.BIReason;
import com.ljsd.jieling.globals.Global;
import com.ljsd.jieling.handler.map.MapManager;
@ -11,7 +14,10 @@ import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.protocols.PlayerInfoProto;
import com.ljsd.jieling.util.*;
import com.ljsd.jieling.util.CBean2Proto;
import com.ljsd.jieling.util.ItemUtil;
import com.ljsd.jieling.util.MessageUtil;
import com.ljsd.jieling.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -245,19 +251,18 @@ public class ItemLogic {
reward.append("#").append(sItem.getResolveReward());
}
}
int reson =BIReason.DECOMPOS_HERO_REWARD;
ItemUtil.combineReward(user, StringUtil.parseFiledInt(reward.toString()),1,baseItemMap,baseCardMap,baseEquipMap,baseRandomMap);
int reson = BIReason.DECOMPOS_HERO_REWARD;
if(null!=filterItem){
reson= BIReason.UPHERO_DECOMPOS_HERO_REWARD;
for (Integer id:filterItem){
if(baseItemMap.containsKey(id)){
baseItemMap.remove(id);
}
}
// filterItem.retainAll(baseItemMap.keySet());
// filterItem.forEach(baseItemMap::remove);
}
ItemUtil.combineReward(user,StringUtil.parseFiledInt(reward.toString()),1,baseItemMap,baseCardMap,baseEquipMap,baseRandomMap);
ItemUtil.drop(user,baseBuilder,baseItemMap,baseCardMap,baseEquipMap,baseRandomMap, reson);
return baseBuilder;
}

View File

@ -8,7 +8,7 @@ public class ArenaRankManager implements BaseDataManager {
public CumulationData.Result updateData(CumulationData data, MissionType missionType, Object... parm) {
if (missionType == MissionType.ARENA_RANK) {
int rank = (int) parm[0];
if (data.arenaRank > rank) {
if (data.arenaRank==0 || data.arenaRank > rank) {
data.arenaRank = rank;
return new CumulationData.Result(missionType);
}

View File

@ -17,6 +17,7 @@ public class ISession extends NettyGameSession {
private int fiveReady; //客户端可以接受服务器5点刷新
private byte[] fiveByteBuf; //五点推送数据缓存
private long loginTime;//BI用
private int lastMsgId;//最后客户端请求协议
private ConcurrentHashMap<Integer, byte[]> indexToMessage = new ConcurrentHashMap();
@ -158,4 +159,12 @@ public class ISession extends NettyGameSession {
this.fiveByteBuf = fiveByteBuf;
}
public int getLastMsgId() {
return lastMsgId;
}
public void setLastMsgId(int lastMsgId) {
this.lastMsgId = lastMsgId;
}
}

View File

@ -1,17 +1,16 @@
package com.ljsd.jieling.util;
import com.google.protobuf.GeneratedMessage;
import com.googlecode.protobuf.format.JsonFormat;
import com.ljsd.jieling.battle.actor.ActorType;
import com.ljsd.jieling.battle.actor.Scene;
import com.ljsd.jieling.battle.actor.SceneActor;
import com.ljsd.jieling.battle.room.BeanToProto;
import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.core.HandlerLogicThread;
import com.ljsd.jieling.core.SimpleTransaction;
import com.ljsd.jieling.logic.OnlineUserManager;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.room.Room;
import com.ljsd.jieling.netty.PackageConstant;
import com.ljsd.jieling.netty.cocdex.Tea;
import com.ljsd.jieling.network.session.ISession;
@ -19,7 +18,6 @@ import com.ljsd.jieling.protocols.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Set;
@ -86,6 +84,11 @@ public class MessageUtil {
}
public static void sendBagIndication(int sendUid,int type, List<CommonProto.Item> sendToFront) {
if(null!= HandlerLogicThread.current()){
PlayerInfoProto.UpdateBagIndication build = PlayerInfoProto.UpdateBagIndication.newBuilder().addAllItem(sendToFront).setType(type).build();
HandlerLogicThread.current().dealWhileCommit(new SimpleTransaction.SendTask(build, MessageTypeProto.MessageType.UPDATE_BAG_INDICATION_VALUE));
return;
}
ISession session = OnlineUserManager.sessionMap.get(sendUid);
if(session!=null){
PlayerInfoProto.UpdateBagIndication build = PlayerInfoProto.UpdateBagIndication.newBuilder().addAllItem(sendToFront).setType(type).build();