Merge branch 'master_test_hw_server_arena' of http://60.1.1.230/backend/jieling_server into master_test_hw_server_arena

lvxinran 2020-12-01 10:25:10 +08:00
commit 88c481126f
11 changed files with 258 additions and 19 deletions

View File

@ -27,6 +27,8 @@ dependencies {
compile("org.springframework.boot:spring-boot-starter-data-redis:1.5.9.RELEASE")
compile group: 'com.google.code.gson', name: 'gson', version: '2.2.4'
compile project(":gamecommon")
compile project(":tablemanager")
compile files("${System.properties['java.home']}/../lib/tools.jar")
}
//JAR

View File

@ -6,6 +6,7 @@ import com.global.redis.RedisUtil;
import com.global.thread.ThreadManager;
import com.global.thrift.pool.GlobalRpcService;
import com.global.thrift.pool.RPCServerTask;
import manager.STableManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@ -40,6 +41,12 @@ public class GlobalServerApplication {
ThreadManager threadManager = ThreadManager.getInstance();
threadManager.init();
try {
STableManager.initialize("config");
}catch (Exception e){
LOGGER.info("STableManager err ->{}", e);
}
GlobalRpcService.initHandler("com.global.handler",GlobalServerApplication.class.getClassLoader());
new RPCServerTask().start();

View File

@ -1,10 +1,9 @@
package com.global.handler;
import com.global.GlobalServerApplication;
import com.global.config.CoreSettings;
import rpc.net.RpcMessage;
import com.google.protobuf.GeneratedMessage;
import rpc.global.GlobalProto;
import rpc.net.RpcMessage;
import rpc.net.gtGBaseHandler;
/**
@ -19,10 +18,14 @@ public class GetWorldServerRequestHandler extends gtGBaseHandler<GlobalProto.Get
//TODO 分组逻辑
System.out.println("rpcMessage = " + rpcMessage.toString());
//TODO 设置分组
//第一版固定一个世界服
String ip = GlobalServerApplication.bean.getWorldip();
int port = GlobalServerApplication.bean.getPort();
return GlobalProto.GetWorldServerResponse.newBuilder().setIp("60.1.1.161").setPort("18080").setGroup(1).build();
return GlobalProto.GetWorldServerResponse.newBuilder().setIp(ip).setPort(String.valueOf(port)).setGroup(1).build();
}

View File

@ -4,14 +4,14 @@ public class RedisKey {
public final static String Delimiter_colon = ":";
public static final String MATCH_UID_KEY = "MATCH_UID_KEY";
public static final String MATCH_ROOM_KEY = "MATCH_ROOM_KEY";
public static final String BLOODY_ROOM_ID = "BLOODY_ROOM_ID";
public static final String BLOODY_ROOM_ADDRESS = "BLOODY_ROOM_ADDRESS"; //房间服务器地址信息
public static final String USER_LOGIN_URL = "USER_LOGIN_URL"; //房间服务器地址信息
public static final String BLOODY_SERVER_INFO = "BLOODY_SERVER_INFO"; //房间服务器地址信息
public static final String MATCH_SERVER_INFO = "MATCH_SERVER_INFO"; //匹配服务器地址信息
public static final String MATCH_SIZE = "MATCH_SIZE"; //匹配人数设置
/**
*
*/
public static final String SERVER_WORLDLEVE_INFO = "SERVER_WORLDLEVE_INFO";
public static final String MACH_SERVERINFO = "MACH_SERVERINFO";
public static final String MATCHED_SPLIT_KEY = "MATCHED_SPLIT_KEY";

View File

@ -9,10 +9,8 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* Author: zsx
@ -250,4 +248,202 @@ public class RedisUtil {
}
// ================================Map=================================
/**
* HashGet
*
* @param key
* null
* @param mapKey
* null
* @return
*/
public Object hget(String key, String mapKey) {
return redisTemplate.opsForHash().get(key, mapKey);
}
/**
* hashKey
*
* @param key
*
* @return
*/
public Map<Object, Object> hmget(String key) {
return redisTemplate.opsForHash().entries(key);
}
/**
* HashSet
*
* @param key
*
* @param map
*
* @return true false
*/
public boolean hmset(String key, Map<String, Object> map) {
try {
redisTemplate.opsForHash().putAll(key, map);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* HashSet
*
* @param key
*
* @param map
*
* @param time
* ()
* @return true false
*/
public boolean hmset(String key, Map<String, Object> map, long time) {
try {
redisTemplate.opsForHash().putAll(key, map);
if (time > 0) {
expire(key, time);
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* hash,
*
* @param key
*
* @param mapKey
*
* @param value
*
* @return true false
*/
public boolean hset(String key, String mapKey, Object value) {
try {
if (!(value instanceof String)){
value = gson.toJson(value);
}
redisTemplate.opsForHash().put(key, mapKey, value);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* hash,
*
* @param key
*
* @param mapKey
*
* @param value
*
* @param time
* () :hash,
* @return true false
*/
public boolean hset(String key, String mapKey, Object value, long time) {
try {
if (!(value instanceof String)){
value = gson.toJson(value);
}
redisTemplate.opsForHash().put(key, mapKey, value);
if (time > 0) {
expire(key, time);
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
*
*
* @param key
*
* @param time
* ()
* @return
*/
public boolean expire(String key, long time) {
try {
if (time > 0) {
redisTemplate.expire(key, time, TimeUnit.SECONDS);
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* hash
*
* @param key
* null
* @param item
* 使 null
*/
public void hdel(String key, Object... item) {
redisTemplate.opsForHash().delete(key, item);
}
/**
* hash
*
* @param key
* null
* @param item
* null
* @return true false
*/
public boolean hHasKey(String key, String item) {
return redisTemplate.opsForHash().hasKey(key, item);
}
/**
* hash ,
*
* @param key
*
* @param item
*
* @param by
* (0)
* @return
*/
public double hincr(String key, String item, double by) {
return redisTemplate.opsForHash().increment(key, item, by);
}
/**
* hash
*
* @param key
*
* @param item
*
* @param by
* (0)
* @return
*/
public double hdecr(String key, String item, double by) {
return redisTemplate.opsForHash().increment(key, item, -by);
}
}

View File

@ -1,5 +1,7 @@
package com.global.thread;
import com.global.redis.RedisKey;
import com.global.redis.RedisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -23,6 +25,7 @@ public class MinuteTask extends Thread {
try {
LOGGER.info("MinuteTask start...");
LOGGER.info("MinuteTask end...");
} catch (Exception e) {
LOGGER.error("e",e);
@ -36,6 +39,13 @@ public class MinuteTask extends Thread {
int minute = calendar.get(Calendar.MINUTE);
if(hour == 0 && minute ==0){
LOGGER.info("DailyOfZeroTask start ...");
//每周1凌晨1 刷新跨服服务器 对服务器分组
// RedisUtil.getInstence().hmset(key, fightInfo, RedisKey.EXPIRE_TIME);
LOGGER.info("DailyOfZeroTask end ...");
}
}

View File

@ -32,6 +32,12 @@ public class RedisKey {
*/
public static final String USER_SERVER_INFO = "JL_USER_SERVER_INFO";
/**
*
*/
public static final String SERVER_WORLDLEVE_INFO = "SERVER_WORLDLEVE_INFO";
public final static String CUser_ServerId_Key = "CUser_ServerId"; //服务器缓存
/**
@ -354,8 +360,8 @@ public class RedisKey {
familyKey.add(FAMILY_FIGHT_TOTAL_EXP);
familyKey.add(FAMILY_FIGHT_FINISH_MATCHING);
}
public static String getKey(String type, String key, boolean withoutServerId) {
if(RedisKey.TOKEN.equals(type)||RedisKey.USER_SERVER_INFO.equals(type)){
public static String getKey(String type, String key, boolean withoutServerId)
if(RedisKey.TOKEN.equals(type)||RedisKey.USER_SERVER_INFO.equals(type)||RedisKey.SERVER_WORLDLEVE_INFO.equals(type)){
return type + RedisKey.Delimiter_colon + key;
}
if(familyKey.contains(type)){

View File

@ -186,6 +186,7 @@ public class GlobleSystemLogic implements IEventHandler {
private static void setGloableWorldLeveCache(int gloableWorldLeveCache) {
GLOABLE_WORLD_LEVE_CACHE = gloableWorldLeveCache;
RedisUtil.getInstence().putMapEntry(RedisKey.USER_SERVER_INFO,"",String.valueOf(GameApplication.areaId),gloableWorldLeveCache);
}
public static int getGloableWorldLeveCacheLine() {
@ -194,5 +195,6 @@ public class GlobleSystemLogic implements IEventHandler {
public static void setGloableWorldLeveCacheLine(int gloableWorldLeveCacheLine) {
GLOABLE_WORLD_LEVE_CACHE_LINE = gloableWorldLeveCacheLine;
}
}

View File

@ -8,4 +8,8 @@ include 'test'
include 'tablemanager'
include 'fightmanager'
include 'gamecommon'
include 'com.jieling'
include 'worldserver'
include 'globalid'
include 'globalidserver'

View File

@ -28,6 +28,8 @@ dependencies {
compile("org.springframework.boot:spring-boot-starter-data-redis:1.5.9.RELEASE")
compile group: 'com.google.code.gson', name: 'gson', version: '2.2.4'
compile project(":gamecommon")
compile project(":tablemanager")
compile files("${System.properties['java.home']}/../lib/tools.jar")
}
//JAR

View File

@ -6,6 +6,7 @@ import com.world.redis.RedisUtil;
import com.world.thread.ThreadManager;
import com.world.thrift.idl.pool.RPCServerTask;
import com.world.thrift.idl.pool.WorldRpcService;
import manager.STableManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@ -32,6 +33,12 @@ public class WorldServerApplication {
//线程池管理器
ThreadManager threadManager = ThreadManager.getInstance();
threadManager.init();
try {
STableManager.initialize("config");
}catch (Exception e){
LOGGER.info("STableManager err ->{}", e);
}
WorldRpcService.initHandler("com.world.handler",WorldServerApplication.class.getClassLoader());
new RPCServerTask().start();
RedisUtil.getInstence().init();