天眼公会

master
duhui 2021-10-27 15:54:02 +08:00
parent 26afff8ba5
commit f094ab62f0
2 changed files with 176 additions and 133 deletions

View File

@ -11,7 +11,9 @@ import com.jmfy.model.CUserInfo;
import com.jmfy.model.ServerInfo;
import com.jmfy.model.UserBanned;
import com.jmfy.redisProperties.RedisUserKey;
import com.jmfy.utils.*;
import com.jmfy.utils.JsonUtil;
import com.jmfy.utils.RPCClient;
import com.jmfy.utils.RedisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
@ -179,16 +181,15 @@ public class GameTitleController {
/**
*
*/
@SuppressWarnings("Duplicates")
@RequestMapping(value = "/skyEye",method = {RequestMethod.GET,RequestMethod.POST})
public @ResponseBody
String skyEye(HttpServletRequest request,HttpSession session){
String skyEye(HttpServletRequest request,HttpSession session) throws Exception {
Map<String,String> map = new HashMap<>();
map.put("code","1");
if(!verify(request,map,privateKey)){
map.put("message","verify");
return JSON.toJSONString(map);
}
try {
}else {
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap(request);
String jsonString = JSON.toJSONString(parameterMap);
LOGGER.info("天眼封禁json=>{}",jsonString);
@ -198,13 +199,18 @@ public class GameTitleController {
map.put("code","0");
map.put("message","success");
}
} catch (Exception e) {
e.printStackTrace();
}finally {
return JSON.toJSONString(map);
}
LOGGER.info("回传天眼参数:{}",map.toString());
return JSON.toJSONString(map);
}
/**
* sign
* @param request
* @param map
* @param secretKey
* @return
*/
private boolean verify(HttpServletRequest request,Map<String,String> map,String secretKey)
{
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap(request);
@ -216,7 +222,8 @@ public class GameTitleController {
String time = parameterMap.get("time");
try {
byte[] bytes = (secretKey + playerId + userId + zoneId + serverId + time).getBytes("UTF-8"); // 输出其utf-8的bytes
// 输出其utf-8的bytes
byte[] bytes = (secretKey + playerId + userId + zoneId + serverId + time).getBytes("UTF-8");
java.security.MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(bytes);
@ -226,10 +233,10 @@ public class GameTitleController {
String newsign = String.format("%032X", bigInt).toLowerCase();
map.put("message","sign:"+sign+" newSign:"+newsign);
LOGGER.info("天眼message,sign=>{},new sign=>{}",sign,newsign);
return newsign.equalsIgnoreCase(sign); // MD5前面会补零
// MD5前面会补零
return newsign.equalsIgnoreCase(sign);
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e)
{
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
e.printStackTrace();
return false;
}

View File

@ -21,9 +21,9 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@Component
public class GMHandler extends BaseHandler {
@ -73,122 +73,136 @@ public class GMHandler extends BaseHandler {
*/
public static final int CANCEL_SKYEYE_BAN = 8;
/**
*
*/
public static final int RESET_GUILD_NAME = 9;
/**
*
*/
public static final int RESET_GUILD_ANNOUNCEMENT = 10;
@Override
public int execute(JSONObject jsonObject,HttpSession session) throws Exception {
LOGGER.info("gm封禁传参:{}",jsonObject.toJSONString());
String openIds = jsonObject.getString("uid");
int dsid = jsonObject.getIntValue("dsid");
int treat_type = jsonObject.getIntValue("treat_type");
boolean allServer = dsid == 0;
// 根据openId查询玩家注册的全部账号
List<CUserInfo> coreUserInfoList = userInfoDao.findUserInfo(openIds);
if (coreUserInfoList == null) {
if (coreUserInfoList == null || coreUserInfoList.isEmpty()) {
throw new Exception("帐号不存在");
} else {
if (coreUserInfoList.size() == 0)
throw new Exception("帐号不存在");
for (CUserInfo coreUserInfo : coreUserInfoList) {
ServerInfo coreServerList = serverListDao.getServerinfo(String.valueOf(coreUserInfo.getServerid()));
if (null == coreServerList) {
continue;
}
if (!allServer && !coreServerList.getServer_id().equals(String.valueOf(dsid))) {
continue;
}
// 获取拼接参数
String cmd = getCmd(jsonObject, coreUserInfo, treat_type);
String rpcString = RedisUtil.getInstence().getObject(RedisUserKey.LOGIC_SERVER_INFO, String.valueOf(coreServerList.getServer_id()), String.class, -1);
if (null == rpcString) {
LOGGER.error("Exception send err rpcString dsid=>{},uid=>{},cmd=>{}", coreUserInfo.getServerid(), openIds, cmd);
continue;
}
String thriftIp = rpcString.split(":")[0];
String thriftPort = rpcString.split(":")[1];
if (thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()) {
continue;
}
Result result = RPCClient.gmSend(cmd, thriftIp, thriftPort);
// 异常或者错误
if (result.getResultCode() != 0) {
LOGGER.error("Exception send err dsid=>{},uid=>{},cmd=>{}", coreUserInfo.getServerid(), openIds, cmd);
}else {
// 封禁入库
updateUserBanner(coreUserInfo,session,jsonObject);
}
}
}
// 遍历全部账号,执行封禁操作
for (CUserInfo coreUserInfo : coreUserInfoList) {
oneUserBanner(coreUserInfo, jsonObject.getIntValue("dsid"), jsonObject, jsonObject.getIntValue("treat_type"), session);
}
return 1;
}
@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");
// 暂时不用
// String nickname = json.getString("nickname");
// String playerId = json.getString("playerId");
// String serverId = json.getString("serverId");
// String sign = json.getString("sign");
// json参数获取
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);
LOGGER.info("message","ty,userId:{},zoneId:{},content:{},time:{}",userId,zoneId,content,time);
CUserInfo coreUserInfo = userInfoDao.findUserInfoByUserId(Integer.valueOf(userId));
jsonBan.put("uid",json.getString("userId"));
jsonBan.put("banTime",json.getString("time"));
jsonBan.put("dsid",json.getString("zoneId"));
int skyEyeType = getSkyEyeType(Integer.parseInt(json.getString("channel")));
jsonBan.put("treat_type",skyEyeType);
jsonBan.put("banReason",json.getString("time"));
jsonBan.put("channel",json.getString("channel"));
jsonBan.put("extra",json.getString("extra"));
// 日志
LOGGER.info("天眼封禁,传参:{}",jsonBan.toJSONString());
CUserInfo coreUserInfo = userInfoDao.findUserInfoByUserId(jsonBan.getIntValue("uid"));
if (coreUserInfo == null) {
map.put("message","帐号不存在"+userId);
LOGGER.error("message","天眼帐号不存在userId:{}",userId);
throw new Exception("帐号不存在");
} else {
ServerInfo coreServerList = serverListDao.getServerinfo(String.valueOf(coreUserInfo.getServerid()));
if (null == coreServerList) {
map.put("message","服务器不存在");
LOGGER.error("天眼服务器不存在");
return false;
}
if (!coreServerList.getServer_id().equals(String.valueOf(zoneId))) {
map.put("message","服务器不存在"+zoneId);
LOGGER.error("天眼服务器不存在{}",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()");
LOGGER.error("天眼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 {
// 封禁入库
LOGGER.info("天眼封禁入库,serverid=>{},uid=>{}", zoneId, userId);
updateUserBanner(coreUserInfo,session,jsonBan);
}
map.put("message","帐号不存在"+jsonBan.getIntValue("uid"));
return false;
}
boolean userBanner = oneUserBanner(coreUserInfo, jsonBan.getIntValue("dsid"), jsonBan, skyEyeType, session);
if (!userBanner){
map.put("message","操作异常,请查看日志"+jsonBan.getIntValue("uid"));
}
return userBanner;
}
/**
*
* @param coreUserInfo
* @param serverId
* @param json
* @param type
* @param session
* @return
* @throws Exception
*/
private boolean oneUserBanner(CUserInfo coreUserInfo, int serverId, JSONObject json, int type, HttpSession session) throws Exception {
ServerInfo coreServerList = serverListDao.getServerinfo(String.valueOf(coreUserInfo.getServerid()));
if (null == coreServerList) {
LOGGER.error("服务器列表为空,serverId:{}", coreUserInfo.getServerid());
return false;
}
if (!coreServerList.getServer_id().equals(String.valueOf(serverId))) {
LOGGER.error("db库里面的服务器id与传参不一致, dbServerId:{},valueServerId:{}", coreServerList.getServer_id(),serverId);
return false;
}
// 获取拼接参数
String cmd = getCmd(json, coreUserInfo, type);
if ("".equals(cmd) || cmd == null){
LOGGER.error("参数拼接失败json:{},uid:{},type:{}", json.toJSONString(),coreUserInfo.getUserId(),type);
return false;
}
String rpcString = RedisUtil.getInstence().getObject(RedisUserKey.LOGIC_SERVER_INFO, String.valueOf(coreServerList.getServer_id()), String.class, -1);
if (null == rpcString) {
LOGGER.error("获取rpc参数报错serverId:{}", coreUserInfo.getServerid());
return false;
}
String thriftIp = rpcString.split(":")[0];
String thriftPort = rpcString.split(":")[1];
if (thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()) {
LOGGER.error("rpc参数存在空值thriftIp{}thriftPort{}", thriftIp,thriftPort);
return false;
}
Result result = RPCClient.gmSend(cmd, thriftIp, thriftPort);
// 异常或者错误
if (result.getResultCode() != 0) {
LOGGER.error("rpc返回值错误code{}msg{}", result.getResultCode(),result.getResultMsg());
return false;
}
// 封禁入库
updateUserBanner(coreUserInfo,session,json);
return true;
}
/**
*
* @param channel
* @return
*/
private int getSkyEyeType(int channel){
int result = 0;
switch (channel){
case 1:
case 2:
case 3:
case 4:
result = 7;
break;
case 9:
case 10:
result = channel;
break;
default:
break;
}
return result;
}
/**
* cmd
* @param jsonObject
@ -197,47 +211,69 @@ public class GMHandler extends BaseHandler {
* @return
* @throws Exception
*/
private String getCmd(JSONObject jsonObject,CUserInfo coreUserInfo,int type) throws Exception{
private String getCmd(JSONObject jsonObject,CUserInfo coreUserInfo,int type){
String cmd = "";
switch (type) {
case BANNED_TO_POST:
cmd = "silence " + coreUserInfo.getUserId() + " 1";
cmd = getCmdContent("silence",coreUserInfo.getUserId(),1);
break;
case CANCEL_BANNED_TO_POST:
cmd = "silence " + coreUserInfo.getUserId() + " 0";
cmd = getCmdContent("silence",coreUserInfo.getUserId(),0);
break;
case KILL_USER:
cmd = "kickuser " + coreUserInfo.getUserId();
cmd = getCmdContent("kickuser",coreUserInfo.getUserId());
break;
case BANNED_LOGIN:
cmd = "addblack " + coreUserInfo.getUserId();
cmd = getCmdContent("addblack",coreUserInfo.getUserId());
break;
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();
cmd = getCmdContent("reblack",coreUserInfo.getUserId());
break;
case UPDATE_USERNAME:
if (!jsonObject.containsKey("actor_id")) {
throw new Exception("缺少参数");
}
if (!jsonObject.containsKey("actor_name")) {
cmd = "changename " + coreUserInfo.getUserId();
} else {
String actor_name = jsonObject.getString("actor_name");
cmd = "changename " + coreUserInfo.getUserId() + " " + actor_name;
if (jsonObject.containsKey("actor_id")) {
if (jsonObject.containsKey("actor_name")) {
cmd = getCmdContent("changename",coreUserInfo.getUserId(),jsonObject.getString("actor_name"));
} else {
cmd = getCmdContent("changename",coreUserInfo.getUserId());
}
}
break;
case SKYEYE_BAN:
String banTime = Optional.ofNullable(jsonObject).map(v->v.getString("banTime")).orElse("0");
cmd = getCmdContent("skyeye",coreUserInfo.getUserId(),SKYEYE_BAN,banTime);
break;
case CANCEL_SKYEYE_BAN:
cmd = getCmdContent("skyeye",coreUserInfo.getUserId(),CANCEL_SKYEYE_BAN,0);
break;
case RESET_GUILD_NAME:
String banTime1 = jsonObject.getString("banTime");
Object guildId = JSONObject.parseObject(jsonObject.getString("extra")).getOrDefault("guildId","0");
cmd = getCmdContent("skyeye",coreUserInfo.getUserId(),RESET_GUILD_NAME,banTime1,guildId);
break;
case RESET_GUILD_ANNOUNCEMENT:
String banTime2 = jsonObject.getString("banTime");
Object guildId2 = JSONObject.parseObject(jsonObject.getString("extra")).getOrDefault("guildId","0");
cmd = getCmdContent("skyeye",coreUserInfo.getUserId(),RESET_GUILD_ANNOUNCEMENT,banTime2,guildId2);
break;
default:
break;
}
return cmd;
}
/**
* cmd
* @param value
* @return
*/
public static String getCmdContent(Object... value){
StringBuilder builder = new StringBuilder();
for (Object s : value) {
builder.append(s).append(" ");
}
return builder.toString();
}
/**
*
* @param cUser