Search in sources :

Example 26 with KafkaMsgKey

use of com.code.server.constant.kafka.KafkaMsgKey in project summer by foxsugar.

the class RoomMsgDispatch method dispatch.

public static void dispatch(ConsumerRecord<String, String> record) {
    try {
        String keyValue = record.key();
        String valueStr = record.value();
        KafkaMsgKey msgKey = JsonUtil.readValue(keyValue, KafkaMsgKey.class);
        JsonNode msgValue = JsonUtil.readTree(valueStr);
        String service = msgValue.get("service").asText();
        String method = msgValue.get("method").asText();
        JsonNode params = msgValue.get("params");
        String roomId = msgKey.getRoomId();
        long userId = msgKey.getUserId();
        int code = dispatchRoomService(method, params, userId, roomId);
        if (code != 0) {
            MsgSender.sendMsg2Player(service, method, code, userId);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 27 with KafkaMsgKey

use of com.code.server.constant.kafka.KafkaMsgKey in project summer by foxsugar.

the class CowRobot method raise.

@Override
public void raise(GameCow game) {
    String roomId = game.getRoom().getRoomId();
    int partition = SpringUtil.getBean(ServerConfig.class).getServerId();
    KafkaMsgKey msgKey = new KafkaMsgKey();
    msgKey.setRoomId(roomId);
    msgKey.setPartition(partition);
    Map<String, Object> put = new HashMap();
    put.put("addChip", 1);
    for (PlayerCow p : game.getPlayerCardInfos().values()) {
        if (p.userId != game.room.getBankerId() && 0 == p.getRaise()) {
            msgKey.setUserId(p.getUserId());
            put.put("userId", p.getUserId());
        }
    }
    ResponseRobotVo result = new ResponseRobotVo("gameService", "raise", put);
    SpringUtil.getBean(MsgProducer.class).send2Partition("gameService", partition, msgKey, result);
}
Also used : ServerConfig(com.code.server.game.poker.config.ServerConfig) HashMap(java.util.HashMap) MsgProducer(com.code.server.kafka.MsgProducer) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey) ResponseRobotVo(com.code.server.game.poker.robot.ResponseRobotVo)

Example 28 with KafkaMsgKey

use of com.code.server.constant.kafka.KafkaMsgKey in project summer by foxsugar.

the class CowRobot method getReady.

@Override
public void getReady(RoomCow roomCow) {
    String roomId = roomCow.getRoomId();
    int partition = SpringUtil.getBean(ServerConfig.class).getServerId();
    KafkaMsgKey msgKey = new KafkaMsgKey();
    msgKey.setRoomId(roomId);
    msgKey.setPartition(partition);
    for (Long l : roomCow.getUserStatus().keySet()) {
        if (0 == roomCow.getUserStatus().get(l)) {
            msgKey.setUserId(l);
        }
    }
    Map<String, Object> put = new HashMap();
    ResponseRobotVo result = new ResponseRobotVo("roomService", "getReady", put);
    SpringUtil.getBean(MsgProducer.class).send2Partition("roomService", partition, msgKey, result);
}
Also used : ServerConfig(com.code.server.game.poker.config.ServerConfig) HashMap(java.util.HashMap) MsgProducer(com.code.server.kafka.MsgProducer) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey) ResponseRobotVo(com.code.server.game.poker.robot.ResponseRobotVo)

Example 29 with KafkaMsgKey

use of com.code.server.constant.kafka.KafkaMsgKey in project summer by foxsugar.

the class CowRobot method compare.

@Override
public void compare(GameCow game) {
    String roomId = game.getRoom().getRoomId();
    int partition = SpringUtil.getBean(ServerConfig.class).getServerId();
    KafkaMsgKey msgKey = new KafkaMsgKey();
    msgKey.setRoomId(roomId);
    msgKey.setPartition(partition);
    Map<String, Object> put = new HashMap();
    for (PlayerCow p : game.getPlayerCardInfos().values()) {
        if (0 == p.getKill()) {
            msgKey.setUserId(p.getUserId());
            put.put("userId", p.getUserId());
        }
    }
    ResponseRobotVo result = new ResponseRobotVo("gameService", "compare", put);
    SpringUtil.getBean(MsgProducer.class).send2Partition("gameService", partition, msgKey, result);
}
Also used : ServerConfig(com.code.server.game.poker.config.ServerConfig) HashMap(java.util.HashMap) MsgProducer(com.code.server.kafka.MsgProducer) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey) ResponseRobotVo(com.code.server.game.poker.robot.ResponseRobotVo)

Example 30 with KafkaMsgKey

use of com.code.server.constant.kafka.KafkaMsgKey in project summer by foxsugar.

the class DouDiZhuGoldRobot method pass.

@Override
public void pass(GameDouDiZhu game) {
    String roomId = game.getRoom().getRoomId();
    int partition = SpringUtil.getBean(ServerConfig.class).getServerId();
    KafkaMsgKey msgKey = new KafkaMsgKey();
    msgKey.setUserId(game.getPlayTurn());
    msgKey.setRoomId(roomId);
    msgKey.setPartition(partition);
    // 按service的名字 分topic
    // {"service":"gameService","method":"pass","params":{"userId":"8"}}
    Map<String, Object> put = new HashMap<>();
    put.put("userId", game.getPlayTurn());
    ResponseRobotVo result = new ResponseRobotVo("gameService", "pass", put);
    SpringUtil.getBean(MsgProducer.class).send2Partition("gameService", partition, msgKey, result);
}
Also used : ServerConfig(com.code.server.game.poker.config.ServerConfig) HashMap(java.util.HashMap) MsgProducer(com.code.server.kafka.MsgProducer) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey) ResponseRobotVo(com.code.server.game.poker.robot.ResponseRobotVo)

Aggregations

KafkaMsgKey (com.code.server.constant.kafka.KafkaMsgKey)32 MsgProducer (com.code.server.kafka.MsgProducer)25 HashMap (java.util.HashMap)14 ServerConfig (com.code.server.game.poker.config.ServerConfig)11 ResponseRobotVo (com.code.server.game.poker.robot.ResponseRobotVo)11 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 KafkaListener (org.springframework.kafka.annotation.KafkaListener)3 UserBean (com.code.server.constant.game.UserBean)2 UserRecord (com.code.server.constant.game.UserRecord)2 ResponseVo (com.code.server.constant.response.ResponseVo)2 UserServiceMsgDispatch (com.code.server.login.service.UserServiceMsgDispatch)2 CardStruct (com.code.server.constant.game.CardStruct)1 GameRecord (com.code.server.constant.game.GameRecord)1 RoomRecord (com.code.server.constant.game.RoomRecord)1 ClubServiceMsgDispatch (com.code.server.login.service.ClubServiceMsgDispatch)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1