generated from root/miduo_server
启服时自动清除冗余工会成员信息
parent
afccc3fb32
commit
7279c3f913
|
|
@ -17,6 +17,7 @@ import com.ljsd.jieling.logic.activity.event.Poster;
|
|||
import com.ljsd.jieling.logic.activity.event.ServerOpenEvent;
|
||||
import com.ljsd.jieling.logic.dao.GuilidManager;
|
||||
import com.ljsd.jieling.logic.dao.MailingSystemManager;
|
||||
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;
|
||||
|
|
@ -163,6 +164,7 @@ public class GameLogicService implements IService {
|
|||
ThriftPoolUtils.getInstance().initContext();
|
||||
GlobalDataManaager.getInstance().init();
|
||||
GuilidManager.init();
|
||||
UserManager.init();
|
||||
ChatLogic.initWorldChat();
|
||||
URL resource = HeroLogic.class.getClassLoader().getResource("mingan.txt");
|
||||
if (resource != null) {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import org.bson.Document;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mongodb.MongoDbFactory;
|
||||
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
|
||||
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
|
||||
|
|
@ -154,7 +155,8 @@ public class MongoUtil {
|
|||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
LjsdMongoTemplate ljsdMongoTemplate = getLjsdMongoTemplate();
|
||||
MongoUtil.getInstence().init();
|
||||
LjsdMongoTemplate ljsdMongoTemplate = MongoUtil.getInstence().getLjsdMongoTemplate();
|
||||
Criteria criatira = new Criteria();
|
||||
Random random = new Random();
|
||||
int minLevel = random.nextInt(10) - 5;
|
||||
|
|
@ -484,4 +486,14 @@ public class MongoUtil {
|
|||
}
|
||||
return cServerInfo.getName();
|
||||
}
|
||||
|
||||
public List<User> getAllUsersByIds(List<Integer> uids) throws Exception {
|
||||
Criteria criteria = new Criteria().andOperator(
|
||||
Criteria.where("_id").in(uids)
|
||||
);
|
||||
Query query = new Query(criteria);
|
||||
query.with(new Sort(Sort.Direction.DESC,"_id"));
|
||||
LjsdMongoTemplate ljsdMongoTemplate = this.getLjsdMongoTemplate();
|
||||
return ljsdMongoTemplate.findAllByCondition(query,User.class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.ljsd.jieling.logic.dao;
|
||||
|
||||
import com.ljsd.GameApplication;
|
||||
import com.ljsd.jieling.core.GlobalsDef;
|
||||
import com.ljsd.jieling.db.mongo.MongoUtil;
|
||||
import com.ljsd.jieling.db.redis.RedisKey;
|
||||
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||
|
|
@ -9,11 +10,16 @@ import com.ljsd.jieling.logic.dao.root.GuildInfo;
|
|||
import com.ljsd.jieling.logic.dao.root.GuildLog;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.logic.family.GuildLogic;
|
||||
import com.ljsd.jieling.protocols.CommonProto;
|
||||
import com.ljsd.jieling.util.CBean2Proto;
|
||||
import com.mongodb.BasicDBObject;
|
||||
import config.SGuildSetting;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.query.BasicQuery;
|
||||
import org.springframework.data.redis.core.ZSetOperations;
|
||||
import util.TimeUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
|
@ -22,6 +28,7 @@ public class GuilidManager {
|
|||
public static Map<Integer,GuildInfo> guildInfoMap = new HashMap<>();
|
||||
public static Map<String,GuildInfo> guildNameInfoMap = new HashMap<>();
|
||||
public static Map<Integer,List<GuildLog>> guildLogInfoMap = new HashMap<>();
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(GuilidManager.class);
|
||||
|
||||
public static void addGuildInfo(GuildInfo guildInfo) throws Exception {
|
||||
|
||||
|
|
@ -88,17 +95,79 @@ public class GuilidManager {
|
|||
public static void init() throws Exception {
|
||||
List<GuildInfo> all = MongoUtil.getInstence().getMyMongoTemplate().findAll(GuildInfo._COLLECTION_NAME, GuildInfo.class);
|
||||
List<GuildLog> guildLogs = MongoUtil.getInstence().getMyMongoTemplate().findAll(GuildLog._COLLECTION_NAME, GuildLog.class);
|
||||
List<String> uids = new ArrayList<>();
|
||||
for(GuildInfo guildInfo : all){
|
||||
guildInfoMap.put(guildInfo.getId(),guildInfo);
|
||||
guildNameInfoMap.put(guildInfo.getName(),guildInfo);
|
||||
loadGuildMemberUids(guildInfo,uids);
|
||||
}
|
||||
|
||||
for(GuildLog guildLog : guildLogs){
|
||||
if(!guildLogInfoMap.containsKey(guildLog.getGuildId())){
|
||||
guildLogInfoMap.put(guildLog.getGuildId(),new ArrayList<>());
|
||||
}
|
||||
guildLogInfoMap.get(guildLog.getGuildId()).add(guildLog);
|
||||
}
|
||||
if(uids.size() > 0){
|
||||
List<PlayerInfoCache> infos = RedisUtil.getInstence().hmget(RedisKey.PLAYER_INFO_CACHE + RedisKey.Delimiter_colon, uids, PlayerInfoCache.class);
|
||||
if(infos != null && infos.size() > 0) {
|
||||
for (PlayerInfoCache userCache :infos){
|
||||
//放置用户基本信息到内存中
|
||||
UserManager.updatePlayerInfoCache(userCache);
|
||||
}
|
||||
};
|
||||
}
|
||||
LOGGER.info("加载公会成员缓存数据:{}条", uids.size());
|
||||
//清除离线大于7天的公会成员信息
|
||||
long now = System.currentTimeMillis();
|
||||
for(GuildInfo guildInfo : all){
|
||||
clearGuildMember(guildInfo,now);
|
||||
}
|
||||
MongoUtil.getInstence().lastUpdate();
|
||||
LOGGER.info("清理冗余公会成员信息耗时:{}ms", System.currentTimeMillis() - now);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载公会成员缓存信息
|
||||
*/
|
||||
public static void loadGuildMemberUids(GuildInfo guildInfo,List<String> uids){
|
||||
Map<Integer, Set<Integer>> members = guildInfo.getMembers();
|
||||
for (Map.Entry<Integer, Set<Integer>> memberEntry : members.entrySet()) {
|
||||
Set<Integer> value = memberEntry.getValue();
|
||||
for (Integer uidTmp : value) {
|
||||
uids.add(String.valueOf(uidTmp));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除离线时间大于7天的公会成员
|
||||
* @param guildInfo
|
||||
*/
|
||||
public static void clearGuildMember(GuildInfo guildInfo,long now){
|
||||
Map<Integer, Set<Integer>> members = guildInfo.getMembers();
|
||||
for (Map.Entry<Integer, Set<Integer>> memberEntry : members.entrySet()) {
|
||||
Integer position = memberEntry.getKey();
|
||||
//会长不处理
|
||||
if(position == GlobalsDef.CHAIRMAN){
|
||||
continue;
|
||||
}
|
||||
Set<Integer> value = memberEntry.getValue();
|
||||
for (Integer uidTmp : value) {
|
||||
if(uidTmp != null) {
|
||||
PlayerInfoCache userTmp = UserManager.getPlayerInfoCache(uidTmp);
|
||||
if (userTmp != null) {
|
||||
long lastLoginTime = userTmp.getOffLineTime();
|
||||
//离线超过一周,踢出公会,并清除内存
|
||||
if((now - lastLoginTime) >= TimeUtils.WEEK){
|
||||
guildInfo.removeMember(guildInfo.getMemberType(userTmp.getId()), userTmp.getId());
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
guildInfo.removeMember(guildInfo.getMemberType(uidTmp), uidTmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -445,4 +445,23 @@ public class UserManager {
|
|||
playerInfoCacheMap.put(playerInfoCache.getId(), playerInfoCache);
|
||||
}
|
||||
|
||||
public static void init() throws Exception {
|
||||
// List<Integer> uids = new ArrayList<>();
|
||||
// uids.add(10000457);
|
||||
// uids.add(10000456);
|
||||
// uids.add(10000455);
|
||||
// uids.add(10000454);
|
||||
// uids.add(10000416);
|
||||
// long start = System.currentTimeMillis();
|
||||
// for (Integer uid : uids) {
|
||||
// User user = UserManager.getUser(uid, true);
|
||||
// }
|
||||
// long end = System.currentTimeMillis();
|
||||
// LOGGER.info("初始化玩家信息缓存耗时:{}ms", end - start);
|
||||
// start = System.currentTimeMillis();
|
||||
// List<User> list = MongoUtil.getInstence().getAllUsersByIds(uids);
|
||||
// end = System.currentTimeMillis();
|
||||
// LOGGER.info("批量初始化" + list.size() + "个玩家信息缓存耗时:{}ms", end - start);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -599,6 +599,7 @@ public class GuildLogic{
|
|||
GuildInfo guildInfo = GuilidManager.guildInfoMap.get(user.getPlayerInfoManager().getGuildId());
|
||||
Family.GetFamilyMemberInfoResponse.Builder builder = Family.GetFamilyMemberInfoResponse.newBuilder();
|
||||
Map<Integer, Set<Integer>> members = guildInfo.getMembers();
|
||||
long now = System.currentTimeMillis();
|
||||
for (Map.Entry<Integer, Set<Integer>> memberEntry : members.entrySet()) {
|
||||
Integer position = memberEntry.getKey();
|
||||
Set<Integer> value = memberEntry.getValue();
|
||||
|
|
@ -608,9 +609,16 @@ public class GuildLogic{
|
|||
User userTmp = UserManager.getUser(uidTmp, true);
|
||||
// LOGGER.info("userTmp={}", userTmp);
|
||||
if (userTmp != null) {
|
||||
long lastLoginTime = userTmp.getPlayerInfoManager().getLoginTime();
|
||||
//离线超过一周,且不是会长,踢出公会,并清除内存
|
||||
if((now - lastLoginTime) >= TimeUtils.WEEK){
|
||||
guildInfo.removeMember(guildInfo.getMemberType(userTmp.getId()), userTmp.getId());
|
||||
UserManager.removeUser(userTmp.getId());
|
||||
continue;
|
||||
}
|
||||
builder.addFamilyUserInfo(CBean2Proto.getFamilyUserInfo(userTmp, position));
|
||||
} else {
|
||||
guildInfo.removeMember(guildInfo.getMemberType(user.getId()), user.getId());
|
||||
guildInfo.removeMember(guildInfo.getMemberType(uidTmp), uidTmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue