Search in sources :

Example 6 with TimerNode

use of com.code.server.util.timer.TimerNode in project summer by foxsugar.

the class CenterService method work.

public static void work() {
    // 检测服务器状态
    CheckHeart.check();
    // 保存玩家
    GameTimer.addTimerNode(new TimerNode(System.currentTimeMillis(), 1000L * 60 * 5, true, CenterService::saveUser));
    // 在线记录
    GameTimer.addTimerNode(new TimerNode(System.currentTimeMillis(), 1000L * 60 * 10, true, CenterService::onlineRecord));
}
Also used : TimerNode(com.code.server.util.timer.TimerNode)

Example 7 with TimerNode

use of com.code.server.util.timer.TimerNode in project summer by foxsugar.

the class MahjongApplication method main.

public static void main(String[] args) throws RegisterFailedException, IOException {
    SpringApplication.run(MahjongApplication.class, args);
    ServerConfig serverConfig = SpringUtil.getBean(ServerConfig.class);
    // 加载数据
    DataManager.initData(serverConfig.getDataFile());
    // 注册
    RedisManager.getGameRedisService().register(serverConfig.getServerType(), serverConfig.getServerId());
    // timer
    ThreadPool.execute(GameTimer.getInstance()::fire);
    // 心跳
    System.out.println("启动心跳");
    GameTimer.addTimerNode(new TimerNode(System.currentTimeMillis(), IConstant.SECOND_5, true, () -> RedisManager.getGameRedisService().heart(serverConfig.getServerId())));
// MsgConsumer.startAConsumer("gameLogicService", serverConfig.getServerId(), MsgDispatch::dispatch);
// MsgConsumer.startAConsumer("reconnService", serverConfig.getServerId(), MsgDispatch::dispatch);
// MsgConsumer.startAConsumer("mahjongRoomService", serverConfig.getServerId(), MsgDispatch::dispatch);
// MsgConsumer.startAConsumer("roomService", serverConfig.getServerId(), RoomMsgDispatch::dispatch);
}
Also used : ServerConfig(com.code.server.game.mahjong.config.ServerConfig) TimerNode(com.code.server.util.timer.TimerNode)

Example 8 with TimerNode

use of com.code.server.util.timer.TimerNode in project summer by foxsugar.

the class RoomHitGoldFlower method createHitGoldFlowerRoom.

public static int createHitGoldFlowerRoom(long userId, int gameNumber, int personNumber, int cricleNumber, int multiple, int caiFen, int menPai, String gameType, String roomType, boolean isAA, boolean isJoin) throws DataNotFoundException {
    RoomHitGoldFlower room = getRoomInstance(roomType);
    room.personNumber = personNumber;
    room.roomId = getRoomIdStr(genRoomId());
    room.createUser = userId;
    room.gameType = gameType;
    room.roomType = roomType;
    room.isAA = isAA;
    room.isCreaterJoin = isJoin;
    room.multiple = multiple;
    room.caiFen = caiFen;
    room.menPai = menPai;
    room.bankerId = userId;
    room.cricleNumber = cricleNumber;
    room.init(gameNumber, multiple);
    int code = room.joinRoom(userId, isJoin);
    if (code != 0) {
        return code;
    }
    // 代建房 定时解散
    if (!isJoin) {
        // 给代建房 开房者 扣钱
        if (RedisManager.getUserRedisService().getUserMoney(userId) < room.createNeedMoney) {
            return ErrorCode.CANNOT_CREATE_ROOM_MONEY;
        }
        room.spendMoney();
        TimerNode prepareRoomNode = new TimerNode(System.currentTimeMillis(), IConstant.HOUR_1, false, room::dissolutionRoom);
        room.prepareRoomTimerNode = prepareRoomNode;
        GameTimer.addTimerNode(prepareRoomNode);
    }
    ServerConfig serverConfig = SpringUtil.getBean(ServerConfig.class);
    RoomManager.addRoom(room.roomId, "" + serverConfig.getServerId(), room);
    IdWorker idWorker = new IdWorker(serverConfig.getServerId(), 0);
    room.setUuid(idWorker.nextId());
    MsgSender.sendMsg2Player(new ResponseVo("pokerRoomService", "createHitGoldFlowerRoom", room.toVo(userId)), userId);
    return 0;
}
Also used : ServerConfig(com.code.server.game.poker.config.ServerConfig) IdWorker(com.code.server.util.IdWorker) TimerNode(com.code.server.util.timer.TimerNode)

Example 9 with TimerNode

use of com.code.server.util.timer.TimerNode in project summer by foxsugar.

the class RoomPaijiuByNotInRoom method createRoomNotInRoom.

public static int createRoomNotInRoom(long userId, String roomType, String gameType, Integer gameNumber, boolean isCreaterJoin) throws DataNotFoundException {
    RoomPaijiu roomPaijiu = new RoomPaijiu();
    roomPaijiu.setRoomId(Room.getRoomIdStr(Room.genRoomId()));
    roomPaijiu.setRoomType(roomType);
    roomPaijiu.setGameType(gameType);
    roomPaijiu.setGameNumber(gameNumber);
    roomPaijiu.setBankerId(0L);
    roomPaijiu.setCreateUser(userId);
    roomPaijiu.setPersonNumber(4);
    roomPaijiu.setCreaterJoin(isCreaterJoin);
    roomPaijiu.init(gameNumber, 1);
    // 代建房 定时解散
    if (!isCreaterJoin) {
        // 给代建房 开房者 扣钱
        if (RedisManager.getUserRedisService().getUserMoney(userId) < roomPaijiu.getCreateNeedMoney()) {
            RoomManager.removeRoom(roomPaijiu.getRoomId());
            return ErrorCode.CANNOT_JOIN_ROOM_NO_MONEY;
        }
        roomPaijiu.spendMoney();
        TimerNode prepareRoomNode = new TimerNode(System.currentTimeMillis(), IConstant.HOUR_1, false, roomPaijiu::dissolutionRoom);
        roomPaijiu.prepareRoomTimerNode = prepareRoomNode;
        GameTimer.addTimerNode(prepareRoomNode);
    }
    ServerConfig serverConfig = SpringUtil.getBean(ServerConfig.class);
    RoomManager.addRoom(roomPaijiu.getRoomId(), "" + serverConfig.getServerId(), roomPaijiu);
    IdWorker idword = new IdWorker(serverConfig.getServerId(), 0);
    roomPaijiu.setUuid(idword.nextId());
    MsgSender.sendMsg2Player(new ResponseVo("pokerRoomService", "createPaijiuRoomNotInRoom", roomPaijiu.toVo(userId)), userId);
    return 0;
}
Also used : ServerConfig(com.code.server.game.poker.config.ServerConfig) IdWorker(com.code.server.util.IdWorker) TimerNode(com.code.server.util.timer.TimerNode) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 10 with TimerNode

use of com.code.server.util.timer.TimerNode in project summer by foxsugar.

the class RoomPullMice method createRoom.

public static int createRoom(long userId, String roomType, String gameType, int gameNumber, int personNumber, boolean isJoin, int multiple, boolean hasWubuFeng) throws DataNotFoundException {
    RoomPullMice room = new RoomPullMice();
    room.personNumber = personNumber;
    room.roomId = getRoomIdStr(genRoomId());
    room.createUser = userId;
    room.gameType = gameType;
    room.isCreaterJoin = isJoin;
    room.multiple = multiple;
    room.bankerId = userId;
    room.roomType = roomType;
    room.setCanWuBuFeng(hasWubuFeng);
    room.init(gameNumber, multiple);
    // 假设最大局数是8局
    room.maxGameCount = gameNumber;
    int code = room.joinRoom(userId, isJoin);
    if (code != 0) {
        return code;
    }
    // 代建房 定时解散
    if (!isJoin) {
        // 给代建房 开房者 扣钱
        if (RedisManager.getUserRedisService().getUserMoney(userId) < room.createNeedMoney) {
            RoomManager.removeRoom(room.getRoomId());
            return ErrorCode.CANNOT_CREATE_ROOM_MONEY;
        }
        room.spendMoney();
        TimerNode prepareRoomNode = new TimerNode(System.currentTimeMillis(), IConstant.HOUR_1, false, room::dissolutionRoom);
        room.prepareRoomTimerNode = prepareRoomNode;
        GameTimer.addTimerNode(prepareRoomNode);
    }
    ServerConfig serverConfig = SpringUtil.getBean(ServerConfig.class);
    RoomManager.addRoom(room.roomId, "" + serverConfig.getServerId(), room);
    IdWorker idWorker = new IdWorker(serverConfig.getServerId(), 0);
    room.setUuid(idWorker.nextId());
    MsgSender.sendMsg2Player(new ResponseVo("pokerRoomService", "createPullMiceRoom", room.toVo(userId)), userId);
    return 0;
}
Also used : ServerConfig(com.code.server.game.poker.config.ServerConfig) IdWorker(com.code.server.util.IdWorker) TimerNode(com.code.server.util.timer.TimerNode) ResponseVo(com.code.server.constant.response.ResponseVo)

Aggregations

TimerNode (com.code.server.util.timer.TimerNode)12 ServerConfig (com.code.server.game.poker.config.ServerConfig)7 IdWorker (com.code.server.util.IdWorker)6 ResponseVo (com.code.server.constant.response.ResponseVo)4 ServerConfig (com.code.server.game.mahjong.config.ServerConfig)1 CowRobot (com.code.server.game.poker.cow.CowRobot)1 DouDiZhuGoldRobot (com.code.server.game.poker.doudizhu.DouDiZhuGoldRobot)1 RobotManager (com.code.server.game.poker.robot.RobotManager)1 TTZRobot (com.code.server.game.poker.tuitongzi.TTZRobot)1