diff --git a/common-data/pom.xml b/common-data/pom.xml
index 803482a..4aa1312 100644
--- a/common-data/pom.xml
+++ b/common-data/pom.xml
@@ -24,6 +24,16 @@
common-game
${common-game.version}
+
+ com.t13max.data.mongo
+ t13max-data-mongo
+ ${t13max-data-mongo.version}
+
+
+ com.t13max.data.redis
+ t13max-data-redis
+ ${t13max-data-redis.version}
+
org.xerial
diff --git a/common-data/src/main/java/com/t13max/data/dao/DefaultRedisUtil.java b/common-data/src/main/java/com/t13max/data/dao/DefaultRedisUtil.java
deleted file mode 100644
index cfae054..0000000
--- a/common-data/src/main/java/com/t13max/data/dao/DefaultRedisUtil.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.t13max.data.dao;
-
-/**
- * 未来真正的redis工具类
- *
- * @author: t13max
- * @since: 14:15 2024/5/29
- */
-public class DefaultRedisUtil implements IRedisUtil {
-
-}
diff --git a/common-data/src/main/java/com/t13max/data/dao/IRedisUtil.java b/common-data/src/main/java/com/t13max/data/dao/IRedisUtil.java
deleted file mode 100644
index 0b3bbc4..0000000
--- a/common-data/src/main/java/com/t13max/data/dao/IRedisUtil.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.t13max.data.dao;
-
-/**
- * @author: t13max
- * @since: 14:13 2024/5/29
- */
-public interface IRedisUtil {
-}
diff --git a/common-data/src/main/java/com/t13max/data/dao/MemoryRedisUtil.java b/common-data/src/main/java/com/t13max/data/dao/MemoryRedisUtil.java
deleted file mode 100644
index d46b24b..0000000
--- a/common-data/src/main/java/com/t13max/data/dao/MemoryRedisUtil.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.t13max.data.dao;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * 内存Redis实现 实际上就是个假的 用于微型启动
- *
- * @author: t13max
- * @since: 13:23 2024/5/29
- */
-public class MemoryRedisUtil implements IRedisUtil {
-
- //假装自己是Redis
- private Map memoryMap = new HashMap<>();
-}
diff --git a/common-data/src/main/java/com/t13max/data/dao/MongoUtil.java b/common-data/src/main/java/com/t13max/data/dao/MongoUtil.java
deleted file mode 100644
index 58bd2f8..0000000
--- a/common-data/src/main/java/com/t13max/data/dao/MongoUtil.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.t13max.data.dao;
-
-import com.t13max.data.entity.IData;
-import lombok.experimental.UtilityClass;
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Mongodb操作工具类
- * 待完善
- *
- * @author: t13max
- * @since: 13:28 2024/5/29
- */
-@UtilityClass
-public class MongoUtil {
-
- public static void save(T data) {
-
- }
-
- public static void delete(long id, Class clazz) {
-
- }
-
- public static T findById(long id, Class clazz) {
- return (T) null;
- }
-
- public static List findList(Class clazz) {
-
- return Collections.emptyList();
- }
-
- public static List findList(long uuid, Class clazz) {
- return Collections.emptyList();
- }
-
-}
diff --git a/common-data/src/main/java/com/t13max/data/dao/SqlLiteUtil.java b/common-data/src/main/java/com/t13max/data/dao/SqlLiteUtil.java
index da9a710..6bb1bb3 100644
--- a/common-data/src/main/java/com/t13max/data/dao/SqlLiteUtil.java
+++ b/common-data/src/main/java/com/t13max/data/dao/SqlLiteUtil.java
@@ -1,9 +1,9 @@
package com.t13max.data.dao;
+import com.t13max.common.config.BaseConfig;
+import com.t13max.common.run.Application;
import com.t13max.data.entity.AccountData;
-import com.t13max.game.config.BaseConfig;
import com.t13max.game.exception.DataException;
-import com.t13max.game.run.Application;
import com.t13max.game.util.Log;
import com.t13max.util.TextUtil;
import lombok.experimental.UtilityClass;
@@ -18,7 +18,6 @@
* @since: 11:10 2024/5/29
*/
@UtilityClass
-@Deprecated
public class SqlLiteUtil {
//暂时就单链接 后续补充优化
diff --git a/common-data/src/main/java/com/t13max/data/entity/EquipData.java b/common-data/src/main/java/com/t13max/data/entity/EquipData.java
index 13b5684..c763980 100644
--- a/common-data/src/main/java/com/t13max/data/entity/EquipData.java
+++ b/common-data/src/main/java/com/t13max/data/entity/EquipData.java
@@ -1,5 +1,6 @@
package com.t13max.data.entity;
+import com.t13max.data.mongo.IData;
import lombok.Data;
/**
diff --git a/common-data/src/main/java/com/t13max/data/entity/IData.java b/common-data/src/main/java/com/t13max/data/entity/IData.java
deleted file mode 100644
index 37dbcad..0000000
--- a/common-data/src/main/java/com/t13max/data/entity/IData.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.t13max.data.entity;
-
-/**
- * @author: t13max
- * @since: 11:50 2024/5/29
- */
-public interface IData {
-
- long getId();
-}
diff --git a/common-data/src/main/java/com/t13max/data/entity/ItemData.java b/common-data/src/main/java/com/t13max/data/entity/ItemData.java
index 607ec76..21056e8 100644
--- a/common-data/src/main/java/com/t13max/data/entity/ItemData.java
+++ b/common-data/src/main/java/com/t13max/data/entity/ItemData.java
@@ -1,5 +1,6 @@
package com.t13max.data.entity;
+import com.t13max.data.mongo.IData;
import lombok.Data;
import java.util.HashMap;
@@ -33,6 +34,7 @@ public ItemData(long uuid) {
* @Author t13max
* @Date 19:24 2024/6/4
*/
+ @Override
public long getId() {
return uuid;
}
diff --git a/common-data/src/main/java/com/t13max/data/entity/RankDumpData.java b/common-data/src/main/java/com/t13max/data/entity/RankDumpData.java
index e454348..a6bd885 100644
--- a/common-data/src/main/java/com/t13max/data/entity/RankDumpData.java
+++ b/common-data/src/main/java/com/t13max/data/entity/RankDumpData.java
@@ -1,8 +1,24 @@
package com.t13max.data.entity;
+import com.t13max.data.mongo.IData;
+import lombok.Data;
+
/**
+ * 排行榜dump数据
+ *
* @author t13max
* @since 17:39 2024/9/4
*/
-public class RankDumpData {
+@Data
+public class RankDumpData implements IData {
+
+ private long id;
+
+ private String rankKey;
+
+ private byte[] scoredSet;
+
+ private byte[] mapperMap;
+
+ private byte[] rankData;
}
diff --git a/common-data/src/main/java/com/t13max/data/entity/RoleData.java b/common-data/src/main/java/com/t13max/data/entity/RoleData.java
index 0c78308..2468f79 100644
--- a/common-data/src/main/java/com/t13max/data/entity/RoleData.java
+++ b/common-data/src/main/java/com/t13max/data/entity/RoleData.java
@@ -1,5 +1,6 @@
package com.t13max.data.entity;
+import com.t13max.data.mongo.IData;
import lombok.Data;
/**
@@ -7,7 +8,7 @@
* @since: 11:05 2024/5/24
*/
@Data
-public class RoleData implements IData{
+public class RoleData implements IData {
//所属玩家的唯一id
private long uuid;
diff --git a/common-data/src/main/java/com/t13max/data/manager/AsyncSaveManager.java b/common-data/src/main/java/com/t13max/data/manager/AsyncSaveManager.java
deleted file mode 100644
index edebb84..0000000
--- a/common-data/src/main/java/com/t13max/data/manager/AsyncSaveManager.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package com.t13max.data.manager;
-
-import com.t13max.common.manager.ManagerBase;
-import com.t13max.data.dao.MongoUtil;
-import com.t13max.data.entity.IData;
-import com.t13max.game.util.Log;
-import com.t13max.util.ThreadNameFactory;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.util.*;
-import java.util.concurrent.*;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/**
- * @author: t13max
- * @since: 19:29 2024/6/4
- */
-public class AsyncSaveManager extends ManagerBase {
-
- public static final int INTERVAL = 100;
-
- private ScheduledExecutorService executorService;
-
- private LinkedBlockingQueue dataQueue = new LinkedBlockingQueue<>();
-
- private LinkedBlockingQueue deleteQueue = new LinkedBlockingQueue<>();
-
- private AtomicBoolean running = new AtomicBoolean(false);
-
- public static AsyncSaveManager inst() {
- return inst(AsyncSaveManager.class);
- }
-
- @Override
- protected void onShutdown() {
- shutdownSave();
- executorService.shutdown();
- }
-
- @Override
- public void init() {
- executorService = Executors.newSingleThreadScheduledExecutor(new ThreadNameFactory("data"));
- executorService.scheduleAtFixedRate(this::tickSave, 0, INTERVAL, TimeUnit.MILLISECONDS);
- }
-
- private void tickSave() {
- if (running.get()) {
- return;
- }
- running.set(true);
- try {
- List dataList = new LinkedList<>();
- dataQueue.drainTo(dataList);
- if (!dataList.isEmpty()) {
- dataList.parallelStream().forEach(MongoUtil::save);
- }
-
- List deleteList = new LinkedList<>();
- deleteQueue.drainTo(deleteList);
- if (!deleteList.isEmpty()) {
- deleteList.parallelStream().forEach(e -> MongoUtil.delete(e.getId(), e.getClass()));
- }
- } catch (Exception e) {
- Log.data.error("tickSave error! error={}", e.getMessage());
- } finally {
- running.set(false);
- }
-
- }
-
- private void shutdownSave() {
- while (!dataQueue.isEmpty() || !deleteQueue.isEmpty()) {
- tickSave();
- }
- }
-
- public void delete(T data) {
- try {
- deleteQueue.add(data);
- } catch (Exception e) {
- Log.data.error("删除数据出错, data={}", data);
- }
- }
-
- public void batchSave(List dataList) {
- for (T data : dataList) {
- save(data);
- }
- }
-
- public void save(T data) {
- try {
- long startInvoke = System.currentTimeMillis();
- Constructor extends IData> constructor = data.getClass().getDeclaredConstructor();
- IData newData = constructor.newInstance();
- for (Field field : data.getClass().getDeclaredFields()) {
- field.setAccessible(true);
- Object value = field.get(data);
- field.set(newData, value);
- }
- dataQueue.add(newData);
- long endInvoke = System.currentTimeMillis();
- Log.data.debug("save data, cost={}", endInvoke - startInvoke);
- } catch (Exception e) {
- Log.data.error("异步存储出错! data={}, error={}", data, e.getMessage());
- }
- }
-}
diff --git a/common-data/src/main/java/com/t13max/data/util/UuidUtil.java b/common-data/src/main/java/com/t13max/data/util/UuidUtil.java
deleted file mode 100644
index 45e1df4..0000000
--- a/common-data/src/main/java/com/t13max/data/util/UuidUtil.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package com.t13max.data.util;
-
-import com.t13max.game.config.BaseConfig;
-import com.t13max.game.run.Application;
-import com.t13max.game.util.Log;
-import lombok.experimental.UtilityClass;
-
-import java.util.concurrent.atomic.AtomicLong;
-
-/**
- * @author: t13max
- * @since: 13:57 2024/5/29
- */
-@UtilityClass
-public class UuidUtil {
- private final static long START_TIME = 1716912000000L;//2024-05-29 00:00:00
-
- private final static AtomicLong ID = new AtomicLong();
-
- private final static int MASK_12 = 0XFFF;//12位掩码
-
- private final static int INSTANCE_NO;
-
- static {
- BaseConfig config = Application.config();
- if (config != null) {
- INSTANCE_NO = Application.config().getInstanceNo();
- } else {
- INSTANCE_NO = 0;
- Log.data.error("config为空, instanceNo为0");
- }
- }
-
- /**
- * 全局唯一
- * 后续优化一下 目前有那么一丢丢的可能就是一毫秒内获取超过4096个id就出事了
- *
- * @Author t13max
- * @Date 11:11 2024/4/16
- */
- public long getNextId() {
- long currentTime = System.currentTimeMillis() - START_TIME;
- return (currentTime << 23) + (INSTANCE_NO << 12) + (ID.getAndIncrement() & MASK_12);
- }
-
-}
diff --git a/common-game/pom.xml b/common-game/pom.xml
index 286319a..5e62ced 100644
--- a/common-game/pom.xml
+++ b/common-game/pom.xml
@@ -30,7 +30,11 @@
t13max-core
${t13max-core.version}
-
+
+ com.t13max.common.rpc
+ t13max-rpc
+ ${t13max-rpc.version}
+
\ No newline at end of file
diff --git a/common-game/src/main/java/com/t13max/game/api/IRankService.java b/common-game/src/main/java/com/t13max/game/api/IRankService.java
new file mode 100644
index 0000000..c187b2f
--- /dev/null
+++ b/common-game/src/main/java/com/t13max/game/api/IRankService.java
@@ -0,0 +1,11 @@
+package com.t13max.game.api;
+
+import com.t13max.rpc.anno.RpcInterface;
+
+/**
+ * @author t13max
+ * @since 14:24 2024/10/31
+ */
+@RpcInterface
+public interface IRankService {
+}
diff --git a/common-game/src/main/java/com/t13max/game/config/ActionConfig.java b/common-game/src/main/java/com/t13max/game/config/ActionConfig.java
deleted file mode 100644
index 2b1c458..0000000
--- a/common-game/src/main/java/com/t13max/game/config/ActionConfig.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.t13max.game.config;
-
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * 业务线程池配置
- *
- * @author: t13max
- * @since: 20:11 2024/5/23
- */
-@Setter
-@Getter
-public class ActionConfig {
-
- private int core;
-
- private int max;
-
- private String name;
-}
diff --git a/common-game/src/main/java/com/t13max/game/config/BaseConfig.java b/common-game/src/main/java/com/t13max/game/config/BaseConfig.java
deleted file mode 100644
index 97231ee..0000000
--- a/common-game/src/main/java/com/t13max/game/config/BaseConfig.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.t13max.game.config;
-
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * 配置基类
- *
- * @author: t13max
- * @since: 17:47 2024/5/23
- */
-@Setter
-@Getter
-public class BaseConfig {
-
- //实例id
- protected String instanceId;
-
- //实例唯一序号
- protected int instanceNo;
-
- //是否阻塞主线程
- protected boolean park;
-
- //netty配置 允许使用默认
- protected NettyConfig netty;
-
- //业务线程池配置
- protected ActionConfig action;
-
- //数据库文件
- protected String dbFile;
-
- protected int saveThreadNum;
-
- /**
- * 校验数据
- *
- * @Author t13max
- * @Date 18:59 2024/5/23
- */
- public boolean check() {
- return true;
- }
-}
diff --git a/common-game/src/main/java/com/t13max/game/config/BattleConfig.java b/common-game/src/main/java/com/t13max/game/config/BattleConfig.java
index b4b430a..98b9a4b 100644
--- a/common-game/src/main/java/com/t13max/game/config/BattleConfig.java
+++ b/common-game/src/main/java/com/t13max/game/config/BattleConfig.java
@@ -1,5 +1,6 @@
package com.t13max.game.config;
+import com.t13max.common.config.BaseConfig;
import lombok.Getter;
import lombok.Setter;
@@ -9,7 +10,7 @@
*/
@Setter
@Getter
-public class BattleConfig extends BaseConfig{
+public class BattleConfig extends BaseConfig {
private boolean test;
}
diff --git a/common-game/src/main/java/com/t13max/game/config/ClientConfig.java b/common-game/src/main/java/com/t13max/game/config/ClientConfig.java
index 70a7d63..4df82cc 100644
--- a/common-game/src/main/java/com/t13max/game/config/ClientConfig.java
+++ b/common-game/src/main/java/com/t13max/game/config/ClientConfig.java
@@ -1,10 +1,12 @@
package com.t13max.game.config;
+import com.t13max.common.config.BaseConfig;
+
/**
* @author: t13max
* @since: 17:26 2024/5/23
*/
-public class ClientConfig extends BaseConfig{
+public class ClientConfig extends BaseConfig {
}
diff --git a/common-game/src/main/java/com/t13max/game/config/NettyConfig.java b/common-game/src/main/java/com/t13max/game/config/NettyConfig.java
deleted file mode 100644
index 20368b9..0000000
--- a/common-game/src/main/java/com/t13max/game/config/NettyConfig.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.t13max.game.config;
-
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * @author: t13max
- * @since: 19:09 2024/5/23
- */
-@Getter
-@Setter
-public class NettyConfig {
-
- //使用epoll
- protected boolean useEpoll;
-
- //对外端口
- protected int port;
-
- private int ringBufferSize = 64 * 1024;
- private int tcpPort = 6000;
- private int connectTimeoutMillis = 3000; // 连接超时
- private int lowWaterMark = 128*1024; // 低水位
- private int highWaterMark = 256*1024; // 高水位
- private int soBackLog = 1024; //
- private boolean ssoReuseAddr = true; //
- private boolean tcpNodelay = true; //
- private boolean ssoKeepAlive = true; //
- private long idleTimeOutMillis = 5 * 60 * 1000; // 空闲超时时间设定
- private int idleScheduleInitial = 10000; // 10秒
- private int idleSchedulePeriod = 60000; // 60秒
- private int reconnectDelayMillis = 3000; // 重连延时3秒
- private boolean csoKeepAlive = true; //
- private boolean csoReuseAddr = true; //
- private long readerIdleTime = 0; // 秒
- private long writerIdleTime = 0; // 秒
- private long clientAllIdleTime = 10000; // 客户端10秒
- private long serverAllIdleTime = 60000; // 服务器60秒
- private int maxFrameLength = 1024*1024; //最大包长度
-}
diff --git a/common-game/src/main/java/com/t13max/game/config/SceneConfig.java b/common-game/src/main/java/com/t13max/game/config/SceneConfig.java
deleted file mode 100644
index 68f30be..0000000
--- a/common-game/src/main/java/com/t13max/game/config/SceneConfig.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.t13max.game.config;
-
-/**
- * @author: t13max
- * @since: 17:26 2024/5/23
- */
-public class SceneConfig extends BaseConfig{
-
-
-}
diff --git a/common-game/src/main/java/com/t13max/game/run/Application.java b/common-game/src/main/java/com/t13max/game/run/Application.java
deleted file mode 100644
index 78189e4..0000000
--- a/common-game/src/main/java/com/t13max/game/run/Application.java
+++ /dev/null
@@ -1,189 +0,0 @@
-package com.t13max.game.run;
-
-import com.t13max.common.exception.CommonException;
-import com.t13max.common.manager.ManagerBase;
-import com.t13max.game.Const;
-import com.t13max.game.config.BaseConfig;
-import com.t13max.game.server.BaseServer;
-import com.t13max.game.util.Log;
-import org.apache.logging.log4j.Logger;
-import org.yaml.snakeyaml.Yaml;
-
-import java.lang.reflect.Constructor;
-import java.util.concurrent.locks.LockSupport;
-
-/**
- * @author: t13max
- * @since: 17:29 2024/5/23
- */
-public class Application {
-
- private static BaseConfig config;
-
- private static String instanceName;
-
- public static void run(Class> clazz, String[] args) throws Exception {
-
- try {
- //初始化所有manager
- ManagerBase.initAllManagers();
-
- //加载配置
- loadConfig(clazz);
-
- initInstance();
-
- //启动监听服
- initServer(clazz);
-
- initData();
-
- //添加停服钩子 manager shutdown
- addShutdownHook(ManagerBase::shutdown);
-
- //阻塞主线程
- if (config.isPark()) LockSupport.park();
- } catch (Exception e) {
- //遇到任何异常 直接退出
- e.printStackTrace();
- System.exit(0);
- }
-
- }
-
- private static void initData() throws ClassNotFoundException {
- String dbFile = config.getDbFile();
- if (dbFile == null) {
- return;
- }
- //尝试加载数据库模块
- Class.forName("com.t13max.data.dao.SqlLiteUtil");
- }
-
- private static void initServer(Class> clazz) throws RuntimeException {
-
- NettyServer annotation = clazz.getAnnotation(NettyServer.class);
-
- if (annotation == null) {
- autoLogger().info("不启动监听...");
- return;
- }
-
- Class extends BaseServer> serverClazz = annotation.serverClazz();
- if (serverClazz == null) {
- autoLogger().info("不启动监听...");
- return;
- }
-
- Constructor extends BaseServer> constructor;
-
- try {
- constructor = serverClazz.getConstructor();
- } catch (NoSuchMethodException e) {
- throw new CommonException("无法启动监听, 没有空参构造");
- }
-
- BaseServer baseServer;
- try {
- baseServer = constructor.newInstance();
- } catch (Exception e) {
- throw new CommonException("无法启动监听, 创建server对象失败, error=" + e.getMessage());
- }
-
- try {
- //开启监听
- baseServer.startTcpServer();
- //停服
- addShutdownHook(baseServer::shutdown);
- } catch (InterruptedException e) {
- throw new CommonException("监听服被打断");
- }
- }
-
- /**
- * 实例初始化
- *
- * @Author t13max
- * @Date 19:02 2024/5/23
- */
- private static void initInstance() {
- String instanceId = config.getInstanceId();
-
- String[] split = instanceId.split("-");
- instanceName = split[0];
- }
-
- /**
- * 获取配置文件
- *
- * @Author t13max
- * @Date 17:58 2024/5/23
- */
- public static T config() {
- return (T) config;
- }
-
- /**
- * 添加停服钩子
- *
- * @Author t13max
- * @Date 18:32 2024/5/23
- */
- public static void addShutdownHook(Runnable runnable) {
- Runtime.getRuntime().addShutdownHook(new Thread(runnable));
- }
-
- /**
- * 加载配置文件
- *
- * @Author t13max
- * @Date 17:58 2024/5/23
- */
- private static void loadConfig(Class> clazz) {
-
- ApplicationConfig annotation = clazz.getAnnotation(ApplicationConfig.class);
-
- Class extends BaseConfig> configClazz = BaseConfig.class;
- if (annotation != null) {
- configClazz = annotation.configClazz();
- }
-
- Yaml yaml = new Yaml();
-
- config = yaml.loadAs(Application.class.getClassLoader().getResourceAsStream(Const.CONFIG_NAME), configClazz);
-
- //校验配置
- if (!configCheck()) {
- throw new CommonException("配置文件校验异常");
- }
- }
-
- private static boolean configCheck() {
- return config.check();
- }
-
- /**
- * 获取自适应log
- *
- * @Author t13max
- * @Date 19:04 2024/5/23
- */
- public static Logger autoLogger() {
-
- switch (instanceName) {
- case "scene" -> {
- return Log.scene;
- }
- case "game" -> {
- return Log.game;
- }
- case "battle" -> {
- return Log.battle;
- }
- default -> {
- return Log.def;
- }
- }
- }
-
-}
diff --git a/common-game/src/main/java/com/t13max/game/run/ApplicationConfig.java b/common-game/src/main/java/com/t13max/game/run/ApplicationConfig.java
deleted file mode 100644
index 83afa59..0000000
--- a/common-game/src/main/java/com/t13max/game/run/ApplicationConfig.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.t13max.game.run;
-
-import com.t13max.game.config.BaseConfig;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface ApplicationConfig {
-
- Class extends BaseConfig> configClazz();
-}
diff --git a/common-game/src/main/java/com/t13max/game/run/NettyServer.java b/common-game/src/main/java/com/t13max/game/run/NettyServer.java
deleted file mode 100644
index e7b43a6..0000000
--- a/common-game/src/main/java/com/t13max/game/run/NettyServer.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.t13max.game.run;
-
-import com.t13max.game.server.BaseServer;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface NettyServer {
-
- Class extends BaseServer> serverClazz();
-}
diff --git a/common-game/src/main/java/com/t13max/game/server/BaseServer.java b/common-game/src/main/java/com/t13max/game/server/BaseServer.java
deleted file mode 100644
index be8bbc9..0000000
--- a/common-game/src/main/java/com/t13max/game/server/BaseServer.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package com.t13max.game.server;
-
-import com.t13max.game.config.BaseConfig;
-import com.t13max.game.config.NettyConfig;
-import com.t13max.game.run.Application;
-import io.netty.bootstrap.ServerBootstrap;
-import io.netty.buffer.PooledByteBufAllocator;
-import io.netty.channel.*;
-import io.netty.channel.epoll.EpollServerSocketChannel;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.channel.socket.SocketChannel;
-import io.netty.channel.socket.nio.NioServerSocketChannel;
-
-import java.net.InetSocketAddress;
-
-/**
- * @author: t13max
- * @since: 18:42 2024/5/23
- */
-public abstract class BaseServer {
-
- private ServerBootstrap bootstrap;
-
- private Channel channel;
-
- protected EventLoopGroup bossGroup;
-
- protected EventLoopGroup workerGroup;
-
- protected ChannelInitializer channelInitializer;
-
- public void startTcpServer() throws InterruptedException {
-
- init();
-
- BaseConfig config = Application.config();
- NettyConfig configNetty = config.getNetty();
-
- bootstrap = new ServerBootstrap();
- bootstrap.group(bossGroup, workerGroup)
- .channel(configNetty.isUseEpoll() ? EpollServerSocketChannel.class : NioServerSocketChannel.class)
- .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, configNetty.getConnectTimeoutMillis())
- // 在defaults.yaml文件中,low.watermark默认大小为8388608,即8M;high.watermark默认大小为16777216,即16M
- .option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(configNetty.getLowWaterMark(), configNetty.getHighWaterMark()))
- .option(ChannelOption.SO_BACKLOG, configNetty.getSoBackLog())
- .option(ChannelOption.SO_REUSEADDR, configNetty.isSsoReuseAddr())
- .childOption(ChannelOption.TCP_NODELAY, configNetty.isTcpNodelay())
- .childOption(ChannelOption.SO_KEEPALIVE, configNetty.isSsoKeepAlive())
- .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
- .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
-
- bootstrap.childHandler(channelInitializer);
-
- InetSocketAddress address = new InetSocketAddress(configNetty.getPort());
- channel = bootstrap.bind(address).sync().channel();
- Application.autoLogger().info("netty server bind on {} success!", address);
-
- }
-
- /**
- * 关闭
- *
- * @Author t13max
- * @Date 19:12 2024/5/23
- */
- public void shutdown() {
- try {
-
- Application.autoLogger().info("netty shutdown begin!");
-
- if (null != channel) {
- ChannelFuture f = channel.close();
- f.awaitUninterruptibly();
- }
-
- } finally {
- if (this.workerGroup != null) {
- this.workerGroup.shutdownGracefully();
- }
- if (this.bossGroup != null) {
- this.bossGroup.shutdownGracefully();
- }
- }
-
- Application.autoLogger().info("NettyServer shutdown success!");
- }
-
- /**
- * 初始化各个组件
- *
- * @Author t13max
- * @Date 19:24 2024/5/23
- */
- protected abstract void init();
-
-}
diff --git a/common-game/src/main/java/com/t13max/game/server/BattleServer.java b/common-game/src/main/java/com/t13max/game/server/BattleServer.java
index 5d23e8c..10ef2c3 100644
--- a/common-game/src/main/java/com/t13max/game/server/BattleServer.java
+++ b/common-game/src/main/java/com/t13max/game/server/BattleServer.java
@@ -1,9 +1,11 @@
package com.t13max.game.server;
-import com.t13max.game.config.NettyConfig;
-import com.t13max.game.run.Application;
+import com.t13max.common.config.NettyConfig;
+import com.t13max.common.net.AbstractServer;
+import com.t13max.common.run.Application;
import com.t13max.game.server.codec.BattleServerHandler;
import com.t13max.game.server.codec.FrameDecoder;
+import com.t13max.game.util.Log;
import com.t13max.util.ThreadNameFactory;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
@@ -18,7 +20,7 @@
* @author: t13max
* @since: 18:44 2024/5/23
*/
-public class BattleServer extends BaseServer {
+public class BattleServer extends AbstractServer {
@Override
protected void init() {
@@ -27,11 +29,11 @@ protected void init() {
if (nettyConfig.isUseEpoll()) {
this.bossGroup = new EpollEventLoopGroup(1, new ThreadNameFactory("epoll-boss"));
this.workerGroup = new EpollEventLoopGroup(threadNum, new ThreadNameFactory("epoll-worker"));
- Application.autoLogger().info("use EpollEventLoopGroup.....");
+ Log.msg.info("use EpollEventLoopGroup.....");
} else {
this.bossGroup = new NioEventLoopGroup(1, new ThreadNameFactory("nio-boss"));
this.workerGroup = new NioEventLoopGroup(threadNum, new ThreadNameFactory("nio-worker"));
- Application.autoLogger().info("use NioEventLoopGroup.....");
+ Log.msg.info("use NioEventLoopGroup.....");
}
this.channelInitializer = new ChannelInitializer() {
diff --git a/common-game/src/main/java/com/t13max/game/server/GameServer.java b/common-game/src/main/java/com/t13max/game/server/GameServer.java
index 0d607b0..2bc1ff0 100644
--- a/common-game/src/main/java/com/t13max/game/server/GameServer.java
+++ b/common-game/src/main/java/com/t13max/game/server/GameServer.java
@@ -1,11 +1,12 @@
package com.t13max.game.server;
-import com.t13max.game.config.NettyConfig;
-import com.t13max.game.run.Application;
+import com.t13max.common.config.NettyConfig;
+import com.t13max.common.net.AbstractServer;
+import com.t13max.common.run.Application;
+import com.t13max.game.util.Log;
import com.t13max.util.ThreadNameFactory;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
-import io.netty.channel.EventLoopGroup;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
@@ -16,7 +17,7 @@
* @author: t13max
* @since: 18:44 2024/5/23
*/
-public class GameServer extends BaseServer {
+public class GameServer extends AbstractServer {
@Override
protected void init() {
@@ -25,11 +26,11 @@ protected void init() {
if (nettyConfig.isUseEpoll()) {
this.bossGroup = new EpollEventLoopGroup(1, new ThreadNameFactory("epoll-boss"));
this.workerGroup = new EpollEventLoopGroup(threadNum, new ThreadNameFactory("epoll-worker"));
- Application.autoLogger().info("use EpollEventLoopGroup.....");
+ Log.msg.info("use EpollEventLoopGroup.....");
} else {
this.bossGroup = new NioEventLoopGroup(1, new ThreadNameFactory("nio-boss"));
this.workerGroup = new NioEventLoopGroup(threadNum, new ThreadNameFactory("nio-worker"));
- Application.autoLogger().info("use NioEventLoopGroup.....");
+ Log.msg.info("use NioEventLoopGroup.....");
}
this.channelInitializer = new ChannelInitializer() {
diff --git a/common-game/src/main/java/com/t13max/game/util/Log.java b/common-game/src/main/java/com/t13max/game/util/Log.java
index 3505f70..1c91c87 100644
--- a/common-game/src/main/java/com/t13max/game/util/Log.java
+++ b/common-game/src/main/java/com/t13max/game/util/Log.java
@@ -12,7 +12,6 @@
public class Log {
public static Logger def = LogManager.getLogger("DEF");
public static Logger msg = LogManager.getLogger("MSG");
- public static Logger scene = LogManager.getLogger("SCENE");
public static Logger game = LogManager.getLogger("GAME");
public static Logger battle = LogManager.getLogger("BATTLE");
public static Logger template = LogManager.getLogger("TEMPLATE");
diff --git a/pom.xml b/pom.xml
index 8f8e385..ab05c86 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,6 +31,9 @@
1.0.1
1.0.1
1.0.1
+ 1.0.1
+ 1.0.0
+ 1.0.0
1.0.0
1.0.0
1.0.0
diff --git a/service-battle/src/main/java/com/t13max/fight/BattleApplication.java b/service-battle/src/main/java/com/t13max/fight/BattleApplication.java
index c0d2b2a..92ab6d8 100644
--- a/service-battle/src/main/java/com/t13max/fight/BattleApplication.java
+++ b/service-battle/src/main/java/com/t13max/fight/BattleApplication.java
@@ -3,12 +3,12 @@
import battle.api.CreateFightMatchReq;
import battle.api.LoginBattleReq;
import com.t13max.common.msg.MessageManager;
+import com.t13max.common.run.Application;
+import com.t13max.common.run.ConfigClazz;
+import com.t13max.common.run.ServerClazz;
import com.t13max.fight.msg.CreateMatchMessage;
import com.t13max.fight.msg.LoginBattleMessage;
import com.t13max.game.config.BattleConfig;
-import com.t13max.game.run.Application;
-import com.t13max.game.run.NettyServer;
-import com.t13max.game.run.ApplicationConfig;
import com.t13max.game.server.BattleServer;
import com.t13max.game.util.Log;
import message.id.MessageId;
@@ -19,8 +19,8 @@
* @author: t13max
* @since: 14:01 2024/5/23
*/
-@ApplicationConfig(configClazz = BattleConfig.class)
-@NettyServer(serverClazz = BattleServer.class)
+@ConfigClazz(configClazz = BattleConfig.class)
+@ServerClazz(serverClazz = BattleServer.class)
public class BattleApplication {
public static void main(String[] args) throws Exception {
diff --git a/service-battle/src/main/java/com/t13max/fight/attr/FightAttrManager.java b/service-battle/src/main/java/com/t13max/fight/attr/FightAttrManager.java
index 60d8254..3ce1b2c 100644
--- a/service-battle/src/main/java/com/t13max/fight/attr/FightAttrManager.java
+++ b/service-battle/src/main/java/com/t13max/fight/attr/FightAttrManager.java
@@ -36,7 +36,6 @@ public FightAttrManager(FightHero fightHero) {
}
private void initAttr() {
- Random random = new Random();
HeroHelper heroHelper = TemplateManager.inst().helper(HeroHelper.class);
TemplateHero template = heroHelper.getTemplate(owner.getTemplateId());
if (template == null) {
@@ -50,6 +49,7 @@ private void initAttr() {
valueAttrMap.put(FightAttrEnum.MASTERY, (double) template.mastery);
//临时
+ Random random = new Random();
rateAttrMap.put(FightAttrEnum.ATTACK, random.nextDouble(100));
rateAttrMap.put(FightAttrEnum.DEF, random.nextDouble(100));
rateAttrMap.put(FightAttrEnum.MAX_HP, random.nextDouble(100));
diff --git a/service-battle/src/main/java/com/t13max/fight/msg/LoginBattleMessage.java b/service-battle/src/main/java/com/t13max/fight/msg/LoginBattleMessage.java
index 5b56482..06e6f80 100644
--- a/service-battle/src/main/java/com/t13max/fight/msg/LoginBattleMessage.java
+++ b/service-battle/src/main/java/com/t13max/fight/msg/LoginBattleMessage.java
@@ -8,7 +8,7 @@
import com.t13max.common.session.ISession;
import com.t13max.data.dao.SqlLiteUtil;
import com.t13max.data.entity.AccountData;
-import com.t13max.data.util.UuidUtil;
+import com.t13max.data.mongo.util.UuidUtil;
import com.t13max.game.msg.*;
import message.id.MessageId;
diff --git a/service-client/src/main/java/com/t13max/client/ClientApplication.java b/service-client/src/main/java/com/t13max/client/ClientApplication.java
index 2eb6212..68a5b8e 100644
--- a/service-client/src/main/java/com/t13max/client/ClientApplication.java
+++ b/service-client/src/main/java/com/t13max/client/ClientApplication.java
@@ -1,16 +1,16 @@
package com.t13max.client;
import com.t13max.client.player.Player;
+import com.t13max.common.run.Application;
+import com.t13max.common.run.ConfigClazz;
import com.t13max.game.config.ClientConfig;
-import com.t13max.game.run.Application;
-import com.t13max.game.run.ApplicationConfig;
import com.t13max.game.util.Log;
/**
* @author: t13max
* @since: 17:19 2024/5/28
*/
-@ApplicationConfig(configClazz = ClientConfig.class)
+@ConfigClazz(configClazz = ClientConfig.class)
public class ClientApplication {
public static void main(String[] args) throws Exception {
diff --git a/service-game/src/main/java/com/t13max/game/feature/activity/ActivityMemory.java b/service-game/src/main/java/com/t13max/game/feature/activity/ActivityMemory.java
index 4f61fa0..7540a4d 100644
--- a/service-game/src/main/java/com/t13max/game/feature/activity/ActivityMemory.java
+++ b/service-game/src/main/java/com/t13max/game/feature/activity/ActivityMemory.java
@@ -1,8 +1,8 @@
package com.t13max.game.feature.activity;
+import com.t13max.data.mongo.MongoManager;
import com.t13max.game.feature.activity.data.ActivityData;
import com.t13max.game.feature.activity.data.IActFeature;
-import com.t13max.data.manager.AsyncSaveManager;
import com.t13max.game.feature.activity.enums.ActModelEnum;
import com.t13max.game.memory.SingleMemory;
import com.t13max.game.util.Log;
@@ -22,7 +22,7 @@ public class ActivityMemory extends SingleMemory {
+public interface IMemory {
// 免库初始化
void init();
diff --git a/service-game/src/main/java/com/t13max/game/memory/MapMemory.java b/service-game/src/main/java/com/t13max/game/memory/MapMemory.java
index 0777b36..b5cc556 100644
--- a/service-game/src/main/java/com/t13max/game/memory/MapMemory.java
+++ b/service-game/src/main/java/com/t13max/game/memory/MapMemory.java
@@ -1,9 +1,9 @@
package com.t13max.game.memory;
import com.google.protobuf.MessageLite;
-import com.t13max.data.dao.MongoUtil;
-import com.t13max.data.entity.IData;
-import com.t13max.data.manager.AsyncSaveManager;
+import com.t13max.data.mongo.AutoSaveManager;
+import com.t13max.data.mongo.IData;
+import com.t13max.data.mongo.MongoManager;
import com.t13max.game.util.Log;
import java.util.HashMap;
@@ -24,7 +24,7 @@ public abstract class MapMemory exte
@Override
public void load() {
- List dataList = MongoUtil.findList(getDataClazz());
+ List dataList = MongoManager.inst().findList(getDataClazz());
for (DATA data : dataList) {
dataMap.put(data.getId(), data);
}
@@ -32,14 +32,14 @@ public void load() {
@Override
public void batchSave() {
- AsyncSaveManager.inst().batchSave(getAll());
+ AutoSaveManager.inst().batchSave(getAll());
}
public abstract PB buildPb(long id);
public void delete(long id) {
DATA remove = dataMap.remove(id);
- AsyncSaveManager.inst().delete(remove);
+ AutoSaveManager.inst().delete(remove);
}
public List buildPbList() {
diff --git a/service-game/src/main/java/com/t13max/game/memory/SingleMemory.java b/service-game/src/main/java/com/t13max/game/memory/SingleMemory.java
index 47c8f2d..d960307 100644
--- a/service-game/src/main/java/com/t13max/game/memory/SingleMemory.java
+++ b/service-game/src/main/java/com/t13max/game/memory/SingleMemory.java
@@ -1,9 +1,9 @@
package com.t13max.game.memory;
import com.google.protobuf.MessageLite;
-import com.t13max.data.dao.MongoUtil;
-import com.t13max.data.entity.IData;
-import com.t13max.data.manager.AsyncSaveManager;
+import com.t13max.data.mongo.AutoSaveManager;
+import com.t13max.data.mongo.IData;
+import com.t13max.data.mongo.MongoManager;
/**
@@ -18,12 +18,12 @@ public abstract class SingleMemory e
@Override
public void load() {
- this.data = MongoUtil.findById(player.getUuid(), getDataClazz());
+ this.data = MongoManager.inst().findById(getDataClazz(), player.getUuid());
}
@Override
public void batchSave() {
- AsyncSaveManager.inst().save(data);
+ AutoSaveManager.inst().save(data);
}
public abstract PB buildPb();
diff --git a/service-game/src/main/java/com/t13max/game/msg/AbstractMessage.java b/service-game/src/main/java/com/t13max/game/msg/AbstractMessage.java
index 0724be9..b72a20f 100644
--- a/service-game/src/main/java/com/t13max/game/msg/AbstractMessage.java
+++ b/service-game/src/main/java/com/t13max/game/msg/AbstractMessage.java
@@ -7,7 +7,6 @@
import com.t13max.common.session.ISession;
import com.t13max.game.player.Player;
import com.t13max.game.player.PlayerManager;
-import com.t13max.game.run.Application;
import com.t13max.game.util.Log;
/**
@@ -24,7 +23,7 @@ public final void doMessage(ISession session, MessagePack messagePack) {
T message = messagePack.getMessageLite();
Player player = PlayerManager.inst().getPlayer(session.getUuid());
if (player == null) {
- Application.autoLogger().error("玩家不存在, 无法处理消息, uuid={}, message={}", session.getUuid(), message);
+ Log.msg.error("玩家不存在, 无法处理消息, uuid={}, message={}", session.getUuid(), message);
return;
}
//在自己的业务线程池中执行
diff --git a/service-game/src/main/java/com/t13max/game/player/Player.java b/service-game/src/main/java/com/t13max/game/player/Player.java
index a4d1519..a8351de 100644
--- a/service-game/src/main/java/com/t13max/game/player/Player.java
+++ b/service-game/src/main/java/com/t13max/game/player/Player.java
@@ -3,8 +3,8 @@
import com.google.protobuf.MessageLite;
import com.t13max.common.action.ActionQueue;
import com.t13max.common.action.IJobName;
-import com.t13max.data.entity.IData;
import com.t13max.data.entity.RoleData;
+import com.t13max.data.mongo.IData;
import com.t13max.game.memory.MemoryTable;
import com.t13max.game.memory.IMemory;
import com.t13max.game.util.Log;
diff --git a/service-game/src/main/java/com/t13max/game/player/PlayerManager.java b/service-game/src/main/java/com/t13max/game/player/PlayerManager.java
index 693f6ea..615e8b8 100644
--- a/service-game/src/main/java/com/t13max/game/player/PlayerManager.java
+++ b/service-game/src/main/java/com/t13max/game/player/PlayerManager.java
@@ -1,9 +1,9 @@
package com.t13max.game.player;
import com.t13max.common.action.ActionExecutor;
+import com.t13max.common.config.ActionConfig;
import com.t13max.common.manager.ManagerBase;
-import com.t13max.game.config.ActionConfig;
-import com.t13max.game.run.Application;
+import com.t13max.common.run.Application;
import lombok.Getter;
import java.util.LinkedList;
@@ -39,8 +39,7 @@ protected void onShutdown() {
@Override
public void init() {
- ActionConfig actionConfig = Application.config().getAction();
- actionExecutor = ActionExecutor.createExecutor(actionConfig.getCore(), actionConfig.getMax(), actionConfig.getName());
+ actionExecutor = ActionExecutor.createExecutor();
}
public Player getPlayer(long uuid) {
diff --git a/service-rank/src/main/java/com/t13max/rank/consts/Const.java b/service-rank/src/main/java/com/t13max/rank/consts/Const.java
new file mode 100644
index 0000000..cd529af
--- /dev/null
+++ b/service-rank/src/main/java/com/t13max/rank/consts/Const.java
@@ -0,0 +1,21 @@
+package com.t13max.rank.consts;
+
+/**
+ * @author t13max
+ * @since 15:12 2024/10/31
+ */
+public interface Const {
+
+ String RANK_DB_CACHE = "rank_db_cache";
+ String RANK_DATA = "rank_data";
+ String VIEW_RANK_DATA = "view_rank_data";
+ String RANK_ALL_VIEW = "rank_all_view";
+ String PID_MAPPER_RANK_DATA = "pid_mapper_rank_data";
+ String REF_RANK_LOCK = "ref_rank_lock";
+ String UP_RANK_LOCK = "up_rank_lock";
+ String RANK_QUEUE = "rank_queue";
+ String RANK_RESTORE_STATE = "rank_restore_state";
+ String RANK_RESTORE_LOCK = "rank_restore_lock";
+ String RANK_TIMING_DUMP = "rank_timing_dump";
+ int MAX_PAGE_LEN = 1000;
+}
diff --git a/service-rank/src/main/java/com/t13max/rank/manager/RankManager.java b/service-rank/src/main/java/com/t13max/rank/manager/RankManager.java
index 9b21636..8d71ec3 100644
--- a/service-rank/src/main/java/com/t13max/rank/manager/RankManager.java
+++ b/service-rank/src/main/java/com/t13max/rank/manager/RankManager.java
@@ -1,6 +1,9 @@
package com.t13max.rank.manager;
import com.t13max.common.manager.ManagerBase;
+import com.t13max.data.redis.RedisManager;
+import com.t13max.rank.consts.Const;
+import org.redisson.api.RBlockingQueue;
import java.util.concurrent.*;
@@ -12,7 +15,8 @@ public class RankManager extends ManagerBase {
private final ScheduledExecutorService autoSaveExecutor = Executors.newSingleThreadScheduledExecutor();
- private BlockingQueue updateQueue=new LinkedBlockingQueue<>();
+ private RBlockingQueue rankQueue;
+
public RankManager inst() {
return inst(RankManager.class);
}
@@ -24,6 +28,8 @@ protected void onShutdown() {
@Override
protected void init() {
+
+ rankQueue = RedisManager.inst().getBlockingQueue(Const.RANK_QUEUE);
//反序列化
autoSaveExecutor.scheduleAtFixedRate(this::rankDump, 5, 5, TimeUnit.SECONDS);
}
diff --git a/service-rank/src/main/java/com/t13max/rank/rpc/RankServiceImpl.java b/service-rank/src/main/java/com/t13max/rank/rpc/RankServiceImpl.java
new file mode 100644
index 0000000..fad54bc
--- /dev/null
+++ b/service-rank/src/main/java/com/t13max/rank/rpc/RankServiceImpl.java
@@ -0,0 +1,12 @@
+package com.t13max.rank.rpc;
+
+import com.t13max.game.api.IRankService;
+import com.t13max.rpc.anno.RpcImpl;
+
+/**
+ * @author t13max
+ * @since 15:00 2024/10/30
+ */
+@RpcImpl
+public class RankServiceImpl implements IRankService {
+}