Search in sources :

Example 1 with Room

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

the class MessageHandler method broadcasting.

@MessageMapping("/ready/{roomId}")
@SendTo("/from/ready/{roomId}")
public ReadySignal broadcasting(ReadySignal ready, @DestinationVariable long roomId) throws Exception {
    log.debug("ReadySignal arrived: /ready/{}, ready: {}", roomId, ready);
    Room room = lobby.getRoom(roomId);
    room.findByNickname(ready.getUserName()).toggleReady();
    if (room.isAllReady()) {
        ready.setStartTimer(true);
        room.createGameManager();
    }
    return ready;
}
Also used : Room(com.mapia.domain.Room) SendTo(org.springframework.messaging.handler.annotation.SendTo) MessageMapping(org.springframework.messaging.handler.annotation.MessageMapping)

Example 2 with Room

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

the class MessageHandler method broadcasting.

@MessageMapping("/access/{roomId}")
@SendTo("/from/access/{roomId}")
public ClientAccess broadcasting(ClientAccess access, @DestinationVariable long roomId) throws Exception {
    log.debug("ClientAccess arrived: /access/{}, access: {}", roomId, access);
    Room room = lobby.getRoom(roomId);
    access.setUsers(room.getUsers());
    return access;
}
Also used : Room(com.mapia.domain.Room) SendTo(org.springframework.messaging.handler.annotation.SendTo) MessageMapping(org.springframework.messaging.handler.annotation.MessageMapping)

Example 3 with Room

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

the class MessageHandler method broadcasting.

@MessageMapping("/gameStart/{roomId}/{userName}")
@SendTo("/from/gameStart/{roomId}/{userName}")
public String broadcasting(GameStart gameStart, @DestinationVariable long roomId, @DestinationVariable String userName) throws Exception {
    log.debug("GameStart arrived: /gameStart/{}/{}, gameStart: {}", roomId, userName, gameStart);
    Room gameRoom = lobby.getRoom(roomId);
    gameRoom.getUsers().forEach(user -> user.gameStart());
    return gameRoom.getUserRoleNameInGame(userName);
}
Also used : Room(com.mapia.domain.Room) SendTo(org.springframework.messaging.handler.annotation.SendTo) MessageMapping(org.springframework.messaging.handler.annotation.MessageMapping)

Example 4 with Room

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

the class RoomController method exitUserFromRoom.

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

Example 5 with Room

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

the class RoomController method enter.

@GetMapping("/{id}")
public String enter(@PathVariable long id, HttpSession session, Model model) {
    if (!HttpSessionUtils.isLoginUser(session)) {
        return "redirect:/login";
    }
    User user = HttpSessionUtils.getUserFromSession(session);
    if (!lobby.isExistRoom(id)) {
        session.removeAttribute(HttpSessionUtils.USER_SESSION_KEY);
        if (!user.isLobby()) {
            exitUserFromRoom(user);
        }
        return "redirect:/";
    }
    Room room = lobby.getRoom(id);
    if (!user.isAbleToEnter(id)) {
        session.removeAttribute(HttpSessionUtils.USER_SESSION_KEY);
        exitUserFromRoom(user);
        return "redirect:/";
    }
    if (room.isFull()) {
        return "redirect:/lobby";
    }
    if (room.isSecretMode()) {
    //TODO Add secret mode logic
    }
    //        room.getUsers().forEach(ser -> ser.ready()); // FOR TEST USE ONLY
    room.enter(user);
    model.addAttribute("room", room);
    model.addAttribute("user", user);
    return "room";
}
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