Search in sources :

Example 21 with KafkaMsgKey

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

the class TTZRobot method getReady.

@Override
public void getReady(RoomTuiTongZi room) {
    String roomId = room.getRoomId();
    int partition = SpringUtil.getBean(ServerConfig.class).getServerId();
    KafkaMsgKey msgKey = new KafkaMsgKey();
    msgKey.setRoomId(roomId);
    msgKey.setPartition(partition);
    for (Long l : room.getUserStatus().keySet()) {
        if (0 == room.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 22 with KafkaMsgKey

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

the class TTZRobot method bet.

@Override
public void bet(GameTuiTongZi 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("zhu", 1);
    for (PlayerTuiTongZi p : game.getPlayerCardInfos().values()) {
        if (p.getUserId() != game.room.getBankerId() && p.getBet() == null) {
            msgKey.setUserId(p.getUserId());
            put.put("userId", p.getUserId());
        }
    }
    ResponseRobotVo result = new ResponseRobotVo("gameService", "bet", 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 23 with KafkaMsgKey

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

the class Game method genRecord.

protected void genRecord(Map<Long, Double> scores, Room room, long id) {
    Map<String, Object> data = new HashMap<>();
    data.put("count", scores.size());
    data.put("room_uuid", room.getUuid());
    data.put("replay_id", id);
    GameRecord gameRecord = new GameRecord();
    gameRecord.setCurGameNumber(room.getCurGameNumber());
    scores.forEach((key, value) -> {
        UserRecord userRecord = new UserRecord();
        userRecord.setScore(value);
        userRecord.setUserId(key);
        userRecord.setRoomId(room.getRoomId());
        UserBean userBean = RedisManager.getUserRedisService().getUserBean(key);
        if (userBean != null) {
            userRecord.setName(userBean.getUsername());
        }
        gameRecord.getRecords().add(userRecord);
    });
    data.put("record", JsonUtil.toJson(gameRecord));
    KafkaMsgKey kafkaMsgKey = new KafkaMsgKey().setMsgId(KAFKA_MSG_ID_GAME_RECORD);
    MsgProducer msgProducer = SpringUtil.getBean(MsgProducer.class);
    msgProducer.send(IKafaTopic.CENTER_TOPIC, kafkaMsgKey, data);
}
Also used : UserRecord(com.code.server.constant.game.UserRecord) UserBean(com.code.server.constant.game.UserBean) HashMap(java.util.HashMap) MsgProducer(com.code.server.kafka.MsgProducer) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey) GameRecord(com.code.server.constant.game.GameRecord)

Example 24 with KafkaMsgKey

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

the class Room method getRoomClubByUser.

@Override
public int getRoomClubByUser(long userId) {
    Map<String, Object> result = new HashMap<>();
    result.put("userId", userId);
    if (this.clubId == null) {
        result.put("clubId", 0);
        MsgSender.sendMsg2Player(new ResponseVo("roomService", "getRoomClubByUser", result), userId);
    } else {
        result.put("clubId", this.clubId);
        KafkaMsgKey kafkaMsgKey = new KafkaMsgKey().setMsgId(KAFKA_MSG_ID_ROOM_CLUB_USER);
        MsgProducer msgProducer = SpringUtil.getBean(MsgProducer.class);
        msgProducer.send(IKafaTopic.CENTER_TOPIC, kafkaMsgKey, result);
    }
    return 0;
}
Also used : MsgProducer(com.code.server.kafka.MsgProducer) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey)

Example 25 with KafkaMsgKey

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

the class Room method genRoomRecord.

/**
 * 生成房间战绩
 */
public void genRoomRecord() {
    RoomRecord roomRecord = new RoomRecord();
    roomRecord.setRoomId(this.roomId);
    roomRecord.setId(this.getUuid());
    roomRecord.setType(this.roomType);
    roomRecord.setTime(System.currentTimeMillis());
    roomRecord.setClubId(clubId);
    roomRecord.setClubRoomModel(clubRoomModel);
    this.userScores.forEach((key, value) -> {
        UserRecord userRecord = new UserRecord();
        userRecord.setScore(value);
        userRecord.setUserId(key);
        UserBean userBean = RedisManager.getUserRedisService().getUserBean(key);
        if (userBean != null) {
            userRecord.setName(userBean.getUsername());
        }
        roomRecord.getRecords().add(userRecord);
    });
    KafkaMsgKey kafkaMsgKey = new KafkaMsgKey().setMsgId(KAFKA_MSG_ID_ROOM_RECORD);
    MsgProducer msgProducer = SpringUtil.getBean(MsgProducer.class);
    msgProducer.send(IKafaTopic.CENTER_TOPIC, kafkaMsgKey, roomRecord);
}
Also used : MsgProducer(com.code.server.kafka.MsgProducer) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey)

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