Showing
1 changed file
with
0 additions
and
236 deletions
server/message/types.ts
deleted
100644 → 0
| 1 | -import { RoomDescription } from "../room/types"; | ||
| 2 | -import { UserData } from "../user/types"; | ||
| 3 | - | ||
| 4 | -export interface Message { | ||
| 5 | - readonly type: string; | ||
| 6 | -} | ||
| 7 | - | ||
| 8 | -/** | ||
| 9 | - * 클라 -> 서버 : 클라이언트에서 서버로 요청할 때 사용하는 메세지입니다. 요청 결과는 MessageResponse<undefined>입니다. | ||
| 10 | - * 클라 -> 서버 -> T : 위와 동일하지만 요청 결과가 MessageResponse<T>입니다. | ||
| 11 | - * 서버 -> 클라 : 서버에서 클라이언트로 전송되는 메세지입니다. | ||
| 12 | - * 클라 <-> 서버 : 양방향으로 사용되는 메세지입니다. | ||
| 13 | - */ | ||
| 14 | - | ||
| 15 | -/** | ||
| 16 | - * 서버에 Event를 보냈을 때 요청에 대한 결과를 전송받습니다. | ||
| 17 | - * @param ok 요청의 성공 여부입니다. | ||
| 18 | - * @param reason 요청 실패 사유입니다. 필요한 경우에만 포함됩니다. | ||
| 19 | - * @param result 요청에 대한 결과 메세지입니다. 특정한 메세지에 대해 요청이 성공하였을 때만 포함됩니다. | ||
| 20 | - */ | ||
| 21 | -export interface MessageResponse<T> { | ||
| 22 | - ok: boolean; | ||
| 23 | - reason?: string; | ||
| 24 | - result?: T; | ||
| 25 | -} | ||
| 26 | - | ||
| 27 | -/** | ||
| 28 | - * 클라 -> 서버 | ||
| 29 | - * 로그인 정보를 서버에게 전송합니다. | ||
| 30 | - */ | ||
| 31 | -export class LoginMessage implements Message { | ||
| 32 | - readonly type = MessageType.LOGIN; | ||
| 33 | - constructor(public username: string) {} | ||
| 34 | -} | ||
| 35 | - | ||
| 36 | -/** | ||
| 37 | - * 클라 -> 서버 -> RoomDescription[] | ||
| 38 | - * 방 목록을 요청합니다. | ||
| 39 | - */ | ||
| 40 | -export class RoomListRequestMessage implements Message { | ||
| 41 | - readonly type = MessageType.ROOM_LIST_REQUEST; | ||
| 42 | - constructor() {} | ||
| 43 | -} | ||
| 44 | - | ||
| 45 | -/** | ||
| 46 | - * 클라 -> 서버 -> RoomInfo | ||
| 47 | - * 방에 접속합니다. | ||
| 48 | - */ | ||
| 49 | -export class RoomJoinMessage implements Message { | ||
| 50 | - readonly type = MessageType.ROOM_JOIN; | ||
| 51 | - constructor(public uuid: string) {} | ||
| 52 | -} | ||
| 53 | - | ||
| 54 | -/** | ||
| 55 | - * 클라 -> 서버 | ||
| 56 | - * 방에서 나갑니다. | ||
| 57 | - */ | ||
| 58 | -export class RoomLeaveMessage implements Message { | ||
| 59 | - readonly type = MessageType.ROOM_LEAVE; | ||
| 60 | - constructor() {} | ||
| 61 | -} | ||
| 62 | - | ||
| 63 | -/** | ||
| 64 | - * 클라 <- 서버 | ||
| 65 | - * 접속한 방에 새로운 유저가 들어오거나 나갈 때 전송됩니다. | ||
| 66 | - * @param state 유저가 입장하면 added, 퇴장하면 removed 값을 가집니다. | ||
| 67 | - * @param userdata 대상 유저입니다. | ||
| 68 | - */ | ||
| 69 | -export class RoomUserUpdateMessage implements Message { | ||
| 70 | - readonly type = MessageType.ROOM_USER_UPDATE; | ||
| 71 | - constructor( | ||
| 72 | - public state: "added" | "updated" | "removed", | ||
| 73 | - public userdata: UserData | ||
| 74 | - ) {} | ||
| 75 | -} | ||
| 76 | - | ||
| 77 | -/** | ||
| 78 | - * 클라 <-> 서버 | ||
| 79 | - * 접속한 방에서 채팅을 보내거나 받을 때 사용됩니다. 자신이 보낸 채팅은 서버에 의해 수신되지 않습니다. | ||
| 80 | - * @param message 메세지 내용입니다. | ||
| 81 | - * @param sender 채팅을 보낸 유저의 username입니다. 채팅이 클라이언트로 수신 될 경우에만 값을 가집니다. | ||
| 82 | - */ | ||
| 83 | -export class RoomChatMessage implements Message { | ||
| 84 | - readonly type = MessageType.ROOM_CHAT; | ||
| 85 | - constructor(public message: string, public sender?: string) {} | ||
| 86 | -} | ||
| 87 | - | ||
| 88 | -/** | ||
| 89 | - * 클라 <- 서버 | ||
| 90 | - * 라운드가 시작되었음을 알립니다. | ||
| 91 | - * @param round 현재 라운드 넘버입니다. (1부터 시작) | ||
| 92 | - * @param duration 초 단위의 라운드 시간입니다. | ||
| 93 | - * @param roles 모든 방 접속 인원의 역할입니다. | ||
| 94 | - */ | ||
| 95 | -export class RoundStartMessage implements Message { | ||
| 96 | - readonly type = MessageType.ROUND_START; | ||
| 97 | - constructor( | ||
| 98 | - public round: number, | ||
| 99 | - public duration: number, | ||
| 100 | - public roles: { | ||
| 101 | - username: string; | ||
| 102 | - role: "drawer" | "guesser" | "winner" | "spectator"; | ||
| 103 | - }[] | ||
| 104 | - ) {} | ||
| 105 | -} | ||
| 106 | - | ||
| 107 | -/** | ||
| 108 | - * 클라 <- 서버 | ||
| 109 | - * 라운드 시작시에 오직 drawer에게만 전송되는 메세지로, drawer가 선택할 수 있는 단어들입니다. | ||
| 110 | - */ | ||
| 111 | -export class RoundWordSetMessage implements Message { | ||
| 112 | - readonly type = MessageType.ROUND_WORD_SET; | ||
| 113 | - constructor(public words: string[]) {} | ||
| 114 | -} | ||
| 115 | - | ||
| 116 | -/** | ||
| 117 | - * 클라 -> 서버 | ||
| 118 | - * drawer가 단어를 선택하면 해당 메세지가 서버로 전송됩니다. | ||
| 119 | - * @param word RoundWordSetMessage에서 수신받은 단어 중 drawer가 선택한 단어입니다. | ||
| 120 | - */ | ||
| 121 | -export class RoundChooseWordMessage implements Message { | ||
| 122 | - readonly type = MessageType.ROUND_CHOOSE_WORD; | ||
| 123 | - constructor(public word: string) {} | ||
| 124 | -} | ||
| 125 | - | ||
| 126 | -/** | ||
| 127 | - * 클라 <- 서버 | ||
| 128 | - * drawer가 단어를 선택하였음을 알립니다. | ||
| 129 | - * @param length 정답 단어의 길이입니다. | ||
| 130 | - */ | ||
| 131 | -export class RoundWordChosenMessage implements Message { | ||
| 132 | - readonly type = MessageType.ROUND_WORD_CHOSEN; | ||
| 133 | - constructor(public length: number) {} | ||
| 134 | -} | ||
| 135 | - | ||
| 136 | -/** | ||
| 137 | - * 클라 <- 서버 | ||
| 138 | - * 서버가 클라이언트의 타이머를 동기화하기 위해 사용됩니다. 라운드가 시작하면 타이머는 초기화되며 기본 상태는 stopped입니다. | ||
| 139 | - * @param state 타이머의 동작, 정지 여부입니다. | ||
| 140 | - * @param time 타이머의 남은 시간입니다. 초 단위로 주어집니다. | ||
| 141 | - */ | ||
| 142 | -export class RoundTimerMessage implements Message { | ||
| 143 | - readonly type = MessageType.ROUND_TIMER; | ||
| 144 | - constructor(public state: "started" | "stopped", public time: number) {} | ||
| 145 | -} | ||
| 146 | - | ||
| 147 | -/** | ||
| 148 | - * 클라 <- 서버 | ||
| 149 | - * 라운드가 종료되었음을 알립니다. | ||
| 150 | - * @param answer 이번 라운드의 정답입니다. | ||
| 151 | - */ | ||
| 152 | -export class RoundFinishMessage implements Message { | ||
| 153 | - readonly type = MessageType.ROUND_FINISH; | ||
| 154 | - constructor(public answer: string) {} | ||
| 155 | -} | ||
| 156 | - | ||
| 157 | -/** | ||
| 158 | - * 클라 <- 서버 | ||
| 159 | - * 플레이어의 역할이 바뀌었음을 알립니다. | ||
| 160 | - * @param username 대상 유저의 username입니다. | ||
| 161 | - * @param role 대상 유저의 새로운 역할입니다. | ||
| 162 | - */ | ||
| 163 | -export class RoundRoleMessage implements Message { | ||
| 164 | - readonly type = MessageType.ROUND_ROLE; | ||
| 165 | - constructor( | ||
| 166 | - public username: string, | ||
| 167 | - public role: "drawer" | "guesser" | "winner" | "spectator" | ||
| 168 | - ) {} | ||
| 169 | -} | ||
| 170 | - | ||
| 171 | -/** | ||
| 172 | - * 클라 <- 서버 | ||
| 173 | - * 플레이어가 정답을 맞췄음을 알립니다. | ||
| 174 | - * @param answer 이번 라운드의 정답입니다. | ||
| 175 | - */ | ||
| 176 | -export class AnswerAcceptedMessage implements Message { | ||
| 177 | - readonly type = MessageType.ANSWER_ACCEPTED; | ||
| 178 | - constructor(public answer: string) {} | ||
| 179 | -} | ||
| 180 | - | ||
| 181 | -/** | ||
| 182 | - * 클라 <- 서버 | ||
| 183 | - * 게임이 종료되었음을 알립니다. 다시 준비 화면으로 돌아갑니다. | ||
| 184 | - */ | ||
| 185 | -export class GameFinishMessage implements Message { | ||
| 186 | - readonly type = MessageType.GAME_FINISH; | ||
| 187 | - constructor() {} | ||
| 188 | -} | ||
| 189 | - | ||
| 190 | -/** | ||
| 191 | - * 클라 <-> 서버 | ||
| 192 | - * 브러시 설정을 동기화합니다. drawer는 메세지를 서버에 보내고, 나머지 플레이어들은 서버에서 수신받습니다. | ||
| 193 | - * @param size 픽셀 단위의 브러시 지름입니다. | ||
| 194 | - * @param color 6자리 소문자 16진수로 표현된 브러시 색상입니다. | ||
| 195 | - * @param drawing 현재 브러시가 캔버스에 닿은 상태인지를 나타냅니다. | ||
| 196 | - */ | ||
| 197 | -export class PaintBrushMessage implements Message { | ||
| 198 | - readonly type = MessageType.PAINT_BRUSH; | ||
| 199 | - constructor( | ||
| 200 | - public size: number, | ||
| 201 | - public color: string, | ||
| 202 | - public drawing: boolean | ||
| 203 | - ) {} | ||
| 204 | -} | ||
| 205 | - | ||
| 206 | -/** | ||
| 207 | - * 클라 <-> 서버 | ||
| 208 | - * 브러시 위치를 동기화합니다. drawer는 메세지를 서버에 보내고, 나머지 플레이어들은 서버에서 수신받습니다. | ||
| 209 | - * 왼쪽 하단이 원점입니다. | ||
| 210 | - * @param x 픽셀 단위의 가로 위치입니다. | ||
| 211 | - * @param y 픽셀 단위의 세로 위치입니다. | ||
| 212 | - */ | ||
| 213 | -export class PaintMoveMessage implements Message { | ||
| 214 | - readonly type = MessageType.PAINT_MOVE; | ||
| 215 | - constructor(public x: number, public y: number) {} | ||
| 216 | -} | ||
| 217 | - | ||
| 218 | -export class MessageType { | ||
| 219 | - static readonly LOGIN = "login"; | ||
| 220 | - static readonly ROOM_LIST_REQUEST = "room_list_request"; | ||
| 221 | - static readonly ROOM_JOIN = "room_join"; | ||
| 222 | - static readonly ROOM_LEAVE = "room_leave"; | ||
| 223 | - static readonly ROOM_USER_UPDATE = "room_user_update"; | ||
| 224 | - static readonly ROOM_CHAT = "room_chat"; | ||
| 225 | - static readonly ROUND_START = "round_start"; | ||
| 226 | - static readonly ROUND_TIMER = "round_timer"; | ||
| 227 | - static readonly ROUND_FINISH = "round_finish"; | ||
| 228 | - static readonly ROUND_ROLE = "round_role"; | ||
| 229 | - static readonly ANSWER_ACCEPTED = "answer_accepted"; | ||
| 230 | - static readonly GAME_FINISH = "game_finish"; | ||
| 231 | - static readonly ROUND_WORD_SET = "round_word_set"; | ||
| 232 | - static readonly ROUND_CHOOSE_WORD = "round_choose_word"; | ||
| 233 | - static readonly ROUND_WORD_CHOSEN = "round_word_chosen"; | ||
| 234 | - static readonly PAINT_BRUSH = "paint_brush"; | ||
| 235 | - static readonly PAINT_MOVE = "paint_move"; | ||
| 236 | -} |
-
Please register or login to post a comment