197 lines
8.5 KiB
Java
197 lines
8.5 KiB
Java
package com.ljsd;
|
||
|
||
|
||
import com.google.gson.Gson;
|
||
import com.ljsd.jieling.core.HandlerLogicThread;
|
||
import com.ljsd.jieling.db.mongo.MongoUtil;
|
||
import com.ljsd.jieling.db.redis.RedisKey;
|
||
import com.ljsd.jieling.db.redis.RedisUtil;
|
||
import com.ljsd.jieling.kefu.GmGlobleAbstract;
|
||
import com.ljsd.jieling.kefu.GmInterface;
|
||
import com.ljsd.jieling.kefu.GmRoleAbstract;
|
||
import com.ljsd.jieling.logic.OnlineUserManager;
|
||
import com.ljsd.jieling.logic.dao.RechargeInfo;
|
||
import com.ljsd.jieling.logic.dao.UserManager;
|
||
import com.ljsd.jieling.logic.dao.root.User;
|
||
import com.ljsd.jieling.logic.hero.HeroLogic;
|
||
import com.ljsd.jieling.network.server.ProtocolsManager;
|
||
import com.ljsd.jieling.network.session.ISession;
|
||
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||
import com.ljsd.jieling.thread.task.DataReportTask;
|
||
import com.ljsd.jieling.thrift.idl.InvalidOperException;
|
||
import com.ljsd.jieling.thrift.idl.RPCRequestGMIFace;
|
||
import com.ljsd.jieling.thrift.idl.Result;
|
||
import com.ljsd.jieling.util.*;
|
||
import org.apache.thrift.TException;
|
||
import org.slf4j.Logger;
|
||
import org.slf4j.LoggerFactory;
|
||
import org.springframework.context.ConfigurableApplicationContext;
|
||
import org.springframework.data.redis.core.ZSetOperations;
|
||
|
||
import java.io.BufferedReader;
|
||
import java.io.File;
|
||
import java.io.FileReader;
|
||
import java.lang.reflect.Field;
|
||
import java.lang.reflect.Method;
|
||
import java.util.*;
|
||
|
||
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 {
|
||
LOGGER.info("gm________________________"+cmd);
|
||
Result result = new Result();
|
||
result.setResultCode(-1);
|
||
String[] arg = cmd.split(" ");
|
||
GmInterface obj;
|
||
try {
|
||
|
||
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;
|
||
}
|
||
|
||
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());
|
||
}
|
||
InnerMessageUtil.broadcastWithRandom( user->{
|
||
LOGGER.info("hotfix user={}",user.getId());
|
||
MongoUtil.getLjsdMongoTemplate().save(user);
|
||
}
|
||
, sendIds, Math.min(10, 10));
|
||
result.setResultCode(1);
|
||
return result;
|
||
}
|
||
obj = (GmInterface) Class.forName(
|
||
GmInterface.class.getPackage().getName() + ".Cmd_"
|
||
+ arg[0].toLowerCase()).newInstance();
|
||
|
||
} catch (Exception ex) {
|
||
result.setResultMsg("Cmd Illegal");
|
||
ex.printStackTrace();
|
||
return result;
|
||
}
|
||
try {
|
||
String[] parameters = java.util.Arrays.copyOfRange(arg, 1, arg.length);
|
||
|
||
|
||
|
||
if (obj instanceof GmRoleAbstract) {
|
||
//todo
|
||
Map<Integer, String> rechargeInfoMap = new HashMap<>();
|
||
if(cmd.contains("recharge")){
|
||
File file = new File("../conf/BuyGoodsLogic.log");
|
||
LOGGER.info("file path={}",file.getAbsolutePath());
|
||
BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
|
||
|
||
String readLine = null;
|
||
Gson gson = new Gson();
|
||
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);
|
||
String rechargeInfoStr = rechargeInfoMap.get(uid);
|
||
RechargeInfo rechargeInfo = new RechargeInfo();
|
||
if( rechargeInfoStr != null){
|
||
rechargeInfo = gson.fromJson(rechargeInfoStr,RechargeInfo.class);
|
||
}
|
||
String goodStr = split[1].split("=")[1];
|
||
int goodID = Integer.parseInt(goodStr);
|
||
if(goodID == 8 || goodID == 7){
|
||
rechargeInfo.setHadBuyFound(1);
|
||
}
|
||
Map<Integer, Integer> buyGoodsTimes = rechargeInfo.getBuyGoodsTimes();
|
||
Integer buyCount = buyGoodsTimes.get(goodID);
|
||
if(buyCount == null){
|
||
buyCount =0;
|
||
}
|
||
buyCount++;
|
||
buyGoodsTimes.put(goodID,buyCount);
|
||
rechargeInfoMap.put(uid,gson.toJson(rechargeInfo));
|
||
}
|
||
}
|
||
|
||
|
||
List<Integer> sendIds = new LinkedList<>();
|
||
if (obj instanceof GmGlobleAbstract) {
|
||
for (ISession session : OnlineUserManager.sessionMap.values()) {
|
||
sendIds.add(session.getUid());
|
||
}
|
||
} else {
|
||
if(cmd.contains("hotfix") || cmd.contains("shop")|| cmd.contains("endStore")){
|
||
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());
|
||
}
|
||
}else if(cmd.contains("recharge")){
|
||
sendIds.addAll(rechargeInfoMap.keySet());
|
||
}else if(cmd.contains("force")){
|
||
|
||
Set<ZSetOperations.TypedTuple<String>> rankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.FORCE_RANK, "", 0, -1);
|
||
for (ZSetOperations.TypedTuple<String> item : rankInfo) {
|
||
String value = item.getValue();
|
||
int uid = Integer.parseInt(value);
|
||
sendIds.add(uid);
|
||
}
|
||
|
||
} else{
|
||
String[] ids = parameters[0].split("#");
|
||
for (String id : ids) {
|
||
sendIds.add(Integer.valueOf(id));
|
||
}
|
||
}
|
||
|
||
}
|
||
int randomTime = sendIds.size() * 1;
|
||
//两分钟内发完所有协议
|
||
Gson gson = new Gson();
|
||
String[] parameters2 = java.util.Arrays.copyOfRange(parameters, 1, parameters.length);
|
||
if(cmd.contains("recharge") ){
|
||
LOGGER.info("recharge map size={}",rechargeInfoMap.size());
|
||
if(!rechargeInfoMap.isEmpty()){
|
||
parameters2[3] = gson.toJson(rechargeInfoMap);
|
||
}
|
||
}
|
||
|
||
InnerMessageUtil.broadcastWithRandom( user->{
|
||
((GmRoleAbstract) obj).setUser(user);
|
||
obj.exec(parameters2);
|
||
}, sendIds, Math.min(randomTime, 120));
|
||
} else {
|
||
LOGGER.info("gm________________________start:"+cmd);
|
||
obj.exec(parameters);
|
||
LOGGER.info("gm________________________end:"+cmd);
|
||
}
|
||
|
||
} catch (final Exception ex) {
|
||
result.setResultMsg("Cmd Illegal");
|
||
LOGGER.info("e={}",ex);
|
||
return result;
|
||
}
|
||
result.setResultCode(0);
|
||
return result;
|
||
}
|
||
|
||
|
||
}
|