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);
|
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为加密轮数
|
public static byte[] encrypt(byte[] content, int offset, int[] key, int times){//times为加密轮数
|
||||||
int[] tempInt = byteToIntArray(content, offset);
|
|
||||||
int delta=0x9e3779b9; //这是算法标准给的值
|
int delta=0x9e3779b9; //这是算法标准给的值
|
||||||
int a = key[0], b = key[1], c = key[2], d = key[3];
|
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++) {
|
for (i = 0; i < times; i++) {
|
||||||
sum += delta;
|
sum += delta;
|
||||||
y += ((z<<4) + a) ^ (z + sum) ^ ((z>>5) + b);
|
y += ((z<<4) + a) ^ (z + sum) ^ ((z>>5) + b);
|
||||||
z += ((y<<4) + c) ^ (y + sum) ^ ((y>>5) + d);
|
z += ((y<<4) + c) ^ (y + sum) ^ ((y>>5) + d);
|
||||||
}
|
}
|
||||||
tempInt[m]=y;
|
intToByte(content, m, y);
|
||||||
tempInt[m+1]=z;
|
intToByte(content, m+4, z);
|
||||||
}
|
}
|
||||||
return intArrayToByte(tempInt, 0);
|
return content;
|
||||||
}
|
}
|
||||||
//解密
|
//解密
|
||||||
public static byte[] decrypt(byte[] encryptContent, int offset, int[] key, int times){
|
public static byte[] decrypt(byte[] encryptContent, int offset, int[] key, int times){
|
||||||
int[] tempInt = byteToIntArray(encryptContent, offset);
|
|
||||||
int delta = 0x9e3779b9; //这是算法标准给的值
|
int delta = 0x9e3779b9; //这是算法标准给的值
|
||||||
int a = key[0], b = key[1], c = key[2], d = key[3];
|
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<encryptContent.length; m+=8) {
|
||||||
int y = tempInt[m], z = tempInt[m+1], sum = 0xC6EF3720, i;
|
int y = byteToInt(encryptContent, m), z = byteToInt(encryptContent, m+4), sum = 0xC6EF3720, i;
|
||||||
for (i = 0; i < times; i++) {
|
for (i = 0; i < times; i++) {
|
||||||
z -= ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
|
z -= ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
|
||||||
y -= ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
|
y -= ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
|
||||||
sum -= delta;
|
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) {
|
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) {
|
public static byte[] encrypt2(byte[] content, int[] key) {
|
||||||
byte[] bys = content;
|
int tobalLen = (content.length+7)/8*8 + 2;
|
||||||
if (bys.length % 8 != 0) {
|
byte[] bys = new byte[tobalLen];
|
||||||
bys = new byte[(bys.length + 7) / 8 * 8];
|
System.arraycopy(content, 0, bys, 2, content.length);
|
||||||
System.arraycopy(content, 0, bys, 0, content.length);
|
|
||||||
}
|
byte[] encryptContent = encrypt(bys, 2, key, TIMES);
|
||||||
byte[] encryptContent = encrypt(bys, 0, key, TIMES);
|
shortToByte(encryptContent, 0, content.length);
|
||||||
byte[] result = new byte[encryptContent.length + 2];
|
return encryptContent;
|
||||||
shortToByte(result, 0, content.length);
|
|
||||||
System.arraycopy(encryptContent, 0, result, 2, encryptContent.length);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -129,9 +129,10 @@ public class GlobalDataManaager {
|
||||||
|
|
||||||
public void openAction(List<Integer> ids){
|
public void openAction(List<Integer> ids){
|
||||||
for(Integer openId : ids){
|
for(Integer openId : ids){
|
||||||
|
FunctionIdEnum type = FunctionIdEnum.getFunctionIdEnumById(openId);
|
||||||
TimeControllerOfFunction timeControllerOfFunction = openTimeOfFuntionCache.get(openId);
|
TimeControllerOfFunction timeControllerOfFunction = openTimeOfFuntionCache.get(openId);
|
||||||
switch (openId){
|
switch (type){
|
||||||
case 8:
|
case Arena:
|
||||||
ArenaLogic.getInstance().updateArenaSeason(timeControllerOfFunction.getTimes());
|
ArenaLogic.getInstance().updateArenaSeason(timeControllerOfFunction.getTimes());
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -139,28 +139,12 @@ public class ArenaLogic {
|
||||||
}
|
}
|
||||||
int uid = session.getUid();
|
int uid = session.getUid();
|
||||||
User user = UserManager.getUser(uid);
|
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();
|
ArenaManager arenaManager = user.getArenaManager();
|
||||||
List<ArenaEnemy> arenaEnemies = arenaManager.getArenaEnemies();
|
List<ArenaEnemy> arenaEnemies = arenaManager.getArenaEnemies();
|
||||||
ArenaEnemy enemyInfo = getEnemyInList(challengeUid, arenaEnemies);
|
ArenaEnemy enemyInfo = getEnemyInList(challengeUid, arenaEnemies);
|
||||||
if( null == enemyInfo ){
|
String err = checkChallenge(user,skipFight,enemyInfo );
|
||||||
MessageUtil.sendErrorResponse(session,0, MessageTypeProto.MessageType.ARENA_CHALLENGE_RESPONSE_VALUE,"对手错误");
|
if(!"".equals(err)){
|
||||||
return;
|
MessageUtil.sendErrorResponse(session,0, MessageTypeProto.MessageType.ARENA_CHALLENGE_RESPONSE_VALUE,err);
|
||||||
}
|
|
||||||
if(!user.getTeamPosManager().getTeamPosForHero().containsKey(GlobalsDef.TEAM_ARENA_DEFENSE)){
|
|
||||||
MessageUtil.sendErrorResponse(session,0, MessageTypeProto.MessageType.ARENA_CHALLENGE_RESPONSE_VALUE,"未设置防守阵容");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int fightResult=0;
|
int fightResult=0;
|
||||||
|
@ -279,7 +263,19 @@ public class ArenaLogic {
|
||||||
return checkResult[0];
|
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();
|
ArenaManager arenaManager = user.getArenaManager();
|
||||||
SArenaSetting sArenaSetting = SArenaSetting.getSArenaSetting();
|
SArenaSetting sArenaSetting = SArenaSetting.getSArenaSetting();
|
||||||
int useFreeTimes = arenaManager.getUseFreeTimes();
|
int useFreeTimes = arenaManager.getUseFreeTimes();
|
||||||
|
|
Loading…
Reference in New Issue