天眼封禁

master
mengchengzhen 2021-05-27 14:30:56 +08:00
parent 096d4a4d0c
commit 859f346083
4 changed files with 144 additions and 1 deletions

View File

@ -23,9 +23,12 @@ import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@Controller
public class GameTitleController {
@ -170,4 +173,59 @@ public class GameTitleController {
return handler.execute(jsonObject,session);
}
/**
*
*/
@RequestMapping(value = "/skyEye",method = {RequestMethod.GET,RequestMethod.POST})
public @ResponseBody
String skyEye(HttpServletRequest request,HttpSession session){
Map<String,String> map = new HashMap<>();
map.put("code","1");
map.put("message","");
if(verify(request)){
return JSON.toJSONString(map);
}
try {
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap(request);
String jsonString = JSON.toJSONString(parameterMap);
JSONObject jsonObject = JSON.parseObject(jsonString);
BaseHandler handler = ManagerManager.getInstance().getBaseHandler("gm");
if(handler.skyEyeExecute(jsonObject,session,map)){
map.put("code","0");
}
} catch (Exception e) {
e.printStackTrace();
}finally {
return JSON.toJSONString(map);
}
}
private boolean verify(HttpServletRequest request)
{
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap(request);
String playerId = parameterMap.get("playerId");
String sign = parameterMap.get("sign");
String userId = parameterMap.get("userId");
String zoneId = parameterMap.get("zoneId");
String serverId = parameterMap.get("serverId");
String time = parameterMap.get("time");
try {
String secretKey = "3dcbb03682d80fea5ee3ead074aebba7";
byte[] bytes = (secretKey + playerId + userId + zoneId + serverId + time).getBytes("UTF-8"); // 输出其utf-8的bytes
java.security.MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(bytes);
byte[] md5sum = digest.digest();
BigInteger bigInt = new BigInteger(1, md5sum);
return String.format("%032X", bigInt).equalsIgnoreCase(sign); // MD5前面会补零
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e)
{
return false;
}
}
}

View File

@ -3,6 +3,7 @@ package com.jmfy.handler;
import com.alibaba.fastjson.JSONObject;
import javax.servlet.http.HttpSession;
import java.util.Map;
public abstract class BaseHandler {
private int pid;
@ -16,6 +17,8 @@ public abstract class BaseHandler {
public abstract int execute(JSONObject json,HttpSession session) throws Exception ;
public abstract boolean skyEyeExecute(JSONObject json, HttpSession session, Map<String,String> map) throws Exception;
public int getPid() {
return pid;
}

View File

@ -23,6 +23,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Component
public class GMHandler extends BaseHandler {
@ -63,6 +64,14 @@ public class GMHandler extends BaseHandler {
*
*/
public static final int UPDATE_USERNAME = 6;
/**
*
*/
public static final int SKYEYE_BAN = 7;
/**
*
*/
public static final int CANCEL_SKYEYE_BAN = 8;
@Override
public int execute(JSONObject jsonObject,HttpSession session) throws Exception {
@ -115,6 +124,65 @@ public class GMHandler extends BaseHandler {
}
@Override
public boolean skyEyeExecute(JSONObject json, HttpSession session, Map<String,String> map) throws Exception {
String nickname = json.getString("nickname");
String playerId = json.getString("playerId");
String userId = json.getString("userId");
String zoneId = json.getString("zoneId");
String serverId = json.getString("serverId");
String content = json.getString("content");
String time = json.getString("time");
String sign = json.getString("sign");
JSONObject jsonBan = new JSONObject();
jsonBan.put("uid",userId);
jsonBan.put("banTime",time);
jsonBan.put("dsid",zoneId);
jsonBan.put("treat_type","7");
jsonBan.put("banReason",content);
CUserInfo coreUserInfo = userInfoDao.findUserInfoByUserId(Integer.valueOf(userId));
if (coreUserInfo == null) {
map.put("message","帐号不存在"+userId);
throw new Exception("帐号不存在");
} else {
ServerInfo coreServerList = serverListDao.getServerinfo(String.valueOf(coreUserInfo.getServerid()));
if (null == coreServerList) {
map.put("message","服务器不存在");
return false;
}
if (!coreServerList.getServer_id().equals(String.valueOf(zoneId))) {
map.put("message","服务器不存在"+zoneId);
return false;
}
// 获取拼接参数
String cmd = getCmd(jsonBan, coreUserInfo, 7);
String rpcString = RedisUtil.getInstence().getObject(RedisUserKey.LOGIC_SERVER_INFO, String.valueOf(coreServerList.getServer_id()), String.class, -1);
if (null == rpcString) {
map.put("message","Exception send err rpcString dsid="+coreUserInfo.getServerid()+",uid="+userId);
LOGGER.error("Exception send err rpcString dsid=>{},uid=>{},cmd=>{}", coreUserInfo.getServerid(), userId, cmd);
return false;
}
String thriftIp = rpcString.split(":")[0];
String thriftPort = rpcString.split(":")[1];
if (thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()) {
map.put("message","thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()");
return false;
}
Result result = RPCClient.gmSend(cmd, thriftIp, thriftPort);
// 异常或者错误
if (result.getResultCode() != 0) {
LOGGER.error("Exception send err dsid=>{},uid=>{},cmd=>{}", coreUserInfo.getServerid(), userId, cmd);
}else {
// 封禁入库
updateUserBanner(coreUserInfo,session,jsonBan);
}
}
return true;
}
/**
* cmd
* @param jsonObject
@ -141,6 +209,12 @@ public class GMHandler extends BaseHandler {
case CANCEL_BANNED_LOGIN:
cmd = "reblack " + coreUserInfo.getUserId();
break;
case SKYEYE_BAN:
cmd = "skyeye " + coreUserInfo.getUserId() + " " +jsonObject.getString("banTime");
break;
case CANCEL_SKYEYE_BAN:
cmd = "skyeyec " + coreUserInfo.getUserId();
break;
case UPDATE_USERNAME:
if (!jsonObject.containsKey("actor_id")) {
throw new Exception("缺少参数");
@ -168,6 +242,7 @@ public class GMHandler extends BaseHandler {
private void updateUserBanner(CUserInfo cUser,HttpSession session,JSONObject jsonObject) throws Exception {
int type = jsonObject.getIntValue("treat_type");
switch (type) {
case GMHandler.SKYEYE_BAN:
case GMHandler.BANNED_TO_POST:
case GMHandler.BANNED_LOGIN:
// 封禁用户
@ -180,6 +255,7 @@ public class GMHandler extends BaseHandler {
throw new Exception("该用户已经处于封禁状态,请删除后重新操作");
}
break;
case GMHandler.CANCEL_SKYEYE_BAN:
case GMHandler.CANCEL_BANNED_TO_POST:
case GMHandler.CANCEL_BANNED_LOGIN:
// 封禁用户
@ -257,6 +333,9 @@ public class GMHandler extends BaseHandler {
case GMHandler.BANNED_LOGIN:
resultType = GMHandler.CANCEL_BANNED_LOGIN;
break;
case GMHandler.SKYEYE_BAN:
resultType = GMHandler.CANCEL_SKYEYE_BAN;
break;
default:break;
}
return resultType;

View File

@ -83,6 +83,9 @@ public class UserBanned {
case GMHandler.BANNED_LOGIN:
string = "禁登录";
break;
case GMHandler.SKYEYE_BAN:
string = "天眼禁言";
break;
default:break;
}
return string;