2019-08-28 11:53:00 +08:00
|
|
|
|
package com.ljsd;
|
|
|
|
|
|
|
|
|
|
|
2019-09-19 18:57:47 +08:00
|
|
|
|
import com.google.gson.Gson;
|
2019-09-18 19:05:50 +08:00
|
|
|
|
import com.ljsd.jieling.core.HandlerLogicThread;
|
2019-09-18 16:45:04 +08:00
|
|
|
|
import com.ljsd.jieling.db.mongo.MongoUtil;
|
2019-09-18 18:30:38 +08:00
|
|
|
|
import com.ljsd.jieling.db.redis.RedisKey;
|
|
|
|
|
import com.ljsd.jieling.db.redis.RedisUtil;
|
2019-08-28 11:53:00 +08:00
|
|
|
|
import com.ljsd.jieling.kefu.GmGlobleAbstract;
|
|
|
|
|
import com.ljsd.jieling.kefu.GmInterface;
|
|
|
|
|
import com.ljsd.jieling.kefu.GmRoleAbstract;
|
|
|
|
|
import com.ljsd.jieling.logic.OnlineUserManager;
|
2019-09-28 17:31:19 +08:00
|
|
|
|
import com.ljsd.jieling.logic.dao.RechargeInfo;
|
2019-08-28 11:53:00 +08:00
|
|
|
|
import com.ljsd.jieling.logic.dao.UserManager;
|
|
|
|
|
import com.ljsd.jieling.logic.dao.root.User;
|
2019-09-18 18:30:38 +08:00
|
|
|
|
import com.ljsd.jieling.logic.hero.HeroLogic;
|
2019-09-18 19:05:50 +08:00
|
|
|
|
import com.ljsd.jieling.network.server.ProtocolsManager;
|
2019-08-28 11:53:00 +08:00
|
|
|
|
import com.ljsd.jieling.network.session.ISession;
|
2019-09-18 18:13:35 +08:00
|
|
|
|
import com.ljsd.jieling.protocols.MessageTypeProto;
|
2019-09-26 13:44:35 +08:00
|
|
|
|
import com.ljsd.jieling.thread.task.DataReportTask;
|
2019-08-28 11:53:00 +08:00
|
|
|
|
import com.ljsd.jieling.thrift.idl.InvalidOperException;
|
|
|
|
|
import com.ljsd.jieling.thrift.idl.RPCRequestGMIFace;
|
|
|
|
|
import com.ljsd.jieling.thrift.idl.Result;
|
2019-09-20 17:39:55 +08:00
|
|
|
|
import com.ljsd.jieling.util.*;
|
2019-08-28 11:53:00 +08:00
|
|
|
|
import org.apache.thrift.TException;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
2019-09-26 13:44:35 +08:00
|
|
|
|
import org.springframework.context.ConfigurableApplicationContext;
|
2019-09-20 17:39:55 +08:00
|
|
|
|
import org.springframework.data.redis.core.ZSetOperations;
|
2019-08-28 11:53:00 +08:00
|
|
|
|
|
2019-09-28 17:31:19 +08:00
|
|
|
|
import java.io.BufferedReader;
|
2019-08-28 11:53:00 +08:00
|
|
|
|
import java.io.File;
|
2019-09-28 17:31:19 +08:00
|
|
|
|
import java.io.FileReader;
|
2019-09-26 13:44:35 +08:00
|
|
|
|
import java.lang.reflect.Field;
|
2019-08-28 11:53:00 +08:00
|
|
|
|
import java.lang.reflect.Method;
|
2019-09-28 17:31:19 +08:00
|
|
|
|
import java.util.*;
|
2019-08-28 11:53:00 +08:00
|
|
|
|
|
|
|
|
|
public class GmService implements RPCRequestGMIFace.Iface {
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(GmService.class);
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Result idipGm(String reserved, String cmd) throws InvalidOperException, TException {
|
2019-08-28 19:46:46 +08:00
|
|
|
|
LOGGER.info("gm________________________"+cmd);
|
2019-08-28 11:53:00 +08:00
|
|
|
|
Result result = new Result();
|
|
|
|
|
result.setResultCode(-1);
|
|
|
|
|
String[] arg = cmd.split(" ");
|
|
|
|
|
GmInterface obj;
|
|
|
|
|
try {
|
2019-09-18 18:13:35 +08:00
|
|
|
|
|
2019-09-26 13:44:35 +08:00
|
|
|
|
if(cmd.contains("restartthread")){
|
|
|
|
|
Field configurableApplicationContextField = GameApplication.class.getDeclaredField("configurableApplicationContext");
|
|
|
|
|
configurableApplicationContextField.setAccessible(true);
|
|
|
|
|
ConfigurableApplicationContext configurableApplicationContext =(ConfigurableApplicationContext) configurableApplicationContextField.get(GameApplication.class);
|
|
|
|
|
DataReportTask bean = configurableApplicationContext.getBean(DataReportTask.class);
|
|
|
|
|
bean.start();
|
|
|
|
|
result.setResultCode(1);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-23 23:40:04 +08:00
|
|
|
|
if(cmd.contains("hotfix")){
|
|
|
|
|
List<User> usersInDB = MongoUtil.getLjsdMongoTemplate().findAll("user", User.class);
|
|
|
|
|
List<Integer> sendIds = new ArrayList<>(usersInDB.size());
|
|
|
|
|
for(User user1 : usersInDB){
|
|
|
|
|
User userInMem = UserManager.getUserInMem(user1.getId());
|
|
|
|
|
if(userInMem == null){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
sendIds.add(user1.getId());
|
|
|
|
|
}
|
2019-09-27 11:16:35 +08:00
|
|
|
|
InnerMessageUtil.broadcastWithRandom( user->{
|
2019-09-23 23:40:04 +08:00
|
|
|
|
LOGGER.info("hotfix user={}",user.getId());
|
|
|
|
|
MongoUtil.getLjsdMongoTemplate().save(user);
|
|
|
|
|
}
|
2019-09-27 11:16:35 +08:00
|
|
|
|
, sendIds, Math.min(10, 10));
|
2019-09-23 23:40:04 +08:00
|
|
|
|
result.setResultCode(1);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2019-08-28 11:53:00 +08:00
|
|
|
|
obj = (GmInterface) Class.forName(
|
|
|
|
|
GmInterface.class.getPackage().getName() + ".Cmd_"
|
|
|
|
|
+ arg[0].toLowerCase()).newInstance();
|
|
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
result.setResultMsg("Cmd Illegal");
|
2019-09-26 13:44:35 +08:00
|
|
|
|
ex.printStackTrace();
|
2019-08-28 11:53:00 +08:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
String[] parameters = java.util.Arrays.copyOfRange(arg, 1, arg.length);
|
2019-09-18 16:45:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-08-28 11:53:00 +08:00
|
|
|
|
if (obj instanceof GmRoleAbstract) {
|
2019-09-28 17:31:19 +08:00
|
|
|
|
//todo
|
2019-09-20 10:56:30 +08:00
|
|
|
|
Map<Integer, String> rechargeInfoMap = new HashMap<>();
|
2019-09-19 18:57:47 +08:00
|
|
|
|
if(cmd.contains("recharge")){
|
2019-09-20 10:05:01 +08:00
|
|
|
|
File file = new File("../conf/BuyGoodsLogic.log");
|
2019-09-20 10:35:03 +08:00
|
|
|
|
LOGGER.info("file path={}",file.getAbsolutePath());
|
2019-09-19 18:57:47 +08:00
|
|
|
|
BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
|
|
|
|
|
|
|
|
|
|
String readLine = null;
|
2019-09-20 10:56:30 +08:00
|
|
|
|
Gson gson = new Gson();
|
2019-09-19 18:57:47 +08:00
|
|
|
|
while ( (readLine= bufferedReader.readLine())!=null){
|
|
|
|
|
if(readLine.contains("class")){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
String[] split = readLine.split(",");
|
|
|
|
|
String uidStr = split[0].split("=")[1];
|
|
|
|
|
int uid = Integer.parseInt(uidStr);
|
2019-09-20 10:56:30 +08:00
|
|
|
|
String rechargeInfoStr = rechargeInfoMap.get(uid);
|
|
|
|
|
RechargeInfo rechargeInfo = new RechargeInfo();
|
|
|
|
|
if( rechargeInfoStr != null){
|
|
|
|
|
rechargeInfo = gson.fromJson(rechargeInfoStr,RechargeInfo.class);
|
2019-09-19 18:57:47 +08:00
|
|
|
|
}
|
|
|
|
|
String goodStr = split[1].split("=")[1];
|
|
|
|
|
int goodID = Integer.parseInt(goodStr);
|
|
|
|
|
if(goodID == 8 || goodID == 7){
|
|
|
|
|
rechargeInfo.setHadBuyFound(1);
|
|
|
|
|
}
|
2019-09-28 17:31:19 +08:00
|
|
|
|
Map<Integer, Integer> buyGoodsTimes = rechargeInfo.getBuyGoodsTimes();
|
|
|
|
|
Integer buyCount = buyGoodsTimes.get(goodID);
|
|
|
|
|
if(buyCount == null){
|
2019-09-19 21:16:27 +08:00
|
|
|
|
buyCount =0;
|
2019-09-28 17:31:19 +08:00
|
|
|
|
}
|
|
|
|
|
buyCount++;
|
|
|
|
|
buyGoodsTimes.put(goodID,buyCount);
|
2019-09-20 10:56:30 +08:00
|
|
|
|
rechargeInfoMap.put(uid,gson.toJson(rechargeInfo));
|
2019-09-28 17:31:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-08-28 11:53:00 +08:00
|
|
|
|
List<Integer> sendIds = new LinkedList<>();
|
|
|
|
|
if (obj instanceof GmGlobleAbstract) {
|
|
|
|
|
for (ISession session : OnlineUserManager.sessionMap.values()) {
|
|
|
|
|
sendIds.add(session.getUid());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2019-09-28 08:22:40 +08:00
|
|
|
|
if(cmd.contains("hotfix") || cmd.contains("shop")|| cmd.contains("endStore")){
|
2019-09-18 19:25:12 +08:00
|
|
|
|
List<User> usersInDB = MongoUtil.getLjsdMongoTemplate().findAll("user", User.class);
|
|
|
|
|
for(User user1 : usersInDB){
|
|
|
|
|
User userInMem = UserManager.getUserInMem(user1.getId());
|
|
|
|
|
if(userInMem == null){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
sendIds.add(user1.getId());
|
|
|
|
|
}
|
2019-09-19 18:57:47 +08:00
|
|
|
|
}else if(cmd.contains("recharge")){
|
|
|
|
|
sendIds.addAll(rechargeInfoMap.keySet());
|
2019-09-20 17:39:55 +08:00
|
|
|
|
}else if(cmd.contains("force")){
|
|
|
|
|
|
2019-09-20 18:24:34 +08:00
|
|
|
|
Set<ZSetOperations.TypedTuple<String>> rankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.FORCE_RANK, "", 0, -1);
|
2019-09-20 17:39:55 +08:00
|
|
|
|
for (ZSetOperations.TypedTuple<String> item : rankInfo) {
|
|
|
|
|
String value = item.getValue();
|
|
|
|
|
int uid = Integer.parseInt(value);
|
|
|
|
|
sendIds.add(uid);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 18:57:47 +08:00
|
|
|
|
} else{
|
2019-09-18 19:25:12 +08:00
|
|
|
|
String[] ids = parameters[0].split("#");
|
|
|
|
|
for (String id : ids) {
|
|
|
|
|
sendIds.add(Integer.valueOf(id));
|
|
|
|
|
}
|
2019-08-28 11:53:00 +08:00
|
|
|
|
}
|
2019-09-20 17:39:55 +08:00
|
|
|
|
|
2019-08-28 11:53:00 +08:00
|
|
|
|
}
|
|
|
|
|
int randomTime = sendIds.size() * 1;
|
|
|
|
|
//两分钟内发完所有协议
|
2019-09-19 18:57:47 +08:00
|
|
|
|
Gson gson = new Gson();
|
2019-08-28 11:53:00 +08:00
|
|
|
|
String[] parameters2 = java.util.Arrays.copyOfRange(parameters, 1, parameters.length);
|
2019-09-19 18:57:47 +08:00
|
|
|
|
if(cmd.contains("recharge") ){
|
2019-09-20 11:12:16 +08:00
|
|
|
|
LOGGER.info("recharge map size={}",rechargeInfoMap.size());
|
2019-09-19 18:57:47 +08:00
|
|
|
|
if(!rechargeInfoMap.isEmpty()){
|
|
|
|
|
parameters2[3] = gson.toJson(rechargeInfoMap);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-26 14:18:27 +08:00
|
|
|
|
InnerMessageUtil.broadcastWithRandom( user->{
|
2019-08-28 11:53:00 +08:00
|
|
|
|
((GmRoleAbstract) obj).setUser(user);
|
|
|
|
|
obj.exec(parameters2);
|
|
|
|
|
}, sendIds, Math.min(randomTime, 120));
|
|
|
|
|
} else {
|
2019-09-26 14:18:27 +08:00
|
|
|
|
LOGGER.info("gm________________________start:"+cmd);
|
2019-08-28 11:53:00 +08:00
|
|
|
|
obj.exec(parameters);
|
2019-09-26 14:18:27 +08:00
|
|
|
|
LOGGER.info("gm________________________end:"+cmd);
|
2019-08-28 11:53:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (final Exception ex) {
|
|
|
|
|
result.setResultMsg("Cmd Illegal");
|
2019-09-20 10:36:14 +08:00
|
|
|
|
LOGGER.info("e={}",ex);
|
2019-08-28 11:53:00 +08:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
result.setResultCode(0);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|