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();
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations