Merge branch 'master_test_hw_server_arena' of http://60.1.1.230/backend/jieling_server into master_test_hw_server_arena
commit
4a2114de4e
|
@ -0,0 +1,29 @@
|
|||
package com.ljsd.fight;
|
||||
|
||||
import rpc.protocols.CommonProto;
|
||||
|
||||
/**
|
||||
* Description: des
|
||||
* Author: zsx
|
||||
* CreateDate: 2020/12/3 14:32
|
||||
*/
|
||||
public class ArenaRecordWrap {
|
||||
private ArenaRecord arenaRecord;
|
||||
private CommonProto.ArenaEnemy arenaEnemy;
|
||||
|
||||
public ArenaRecord getArenaRecord() {
|
||||
return arenaRecord;
|
||||
}
|
||||
|
||||
public void setArenaRecord(ArenaRecord arenaRecord) {
|
||||
this.arenaRecord = arenaRecord;
|
||||
}
|
||||
|
||||
public CommonProto.ArenaEnemy getArenaEnemy() {
|
||||
return arenaEnemy;
|
||||
}
|
||||
|
||||
public void setArenaEnemy(CommonProto.ArenaEnemy arenaEnemy) {
|
||||
this.arenaEnemy = arenaEnemy;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: GlobalProto.proto
|
||||
// source: gtGprotos/GlobalProto.proto
|
||||
|
||||
package rpc.global;
|
||||
|
||||
|
@ -1163,10 +1163,10 @@ public final class GlobalProto {
|
|||
descriptor;
|
||||
static {
|
||||
java.lang.String[] descriptorData = {
|
||||
"\n\021GlobalProto.proto\022\nrpc.global\")\n\025GetWo" +
|
||||
"rldServerRequest\022\020\n\010serverID\030\001 \001(\005\"A\n\026Ge" +
|
||||
"tWorldServerResponse\022\n\n\002ip\030\001 \001(\t\022\014\n\004port" +
|
||||
"\030\002 \001(\t\022\r\n\005group\030\003 \001(\005B\002H\001"
|
||||
"\n\033gtGprotos/GlobalProto.proto\022\nrpc.globa" +
|
||||
"l\")\n\025GetWorldServerRequest\022\020\n\010serverID\030\001" +
|
||||
" \001(\005\"A\n\026GetWorldServerResponse\022\n\n\002ip\030\001 \001" +
|
||||
"(\t\022\014\n\004port\030\002 \001(\t\022\r\n\005group\030\003 \001(\005B\002H\001"
|
||||
};
|
||||
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
|
||||
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
|
||||
|
|
|
@ -2,6 +2,7 @@ package rpc.net;
|
|||
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import com.google.protobuf.Parser;
|
||||
import com.googlecode.protobuf.format.JsonFormat;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import rpc.protocols.MessageTypeProto;
|
||||
|
@ -31,7 +32,8 @@ public abstract class gtGBaseHandler<T extends GeneratedMessage> {
|
|||
if(generatedMessage==null){
|
||||
return null;
|
||||
}
|
||||
return new RpcMessage(rpc.getServerId(), getProtoIdBySimpleName(generatedMessage.getClass().getSimpleName()), ByteBuffer.wrap(generatedMessage.toByteArray()));
|
||||
LOGGER.info("wrappedBuffer uid=>{}, generatedMessage=>{}", rpc.getUid(), JsonFormat.printToString(generatedMessage));
|
||||
return new RpcMessage(rpc.getServerId(),rpc.getUid(), getProtoIdBySimpleName(generatedMessage.getClass().getSimpleName()), ByteBuffer.wrap(generatedMessage.toByteArray()));
|
||||
}
|
||||
|
||||
public static int getProtoIdBySimpleName(String name){
|
||||
|
|
|
@ -4085,6 +4085,54 @@ public final class MessageTypeProto {
|
|||
* <code>GetWorldArenaInfoResponse = 900002;</code>
|
||||
*/
|
||||
GetWorldArenaInfoResponse(659, 900002),
|
||||
/**
|
||||
* <code>GetWorldArenaChallengeRequest = 900003;</code>
|
||||
*
|
||||
* <pre>
|
||||
*跨服天梯挑战
|
||||
* </pre>
|
||||
*/
|
||||
GetWorldArenaChallengeRequest(660, 900003),
|
||||
/**
|
||||
* <code>GetWorldArenaChallengeResponse = 900004;</code>
|
||||
*/
|
||||
GetWorldArenaChallengeResponse(661, 900004),
|
||||
/**
|
||||
* <code>GetWorldArenaProudRequest = 900005;</code>
|
||||
*
|
||||
* <pre>
|
||||
*膜拜
|
||||
* </pre>
|
||||
*/
|
||||
GetWorldArenaProudRequest(662, 900005),
|
||||
/**
|
||||
* <code>GetWorldArenaProudResponse = 900006;</code>
|
||||
*/
|
||||
GetWorldArenaProudResponse(663, 900006),
|
||||
/**
|
||||
* <code>GetWorldArenaRecordInfoRequest = 900007;</code>
|
||||
*
|
||||
* <pre>
|
||||
*跨服天梯挑战与被挑战 战斗记录
|
||||
* </pre>
|
||||
*/
|
||||
GetWorldArenaRecordInfoRequest(664, 900007),
|
||||
/**
|
||||
* <code>GetWorldArenaRecordInfoResponse = 900008;</code>
|
||||
*/
|
||||
GetWorldArenaRecordInfoResponse(665, 900008),
|
||||
/**
|
||||
* <code>GetGSUserArenaInfoRequest = 900009;</code>
|
||||
*
|
||||
* <pre>
|
||||
*gs --》word
|
||||
* </pre>
|
||||
*/
|
||||
GetGSUserArenaInfoRequest(666, 900009),
|
||||
/**
|
||||
* <code>GetGSUserArenaInfoResponse = 900010;</code>
|
||||
*/
|
||||
GetGSUserArenaInfoResponse(667, 900010),
|
||||
;
|
||||
|
||||
/**
|
||||
|
@ -8159,6 +8207,54 @@ public final class MessageTypeProto {
|
|||
* <code>GetWorldArenaInfoResponse = 900002;</code>
|
||||
*/
|
||||
public static final int GetWorldArenaInfoResponse_VALUE = 900002;
|
||||
/**
|
||||
* <code>GetWorldArenaChallengeRequest = 900003;</code>
|
||||
*
|
||||
* <pre>
|
||||
*跨服天梯挑战
|
||||
* </pre>
|
||||
*/
|
||||
public static final int GetWorldArenaChallengeRequest_VALUE = 900003;
|
||||
/**
|
||||
* <code>GetWorldArenaChallengeResponse = 900004;</code>
|
||||
*/
|
||||
public static final int GetWorldArenaChallengeResponse_VALUE = 900004;
|
||||
/**
|
||||
* <code>GetWorldArenaProudRequest = 900005;</code>
|
||||
*
|
||||
* <pre>
|
||||
*膜拜
|
||||
* </pre>
|
||||
*/
|
||||
public static final int GetWorldArenaProudRequest_VALUE = 900005;
|
||||
/**
|
||||
* <code>GetWorldArenaProudResponse = 900006;</code>
|
||||
*/
|
||||
public static final int GetWorldArenaProudResponse_VALUE = 900006;
|
||||
/**
|
||||
* <code>GetWorldArenaRecordInfoRequest = 900007;</code>
|
||||
*
|
||||
* <pre>
|
||||
*跨服天梯挑战与被挑战 战斗记录
|
||||
* </pre>
|
||||
*/
|
||||
public static final int GetWorldArenaRecordInfoRequest_VALUE = 900007;
|
||||
/**
|
||||
* <code>GetWorldArenaRecordInfoResponse = 900008;</code>
|
||||
*/
|
||||
public static final int GetWorldArenaRecordInfoResponse_VALUE = 900008;
|
||||
/**
|
||||
* <code>GetGSUserArenaInfoRequest = 900009;</code>
|
||||
*
|
||||
* <pre>
|
||||
*gs --》word
|
||||
* </pre>
|
||||
*/
|
||||
public static final int GetGSUserArenaInfoRequest_VALUE = 900009;
|
||||
/**
|
||||
* <code>GetGSUserArenaInfoResponse = 900010;</code>
|
||||
*/
|
||||
public static final int GetGSUserArenaInfoResponse_VALUE = 900010;
|
||||
|
||||
|
||||
public final int getNumber() { return value; }
|
||||
|
@ -8825,6 +8921,14 @@ public final class MessageTypeProto {
|
|||
case 800002: return GetWorldServerResponse;
|
||||
case 900001: return GetWorldArenaInfoRequest;
|
||||
case 900002: return GetWorldArenaInfoResponse;
|
||||
case 900003: return GetWorldArenaChallengeRequest;
|
||||
case 900004: return GetWorldArenaChallengeResponse;
|
||||
case 900005: return GetWorldArenaProudRequest;
|
||||
case 900006: return GetWorldArenaProudResponse;
|
||||
case 900007: return GetWorldArenaRecordInfoRequest;
|
||||
case 900008: return GetWorldArenaRecordInfoResponse;
|
||||
case 900009: return GetGSUserArenaInfoRequest;
|
||||
case 900010: return GetGSUserArenaInfoResponse;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
@ -8886,7 +8990,7 @@ public final class MessageTypeProto {
|
|||
static {
|
||||
java.lang.String[] descriptorData = {
|
||||
"\n\026MessageTypeProto.proto\022\rrpc.protocols*" +
|
||||
"\323\250\001\n\013MessageType\022\027\n\022HEART_BEAT_REQUEST\020\350" +
|
||||
"\361\252\001\n\013MessageType\022\027\n\022HEART_BEAT_REQUEST\020\350" +
|
||||
"\007\022\030\n\023HEART_BEAT_RESPONSE\020\351\007\022\036\n\031ACTIVITE_" +
|
||||
"WORKSHOP_REQUEST\020\224N\022\037\n\032ACTIVITE_WORKSHOP" +
|
||||
"_RESPONSE\020\225N\022\027\n\022ARENA_INFO_REQUEST\020\226N\022\030\n" +
|
||||
|
@ -9425,7 +9529,14 @@ public final class MessageTypeProto {
|
|||
"tSubRewardPoolResponse\020\270\304\022\022\033\n\025GetWorldSe" +
|
||||
"rverRequest\020\201\3520\022\034\n\026GetWorldServerRespons" +
|
||||
"e\020\202\3520\022\036\n\030GetWorldArenaInfoRequest\020\241\3676\022\037\n",
|
||||
"\031GetWorldArenaInfoResponse\020\242\3676B\002H\001"
|
||||
"\031GetWorldArenaInfoResponse\020\242\3676\022#\n\035GetWor" +
|
||||
"ldArenaChallengeRequest\020\243\3676\022$\n\036GetWorldA" +
|
||||
"renaChallengeResponse\020\244\3676\022\037\n\031GetWorldAre" +
|
||||
"naProudRequest\020\245\3676\022 \n\032GetWorldArenaProud" +
|
||||
"Response\020\246\3676\022$\n\036GetWorldArenaRecordInfoR" +
|
||||
"equest\020\247\3676\022%\n\037GetWorldArenaRecordInfoRes" +
|
||||
"ponse\020\250\3676\022\037\n\031GetGSUserArenaInfoRequest\020\251" +
|
||||
"\3676\022 \n\032GetGSUserArenaInfoResponse\020\252\3676B\002H\001"
|
||||
};
|
||||
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
|
||||
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -10,7 +10,7 @@ public class Lockeys {
|
|||
|
||||
private static Lockeys lockeys = new Lockeys();
|
||||
|
||||
private final Map<Lockey, LockeyHolder> locks = new HashMap<>();
|
||||
private final ThreadLocal<Map<Lockey, LockeyHolder> >locks =new ThreadLocal<>(); ;
|
||||
|
||||
public static Lockeys getLockeys() {
|
||||
return lockeys;
|
||||
|
@ -39,8 +39,12 @@ public class Lockeys {
|
|||
|
||||
public synchronized Lockey get(Lockey lockey) {
|
||||
|
||||
|
||||
LockeyHolder holder = locks.get(lockey);
|
||||
Map<Lockey, LockeyHolder> lockeyLockeyHolderMap = locks.get();
|
||||
if(lockeyLockeyHolderMap==null){
|
||||
lockeyLockeyHolderMap= new HashMap<>();
|
||||
locks.set(lockeyLockeyHolderMap);
|
||||
}
|
||||
LockeyHolder holder = locks.get().get(lockey);
|
||||
if (holder != null)
|
||||
return holder.lockey;
|
||||
int h = lockey.hashCode();
|
||||
|
@ -65,14 +69,11 @@ public class Lockeys {
|
|||
|
||||
|
||||
public void lock(String key, Integer index) {
|
||||
wAddLockey(Lockeys.getLockeys().getLockey(key, index));
|
||||
}
|
||||
|
||||
void wAddLockey(Lockey key) {
|
||||
LockeyHolder holder = this.locks.get(key);
|
||||
Lockey lockey = getLockey(key, index);
|
||||
LockeyHolder holder = this.locks.get().get(lockey);
|
||||
if (holder == null) {
|
||||
key.wLock();
|
||||
this.locks.put(key, new LockeyHolder(key, true));
|
||||
lockey.wLock();
|
||||
this.locks.get().put(lockey, new LockeyHolder(lockey, true));
|
||||
} else if (!holder.write) {
|
||||
holder.lockey.rUnlock();
|
||||
holder.lockey.wLock();
|
||||
|
@ -80,14 +81,21 @@ public class Lockeys {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void reset() {
|
||||
locks.values().forEach(holder -> {
|
||||
if (holder.write)
|
||||
holder.lockey.wUnlock();
|
||||
else
|
||||
holder.lockey.rUnlock();
|
||||
});
|
||||
locks.clear();
|
||||
try {
|
||||
locks.get().values().forEach(holder -> {
|
||||
if (holder.write)
|
||||
holder.lockey.wUnlock();
|
||||
else
|
||||
holder.lockey.rUnlock();
|
||||
});
|
||||
locks.get().clear();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LockeyHolder implements Comparable<LockeyHolder> {
|
||||
|
|
|
@ -25,7 +25,7 @@ public class GetWorldServerRequestHandler extends gtGBaseHandler<GlobalProto.Get
|
|||
//TODO 设置分组
|
||||
//第一版固定一个世界服
|
||||
String ip = GlobalServerApplication.bean.getWorldip();
|
||||
int port = GlobalServerApplication.bean.getPort();
|
||||
int port = GlobalServerApplication.bean.getWorldport();
|
||||
return GlobalProto.GetWorldServerResponse.newBuilder().setIp(ip).setPort(String.valueOf(port)).setGroup(GlobalLogic.getInstance().getSplitInfo(proto.getServerID())).build();
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ public class AreaManager {
|
|||
areaId = myServerId;
|
||||
masterServerId = myServerId;
|
||||
serverIds.add(myServerId);
|
||||
serverIds.add(99999);
|
||||
// serverIds.add(99999);
|
||||
ServerAreaInfoManager serverArenaInfoManager = CoreLogic.getInstance().findServerArenaInfoManager();
|
||||
if (serverArenaInfoManager != null) {
|
||||
Integer areaIdTmp = serverArenaInfoManager.getAreaIdByServerIdMap().get(myServerId);
|
||||
|
|
|
@ -159,6 +159,10 @@ public interface BIReason {
|
|||
int SKIN_USE_REWARD = 90;//激活皮肤获得头像
|
||||
int SUB_ACTIVITY_FINISH = 91;//易经宝库活动结束补发
|
||||
|
||||
int WORLD_CHANGE_DROP =100;//跨服天梯
|
||||
|
||||
|
||||
|
||||
int ADVENTURE_UPLEVEL_CONSUME = 1000;//秘境升级
|
||||
int SECRETBOX_CONSUME = 1001;//秘盒抽卡
|
||||
int DECOMPOSE_ITEM_CONSUME = 1002;//分解道具消耗
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package com.ljsd.jieling.handler.gtw;
|
||||
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import com.ljsd.jieling.logic.arena.ArenaLogic;
|
||||
import rpc.net.RpcMessage;
|
||||
import rpc.net.gtGBaseHandler;
|
||||
import rpc.world.WorldProto;
|
||||
|
||||
/**
|
||||
* rpc get userinfo
|
||||
*/
|
||||
public class GetGSUserArenaInfoRequestHandler extends gtGBaseHandler<WorldProto.GetGSUserArenaInfoRequest> {
|
||||
|
||||
@Override
|
||||
public GeneratedMessage processWithProto(RpcMessage rpcMessage, WorldProto.GetGSUserArenaInfoRequest proto) throws Exception {
|
||||
return ArenaLogic.getInstance().getArenaEnemy(proto.getUid(), 1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.ljsd.jieling.handler.gtw;
|
||||
|
||||
import com.ljsd.jieling.exception.ErrorCode;
|
||||
import com.ljsd.jieling.exception.ErrorCodeException;
|
||||
import com.ljsd.jieling.handler.BaseHandler;
|
||||
import com.ljsd.jieling.logic.arena.ArenaLogic;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.logic.fight.FightUtil;
|
||||
import com.ljsd.jieling.network.server.GlobalidHelper;
|
||||
import com.ljsd.jieling.network.server.WorldHelper;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import rpc.protocols.MessageTypeProto;
|
||||
import rpc.world.WorldProto;
|
||||
|
||||
/**
|
||||
* Description: gs 继承basehandler 做消息拦截 包装消息再转发到w
|
||||
* Author: zsx
|
||||
* CreateDate: 2020/11/19 10:51
|
||||
*/
|
||||
public class GetWorldArenaChallengeRequestHandler extends BaseHandler<WorldProto.GetWorldArenaChallengeRequest> {
|
||||
|
||||
@Override
|
||||
public MessageTypeProto.MessageType getMessageCode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processWithProto(ISession iSession, WorldProto.GetWorldArenaChallengeRequest proto) throws Exception {
|
||||
GlobalidHelper.WorldInfo worldInfo = GlobalidHelper.getWorldInfo();
|
||||
if (null == worldInfo) {
|
||||
throw new ErrorCodeException("world unavailable or play not open");
|
||||
}
|
||||
boolean b;
|
||||
if (proto.getSkipFight() == 0) {
|
||||
WorldProto.GetWorldArenaChallengeRequest.Builder builder = WorldProto.GetWorldArenaChallengeRequest.newBuilder()
|
||||
.setChallengeUid(proto.getChallengeUid())
|
||||
.setTeamId(proto.getTeamId())
|
||||
.setChallengeRank(proto.getChallengeRank())
|
||||
.setSkipFight(proto.getSkipFight())
|
||||
.setArenaEnemys(ArenaLogic.getInstance().getUserArenaEnemy(iSession.getUid(), proto.getTeamId()))
|
||||
.setFightTeamInfo(FightUtil.getFightTeamInfo(UserManager.getUser(iSession.getUid()), proto.getTeamId()));
|
||||
//转发到world服
|
||||
b = WorldHelper.sendMessageToWord(iSession.getUid(), builder.build());
|
||||
} else {
|
||||
b =WorldHelper.sendMessageToWord(iSession.getUid(), proto);
|
||||
}
|
||||
|
||||
if (!b) {
|
||||
throw new ErrorCodeException(ErrorCode.UNKNOWN);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.ljsd.jieling.handler.gtw;
|
||||
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import com.ljsd.jieling.globals.BIReason;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.util.ItemUtil;
|
||||
import com.ljsd.jieling.util.MessageUtil;
|
||||
import config.SMServerArenaSetting;
|
||||
import manager.STableManager;
|
||||
import rpc.net.RpcMessage;
|
||||
import rpc.net.gtGBaseHandler;
|
||||
import rpc.protocols.CommonProto;
|
||||
import rpc.world.WorldProto;
|
||||
|
||||
/**
|
||||
* Description: des
|
||||
* Author: zsx
|
||||
* CreateDate: 2020/12/4 14:53
|
||||
*/
|
||||
public class GetWorldArenaChallengeResponseHandler extends gtGBaseHandler<WorldProto.GetWorldArenaChallengeResponse> {
|
||||
|
||||
@Override
|
||||
public GeneratedMessage processWithProto(RpcMessage rpcMessage, WorldProto.GetWorldArenaChallengeResponse proto) throws Exception {
|
||||
|
||||
//检查一下 没有定义handler 世界服回传的消息不拦截则透传
|
||||
WorldProto.GetWorldArenaChallengeResponse.Builder builder = WorldProto.GetWorldArenaChallengeResponse.newBuilder(proto);
|
||||
SMServerArenaSetting setting = STableManager.getConfig(SMServerArenaSetting.class).get(1);
|
||||
int[][] reward = new int[1][];
|
||||
reward[0]=setting.getBattleWinReward();
|
||||
CommonProto.Drop.Builder drop = ItemUtil.drop(UserManager.getUser(rpcMessage.getUid()), reward, BIReason.WORLD_CHANGE_DROP);
|
||||
builder.setDrop(drop);
|
||||
MessageUtil.sendIndicationMessage(rpcMessage.getUid(),rpcMessage.getProtpId(),builder.build().toByteArray());
|
||||
return super.processWithProto(rpcMessage, proto);
|
||||
}
|
||||
}
|
|
@ -1,18 +1,38 @@
|
|||
package com.ljsd.jieling.handler.gtw;
|
||||
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import com.ljsd.jieling.logic.arena.ArenaLogic;
|
||||
import rpc.net.RpcMessage;
|
||||
import rpc.net.gtGBaseHandler;
|
||||
import com.ljsd.jieling.exception.ErrorCode;
|
||||
import com.ljsd.jieling.exception.ErrorCodeException;
|
||||
import com.ljsd.jieling.handler.BaseHandler;
|
||||
import com.ljsd.jieling.network.server.GlobalidHelper;
|
||||
import com.ljsd.jieling.network.server.WorldHelper;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import rpc.protocols.MessageTypeProto;
|
||||
import rpc.world.WorldProto;
|
||||
|
||||
/**
|
||||
* rpc get userinfo
|
||||
* Description: gs 继承basehandler 做消息拦截 然后再转发到w
|
||||
* Author: zsx
|
||||
* CreateDate: 2020/11/19 10:51
|
||||
*/
|
||||
public class GetWorldArenaInfoRequestHandler extends gtGBaseHandler<WorldProto.GetGSUserArenaInfoRequest> {
|
||||
public class GetWorldArenaInfoRequestHandler extends BaseHandler<WorldProto.GetWorldArenaInfoRequest> {
|
||||
|
||||
@Override
|
||||
public GeneratedMessage processWithProto(RpcMessage rpcMessage, WorldProto.GetGSUserArenaInfoRequest proto) throws Exception {
|
||||
return ArenaLogic.getInstance().getArenaEnemy(proto.getUid(), 1);
|
||||
public MessageTypeProto.MessageType getMessageCode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processWithProto(ISession iSession, WorldProto.GetWorldArenaInfoRequest proto) throws Exception {
|
||||
GlobalidHelper.WorldInfo worldInfo = GlobalidHelper.getWorldInfo();
|
||||
if (null == worldInfo){
|
||||
throw new ErrorCodeException("world unavailable or play not open");
|
||||
}
|
||||
|
||||
//转发到world服
|
||||
boolean b = WorldHelper.sendMessageToWord(iSession.getUid(),proto);
|
||||
if(!b){
|
||||
throw new ErrorCodeException(ErrorCode.UNKNOWN);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
package com.ljsd.jieling.handler.gtw;
|
||||
|
||||
import com.ljsd.jieling.exception.ErrorCode;
|
||||
import com.ljsd.jieling.exception.ErrorCodeException;
|
||||
import com.ljsd.jieling.handler.BaseHandler;
|
||||
import com.ljsd.jieling.network.server.GlobalidHelper;
|
||||
import com.ljsd.jieling.network.server.WorldHelper;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import rpc.protocols.MessageTypeProto;
|
||||
import rpc.world.WorldProto;
|
||||
|
||||
/**
|
||||
* Description: gs 继承basehandler 做消息拦截 然后再转发到w
|
||||
* Author: zsx
|
||||
* CreateDate: 2020/11/19 10:51
|
||||
*/
|
||||
public class GetWorldArenaInfoResponseHandler extends BaseHandler<WorldProto.GetWorldArenaInfoRequest> {
|
||||
|
||||
@Override
|
||||
public MessageTypeProto.MessageType getMessageCode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processWithProto(ISession iSession, WorldProto.GetWorldArenaInfoRequest proto) throws Exception {
|
||||
GlobalidHelper.WorldInfo worldInfo = GlobalidHelper.getWorldInfo();
|
||||
if (null == worldInfo){
|
||||
throw new ErrorCodeException("world unavailable or play not open");
|
||||
}
|
||||
|
||||
|
||||
//check 跨服逻辑
|
||||
|
||||
//转发到world服
|
||||
boolean b = WorldHelper.sendMessageToWord(iSession.getUid(),proto);
|
||||
if(!b){
|
||||
throw new ErrorCodeException(ErrorCode.UNKNOWN);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -168,7 +168,7 @@ public class GlobleSystemLogic implements IEventHandler {
|
|||
i++;
|
||||
}
|
||||
|
||||
setGloableWorldLeveCache((int)Math.ceil(sum/ (double) rankEndLine));
|
||||
setGloableWorldLeveCache((int)Math.ceil(sum/ (double) Math.min(rankInfo.size(),rankEndLine)));
|
||||
|
||||
// if (rankInfo.size() > rankEndLine + 100) {
|
||||
// //删除多余数据 预留一些 长度maxSize
|
||||
|
@ -187,7 +187,7 @@ public class GlobleSystemLogic implements IEventHandler {
|
|||
|
||||
private static void setGloableWorldLeveCache(int gloableWorldLeveCache) {
|
||||
GLOABLE_WORLD_LEVE_CACHE = gloableWorldLeveCache;
|
||||
RedisUtil.getInstence().putMapEntry(RedisKey.SERVER_WORLDLEVE_INFO,"",String.valueOf(GameApplication.areaId),gloableWorldLeveCache);
|
||||
RedisUtil.getInstence().putMapEntry(RedisKey.SERVER_WORLDLEVE_INFO,"",String.valueOf(GameApplication.serverId),gloableWorldLeveCache);
|
||||
}
|
||||
|
||||
public static int getGloableWorldLeveCacheLine() {
|
||||
|
|
|
@ -87,6 +87,10 @@ class SheJiActivity extends AbstractActivity {
|
|||
public void onEvent(IEvent event) throws Exception {
|
||||
if (!(event instanceof CommitSheJiEvent)) return;
|
||||
|
||||
boolean b = ActivityLogic.getInstance().checkGlobleActivityOpen(id);
|
||||
if(!b){
|
||||
return;
|
||||
}
|
||||
int guildId = ((CommitSheJiEvent) event).getGuild();
|
||||
if (guildId == 0) {
|
||||
LOGGER.error("Exception guild id=>{} not exit", guildId);
|
||||
|
|
|
@ -122,6 +122,37 @@ public class ArenaLogic {
|
|||
}
|
||||
|
||||
|
||||
public CommonProto.ArenaEnemy getUserArenaEnemy(int enemyId ,int teamId) throws Exception {
|
||||
|
||||
User user = UserManager.getUser(enemyId);
|
||||
int totalForce = HeroLogic.getInstance().calTeamTotalForce(user, teamId,false);
|
||||
List<TeamPosHeroInfo> teamPosHeroInfoList = user.getTeamPosManager().getTeamPosForHero().get(teamId);
|
||||
Map<String, Hero> heroMap = user.getHeroManager().getHeroMap();
|
||||
List<Integer> heroTids = new ArrayList<>(teamPosHeroInfoList.size());
|
||||
for(TeamPosHeroInfo teamPosHeroInfo:teamPosHeroInfoList){
|
||||
heroTids.add(heroMap.get(teamPosHeroInfo.getHeroId()).getTemplateId());
|
||||
}
|
||||
CommonProto.Team teamBuild = CommonProto.Team.newBuilder().addAllHeroTid(heroTids).build();
|
||||
PlayerManager playerInfoManager = user.getPlayerInfoManager();
|
||||
int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK, Integer.toString(curSeason), Integer.toString(enemyId)).intValue();
|
||||
if(score == -1){
|
||||
score = SArenaSetting.getSArenaSetting().getScore();
|
||||
}
|
||||
CommonProto.ArenaPersonInfo personInfoBuild = CommonProto.ArenaPersonInfo.newBuilder()
|
||||
.setUid(enemyId)
|
||||
.setLevel(playerInfoManager.getLevel())
|
||||
.setName(playerInfoManager.getNickName())
|
||||
.setScore(score)
|
||||
.setHead(playerInfoManager.getHead())
|
||||
.setTotalForce(totalForce)
|
||||
.build();
|
||||
return CommonProto.ArenaEnemy.newBuilder()
|
||||
.setPersonInfo(personInfoBuild)
|
||||
.setTeam(teamBuild)
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void setMyArenaEnemys(int uid,User user){
|
||||
int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason), Integer.toString(uid)).intValue();
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
package config;
|
||||
|
||||
import manager.STableManager;
|
||||
import manager.Table;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Table(name ="HeroRankupConfig")
|
||||
public class SHeroRankupConfig implements BaseConfig {
|
||||
|
||||
private int id;
|
||||
|
||||
private int type;
|
||||
|
||||
private int[][] rankupPara;
|
||||
|
||||
private int limitLevel;
|
||||
|
||||
private int openLevel;
|
||||
|
||||
private int limitStar;
|
||||
|
||||
private int openStar;
|
||||
|
||||
private int[][] consumeMaterial;
|
||||
|
||||
private int star;
|
||||
|
||||
private int show;
|
||||
|
||||
private int[][] sumConsume;
|
||||
|
||||
private int[] phase;
|
||||
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int[][] getRankupPara() {
|
||||
return rankupPara;
|
||||
}
|
||||
|
||||
public int getLimitLevel() {
|
||||
return limitLevel;
|
||||
}
|
||||
|
||||
public int getOpenLevel() {
|
||||
return openLevel;
|
||||
}
|
||||
|
||||
public int getLimitStar() {
|
||||
return limitStar;
|
||||
}
|
||||
|
||||
public int getOpenStar() {
|
||||
return openStar;
|
||||
}
|
||||
|
||||
public int[][] getConsumeMaterial() {
|
||||
return consumeMaterial;
|
||||
}
|
||||
|
||||
public int getStar() {
|
||||
return star;
|
||||
}
|
||||
|
||||
public int getShow() {
|
||||
return show;
|
||||
}
|
||||
|
||||
public int[][] getSumConsume() {
|
||||
return sumConsume;
|
||||
}
|
||||
|
||||
public int[] getPhase() {
|
||||
return phase;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -28,7 +28,7 @@ public class SMServerArenaMatchConfig implements BaseConfig {
|
|||
|
||||
Map<Integer, SMServerArenaMatchConfig> config = STableManager.getConfig(SMServerArenaMatchConfig.class);
|
||||
for (SMServerArenaMatchConfig smServerArenaMatchConfig : config.values()) {
|
||||
rank2miss.put(id,(int)smServerArenaMatchConfig.getPlayerPos()[0]);
|
||||
rank2miss.put((int)(smServerArenaMatchConfig.getPlayerPos()[0]),smServerArenaMatchConfig.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,10 @@ public class SPassiveSkillLogicConfig implements BaseConfig {
|
|||
private int effectiveRange;
|
||||
|
||||
private int coverID;
|
||||
private int judge;
|
||||
|
||||
public static Map<Integer, SPassiveSkillLogicConfig> config;
|
||||
|
||||
public static Map<Integer, SPassiveSkillLogicConfig> config;
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
|
@ -60,4 +62,8 @@ public class SPassiveSkillLogicConfig implements BaseConfig {
|
|||
public int getCoverID() {
|
||||
return coverID;
|
||||
}
|
||||
|
||||
public int getJudge() {
|
||||
return judge;
|
||||
}
|
||||
}
|
|
@ -1,11 +1,12 @@
|
|||
package com;
|
||||
|
||||
import com.world.config.ConfigurableApplicationContextManager;
|
||||
import com.world.config.CoreSettings;
|
||||
import com.world.config.WorldCoreSettings;
|
||||
import com.world.db.mongo.MongoUtil;
|
||||
import com.world.network.NetManager;
|
||||
import com.world.logic.arean.ArenaLogic;
|
||||
import com.world.redis.RedisUtil;
|
||||
import com.world.thread.ThreadManager;
|
||||
import com.world.thrift.idl.pool.RPCServerTask;
|
||||
import com.world.thrift.idl.pool.WorldRpcService;
|
||||
import manager.STableManager;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -15,8 +16,6 @@ import org.springframework.context.annotation.ComponentScan;
|
|||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Description: 提供跨服玩法
|
||||
* 不入库玩家数据
|
||||
|
@ -30,7 +29,7 @@ import java.util.HashMap;
|
|||
@EnableScheduling
|
||||
public class WorldServerApplication {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(WorldServerApplication.class);
|
||||
public static CoreSettings bean;
|
||||
public static WorldCoreSettings bean;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
|
@ -38,6 +37,14 @@ public class WorldServerApplication {
|
|||
|
||||
try {
|
||||
MongoUtil.getInstence().init();
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.info("MongoUtil err ->{}", e);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
RedisUtil.getInstence().init();
|
||||
} catch (Exception e) {
|
||||
LOGGER.info("MongoUtil err ->{}", e);
|
||||
}
|
||||
|
@ -55,12 +62,19 @@ public class WorldServerApplication {
|
|||
WorldRpcService.initHandler("com.world.handler", WorldServerApplication.class.getClassLoader());
|
||||
|
||||
|
||||
// new RPCServerTask().start();
|
||||
new RPCServerTask().start();
|
||||
//切换netty通信
|
||||
NetManager.getInstance().init();
|
||||
// NetManager.getInstance().init();
|
||||
|
||||
RedisUtil.getInstence().init();
|
||||
bean = ConfigurableApplicationContextManager.getBean(CoreSettings.class);
|
||||
|
||||
try {
|
||||
ArenaLogic.initRank();
|
||||
}catch (Exception e){
|
||||
LOGGER.info("ArenaLogic err ->{}", e);
|
||||
}
|
||||
|
||||
|
||||
bean = ConfigurableApplicationContextManager.getBean(WorldCoreSettings.class);
|
||||
LOGGER.info("ServerProperties ->{}", bean.toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.springframework.stereotype.Component;
|
|||
*/
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "services.core")
|
||||
public class CoreSettings {
|
||||
public class WorldCoreSettings {
|
||||
|
||||
private String ip;
|
||||
private int port;
|
|
@ -14,7 +14,7 @@ import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
|||
import java.net.UnknownHostException;
|
||||
|
||||
@Configuration
|
||||
public class MongoConfig {
|
||||
public class WorldMongoConfig {
|
||||
|
||||
|
||||
// 注入配置实体
|
|
@ -13,7 +13,7 @@ public class CServerInfo {
|
|||
@Field(value = "server_id")
|
||||
private int serverId;
|
||||
@Field(value = "name")
|
||||
private int name;
|
||||
private String name;
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -30,11 +30,12 @@ public class CServerInfo {
|
|||
this.serverId = serverId;
|
||||
}
|
||||
|
||||
public int getName() {
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(int name) {
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.world.function;
|
||||
|
||||
import com.ljsd.jieling.logic.dao.TimeControllerOfFunction;
|
||||
|
||||
/**
|
||||
* Description: 跨服天梯
|
||||
* Author: zsx
|
||||
|
@ -13,8 +15,7 @@ public class ArenaWorldFunction implements FunctionManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void startAction(TimeControllerOfFunction timeControllerOfFunction) {
|
||||
// ArenaLogic.getInstance().updateArenaSeason(timeControllerOfFunction.getTimes());
|
||||
public void startAction(TimeControllerOfFunction timeControllerOfFunction) throws Exception {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.world.handler;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import com.ljsd.fight.ArenaRecord;
|
||||
import com.ljsd.fight.ArenaRecordWrap;
|
||||
import com.ljsd.jieling.logic.fight.result.FightResult;
|
||||
import com.world.logic.arean.ArenaEnemy;
|
||||
import com.world.logic.arean.ArenaLogic;
|
||||
|
@ -8,7 +11,10 @@ import com.world.logic.arean.fight.FightUtil;
|
|||
import com.world.network.server.gsHelper;
|
||||
import com.world.redis.RedisKey;
|
||||
import com.world.redis.RedisUtil;
|
||||
import config.SArenaRobotConfig;
|
||||
import config.SArenaSetting;
|
||||
import config.SMServerArenaSetting;
|
||||
import manager.STableManager;
|
||||
import rpc.net.RpcMessage;
|
||||
import rpc.net.gtGBaseHandler;
|
||||
import rpc.protocols.CommonProto;
|
||||
|
@ -27,8 +33,19 @@ public class GetWorldArenaChallengeRequestHandler extends gtGBaseHandler<WorldPr
|
|||
@Override
|
||||
public GeneratedMessage processWithProto(RpcMessage rpcMessage, WorldProto.GetWorldArenaChallengeRequest proto) throws Exception {
|
||||
|
||||
Lockeys.getInstance().lock("arena",rpcMessage.getServerId());
|
||||
WorldProto.GetWorldArenaChallengeResponse.Builder builder1 = WorldProto.GetWorldArenaChallengeResponse.newBuilder();
|
||||
if (proto.getSkipFight() == 1) {
|
||||
//扫荡直接发 奖励
|
||||
//TODO DROP 放在gs做了
|
||||
// SMServerArenaSetting setting = STableManager.getConfig(SMServerArenaSetting.class).get(1);
|
||||
// setting.getBattleWinReward();
|
||||
builder1.setFightResult(1);
|
||||
return builder1.build();
|
||||
}
|
||||
|
||||
|
||||
Lockeys.getInstance().lock("arena",rpcMessage.getServerId());
|
||||
|
||||
try {
|
||||
//TODO 校验需要对手是否在匹配范围内
|
||||
|
||||
|
@ -36,27 +53,40 @@ public class GetWorldArenaChallengeRequestHandler extends gtGBaseHandler<WorldPr
|
|||
HashMap<Integer, ArenaEnemy> integerIntegerHashMap = ArenaLogic.ranInfo.get(integer);
|
||||
//判断信息是否改变
|
||||
//我的信息
|
||||
Set<Integer> hisRank =( Set<Integer>) RedisUtil.getInstence().getObject(RedisUtil.getInstence().getKey(RedisKey.WORLD_ARENA_RANK_MY_MATH, String.valueOf(rpcMessage.getUid())), HashMap.class);
|
||||
Set<Integer> hisRank =RedisUtil.getInstence().getObject(RedisUtil.getInstence().getKey(RedisKey.WORLD_ARENA_RANK_MY_MATH, String.valueOf(rpcMessage.getUid())), new TypeToken<Set<Integer>>() {
|
||||
}.getType());
|
||||
if(hisRank.size()==0){
|
||||
//被替了
|
||||
//重新拿数据
|
||||
builder1.setFightResult(-2);
|
||||
builder1.setErr(-2);
|
||||
return builder1.build();
|
||||
}
|
||||
//对方信息
|
||||
Map.Entry<Integer, ArenaEnemy> challRank = ArenaLogic.getKey(integerIntegerHashMap, proto.getChallengeUid());
|
||||
if(challRank==null||challRank.getKey()!=proto.getChallengeUid()){
|
||||
builder1.setFightResult(-2);
|
||||
ArenaEnemy arenaEnemy = integerIntegerHashMap.get(proto.getChallengeRank());
|
||||
if(arenaEnemy==null||arenaEnemy.getEnemyId()!=proto.getChallengeUid()){
|
||||
builder1.setErr(-2);
|
||||
return builder1.build();
|
||||
}
|
||||
|
||||
WorldProto.GetGSUserArenaInfoResponse getGSUserArenaInfoResponse = gsHelper.sendMessageToGs(challRank.getValue().getServerID(), challRank.getValue().getEnemyId(), WorldProto.GetGSUserArenaInfoRequest.newBuilder().setUid(challRank.getValue().getEnemyId()).build(), WorldProto.GetGSUserArenaInfoResponse.class);
|
||||
if (getGSUserArenaInfoResponse == null) {
|
||||
builder1.setFightResult(-2);
|
||||
return builder1.build();
|
||||
|
||||
int force;
|
||||
CommonProto.FightTeamInfo teamInfo;
|
||||
if(arenaEnemy.getEnemyType()==1){
|
||||
WorldProto.GetGSUserArenaInfoResponse getGSUserArenaInfoResponse = gsHelper.sendMessageToGs(arenaEnemy.getServerID(), arenaEnemy.getEnemyId(), WorldProto.GetGSUserArenaInfoRequest.newBuilder().setUid(arenaEnemy.getEnemyId()).build(), WorldProto.GetGSUserArenaInfoResponse.class);
|
||||
if (getGSUserArenaInfoResponse == null) {
|
||||
builder1.setErr(-2);
|
||||
return builder1.build();
|
||||
}
|
||||
force=getGSUserArenaInfoResponse.getTotalForce();
|
||||
teamInfo = getGSUserArenaInfoResponse.getFightTeamInfo();
|
||||
}else {
|
||||
teamInfo = FightUtil.makeRobotFightData(arenaEnemy.getEnemyId());
|
||||
force = SArenaRobotConfig.getsArenaRobotConfigById(arenaEnemy.getEnemyId()).getTotalForce();
|
||||
}
|
||||
boolean isRevert = proto.getTotalForce()<getGSUserArenaInfoResponse.getTotalForce();
|
||||
FightResult fightResult = FightUtil.getFightForPVP(rpcMessage.getUid(), proto.getChallengeUid(), proto.getFightTeamInfo(), getGSUserArenaInfoResponse.getFightTeamInfo(), FightUtil.getFightSeed(), isRevert);
|
||||
|
||||
|
||||
boolean isRevert = proto.getTotalForce()<force;
|
||||
FightResult fightResult = FightUtil.getFightForPVP(rpcMessage.getUid(), proto.getChallengeUid(), proto.getFightTeamInfo(), teamInfo, FightUtil.getFightSeed(), isRevert);
|
||||
builder1.setFightResult(fightResult.getCheckResult()[0]);
|
||||
int seed = fightResult.getSeed();
|
||||
CommonProto.FightData build = CommonProto.FightData.newBuilder()
|
||||
|
@ -66,24 +96,42 @@ public class GetWorldArenaChallengeRequestHandler extends gtGBaseHandler<WorldPr
|
|||
.addMonsterList(fightResult.getDefFightTeamInfo())
|
||||
.build();
|
||||
builder1.setFightData(build);
|
||||
//交换队伍
|
||||
Map.Entry<Integer, ArenaEnemy> myRank = ArenaLogic.getKey(integerIntegerHashMap, rpcMessage.getUid());
|
||||
if(myRank!=null){
|
||||
integerIntegerHashMap.put(myRank.getKey(),challRank.getValue());
|
||||
integerIntegerHashMap.put(challRank.getKey(),myRank.getValue());
|
||||
if(challRank.getValue().getEnemyType()==0){
|
||||
//清空匹配
|
||||
RedisUtil.getInstence().set(RedisKey.WORLD_ARENA_RANK_MY_MATH, String.valueOf( challRank.getValue().getEnemyId()), new HashSet<>());
|
||||
CommonProto.ArenaInfo.Builder arenaInfoBuild = CommonProto.ArenaInfo.newBuilder();
|
||||
if(fightResult.getCheckResult()[0]>0){
|
||||
//交换队伍
|
||||
Map.Entry<Integer, ArenaEnemy> myRank = ArenaLogic.getKey(integerIntegerHashMap, rpcMessage.getUid());
|
||||
if(myRank!=null){
|
||||
integerIntegerHashMap.put(myRank.getKey(),arenaEnemy);
|
||||
integerIntegerHashMap.put(proto.getChallengeRank(),myRank.getValue());
|
||||
if(arenaEnemy.getEnemyType()==0){
|
||||
//清空匹配
|
||||
RedisUtil.getInstence().set(RedisKey.WORLD_ARENA_RANK_MY_MATH, String.valueOf( arenaEnemy.getEnemyId()), new HashSet<>());
|
||||
}
|
||||
}else {
|
||||
integerIntegerHashMap.put(proto.getChallengeRank(), new ArenaEnemy(rpcMessage.getUid(),rpcMessage.getServerId(),1,0));
|
||||
}
|
||||
}else {
|
||||
integerIntegerHashMap.put(challRank.getKey(), new ArenaEnemy(rpcMessage.getProtpId(),rpcMessage.getServerId(),1,0));
|
||||
//处理匹配信息
|
||||
RedisUtil.getInstence().set(RedisKey.WORLD_ARENA_RANK_MY_MATH, String.valueOf( rpcMessage.getUid()), new HashSet<>());
|
||||
List<ArenaEnemy> arenaEnemies = ArenaLogic.randomRank(integerIntegerHashMap, rpcMessage.getUid(), myRank==null?9999:myRank.getKey());
|
||||
|
||||
//notify client
|
||||
List<CommonProto.ArenaEnemy> arenaEnemyList = ArenaLogic.getInstance().getArenaEnemyList(new LinkedList<>(arenaEnemies));
|
||||
arenaInfoBuild.addAllArenaEnemys(arenaEnemyList);
|
||||
arenaInfoBuild.setScore(proto.getChallengeRank());
|
||||
|
||||
|
||||
ArenaRecord arenaRecord = new ArenaRecord();
|
||||
arenaRecord.setAttackId(rpcMessage.getUid());
|
||||
arenaRecord.setDefScore(defScoreChange);
|
||||
arenaRecord.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
||||
arenaRecord.setId(KeyGenUtils.produceIdByModule(UUIDEnum.ARENARECORD, uid));
|
||||
arenaRecord.setFightResult(fightResult ^ 1);
|
||||
RedisUtil.getInstence().putMapEntry(RedisKey.ARENA_RRECORD, Integer.toString(challengeUid), arenaRecord.getId(), ArenaRecordWrap);
|
||||
}
|
||||
|
||||
RedisUtil.getInstence().set(RedisKey.WORLD_ARENA_RANK_MY_MATH, String.valueOf( rpcMessage.getUid()), new HashSet<>());
|
||||
List<ArenaEnemy> arenaEnemies = ArenaLogic.randomRank(integerIntegerHashMap, rpcMessage.getUid(), myRank.getKey());
|
||||
List<CommonProto.ArenaEnemy> arenaEnemyList = ArenaLogic.getInstance().getArenaEnemyList(new LinkedList<>(arenaEnemies));
|
||||
builder1.addAllArenaEnemys(arenaEnemyList);
|
||||
builder1.setArenaInfo(arenaInfoBuild);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
Lockeys.getInstance().reset();
|
||||
}
|
||||
|
||||
|
|
|
@ -30,38 +30,34 @@ public class GetWorldArenaInfoRequestHandler extends gtGBaseHandler<WorldProto.G
|
|||
|
||||
@Override
|
||||
public GeneratedMessage processWithProto(RpcMessage rpcMessage, WorldProto.GetWorldArenaInfoRequest proto) throws Exception {
|
||||
WorldProto.GetWorldArenaInfoResponse.Builder builder = WorldProto.GetWorldArenaInfoResponse.newBuilder();
|
||||
CommonProto.ArenaInfo.Builder builder1 = CommonProto.ArenaInfo.newBuilder();
|
||||
try {
|
||||
Lockeys.getInstance().lock("arena",rpcMessage.getServerId());
|
||||
Lockeys.getInstance().lock("arena", rpcMessage.getServerId());
|
||||
int serverId = rpcMessage.getServerId();
|
||||
Integer integer = ArenaLogic.serverSplit.get(String.valueOf(serverId));
|
||||
HashMap<Integer, ArenaEnemy> integerIntegerHashMap = ArenaLogic.ranInfo.get(integer);
|
||||
|
||||
WorldProto.GetWorldArenaInfoResponse.Builder builder = WorldProto.GetWorldArenaInfoResponse.newBuilder();
|
||||
if(integerIntegerHashMap==null){
|
||||
if (integerIntegerHashMap == null) {
|
||||
builder.setStage(1);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
//获取我的排名
|
||||
Map.Entry<Integer, ArenaEnemy> myRank = ArenaLogic.getKey(integerIntegerHashMap, rpcMessage.getUid());
|
||||
if(myRank==null){
|
||||
builder.setStage(1);
|
||||
return builder.build();
|
||||
Map.Entry<Integer, ArenaEnemy> myRank = ArenaLogic.getKey(integerIntegerHashMap, rpcMessage.getUid());
|
||||
int myIndex = 9999;
|
||||
if (myRank != null) {
|
||||
myIndex = myRank.getKey();
|
||||
}
|
||||
|
||||
List<ArenaEnemy> arenaEnemies = ArenaLogic.randomRank(integerIntegerHashMap, rpcMessage.getUid(), myRank.getKey());
|
||||
builder1.setScore(myRank.getKey()).addAllArenaEnemys(ArenaLogic.getInstance().getArenaEnemyList(new LinkedList<>(arenaEnemies))).build();
|
||||
}catch (Exception e){
|
||||
List<ArenaEnemy> arenaEnemies = ArenaLogic.randomRank(integerIntegerHashMap, rpcMessage.getUid(), myIndex);
|
||||
builder.setStage(2);
|
||||
builder1.setScore(myIndex).addAllArenaEnemys(ArenaLogic.getInstance().getArenaEnemyList(new LinkedList<>(arenaEnemies))).build();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.toString());
|
||||
} finally {
|
||||
Lockeys.getInstance().reset();
|
||||
}
|
||||
|
||||
//获取竞技场信息
|
||||
|
||||
return WorldProto.GetWorldArenaInfoResponse.newBuilder().setArenaInfo(builder1).build();
|
||||
return builder.setArenaInfo(builder1).build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@ public class GetWorldArenaProudRequestHandler extends gtGBaseHandler<WorldCommon
|
|||
WorldCommonProto.GetWorldArenaProudResponse.Builder builder = WorldCommonProto.GetWorldArenaProudResponse.newBuilder();
|
||||
|
||||
try {
|
||||
//check 膜拜
|
||||
//check 膜拜 在逻辑服做
|
||||
|
||||
Integer integer = ArenaLogic.serverSplit.get(String.valueOf(rpcMessage.getServerId()));
|
||||
HashMap<Integer, ArenaEnemy> integerIntegerHashMap = ArenaLogic.ranInfo.get(integer);
|
||||
Map.Entry<Integer, ArenaEnemy> challRank = ArenaLogic.getKey(integerIntegerHashMap, proto.getChallengeUid());
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.world.handler;
|
||||
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import com.ljsd.fight.ArenaRecord;
|
||||
import com.ljsd.fight.ArenaRecordWrap;
|
||||
import com.world.logic.arean.ArenaEnemy;
|
||||
import com.world.logic.arean.ArenaLogic;
|
||||
import com.world.redis.RedisKey;
|
||||
|
@ -14,11 +14,11 @@ import rpc.world.WorldProto;
|
|||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Description: des
|
||||
* Description: 许愿
|
||||
* Author: zsx
|
||||
* CreateDate: 2020/12/2 21:32
|
||||
* CreateDate: 2020/12/4 16:27
|
||||
*/
|
||||
public class GetWorldArenaRecordInfoRequestHandler extends gtGBaseHandler<WorldProto.GetWorldArenaRecordInfoRequest> {
|
||||
public class GetWorldArenaRecordInfoRequestHandler extends gtGBaseHandler<WorldProto.GetWorldArenaRecordInfoRequest> {
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -30,58 +30,37 @@ public class GetWorldArenaRecordInfoRequestHandler extends gtGBaseHandler<World
|
|||
HashMap<Integer, ArenaEnemy> integerIntegerHashMap = ArenaLogic.ranInfo.get(integer);
|
||||
//个人信息
|
||||
Map.Entry<Integer, ArenaEnemy> challRank = ArenaLogic.getKey(integerIntegerHashMap, rpcMessage.getUid());
|
||||
if(challRank==null){
|
||||
if (challRank == null) {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
Map<String, ArenaRecord> result = RedisUtil.getInstence().getMapValues(RedisKey.WORLD_ARENA_RRECORD, Integer.toString(rpcMessage.getUid()), String.class, ArenaRecord.class);
|
||||
if(result!=null && !result.isEmpty()){
|
||||
Map<String, ArenaRecordWrap> result = RedisUtil.getInstence().getMapValues(RedisKey.WORLD_ARENA_RRECORD, Integer.toString(rpcMessage.getUid()), String.class, ArenaRecordWrap.class);
|
||||
if (result != null && !result.isEmpty()) {
|
||||
List<CommonProto.ArenaRecordInfo> arenaRecordInfos = new ArrayList<>();
|
||||
List<ArenaRecord> arenaRecordList = new ArrayList<>(result.values());
|
||||
Collections.sort(arenaRecordList, new Comparator<ArenaRecord>() {
|
||||
@Override
|
||||
public int compare(ArenaRecord o1, ArenaRecord o2) {
|
||||
return Integer.compare(o1.getCreateTime(), o2.getCreateTime());
|
||||
}
|
||||
});
|
||||
List<ArenaRecordWrap> arenaRecordList = new ArrayList<>(result.values());
|
||||
arenaRecordList.sort(Comparator.comparingInt(o -> o.getArenaRecord().getCreateTime()));
|
||||
int size = arenaRecordList.size();
|
||||
if(size>10){
|
||||
String[] removeMapKeys = new String[size - 10];
|
||||
for(int i=0;i<size-10;i++){
|
||||
ArenaRecord remove = arenaRecordList.remove(0);
|
||||
String removeId = remove.getId();
|
||||
removeMapKeys[i]=(removeId);
|
||||
if (size > 20) {
|
||||
String[] removeMapKeys = new String[size - 10];
|
||||
for (int i = 0; i < size - 10; i++) {
|
||||
ArenaRecordWrap remove = arenaRecordList.remove(0);
|
||||
String removeId = remove.getArenaRecord().getId();
|
||||
removeMapKeys[i] = (removeId);
|
||||
}
|
||||
RedisUtil.getInstence().removeMapEntrys(RedisKey.WORLD_ARENA_RRECORD,Integer.toString(rpcMessage.getUid()),removeMapKeys);
|
||||
RedisUtil.getInstence().removeMapEntrys(RedisKey.WORLD_ARENA_RRECORD, Integer.toString(rpcMessage.getUid()), removeMapKeys);
|
||||
}
|
||||
|
||||
|
||||
// for(ArenaRecord arenaRecord : arenaRecordList){
|
||||
// int attackId = arenaRecord.getAttackId();
|
||||
// int attackForce = arenaRecord.getAttackForce();
|
||||
//
|
||||
//
|
||||
// CommonProto.ArenaPersonInfo arenaPersonInfo = CommonProto.ArenaPersonInfo.newBuilder()
|
||||
// .setUid(attackId)
|
||||
// .setName(playerInfoManager.getNickName())
|
||||
// .setLevel(playerInfoManager.getLevel())
|
||||
// .setHead(playerInfoManager.getHead())
|
||||
// .setTotalForce(attackForce)
|
||||
// .setScore( RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason), Integer.toString(attackId)).intValue())
|
||||
// .build();
|
||||
//
|
||||
// arenaRecordInfos.add(CommonProto.ArenaRecordInfo.newBuilder()
|
||||
// .setId(arenaRecord.getId())
|
||||
// .setAttackInfo(arenaPersonInfo)
|
||||
// .setMyScoreChange(arenaRecord.getDefScore())
|
||||
// .setAttackTime(arenaRecord.getCreateTime())
|
||||
// .setFightResult(arenaRecord.getFightResult())
|
||||
// .build());
|
||||
// }
|
||||
//
|
||||
// ArenaInfoProto.ArenaRecordInfoResponse build = ArenaInfoProto.ArenaRecordInfoResponse.newBuilder().addAllArenaRecordInfo(arenaRecordInfos).build();
|
||||
|
||||
for (ArenaRecordWrap arenaRecord : arenaRecordList) {
|
||||
arenaRecordInfos.add(CommonProto.ArenaRecordInfo.newBuilder()
|
||||
.setId(arenaRecord.getArenaRecord().getId())
|
||||
.setAttackInfo(arenaRecord.getArenaEnemy().getPersonInfo())
|
||||
.setMyScoreChange(arenaRecord.getArenaRecord().getDefScore())
|
||||
.setAttackTime(arenaRecord.getArenaRecord().getCreateTime())
|
||||
.setFightResult(arenaRecord.getArenaRecord().getFightResult())
|
||||
.build());
|
||||
}
|
||||
builder.addAllArenaRecordInfo(arenaRecordInfos);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
package com.world.logic.arean;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class ArenaEnemy {
|
||||
public class ArenaEnemy extends Object{
|
||||
private int enemyId;
|
||||
private int serverID;
|
||||
// 0:玩家,1:机器人
|
||||
private int enemyType;
|
||||
// 0:未挑战,1:挑战成功,2:挑战失败
|
||||
private int enemyStatus;
|
||||
|
||||
private AtomicInteger worshipTime;//膜拜次数
|
||||
private int rank;//排名
|
||||
private int worshipTime;//膜拜次数
|
||||
|
||||
public ArenaEnemy(int enemyId, int serverID, int enemyType, int enemyStatus) {
|
||||
this.enemyId = enemyId;
|
||||
|
@ -19,6 +18,14 @@ public class ArenaEnemy {
|
|||
this.enemyStatus = enemyStatus;
|
||||
}
|
||||
|
||||
public int getRank() {
|
||||
return rank;
|
||||
}
|
||||
|
||||
public void setRank(int rank) {
|
||||
this.rank = rank;
|
||||
}
|
||||
|
||||
public int getServerID() {
|
||||
return serverID;
|
||||
}
|
||||
|
@ -28,20 +35,22 @@ public class ArenaEnemy {
|
|||
}
|
||||
|
||||
public int getEnemyType() {
|
||||
return enemyType;
|
||||
return enemyType>0?1:0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getEnemyStatus() {
|
||||
return enemyStatus;
|
||||
}
|
||||
|
||||
|
||||
public int getWorshipTime() {
|
||||
return worshipTime.get();
|
||||
return worshipTime;
|
||||
}
|
||||
|
||||
public void addWorshipTime() {
|
||||
this.worshipTime.incrementAndGet();
|
||||
public synchronized void addWorshipTime() {
|
||||
this.worshipTime+=1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.world.logic.arean;
|
||||
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.ljsd.fight.ArenaRecord;
|
||||
import com.ljsd.jieling.config.clazzStaticCfg.SArenaRobotStaticConfig;
|
||||
import com.ljsd.jieling.core.GlobalsDef;
|
||||
|
@ -60,16 +61,23 @@ public class ArenaLogic {
|
|||
|
||||
public static void initRank() throws Exception{
|
||||
|
||||
Map<String, Integer> serverSplit = RedisUtil.getInstence().getMapValues(RedisKey.SERVER_SPLIT_INFO, String.class, Integer.class);
|
||||
serverSplit.forEach((s, integer) -> {
|
||||
HashSet<String> strings = map.getOrDefault(integer, new HashSet<>());
|
||||
strings.add(s);
|
||||
map.put(integer, strings);
|
||||
});
|
||||
ArenaLogic.serverSplit =serverSplit;
|
||||
|
||||
Set<String> keys = new HashSet<>();
|
||||
Cursor<String> cursor = com.ljsd.jieling.db.redis.RedisUtil.getInstence().scan("WORLD_ARENA_RANK*", 200);
|
||||
Cursor<String> cursor =RedisUtil.getInstence().scan("WORLD_ARENA_RANK:*", 200);
|
||||
while (cursor.hasNext()) {
|
||||
//找到一次就添加一次
|
||||
keys.add(cursor.next());
|
||||
}
|
||||
cursor.close();
|
||||
keys.forEach(k->{
|
||||
HashMap<Integer, ArenaEnemy> object =( HashMap<Integer, ArenaEnemy>) RedisUtil.getInstence().getObject(RedisUtil.getInstence().getKey(RedisKey.WORLD_ARENA_RANK, k), HashMap.class);
|
||||
|
||||
HashMap<Integer, ArenaEnemy> object =RedisUtil.getInstence().getObject(k,new TypeToken< HashMap<Integer, ArenaEnemy>>(){}.getType());
|
||||
|
||||
ranInfo.put(Integer.valueOf(k.split(":")[1]),object);
|
||||
});
|
||||
|
@ -96,17 +104,17 @@ public class ArenaLogic {
|
|||
map.put(integer, strings);
|
||||
});
|
||||
//为每组生成排行榜
|
||||
this.serverSplit =serverSplit;
|
||||
ArenaLogic.serverSplit =serverSplit;
|
||||
int[] fightArea = STableManager.getConfig(SMServerArenaSetting.class).get(1).getFightArea();
|
||||
|
||||
map.forEach((integer, strings) -> {
|
||||
List<Integer> robotIds = randomRobot(fightArea[0], fightArea[1], 1000);
|
||||
HashMap<Integer, ArenaEnemy> orDefault = ranInfo.getOrDefault(integer, new HashMap<>());
|
||||
for (int i = 1; i <= robotIds.size(); i++) {
|
||||
orDefault.put(i,new ArenaEnemy(robotIds.get(i - 1),0,1,0));
|
||||
orDefault.put(i,new ArenaEnemy(robotIds.get(i - 1),0,0,0));
|
||||
}
|
||||
ranInfo.put(integer, orDefault);
|
||||
RedisUtil.getInstence().set(RedisKey.WORLD_ARENA_RANK, String.valueOf(integer), orDefault);
|
||||
RedisUtil.getInstence().set(RedisKey.WORLD_ARENA_RANK, String.valueOf(integer), orDefault,new TypeToken< HashMap<Integer, ArenaEnemy>>(){}.getType());
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -121,12 +129,13 @@ public class ArenaLogic {
|
|||
for (ArenaEnemy arenaEnemy : arenaEnemies) {
|
||||
int enemyId = arenaEnemy.getEnemyId();
|
||||
int enemyType = arenaEnemy.getEnemyType();
|
||||
arenaEnemyList.add(getArenaEnemy(enemyId, arenaEnemy.getServerID(), enemyType));
|
||||
int rank = arenaEnemy.getRank();//only robot
|
||||
arenaEnemyList.add(getArenaEnemy(enemyId, arenaEnemy.getServerID(), enemyType,rank));
|
||||
}
|
||||
return arenaEnemyList;
|
||||
}
|
||||
|
||||
public CommonProto.ArenaEnemy getArenaEnemy(int enemyId, int serverId, int enemyType) throws Exception {
|
||||
public CommonProto.ArenaEnemy getArenaEnemy(int enemyId, int serverId, int enemyType,int rank) throws Exception {
|
||||
if (enemyType == 0) { //机器人
|
||||
SArenaRobotConfig sArenaRobotConfig = SArenaRobotConfig.getsArenaRobotConfigById(enemyId);
|
||||
CommonProto.Team teamBuild = CommonProto.Team.newBuilder().addAllHeroTid(sArenaRobotConfig.getHeroList()).build();
|
||||
|
@ -136,7 +145,7 @@ public class ArenaLogic {
|
|||
.setName(sArenaRobotConfig.getRobotName())
|
||||
.setScore(sArenaRobotConfig.getRobotScore())
|
||||
.setTotalForce(sArenaRobotConfig.getTotalForce())
|
||||
|
||||
.setRank(rank)
|
||||
.build();
|
||||
return CommonProto.ArenaEnemy.newBuilder()
|
||||
.setPersonInfo(personInfoBuild)
|
||||
|
@ -216,7 +225,7 @@ public class ArenaLogic {
|
|||
static List<Integer> randomRobot(int start, int end, int nums) {
|
||||
List<Integer> robotIds = new LinkedList<>();
|
||||
int index = 0;
|
||||
while (robotIds.size() == nums) {
|
||||
while (robotIds.size() < nums) {
|
||||
index++;
|
||||
if (index == 10000) {
|
||||
break;
|
||||
|
@ -321,10 +330,9 @@ public class ArenaLogic {
|
|||
|
||||
|
||||
public static Map.Entry<Integer, ArenaEnemy> getKey(HashMap<Integer, ArenaEnemy> map ,int value) {
|
||||
Iterator it = map.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<Integer, ArenaEnemy> entry =( Map.Entry<Integer, ArenaEnemy> )(it.next());
|
||||
if (entry.getValue().getEnemyId()==value){
|
||||
for (Map.Entry<Integer, ArenaEnemy> entry : map.entrySet()) {
|
||||
ArenaEnemy value1 = entry.getValue();
|
||||
if (value1.getEnemyId() == value) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
@ -334,20 +342,18 @@ public class ArenaLogic {
|
|||
|
||||
/**
|
||||
* 上层加锁
|
||||
* @param uid
|
||||
* @param myRank
|
||||
*/
|
||||
public static List<ArenaEnemy> randomRank(HashMap<Integer, ArenaEnemy> integerIntegerHashMap ,int uid,int myRank){
|
||||
//缓存每次匹配结果
|
||||
Set<Integer> hisRank =( Set<Integer>) RedisUtil.getInstence().getObject(RedisUtil.getInstence().getKey(RedisKey.WORLD_ARENA_RANK_MY_MATH, String.valueOf(uid)), HashMap.class);
|
||||
Set<Integer> hisRank = RedisUtil.getInstence().getObject(RedisUtil.getInstence().getKey(RedisKey.WORLD_ARENA_RANK_MY_MATH, String.valueOf(uid)), new TypeToken<Set<Integer>>(){}.getType());
|
||||
List<ArenaEnemy> arenaEnemies = new ArrayList<>();
|
||||
|
||||
Set<Integer> matchRank;
|
||||
TreeSet<Integer> matchRank;
|
||||
if(hisRank==null||hisRank.size()==0){
|
||||
//获取匹配对手
|
||||
matchRank = getMatchID(myRank);
|
||||
}else {
|
||||
matchRank = new HashSet<>(hisRank);
|
||||
matchRank = new TreeSet<>(hisRank);
|
||||
}
|
||||
|
||||
matchRank.forEach(rank -> {
|
||||
|
@ -355,8 +361,9 @@ public class ArenaLogic {
|
|||
return;
|
||||
}
|
||||
ArenaEnemy matchInfo = integerIntegerHashMap.get(rank);
|
||||
matchInfo.setRank(rank);
|
||||
arenaEnemies.add(matchInfo);
|
||||
matchRank.add(rank);
|
||||
// matchRank.add(rank);
|
||||
});
|
||||
RedisUtil.getInstence().set(RedisKey.WORLD_ARENA_RANK_MY_MATH, String.valueOf( uid), matchRank);
|
||||
return arenaEnemies;
|
||||
|
@ -365,16 +372,17 @@ public class ArenaLogic {
|
|||
/**
|
||||
* 实时随机 暂时不缓存
|
||||
*/
|
||||
private static Set<Integer> getMatchID(int index){
|
||||
private static TreeSet<Integer> getMatchID(int index){
|
||||
//玩家排名 获取配置
|
||||
Integer integer = SMServerArenaMatchConfig.rank2miss.floorKey(index);
|
||||
HashSet<Integer> objects = new HashSet<>();
|
||||
Integer integer1 = SMServerArenaMatchConfig.rank2miss.get(integer);
|
||||
TreeSet<Integer> objects = new TreeSet<>();
|
||||
//分配对手
|
||||
SMServerArenaMatchConfig serverArenaMatchConfig = STableManager.getConfig(SMServerArenaMatchConfig.class).get(integer);
|
||||
int blockID1 = (int)( Math.random()*(serverArenaMatchConfig.getBlock1()[1]-serverArenaMatchConfig.getBlock1()[0])+serverArenaMatchConfig.getBlock1()[0]);
|
||||
int blockID2 = (int)( Math.random()*(serverArenaMatchConfig.getBlock2()[1]-serverArenaMatchConfig.getBlock2()[0])+serverArenaMatchConfig.getBlock2()[0]);
|
||||
int blockID3 = (int)( Math.random()*(serverArenaMatchConfig.getBlock3()[1]-serverArenaMatchConfig.getBlock3()[0])+serverArenaMatchConfig.getBlock3()[0]);
|
||||
int blockID4 = (int)( Math.random()*(serverArenaMatchConfig.getBlock4()[1]-serverArenaMatchConfig.getBlock4()[0])+serverArenaMatchConfig.getBlock4()[0]);
|
||||
SMServerArenaMatchConfig serverArenaMatchConfig = STableManager.getConfig(SMServerArenaMatchConfig.class).get(integer1);
|
||||
int blockID1 = (int)( Math.random()*(serverArenaMatchConfig.getBlock1()[1]-serverArenaMatchConfig.getBlock1()[0])+serverArenaMatchConfig.getBlock1()[0])+index;
|
||||
int blockID2 = (int)( Math.random()*(serverArenaMatchConfig.getBlock2()[1]-serverArenaMatchConfig.getBlock2()[0])+serverArenaMatchConfig.getBlock2()[0])+index;
|
||||
int blockID3 = (int)( Math.random()*(serverArenaMatchConfig.getBlock3()[1]-serverArenaMatchConfig.getBlock3()[0])+serverArenaMatchConfig.getBlock3()[0])+index;
|
||||
int blockID4 = (int)( Math.random()*(serverArenaMatchConfig.getBlock4()[1]-serverArenaMatchConfig.getBlock4()[0])+serverArenaMatchConfig.getBlock4()[0])+index;
|
||||
objects.add(blockID1);
|
||||
objects.add(blockID2);
|
||||
objects.add(blockID3);
|
||||
|
|
|
@ -2,19 +2,20 @@ package com.world.logic.arean.fight;
|
|||
|
||||
import com.ljsd.fight.CheckFight;
|
||||
import com.ljsd.fight.FightType;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.logic.fight.FightEvent;
|
||||
import com.ljsd.jieling.logic.fight.GameFightType;
|
||||
import com.ljsd.jieling.logic.fight.PVPFightEvent;
|
||||
import com.ljsd.jieling.logic.fight.result.FightResult;
|
||||
import com.ljsd.jieling.logic.hero.HeroAttributeEnum;
|
||||
import com.ljsd.jieling.logic.hero.HeroLogic;
|
||||
import com.ljsd.jieling.util.FightDataUtil;
|
||||
import config.SArenaRobotConfig;
|
||||
import config.SArenaSetting;
|
||||
import config.SCHero;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import rpc.protocols.CommonProto;
|
||||
|
||||
import static com.ljsd.jieling.handler.map.EventType.fightEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* Description: des
|
||||
|
@ -28,7 +29,6 @@ public class FightUtil {
|
|||
}
|
||||
|
||||
public static FightResult getFightForPVP(int attachId,int defUid,CommonProto.FightTeamInfo fightTeamInfo, CommonProto.FightTeamInfo deffightTeamInfo,int seed,boolean isRever) throws Exception {
|
||||
int fightSeed =seed;
|
||||
LuaValue getFightData ;
|
||||
if(isRever){
|
||||
deffightTeamInfo = CommonProto.FightTeamInfo.newBuilder().mergeFrom(deffightTeamInfo).setFirstCamp(1).build();
|
||||
|
@ -37,16 +37,66 @@ public class FightUtil {
|
|||
getFightData = FightDataUtil.getFinalPlayerFightData(fightTeamInfo, deffightTeamInfo);
|
||||
}
|
||||
LuaValue getOptionData = FightDataUtil.getOptionData(attachId+"");
|
||||
int[] fightResult = CheckFight.getInstance().checkFight(fightSeed, SArenaSetting.getSArenaSetting().getMostTime(), getFightData, getOptionData, FightType.ArenaFight);
|
||||
int[] fightResult = CheckFight.getInstance().checkFight(seed, SArenaSetting.getSArenaSetting().getMostTime(), getFightData, getOptionData, FightType.ArenaFight);
|
||||
|
||||
FightResult.Builder builder = FightResult.newBuilder();
|
||||
builder.setCheckResult(fightResult);
|
||||
builder.setSeed(fightSeed);
|
||||
builder.setSeed(seed);
|
||||
builder.setFightTeamInfo(fightTeamInfo);
|
||||
builder.setDefFightTeamInfo(deffightTeamInfo);
|
||||
CommonProto.FightData fightData = CommonProto.FightData.newBuilder().setFightType(FightType.ArenaFight.getType()).setHeroFightInfos(fightTeamInfo).addMonsterList(deffightTeamInfo).setFightSeed(fightSeed).setFightMaxTime(fightEvent.getMostTime()).build();
|
||||
CommonProto.FightData fightData = CommonProto.FightData.newBuilder().setFightType(FightType.ArenaFight.getType()).setHeroFightInfos(fightTeamInfo).addMonsterList(deffightTeamInfo).setFightSeed(seed).setFightMaxTime(SArenaSetting.getSArenaSetting().getMostTime()).build();
|
||||
builder.setFightData(fightData);
|
||||
return builder.build();
|
||||
}
|
||||
//防守方是机器人(目前是竞技场适用)
|
||||
public static CommonProto.FightTeamInfo makeRobotFightData(int robotId){
|
||||
SArenaRobotConfig sArenaRobotConfig = SArenaRobotConfig.getsArenaRobotConfigById(robotId);
|
||||
return getRobotFightTeamInfo(sArenaRobotConfig);
|
||||
}
|
||||
private static CommonProto.FightTeamInfo getRobotFightTeamInfo(SArenaRobotConfig sArenaRobotConfig) {
|
||||
return getRobotFightTeamInfo(sArenaRobotConfig,null);
|
||||
}
|
||||
private static CommonProto.FightTeamInfo getRobotFightTeamInfo(SArenaRobotConfig sArenaRobotConfig, Map<String,Double> remainHp) {
|
||||
List<CommonProto.FightUnitInfo> heroFightInfos = new ArrayList<>();
|
||||
Map<Integer,Integer> heroStarsMap = sArenaRobotConfig.getStarOfHeroMap();
|
||||
int i=0;
|
||||
for(Map.Entry<Integer,Integer> item : heroStarsMap.entrySet()){
|
||||
StringBuilder skillSb = new StringBuilder();
|
||||
StringBuilder propertySb = new StringBuilder();
|
||||
Integer heroTid = item.getKey();
|
||||
Integer heroStar = item.getValue();
|
||||
SCHero scHero = SCHero.getsCHero().get(heroTid);
|
||||
List<Integer> skillIds = scHero.getSkillListByStar(heroStar);
|
||||
String heroSkill = HeroLogic.getInstance().getRobotHeroSkills(skillIds,skillSb).toString();
|
||||
|
||||
int[] differDemonsId = sArenaRobotConfig.getDifferDemonsId();
|
||||
int differDemonsLv = sArenaRobotConfig.getDifferDemonsLv();
|
||||
int robotLevel = sArenaRobotConfig.getRoleLv();
|
||||
Map<Integer, Integer> robotHeroAttribute =HeroLogic.getInstance(). calRobotHeroAttribute(scHero, robotLevel, sArenaRobotConfig.getBreakId(), differDemonsId, differDemonsLv,false);
|
||||
|
||||
if(remainHp!=null&&remainHp.containsKey(heroTid.toString())){
|
||||
robotHeroAttribute.put(HeroAttributeEnum.CurHP.getPropertyId(),(int)(remainHp.getOrDefault(heroTid.toString(),1d)*robotHeroAttribute.get(HeroAttributeEnum.Hp.getPropertyId())));
|
||||
}
|
||||
|
||||
String property = HeroLogic.getInstance().getRobotHeroProperty(sArenaRobotConfig,scHero,propertySb,robotHeroAttribute).toString();
|
||||
CommonProto.FightUnitInfo heroFightInfo = CommonProto.FightUnitInfo
|
||||
.newBuilder()
|
||||
.setUnitId(Integer.toString(heroTid))
|
||||
.setUnitSkillIds(heroSkill.substring(0,heroSkill.length()-1))
|
||||
.setProperty(property.substring(0, property.length()-1))
|
||||
.setPosition(++i)
|
||||
.setStar(heroStar)
|
||||
.build();
|
||||
heroFightInfos.add(heroFightInfo);
|
||||
}
|
||||
|
||||
return CommonProto.FightTeamInfo.
|
||||
newBuilder()
|
||||
.addAllFightUnitList(heroFightInfos)
|
||||
// .addAllPokemonUnitList(HeroLogic.getInstance().getPokemonSkills(user))
|
||||
.setTeamPassiveList(HeroLogic.getInstance().getRobotPokenmonPassiveSkills(sArenaRobotConfig))
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
package com.world.network;
|
||||
|
||||
import com.IManager;
|
||||
import com.WorldServerApplication;
|
||||
import com.ljsd.jieling.NetWorkFactory;
|
||||
import com.ljsd.jieling.netty.config.EndPortCfg;
|
||||
import com.ljsd.jieling.netty.server.NettyGameServer;
|
||||
import com.world.config.ConfigurableApplicationContextManager;
|
||||
import com.world.network.server.SessionManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Description: 网络服务管理器
|
||||
* Author: zsx
|
||||
* CreateDate: 2019/11/6 17:34
|
||||
*/
|
||||
public class NetManager implements IManager {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(WorldServerApplication.class);
|
||||
public final static NetManager instance = new NetManager();
|
||||
|
||||
public static NetManager getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private static NettyGameServer nettyServer = null;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void init() throws Exception {
|
||||
try {
|
||||
final NettyServerAutoConfiguration netServerConfig = ConfigurableApplicationContextManager.getBean(NettyServerAutoConfiguration.class);
|
||||
NettyProperties properties = netServerConfig.getNettyProperties();
|
||||
LOGGER.info("main->NettyServerAutoConfiguration start...");
|
||||
//连接处理
|
||||
nettyServer = NetWorkFactory.getServer(new EndPortCfg(properties.getTcpPort(), properties.getReadTimeout(),
|
||||
properties.getWriteTimeout(), properties.getAllTimeout()), SessionManager.getInstance());
|
||||
nettyServer.start();
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("main->msg={}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit() throws Exception {
|
||||
LOGGER.info("close->QuartzManager.getInstance().shutdownJob-------------------");
|
||||
try {
|
||||
nettyServer.stop();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("close->msg={}", e.getMessage(), e);
|
||||
}
|
||||
LOGGER.info("close->nettyServer.stop-------------------");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,130 +0,0 @@
|
|||
package com.world.network;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "netty")
|
||||
public class NettyProperties {
|
||||
|
||||
private int logintcpPort;
|
||||
private int chatTcpPort;
|
||||
private int tcpPort;
|
||||
private int udpPort;
|
||||
private String udpTargetIp;
|
||||
private int udpTargetPort;
|
||||
private int reconnectDelay=300000;
|
||||
private int bossThreadCount=2;
|
||||
private int workerThreadCount=2;
|
||||
private int readTimeout=600;
|
||||
private int writeTimeout=600;
|
||||
private int allTimeout=1000;
|
||||
private String tcpIp;
|
||||
|
||||
public NettyProperties(){}
|
||||
|
||||
public int getLogintcpPort() {
|
||||
return logintcpPort;
|
||||
}
|
||||
|
||||
public void setLogintcpPort(int logintcpPort) {
|
||||
this.logintcpPort = logintcpPort;
|
||||
}
|
||||
|
||||
public int getTcpPort() {
|
||||
return tcpPort;
|
||||
}
|
||||
|
||||
public void setTcpPort(int tcpPort) {
|
||||
this.tcpPort = tcpPort;
|
||||
}
|
||||
|
||||
public int getUdpPort() {
|
||||
return udpPort;
|
||||
}
|
||||
|
||||
public void setUdpPort(int udpPort) {
|
||||
this.udpPort = udpPort;
|
||||
}
|
||||
|
||||
public int getReconnectDelay() {
|
||||
return reconnectDelay;
|
||||
}
|
||||
|
||||
public void setReconnectDelay(int reconnectDelay) {
|
||||
this.reconnectDelay = reconnectDelay;
|
||||
}
|
||||
|
||||
public int getBossThreadCount() {
|
||||
return bossThreadCount;
|
||||
}
|
||||
|
||||
public void setBossThreadCount(int bossThreadCount) {
|
||||
this.bossThreadCount = bossThreadCount;
|
||||
}
|
||||
|
||||
public int getWorkerThreadCount() {
|
||||
return workerThreadCount;
|
||||
}
|
||||
|
||||
public void setWorkerThreadCount(int workerThreadCount) {
|
||||
this.workerThreadCount = workerThreadCount;
|
||||
}
|
||||
|
||||
public int getReadTimeout() {
|
||||
return readTimeout;
|
||||
}
|
||||
|
||||
public void setReadTimeout(int readTimeout) {
|
||||
this.readTimeout = readTimeout;
|
||||
}
|
||||
|
||||
public int getWriteTimeout() {
|
||||
return writeTimeout;
|
||||
}
|
||||
|
||||
public void setWriteTimeout(int writeTimeout) {
|
||||
this.writeTimeout = writeTimeout;
|
||||
}
|
||||
|
||||
public int getAllTimeout() {
|
||||
return allTimeout;
|
||||
}
|
||||
|
||||
public void setAllTimeout(int allTimeout) {
|
||||
this.allTimeout = allTimeout;
|
||||
}
|
||||
|
||||
public String getUdpTargetIp() {
|
||||
return udpTargetIp;
|
||||
}
|
||||
|
||||
public void setUdpTargetIp(String udpTargetIp) {
|
||||
this.udpTargetIp = udpTargetIp;
|
||||
}
|
||||
|
||||
public int getUdpTargetPort() {
|
||||
return udpTargetPort;
|
||||
}
|
||||
|
||||
public void setUdpTargetPort(int udpTargetPort) {
|
||||
this.udpTargetPort = udpTargetPort;
|
||||
}
|
||||
|
||||
public int getChatTcpPort() {
|
||||
return chatTcpPort;
|
||||
}
|
||||
|
||||
public void setChatTcpPort(int chatTcpPort) {
|
||||
this.chatTcpPort = chatTcpPort;
|
||||
}
|
||||
|
||||
public String getTcpIp() {
|
||||
return tcpIp;
|
||||
}
|
||||
|
||||
public void setTcpIp(String tcpIp) {
|
||||
this.tcpIp = tcpIp;
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package com.world.network;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(NettyProperties.class)
|
||||
public class NettyServerAutoConfiguration {
|
||||
|
||||
@Autowired
|
||||
private NettyProperties nettyProperties;
|
||||
|
||||
public NettyProperties getNettyProperties() {
|
||||
return nettyProperties;
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
package com.world.network.server;
|
||||
|
||||
import com.ljsd.jieling.db.redis.RedisKey;
|
||||
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
|
||||
/**
|
||||
* Description: 登录校验
|
||||
* Author: zsx
|
||||
* CreateDate: 2019/11/20 20:41
|
||||
*/
|
||||
class AuthManager {
|
||||
|
||||
|
||||
static boolean auVertiyFromRedis(ISession session, PacketNetData packetNetData) {
|
||||
int uid = packetNetData.getUserId();
|
||||
int token = packetNetData.getToken();
|
||||
session.setUid(uid);
|
||||
String tokenKey = RedisKey.getKey(RedisKey.TOKEN, String.valueOf(uid), false);
|
||||
if (tokenKey.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
String tokenK = (String) RedisUtil.getInstence().get(tokenKey);
|
||||
if (null == tokenK || tokenK.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
int serverToken = Integer.parseInt((String) RedisUtil.getInstence().get(tokenKey));
|
||||
if (token == serverToken) {
|
||||
session.setToken(token);
|
||||
session.setUserLoginTime(System.currentTimeMillis());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static boolean auCheck(ISession session, PacketNetData packetNetData) {
|
||||
if (session.getToken() != packetNetData.getToken()) {
|
||||
SessionManager.getInstance().serverKick(session,"您的账号token不正确,请退出游戏重新登陆!");
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean b = Blocker.checkForbidUser(session);
|
||||
if (b) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
package com.world.network.server;
|
||||
|
||||
import com.ljsd.jieling.exception.ErrorCode;
|
||||
import com.ljsd.jieling.logic.OnlineUserManager;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import com.ljsd.jieling.util.MessageUtil;
|
||||
import io.netty.util.internal.ConcurrentSet;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Description: 检查
|
||||
* Author: zsx
|
||||
* CreateDate: 2019/11/5 14:42
|
||||
*/
|
||||
public class Blocker {
|
||||
|
||||
public static final AtomicInteger maxAllowedOnlineAccountCount = new AtomicInteger(5000);
|
||||
private static ConcurrentSet<Integer> forbidLogin = new ConcurrentSet<>();
|
||||
|
||||
public static boolean checkForbidUser(ISession iSession){
|
||||
if(forbidLogin.size()<1){
|
||||
return false;
|
||||
}
|
||||
if(iSession!=null) {
|
||||
if(forbidLogin.contains(iSession.getUid())){
|
||||
MessageUtil.sendErrorCode(iSession, ErrorCode.reloginCode, "您已被踢下线!");
|
||||
iSession.setOfflineType(ErrorCode.reloginCode);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean checkFlow(ISession iSession){
|
||||
if(iSession!=null) {
|
||||
if(OnlineUserManager.sessionMap.size()>maxAllowedOnlineAccountCount.get()){
|
||||
MessageUtil.sendErrorCode(iSession, ErrorCode.ONLINE_FLOW.code(), "当前在线人数过多,请稍等哦!");
|
||||
iSession.setOfflineType(ErrorCode.reloginCode);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static Set<Integer> getForbidLogin() {
|
||||
return forbidLogin;
|
||||
}
|
||||
|
||||
static void setForbidLogin(Set<Integer> forbidLogin) {
|
||||
Blocker.forbidLogin.clear();
|
||||
Blocker.forbidLogin.addAll(forbidLogin);
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
package com.world.network.server;
|
||||
|
||||
import com.WorldServerApplication;
|
||||
import com.ljsd.jieling.handler.BaseHandler;
|
||||
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||
import com.ljsd.jieling.protocol.ProtocolsAbstract;
|
||||
import com.world.config.ConfigurableApplicationContextManager;
|
||||
import com.world.handler.BaseHandler;
|
||||
import com.world.network.session.ISession;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -22,7 +22,6 @@ import java.util.Map;
|
|||
*
|
||||
* world 模块协议解析
|
||||
*/
|
||||
@Component
|
||||
public class ProtocolsManager implements ProtocolsAbstract {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolsManager.class);
|
||||
|
|
|
@ -9,8 +9,8 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.data.redis.RedisConnectionFailureException;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.ReturnType;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.core.ZSetOperations;
|
||||
import org.springframework.data.redis.core.*;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import redis.clients.jedis.Protocol;
|
||||
import util.TimeUtils;
|
||||
|
@ -79,12 +79,20 @@ public class RedisUtil {
|
|||
return key == null ? null : redisTemplate.opsForValue().get(key);
|
||||
}
|
||||
|
||||
public <T> T getObject(String key,java.lang.reflect.Type type){
|
||||
String source = redisTemplate.opsForValue().get(key);
|
||||
if(source == null){
|
||||
return null;
|
||||
}
|
||||
return gson.fromJson(source,type);
|
||||
}
|
||||
|
||||
public <T> T getObject(String key,Class<T> clazz){
|
||||
String source = redisTemplate.opsForValue().get(key);
|
||||
if(source == null){
|
||||
return null;
|
||||
}
|
||||
return gson.fromJson(source,clazz);
|
||||
return gson.fromJson(source, clazz);
|
||||
}
|
||||
/**
|
||||
* 获取Object
|
||||
|
@ -136,7 +144,10 @@ public class RedisUtil {
|
|||
String key = getKey(type, rkey);
|
||||
redisTemplate.opsForValue().set(key, gson.toJson(t));
|
||||
}
|
||||
|
||||
public <T> void set(String mtype, String rkey, T t,java.lang.reflect.Type type) {
|
||||
String key = getKey(mtype, rkey);
|
||||
redisTemplate.opsForValue().set(key, gson.toJson(t,type));
|
||||
}
|
||||
// ===============================set=================================
|
||||
|
||||
public void saddAll(String key, String[] members){
|
||||
|
@ -710,6 +721,12 @@ public class RedisUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public Cursor<String> scan(String match, int count){
|
||||
ScanOptions scanOptions = ScanOptions.scanOptions().match(match).count(count).build();
|
||||
RedisSerializer<String> redisSerializer = (RedisSerializer<String>) redisTemplate.getKeySerializer();
|
||||
return (Cursor) redisTemplate.executeWithStickyConnection((RedisCallback) redisConnection ->
|
||||
new ConvertingCursor<>(redisConnection.scan(scanOptions), redisSerializer::deserialize));
|
||||
}
|
||||
|
||||
private final static String UNLOCK_SCRIPT = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end";
|
||||
//requestId:加锁者,才能解锁
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.world.thrift.idl.pool;
|
|||
|
||||
|
||||
import com.world.config.ConfigurableApplicationContextManager;
|
||||
import com.world.config.CoreSettings;
|
||||
import com.world.config.WorldCoreSettings;
|
||||
import com.world.thrift.idl.RPCgTwRequestIFace;
|
||||
import org.apache.thrift.TProcessor;
|
||||
import org.apache.thrift.protocol.TBinaryProtocol;
|
||||
|
@ -16,7 +16,7 @@ import org.slf4j.LoggerFactory;
|
|||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* Gloable服务器
|
||||
* World服务器
|
||||
*
|
||||
* Author: zsx
|
||||
* CreateDate: 2020/11/18 17:30
|
||||
|
@ -25,10 +25,10 @@ public class RPCServerTask extends Thread{
|
|||
private static final Logger LOGGER = LoggerFactory.getLogger(RPCServerTask.class);
|
||||
|
||||
|
||||
private CoreSettings coreSettings;
|
||||
private WorldCoreSettings coreSettings;
|
||||
|
||||
public RPCServerTask(){
|
||||
this.coreSettings = ConfigurableApplicationContextManager.getBean(CoreSettings.class);
|
||||
this.coreSettings = ConfigurableApplicationContextManager.getBean(WorldCoreSettings.class);
|
||||
setName("rpc");
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ public class ThriftPoolUtils {
|
|||
}
|
||||
public void initContext(ConfigurableApplicationContext configurableApplicationContext){
|
||||
this.configurableApplicationContext = configurableApplicationContext;
|
||||
ThriftPoolAutoConfiguration thriftPool = configurableApplicationContext.getBean(ThriftPoolAutoConfiguration.class);
|
||||
WorldThriftPoolAutoConfiguration thriftPool = configurableApplicationContext.getBean(WorldThriftPoolAutoConfiguration.class);
|
||||
|
||||
pool = thriftPool.thriftPool();
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public class WorldRpcService extends GlobalProtocolsManager implements RPCgTwReq
|
|||
public InnerResult messageRequest(int serverId, int uid, int protpId, ByteBuffer message) throws TException {
|
||||
try {
|
||||
System.out.println("messageRequest serverId = " + serverId);
|
||||
return processMessage(new RpcMessage(serverId, protpId, message));
|
||||
return processMessage(new RpcMessage(serverId,uid, protpId, message));
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(ErrorPrintUtil.getExceptionStackTraceFileLineAndMethod(e));
|
||||
}
|
||||
|
|
|
@ -36,9 +36,9 @@ import rpc.thrift.ServiceKey;
|
|||
* **************************************************************************
|
||||
*/
|
||||
@Component
|
||||
public class ThriftFactory extends BaseKeyedPooledObjectFactory<String, TTransport>
|
||||
public class WorldThriftFactory extends BaseKeyedPooledObjectFactory<String, TTransport>
|
||||
{
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ThriftFactory.class);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(WorldThriftFactory.class);
|
||||
|
||||
|
||||
|
|
@ -36,16 +36,16 @@ import org.springframework.context.annotation.Configuration;
|
|||
* **************************************************************************
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(ThriftPoolSettings.class)
|
||||
public class ThriftPoolAutoConfiguration {
|
||||
@EnableConfigurationProperties(WorldThriftPoolSettings.class)
|
||||
public class WorldThriftPoolAutoConfiguration {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ThriftPoolAutoConfiguration.class);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(WorldThriftPoolAutoConfiguration.class);
|
||||
|
||||
@Autowired
|
||||
private ThriftFactory thriftFactory;
|
||||
private WorldThriftFactory thriftFactory;
|
||||
|
||||
@Autowired
|
||||
private ThriftPoolSettings thriftPoolSettings;
|
||||
private WorldThriftPoolSettings thriftPoolSettings;
|
||||
|
||||
|
||||
public GenericKeyedObjectPool thriftPool(){
|
|
@ -29,7 +29,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||
*/
|
||||
|
||||
@ConfigurationProperties(prefix = "services.pool")
|
||||
public class ThriftPoolSettings {
|
||||
public class WorldThriftPoolSettings {
|
||||
|
||||
private int maxTotal = 700000; //整个池最大值
|
||||
private int maxTotalPerKey = 100000;//每个key的最大
|
Loading…
Reference in New Issue