Search in sources :

Example 6 with Room

use of com.mapia.domain.Room in project 2017-01-HUDI-MAC-CHAR by NHNNEXT.

the class MessageHandler method broadcasting.

@MessageMapping("/vote/{roomId}")
@SendTo("/from/vote/{roomId}")
public GameResult broadcasting(VoteMessage voteMessage, @DestinationVariable long roomId) throws Exception {
    log.debug("voteMessage arrived: /vote/{}, voteMessage: {}", roomId, voteMessage);
    Room gameRoom = lobby.getRoom(roomId);
    return gameRoom.returnVoteResult(voteMessage);
}
Also used : Room(com.mapia.domain.Room) SendTo(org.springframework.messaging.handler.annotation.SendTo) MessageMapping(org.springframework.messaging.handler.annotation.MessageMapping)

Example 7 with Room

use of com.mapia.domain.Room in project 2017-01-HUDI-MAC-CHAR by NHNNEXT.

the class ApiRoomController method exitUserFromRoom.

private long exitUserFromRoom(User user) {
    long currentRoomId = user.getEnteredRoomId();
    Room room = lobby.getRoom(currentRoomId);
    room.exit(user);
    if (room.isEmpty()) {
        lobby.delRoom(currentRoomId);
    }
    return currentRoomId;
}
Also used : Room(com.mapia.domain.Room)

Example 8 with Room

use of com.mapia.domain.Room in project 2017-01-HUDI-MAC-CHAR by NHNNEXT.

the class ApiRoomController method enter.

@GetMapping("/{id}")
public RoomResult enter(@PathVariable long id, HttpSession session, Model model) {
    if (!HttpSessionUtils.isLoginUser(session)) {
        return RoomResult.invalidAccess(id);
    }
    User user = HttpSessionUtils.getUserFromSession(session);
    if (!lobby.isExistRoom(id)) {
        session.removeAttribute(HttpSessionUtils.USER_SESSION_KEY);
        if (!user.isLobby()) {
            exitUserFromRoom(user);
        }
        return RoomResult.invalidAccess(id);
    }
    Room room = lobby.getRoom(id);
    if (!user.isAbleToEnter(id)) {
        session.removeAttribute(HttpSessionUtils.USER_SESSION_KEY);
        exitUserFromRoom(user);
        return RoomResult.invalidAccess(id);
    }
    if (room.isFull()) {
        return RoomResult.rejectToEnterRoomOfFull(id);
    }
    if (room.isSecretMode()) {
    //TODO Add secret mode logic
    }
    room.enter(user);
    model.addAttribute("room", room);
    model.addAttribute("user", user);
    return RoomResult.successToEnterRoom(id);
}
Also used : User(com.mapia.domain.User) Room(com.mapia.domain.Room)

Aggregations

Room (com.mapia.domain.Room)8 MessageMapping (org.springframework.messaging.handler.annotation.MessageMapping)4 SendTo (org.springframework.messaging.handler.annotation.SendTo)4 User (com.mapia.domain.User)2