master
duhui 2020-12-18 11:32:06 +08:00
parent 8d48663a8c
commit d35d4a4905
2 changed files with 136 additions and 1 deletions

View File

@ -28,11 +28,13 @@ public class WebSecurityConfig extends WebMvcConfigurerAdapter{
return new SecurityInterceptor();
}
public void addInterceptors(InterceptorRegistry registry){
@Override
public void addInterceptors(InterceptorRegistry registry){
InterceptorRegistration addInterceptor = registry.addInterceptor(getSecurityInterceptor());
addInterceptor.excludePathPatterns("/error");
addInterceptor.excludePathPatterns("/login**");
addInterceptor.excludePathPatterns("/req/**");
addInterceptor.addPathPatterns("/**");
}

View File

@ -0,0 +1,133 @@
package com.jmfy.controller;
import com.jmfy.dao.UserInfoDao;
import com.jmfy.model.CUserInfo;
import com.jmfy.redisProperties.RedisUserKey;
import com.jmfy.thrift.idl.Result;
import com.jmfy.utils.RPCClient;
import com.jmfy.utils.RedisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author hj
*/
@RestController
@RequestMapping(value = "req")
public class HttpRequestController {
private static final Logger LOGGER = LoggerFactory.getLogger(UserInfoController.class);
@Resource
private UserInfoDao userInfoDao;
/**
*
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = "/getFightRecord", method = {RequestMethod.POST, RequestMethod.GET})
public String getFightRecord (HttpServletRequest request, HttpServletResponse response) throws Exception {
// 玩家id和战斗id玩家id_服务器id_战斗类型_时间戳
String uid = request.getParameter("uid");
String fightid = request.getParameter("fightid");
// 拼接参数
String cmd = "fightrecord " + fightid;
// 读库找到玩家信息
CUserInfo cUserInfo = userInfoDao.findUserInfoById(uid);
// 获取玩家服务器ip和端口
String rpcString = RedisUtil.getInstence().getObject(RedisUserKey.LOGIC_SERVER_INFO, String.valueOf(cUserInfo.getServerid()), String.class, -1);
if (null == rpcString) {
return null;
}
// ip
String thriftIp = rpcString.split(":")[0];
// 端口
String thriftPort = rpcString.split(":")[1];
if (thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()) {
return null;
}
// 通信游戏服
Result result = RPCClient.gmSend(cmd, thriftIp, thriftPort);
if (result.getResultCode() != 0) {
LOGGER.error("->userid:{},fightId:{}",uid,fightid);
return null;
}
// 返回
return result.getResultMsg() == null ? "":result.getResultMsg();
}
/**
*
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = "/clearFightRecord", method = {RequestMethod.POST, RequestMethod.GET})
public String clearFightRecord (HttpServletRequest request, HttpServletResponse response) throws Exception {
String uid = request.getParameter("uid");
String cmd = "fightrecord delete";
CUserInfo cUserInfo = userInfoDao.findUserInfoById(uid);
String rpcString = RedisUtil.getInstence().getObject(RedisUserKey.LOGIC_SERVER_INFO, String.valueOf(cUserInfo.getServerid()), String.class, -1);
if (null == rpcString) {
return "no";
}
String thriftIp = rpcString.split(":")[0];
String thriftPort = rpcString.split(":")[1];
if (thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()) {
return "no";
}
Result result = RPCClient.gmSend(cmd, thriftIp, thriftPort);
if (result.getResultCode() != 0) {
return "no";
}
return "ok";
}
/**
*
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = "/getAllFightRecord", method = {RequestMethod.POST, RequestMethod.GET})
public String getAllFightRecord (HttpServletRequest request, HttpServletResponse response) throws Exception {
String uid = request.getParameter("uid");
String cmd = "fightrecord all " + uid;
CUserInfo cUserInfo = userInfoDao.findUserInfoById(uid);
String rpcString = RedisUtil.getInstence().getObject(RedisUserKey.LOGIC_SERVER_INFO, String.valueOf(cUserInfo.getServerid()), String.class, -1);
if (null == rpcString) {
return "no";
}
String thriftIp = rpcString.split(":")[0];
String thriftPort = rpcString.split(":")[1];
if (thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()) {
return "no";
}
Result result = RPCClient.gmSend(cmd, thriftIp, thriftPort);
if (result.getResultCode() != 0) {
return "no";
}
return "ok";
}
}