Merge branch 'master' of http://60.1.1.230/backend/jieling_server
commit
8c3b106e06
|
@ -46,62 +46,40 @@ public class Tea {
|
|||
bys[offset] = (byte) ((content >> 24) & 0xff);
|
||||
}
|
||||
|
||||
//byte[]型数据转成int[]型数据
|
||||
private static int[] byteToIntArray(byte[] content, int offset) {
|
||||
|
||||
int[] result = new int[content.length >> 2]; //除以2的n次方 == 右移n位 即 content.length / 4 == content.length >> 2
|
||||
for (int i = 0, j = offset; j < content.length; i++, j += 4) {
|
||||
result[i] = byteToInt(content, j);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//int[]型数据转成byte[]型数据
|
||||
private static byte[] intArrayToByte(int[] content, int offset) {
|
||||
byte[] result = new byte[content.length << 2]; //乘以2的n次方 == 左移n位 即 content.length * 4 == content.length << 2
|
||||
for (int i = 0, j = offset; j < result.length; i++, j += 4) {
|
||||
intToByte(result, j, content[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//加密
|
||||
public static byte[] encrypt(byte[] content, int offset, int[] key, int times){//times为加密轮数
|
||||
int[] tempInt = byteToIntArray(content, offset);
|
||||
int delta=0x9e3779b9; //这是算法标准给的值
|
||||
int a = key[0], b = key[1], c = key[2], d = key[3];
|
||||
for(int m=0; m<tempInt.length; m+=2)
|
||||
for(int m=offset; m<content.length; m+=8)
|
||||
{
|
||||
int y = tempInt[m], z = tempInt[m+1], sum = 0, i;
|
||||
int y = byteToInt(content, m), z = byteToInt(content, m+4), sum = 0, i;
|
||||
for (i = 0; i < times; i++) {
|
||||
sum += delta;
|
||||
y += ((z<<4) + a) ^ (z + sum) ^ ((z>>5) + b);
|
||||
z += ((y<<4) + c) ^ (y + sum) ^ ((y>>5) + d);
|
||||
}
|
||||
tempInt[m]=y;
|
||||
tempInt[m+1]=z;
|
||||
intToByte(content, m, y);
|
||||
intToByte(content, m+4, z);
|
||||
}
|
||||
return intArrayToByte(tempInt, 0);
|
||||
return content;
|
||||
}
|
||||
//解密
|
||||
public static byte[] decrypt(byte[] encryptContent, int offset, int[] key, int times){
|
||||
int[] tempInt = byteToIntArray(encryptContent, offset);
|
||||
int delta = 0x9e3779b9; //这是算法标准给的值
|
||||
int a = key[0], b = key[1], c = key[2], d = key[3];
|
||||
|
||||
for(int m=0; m<tempInt.length; m+=2) {
|
||||
int y = tempInt[m], z = tempInt[m+1], sum = 0xC6EF3720, i;
|
||||
for(int m=offset; m<encryptContent.length; m+=8) {
|
||||
int y = byteToInt(encryptContent, m), z = byteToInt(encryptContent, m+4), sum = 0xC6EF3720, i;
|
||||
for (i = 0; i < times; i++) {
|
||||
z -= ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
|
||||
y -= ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
|
||||
sum -= delta;
|
||||
}
|
||||
tempInt[m] = y;
|
||||
tempInt[m+1] = z;
|
||||
}
|
||||
|
||||
return intArrayToByte(tempInt, 0);
|
||||
intToByte(encryptContent, m, y);
|
||||
intToByte(encryptContent, m+4, z);
|
||||
}
|
||||
return encryptContent;
|
||||
}
|
||||
|
||||
public static void shortToByte(byte[] bys, int offset, int content) {
|
||||
|
@ -115,16 +93,13 @@ public class Tea {
|
|||
}
|
||||
|
||||
public static byte[] encrypt2(byte[] content, int[] key) {
|
||||
byte[] bys = content;
|
||||
if (bys.length % 8 != 0) {
|
||||
bys = new byte[(bys.length + 7) / 8 * 8];
|
||||
System.arraycopy(content, 0, bys, 0, content.length);
|
||||
}
|
||||
byte[] encryptContent = encrypt(bys, 0, key, TIMES);
|
||||
byte[] result = new byte[encryptContent.length + 2];
|
||||
shortToByte(result, 0, content.length);
|
||||
System.arraycopy(encryptContent, 0, result, 2, encryptContent.length);
|
||||
return result;
|
||||
int tobalLen = (content.length+7)/8*8 + 2;
|
||||
byte[] bys = new byte[tobalLen];
|
||||
System.arraycopy(content, 0, bys, 2, content.length);
|
||||
|
||||
byte[] encryptContent = encrypt(bys, 2, key, TIMES);
|
||||
shortToByte(encryptContent, 0, content.length);
|
||||
return encryptContent;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -129,9 +129,10 @@ public class GlobalDataManaager {
|
|||
|
||||
public void openAction(List<Integer> ids){
|
||||
for(Integer openId : ids){
|
||||
FunctionIdEnum type = FunctionIdEnum.getFunctionIdEnumById(openId);
|
||||
TimeControllerOfFunction timeControllerOfFunction = openTimeOfFuntionCache.get(openId);
|
||||
switch (openId){
|
||||
case 8:
|
||||
switch (type){
|
||||
case Arena:
|
||||
ArenaLogic.getInstance().updateArenaSeason(timeControllerOfFunction.getTimes());
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -139,28 +139,12 @@ public class ArenaLogic {
|
|||
}
|
||||
int uid = session.getUid();
|
||||
User user = UserManager.getUser(uid);
|
||||
if(skipFight == 0){
|
||||
boolean allowed = user.getPlayerInfoManager().checkFunctionIsAllowed(VipPrivilegeType.UNLOCK_SKIP_FIGHT);
|
||||
if(!allowed){
|
||||
MessageUtil.sendErrorResponse(session,0, MessageTypeProto.MessageType.ARENA_CHALLENGE_RESPONSE_VALUE,"not allowed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String err = checkChallenge(user);
|
||||
if(!"".equals(err)){
|
||||
MessageUtil.sendErrorResponse(session,0, MessageTypeProto.MessageType.ARENA_CHALLENGE_RESPONSE_VALUE,err);
|
||||
return;
|
||||
}
|
||||
ArenaManager arenaManager = user.getArenaManager();
|
||||
List<ArenaEnemy> arenaEnemies = arenaManager.getArenaEnemies();
|
||||
ArenaEnemy enemyInfo = getEnemyInList(challengeUid, arenaEnemies);
|
||||
if( null == enemyInfo ){
|
||||
MessageUtil.sendErrorResponse(session,0, MessageTypeProto.MessageType.ARENA_CHALLENGE_RESPONSE_VALUE,"对手错误");
|
||||
return;
|
||||
}
|
||||
if(!user.getTeamPosManager().getTeamPosForHero().containsKey(GlobalsDef.TEAM_ARENA_DEFENSE)){
|
||||
MessageUtil.sendErrorResponse(session,0, MessageTypeProto.MessageType.ARENA_CHALLENGE_RESPONSE_VALUE,"未设置防守阵容");
|
||||
String err = checkChallenge(user,skipFight,enemyInfo );
|
||||
if(!"".equals(err)){
|
||||
MessageUtil.sendErrorResponse(session,0, MessageTypeProto.MessageType.ARENA_CHALLENGE_RESPONSE_VALUE,err);
|
||||
return;
|
||||
}
|
||||
int fightResult=0;
|
||||
|
@ -279,7 +263,19 @@ public class ArenaLogic {
|
|||
return checkResult[0];
|
||||
}
|
||||
|
||||
private String checkChallenge(User user) throws Exception {
|
||||
private String checkChallenge(User user,int skipFight, ArenaEnemy enemyInfo) throws Exception {
|
||||
if( null == enemyInfo ){
|
||||
return "对手错误";
|
||||
}
|
||||
if(skipFight == 0){
|
||||
boolean allowed = user.getPlayerInfoManager().checkFunctionIsAllowed(VipPrivilegeType.UNLOCK_SKIP_FIGHT);
|
||||
if(!allowed){
|
||||
return "not allowed";
|
||||
}
|
||||
}
|
||||
if(!user.getTeamPosManager().getTeamPosForHero().containsKey(GlobalsDef.TEAM_ARENA_DEFENSE)){
|
||||
return "未设置防守阵容";
|
||||
}
|
||||
ArenaManager arenaManager = user.getArenaManager();
|
||||
SArenaSetting sArenaSetting = SArenaSetting.getSArenaSetting();
|
||||
int useFreeTimes = arenaManager.getUseFreeTimes();
|
||||
|
|
Loading…
Reference in New Issue