Merge branch 'master_test_hw_server_arena' of http://60.1.1.230/backend/jieling_server into master_test_hw_server_arena
commit
88c481126f
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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 ...");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)){
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,4 +8,8 @@ include 'test'
|
|||
include 'tablemanager'
|
||||
include 'fightmanager'
|
||||
include 'gamecommon'
|
||||
include 'com.jieling'
|
||||
include 'worldserver'
|
||||
include 'globalid'
|
||||
include 'globalidserver'
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue