back_recharge
lvxinran 2019-10-23 22:12:19 +08:00
commit fa6f4e546d
10 changed files with 270 additions and 27 deletions

View File

@ -2,6 +2,9 @@ package com.ljsd.jieling.core;
import com.ljsd.GameApplication; import com.ljsd.GameApplication;
import com.ljsd.jieling.db.mongo.MongoUtil; import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.exception.ErrorUtil;
import com.ljsd.jieling.handler.BaseHandler; import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.GlobalDataManaager; import com.ljsd.jieling.logic.GlobalDataManaager;
import com.ljsd.jieling.logic.OnlineUserManager; import com.ljsd.jieling.logic.OnlineUserManager;
@ -126,7 +129,7 @@ public class HandlerLogicThread extends Thread{
return; return;
} }
session.setLastMsgId(msgId); session.setLastMsgId(msgId);
setTransaction(session); SimpleTransaction transaction = setTransaction(session);
BaseHandler baseHandler = ProtocolsManager.getInstance().getHandler(msgId); BaseHandler baseHandler = ProtocolsManager.getInstance().getHandler(msgId);
if(baseHandler == null){ if(baseHandler == null){
LOGGER.info("request uid=>{} , msgId=>{}, not find the baseHandler",userId,msgId); LOGGER.info("request uid=>{} , msgId=>{}, not find the baseHandler",userId,msgId);
@ -137,33 +140,49 @@ public class HandlerLogicThread extends Thread{
if(!b){ if(!b){
MessageUtil.sendErrorResponse(session,0,msgId+1,"funciton not"); MessageUtil.sendErrorResponse(session,0,msgId+1,"funciton not");
return; return;
// throw new ErrorCodeException(ErrorCode.newDefineCode("funciton not"));
} }
b = checkIsPermit(msgId, session); b = checkIsPermit(msgId, session);
if(!b){ if(!b){
MessageUtil.sendErrorResponse(session,0,msgId+1,"在地图探索中,不可以操作"); MessageUtil.sendErrorResponse(session,0,msgId+1,"在地图探索中,不可以操作");
return; return;
// throw new ErrorCodeException(ErrorCode.newDefineCode("在地图探索中,不可以操作"));
} }
} }
long curTimeMillis = System.currentTimeMillis();
if (msgId != MessageTypeProto.MessageType.GET_CHAT_MESSAGE_REQUEST_VALUE) { if (msgId != MessageTypeProto.MessageType.GET_CHAT_MESSAGE_REQUEST_VALUE) {
LOGGER.info("doWork->uid={},mType={};start", userId, MessageTypeProto.MessageType.valueOf(msgId)); LOGGER.info("doWork->uid={},mType={};start", userId, MessageTypeProto.MessageType.valueOf(msgId));
} }
long curTimeMillis = System.nanoTime();
MissionEventDistributor.requestStart(); transaction.beafore();
baseHandler.execute(session, packetNetData); baseHandler.execute(session, packetNetData);
MissionEventDistributor.requestEnd(session,true); transaction.commit();
current().commit();
MongoUtil.getInstence().lastUpdate();
if (msgId != MessageTypeProto.MessageType.GET_CHAT_MESSAGE_REQUEST_VALUE) { if (msgId != MessageTypeProto.MessageType.GET_CHAT_MESSAGE_REQUEST_VALUE) {
long useTime = System.currentTimeMillis() - curTimeMillis; long useTime = System.nanoTime() - curTimeMillis;
LOGGER.info("doWork->uid={},mType={},useTime={},;end", userId, MessageTypeProto.MessageType.valueOf(msgId), useTime); LOGGER.info("doWork->uid={},mType={},useTime={},;end", userId, MessageTypeProto.MessageType.valueOf(msgId), useTime);
} }
}catch (Exception e){ }
catch (Exception e){
SimpleTransaction transaction = current(); SimpleTransaction transaction = current();
if(null!=transaction){ if(null!=transaction){
ISession session = transaction.getSession(); ISession session = transaction.getSession();
try { try {
//内部codeErr统一处理
if(e instanceof ErrorCodeException){
int errCode = ErrorUtil.getExceptionErrorCodeValue(e);
if (errCode <= 0) {
//打印堆栈定位错误
LOGGER.error(ErrorUtil.getExceptionStackTraceFileLineAndMethod(e));
}else {
LOGGER.info(e.toString());
}
MessageUtil.sendErrorResponse(session, errCode, session.getLastMsgId() + 1, ErrorUtil.getExceptionMessage(e));
return;
}
current().callback(); current().callback();
LOGGER.error("\nuser:"+ session.getUid(),e); LOGGER.error("\nuser:"+ session.getUid(),e);
User user = UserManager.getUserInMem(session.getUid()); User user = UserManager.getUserInMem(session.getUid());

View File

@ -1,6 +1,8 @@
package com.ljsd.jieling.core; package com.ljsd.jieling.core;
import com.google.protobuf.GeneratedMessage; import com.google.protobuf.GeneratedMessage;
import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.logic.mission.event.MissionEventDistributor;
import com.ljsd.jieling.network.session.ISession; import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.MessageTypeProto; import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.protocols.PlayerInfoProto; import com.ljsd.jieling.protocols.PlayerInfoProto;
@ -67,13 +69,20 @@ public class SimpleTransaction {
dealWhileCommit(transTask); dealWhileCommit(transTask);
} }
public void beafore() throws Exception{
MissionEventDistributor.requestStart();
}
public void commit() { public void commit() throws Exception{
doAddSendCache(); doAddSendCache();
for (TransTask transTask : tasks) { for (TransTask transTask : tasks) {
if (!transTask.isCallback()) if (!transTask.isCallback())
transTask.run(); transTask.run();
} }
//miss
MissionEventDistributor.requestEnd(session,true);
//mongo
MongoUtil.getInstence().lastUpdate();
} }
void callback() { void callback() {

View File

@ -1,6 +1,38 @@
package com.ljsd.jieling.exception; package com.ljsd.jieling.exception;
public class ErrorCode {
/**
* Description:
* a
* b
*
* 1 code>=0 0
* 2 code=-1
* 3 code= -* 线
*
* <p>
* 1 2使msgId+1
* 3
*a
* Author: zsx
* CreateDate: 2019/10/21 11:23
*/
public enum ErrorCode implements IErrorCode {
SYS_ERROR_CODE(-100, "系统错误"),
RELOGIN_CODE(-101, "重复登陆"),
KICK_USER_CODE(-102, "踢用户下线"),
SERVER_SELF_DEFINE(-1, "正在紧急修复中,请稍后再试"),
UNKNOWN(0, "正在紧急修复中,请稍后再试"),
NAME_USE(1,"该名字已被使用"),
NAME_LENTH(2,"名字长度为2-6个字"),
LOGIN_ERR(3,"登录密码错误"),
USE_NOT_EXIT(5,"该用户不存在"),
ITEM_POCKET_IS_FULL(6, "背包已满"),
;
//系统错误 //系统错误
public static final int sysErrorCode = -100; public static final int sysErrorCode = -100;
@ -12,4 +44,30 @@ public class ErrorCode {
public static final int kickUserCode = -102; public static final int kickUserCode = -102;
int codeId;
String errMsg;
ErrorCode(int codeId, String errMsg) {
this.codeId = codeId;
this.errMsg = errMsg;
}
@Override
public int code() {
return codeId;
}
@Override
public String message() {
return errMsg;
}
private ErrorCode reDefineMsg(String errMsg) {
this.errMsg = errMsg;
return this;
}
public static ErrorCode newDefineCode(String errMsg) {
return SERVER_SELF_DEFINE.reDefineMsg(errMsg);
}
} }

View File

@ -0,0 +1,26 @@
package com.ljsd.jieling.exception;
/**
* Description:
* Author: zsx
* CreateDate: 2019/10/21 11:44
*/
public class ErrorCodeException extends Exception {
public ErrorCodeException(ErrorCode errorCode) {
this.errorCode = errorCode;
}
private final ErrorCode errorCode;
public ErrorCode getCode() {
return this.errorCode;
}
public String toString() {
return "[CODE: " + this.errorCode.code() + "][" + this.errorCode.message() + "] " + super.getMessage();
}
public String getMessage() {
return "" + super.getMessage();
}
}

View File

@ -0,0 +1,83 @@
package com.ljsd.jieling.exception;
/**
* Description:
* Author: zsx
* CreateDate: 2019/10/21 11:23
*/
public class ErrorUtil {
public ErrorUtil() {
}
private static ErrorCode getExceptionErrorCode(Throwable e) {
if (e == null) {
return ErrorCode.UNKNOWN;
} else {
Throwable t = e;
ErrorCode r = ErrorCode.UNKNOWN;
do {
if (t instanceof ErrorCodeException) {
r = ((ErrorCodeException) t).getCode();
}
t = t.getCause();
} while (t != null);
return r;
}
}
public static int getExceptionErrorCodeValue(Throwable e) {
return getExceptionErrorCode(e).code();
}
public static String getExceptionMessage(Throwable e) {
if (e == null) {
return "";
} else {
StringBuilder builder = new StringBuilder();
Throwable t = e;
do {
if (!(t instanceof ErrorCodeException)) {
builder.append(t.getClass().getSimpleName()).append(":").append(t.getMessage()).append(" ");
} else if (t.getMessage() != null && t.getMessage().length() > 0) {
builder.append(t.getMessage()).append(" ");
}
t = t.getCause();
} while (t != null);
return builder.toString();
}
}
/**
*
*/
public static String getExceptionStackTraceFileLineAndMethod(Throwable e) {
if (e == null) {
return "";
} else {
StringBuilder builder = new StringBuilder();
Throwable t = e;
while (t != null) {
StackTraceElement[] stackTraceElements = t.getStackTrace();
if (stackTraceElements != null && stackTraceElements.length > 0) {
builder.append(System.getProperty("line.separator"));
int var5 = stackTraceElements.length;
for (StackTraceElement stackTraceElement : stackTraceElements) {
builder.append(" at ").append(stackTraceElement).append(System.getProperty("line.separator"));
}
}
t = t.getCause();
if (t != null) {
builder.append(t);
}
}
return builder.toString();
}
}
}

View File

@ -0,0 +1,15 @@
package com.ljsd.jieling.exception;
/**
* Description:
* Author: zsx
* CreateDate: 2019/10/21 11:10
*/
public interface IErrorCode {
int code();
String message();
}

View File

@ -141,6 +141,7 @@ public class GMRequestHandler extends BaseHandler{
break; break;
} }
} }
break;
case GlobalGm.ADOPT_FIGHT_BY_VALUE: case GlobalGm.ADOPT_FIGHT_BY_VALUE:
int fightId = cUser.getMainLevelManager().getFightId(); int fightId = cUser.getMainLevelManager().getFightId();
if(SMainLevelConfig.biggerThanFight(fightId,prarm1)){ if(SMainLevelConfig.biggerThanFight(fightId,prarm1)){

View File

@ -39,6 +39,13 @@ public enum ActivityTypeEnum {
private int type; private int type;
private Function<Integer, AbstractActivity> toActivityFunction; private Function<Integer, AbstractActivity> toActivityFunction;
private static HashMap<Integer, AbstractActivity> acticityCache = new HashMap<>(); private static HashMap<Integer, AbstractActivity> acticityCache = new HashMap<>();
private static final HashMap<Integer,ActivityTypeEnum> activityEnumMap = new HashMap<>();
static {
for (ActivityTypeEnum item:ActivityTypeEnum.values()) {
activityEnumMap.put(item.getType(),item);
}
}
ActivityTypeEnum(int type, Function<Integer, AbstractActivity> toActivityFunction) { ActivityTypeEnum(int type, Function<Integer, AbstractActivity> toActivityFunction) {
this.type = type; this.type = type;
@ -56,11 +63,13 @@ public enum ActivityTypeEnum {
public static AbstractActivity getActicityType(int id) { public static AbstractActivity getActicityType(int id) {
SGlobalActivity sGlobalActivity = SGlobalActivity.getsGlobalActivityMap().get(id); SGlobalActivity sGlobalActivity = SGlobalActivity.getsGlobalActivityMap().get(id);
for (ActivityTypeEnum activityType:ActivityTypeEnum.values()) { // for (ActivityTypeEnum activityType:ActivityTypeEnum.values()) {
if(activityType.getType()==sGlobalActivity.getType()){ // if(activityType.getType()==sGlobalActivity.getType()){
return activityType.toActivity(id); // return activityType.toActivity(id);
} // }
} // }
if (activityEnumMap.containsKey(sGlobalActivity.getType()))
return activityEnumMap.get(sGlobalActivity.getType()).toActivity(id);
return null; return null;
} }

View File

@ -251,14 +251,6 @@ public class CombatLogic {
} }
int fightId = mainLevelManager.getFightId(); int fightId = mainLevelManager.getFightId();
SMainLevelConfig targetMainLevelConfig = SMainLevelConfig.config.get(fightId); SMainLevelConfig targetMainLevelConfig = SMainLevelConfig.config.get(fightId);
if(mainLevelManager.getState()==-1){
for( SMainLevelConfig sMainLevelConfig : SMainLevelConfig.config.values() ){
if(sMainLevelConfig.getNextLevel() == mainLevelManager.getFightId()){
targetMainLevelConfig = sMainLevelConfig;
break;
}
}
}
int lastTime = mainLevelManager.getLastTime(); int lastTime = mainLevelManager.getLastTime();
int now = (int) (System.currentTimeMillis() / 1000); int now = (int) (System.currentTimeMillis() / 1000);
int times = (now - lastTime)/STableManager.getFigureConfig(CommonStaticConfig.class).getGameSetting().getAdventureRefresh(); int times = (now - lastTime)/STableManager.getFigureConfig(CommonStaticConfig.class).getGameSetting().getAdventureRefresh();

View File

@ -0,0 +1,31 @@
package config;
import manager.STableManager;
import manager.Table;
import java.util.Map;
@Table(name ="ErrorCodeHint")
public class SErrorCodeHint implements BaseConfig {
private int id;
private int showType;
@Override
public void init() throws Exception {
}
public int getId() {
return id;
}
public int getShowType() {
return showType;
}
}