Toggle navigation
Toggle navigation
This project
Loading...
Sign in
강동현
/
nodejs-game
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
강동현
2021-05-26 22:04:41 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
54fd6c8da83102a85c1a02afdbee22f1d9ad9015
54fd6c8d
1 parent
ab43ac70
RoomListRequestMessage 추가
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
14 deletions
PROTOCOL.md
server/message/MessageHandlerRegistry.ts
server/message/handler/LoginHandler.ts
server/message/handler/roomListRequestHandler.ts
server/message/types.ts
server/room/RoomManager.ts
PROTOCOL.md
View file @
54fd6c8
...
...
@@ -12,7 +12,7 @@
## 로비
로비에서는 모든 방 목록을 확인하고 접속할 수 있습니다.
로그인에 성공하면 서버에서
`RoomListMessage`
가 전송
됩니다. 이 메세지는 모든 방에 관한 정보를 가지고 있습니다. 각 방은 고유한
`uuid`
값으로 구분됩니다.
로비에서는 모든 방 목록을 확인하고 접속할 수 있습니다.
서버에
`RoomListRequestMessage`
를 전송하면
`RoomDescription[]`
가 반환
됩니다. 이 메세지는 모든 방에 관한 정보를 가지고 있습니다. 각 방은 고유한
`uuid`
값으로 구분됩니다.
특정한 방에 접속하기 위해서는 서버에
`RoomJoinMessage`
를 보내면 됩니다. 요청이 성공하면
`RoomInfo`
가 반환됩니다.
`RoomInfo`
에는 본인을 제외한 다른 플레이어들의 정보만이 담겨 있습니다.
...
...
server/message/MessageHandlerRegistry.ts
View file @
54fd6c8
...
...
@@ -4,6 +4,7 @@ import { loginHandler } from "./handler/loginHandler";
import
{
roomChatHandler
}
from
"./handler/roomChatHandler"
;
import
{
roomJoinHandler
}
from
"./handler/roomJoinHandler"
;
import
{
roomLeaveHandler
}
from
"./handler/roomLeaveHandler"
;
import
{
roomListRequestHandler
}
from
"./handler/roomListRequestHandler"
;
import
{
Message
,
MessageResponse
,
MessageType
}
from
"./types"
;
export
class
MessageHandlerRegistry
{
...
...
@@ -11,6 +12,11 @@ export class MessageHandlerRegistry {
this
.
registerHandler
(
connection
,
MessageType
.
LOGIN
,
loginHandler
);
this
.
registerHandlerAuthed
(
connection
,
MessageType
.
ROOM_LIST_REQUEST
,
roomListRequestHandler
);
this
.
registerHandlerAuthed
(
connection
,
MessageType
.
ROOM_JOIN
,
roomJoinHandler
);
...
...
server/message/handler/LoginHandler.ts
View file @
54fd6c8
...
...
@@ -10,7 +10,5 @@ export function loginHandler(
connection
.
user
=
new
User
(
message
.
username
,
connection
);
console
.
log
(
`User
${
message
.
username
}
has logged in!`
);
RoomManager
.
instance
().
sendList
(
connection
);
return
{
ok
:
true
};
}
...
...
server/message/handler/roomListRequestHandler.ts
0 → 100644
View file @
54fd6c8
import
{
Connection
}
from
"../../connection/Connection"
;
import
{
RoomManager
}
from
"../../room/RoomManager"
;
import
{
RoomDescription
,
RoomInfo
}
from
"../../room/types"
;
import
{
User
}
from
"../../user/User"
;
import
{
MessageResponse
,
RoomListRequestMessage
}
from
"../types"
;
export
function
roomListRequestHandler
(
user
:
User
,
message
:
RoomListRequestMessage
):
MessageResponse
<
RoomDescription
[]
>
{
return
{
ok
:
true
,
result
:
RoomManager
.
instance
().
list
()
};
}
server/message/types.ts
View file @
54fd6c8
...
...
@@ -34,12 +34,12 @@ export class LoginMessage implements Message {
}
/**
* 클라
<- 서버
* 방
리스트를 서버에서 받아옵
니다.
* 클라
-> 서버 -> RoomDescription[]
* 방
목록을 요청합
니다.
*/
export
class
RoomListMessage
implements
Message
{
readonly
type
=
MessageType
.
ROOM_LIST
;
constructor
(
public
rooms
:
RoomDescription
[]
)
{}
export
class
RoomList
Request
Message
implements
Message
{
readonly
type
=
MessageType
.
ROOM_LIST
_REQUEST
;
constructor
()
{}
}
/**
...
...
@@ -87,7 +87,7 @@ export class RoomChatMessage implements Message {
export
class
MessageType
{
static
readonly
LOGIN
=
"login"
;
static
readonly
ROOM_LIST
=
"room_li
st"
;
static
readonly
ROOM_LIST
_REQUEST
=
"room_list_reque
st"
;
static
readonly
ROOM_JOIN
=
"room_join"
;
static
readonly
ROOM_LEAVE
=
"room_leave"
;
static
readonly
ROOM_USER_UPDATE
=
"room_user_update"
;
...
...
server/room/RoomManager.ts
View file @
54fd6c8
import
{
Connection
}
from
"../connection/Connection"
;
import
{
RoomListMessage
}
from
"../message/types"
;
import
{
Room
}
from
"./Room"
;
import
{
RoomDescription
}
from
"./types"
;
...
...
@@ -35,12 +33,11 @@ export class RoomManager {
}
}
public
sendList
(
connection
:
Connection
):
void
{
public
list
():
RoomDescription
[]
{
var
roomData
:
RoomDescription
[]
=
[];
this
.
rooms
.
forEach
((
room
)
=>
{
roomData
.
push
(
room
.
getDescription
());
});
connection
.
send
(
new
RoomListMessage
(
roomData
));
return
roomData
;
}
}
...
...
Please
register
or
login
to post a comment