Search in sources :

Example 11 with MsgProducer

use of com.code.server.kafka.MsgProducer 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 12 with MsgProducer

use of com.code.server.kafka.MsgProducer 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 13 with MsgProducer

use of com.code.server.kafka.MsgProducer 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)

Example 14 with MsgProducer

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

the class GameDouDiZhu method genRecord.

protected void genRecord() {
    long id = IdWorker.getDefaultInstance().nextId();
    genRecord(playerCardInfos.values().stream().collect(Collectors.toMap(PlayerCardInfoDouDiZhu::getUserId, PlayerCardInfoDouDiZhu::getScore)), room, id);
    // 回放
    replay.setId(id);
    replay.setCount(playerCardInfos.size());
    replay.setRoom_uuid(this.room.getUuid());
    replay.setRoomInfo(this.room.toVo(0));
    KafkaMsgKey kafkaMsgKey = new KafkaMsgKey().setMsgId(KAFKA_MSG_ID_REPLAY);
    MsgProducer msgProducer = SpringUtil.getBean(MsgProducer.class);
    msgProducer.send(IKafaTopic.CENTER_TOPIC, kafkaMsgKey, replay);
}
Also used : MsgProducer(com.code.server.kafka.MsgProducer) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey)

Aggregations

MsgProducer (com.code.server.kafka.MsgProducer)14 KafkaMsgKey (com.code.server.constant.kafka.KafkaMsgKey)13 HashMap (java.util.HashMap)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 GameRecord (com.code.server.constant.game.GameRecord)1 RoomRecord (com.code.server.constant.game.RoomRecord)1 Club (com.code.server.db.model.Club)1