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-25 15:34:28 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
0177f1994084c9f88ac82b4541156f5a9bef5d47
0177f199
1 parent
cde2403a
RoomChatMessage 구현
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
0 deletions
server/message/MessageHandlerRegistry.ts
server/message/handler/roomChatHandler.ts
server/message/types.ts
server/room/Room.ts
server/message/MessageHandlerRegistry.ts
View file @
0177f19
import
{
Connection
}
from
"../connection/Connection"
;
import
{
User
}
from
"../user/User"
;
import
{
loginHandler
}
from
"./handler/loginHandler"
;
import
{
roomChatHandler
}
from
"./handler/roomChatHandler"
;
import
{
roomJoinHandler
}
from
"./handler/roomJoinHandler"
;
import
{
roomLeaveHandler
}
from
"./handler/roomLeaveHandler"
;
import
{
Message
,
MessageType
}
from
"./types"
;
...
...
@@ -18,6 +19,11 @@ export class MessageHandlerRegistry {
MessageType
.
ROOM_LEAVE
,
roomLeaveHandler
);
this
.
registerHandlerAuthed
(
connection
,
MessageType
.
ROOM_CHAT
,
roomChatHandler
);
}
private
static
registerHandler
<
T
extends
Message
>
(
...
...
server/message/handler/roomChatHandler.ts
0 → 100644
View file @
0177f19
import
{
Connection
}
from
"../../connection/Connection"
;
import
{
RoomManager
}
from
"../../room/RoomManager"
;
import
{
User
}
from
"../../user/User"
;
import
{
RoomChatMessage
,
RoomJoinMessage
}
from
"../types"
;
export
function
roomChatHandler
(
user
:
User
,
message
:
RoomChatMessage
):
void
{
user
.
room
?.
sendChat
(
user
,
message
.
message
);
}
server/message/types.ts
View file @
0177f19
...
...
@@ -65,6 +65,17 @@ export class RoomUserUpdateMessage implements Message {
)
{}
}
/**
* 클라 <-> 서버
* 접속한 방에서 채팅을 보내거나 받을 때 사용됩니다. 자신이 보낸 채팅은 서버에 의해 수신되지 않습니다.
* @param message 메세지 내용입니다.
* @param sender 채팅을 보낸 유저의 username입니다. 채팅이 클라이언트로 수신 될 경우에만 값을 가집니다.
*/
export
class
RoomChatMessage
implements
Message
{
readonly
type
=
MessageType
.
ROOM_CHAT
;
constructor
(
public
message
:
string
,
public
sender
?:
string
)
{}
}
export
class
MessageType
{
static
readonly
LOGIN
=
"login"
;
static
readonly
ROOM_LIST
=
"room_list"
;
...
...
@@ -72,4 +83,5 @@ export class MessageType {
static
readonly
ROOM_LEAVE
=
"room_leave"
;
static
readonly
ROOM_INFO
=
"room_info"
;
static
readonly
ROOM_USER_UPDATE
=
"room_user_update"
;
static
readonly
ROOM_CHAT
=
"room_chat"
;
}
...
...
server/room/Room.ts
View file @
0177f19
...
...
@@ -3,6 +3,7 @@ import { v4 as uuidv4 } from "uuid";
import
{
RoomData
}
from
"./types"
;
import
{
Message
,
RoomChatMessage
,
RoomInfoMessage
,
RoomUserUpdateMessage
,
}
from
"../message/types"
;
...
...
@@ -54,6 +55,10 @@ export class Room {
}
}
public
sendChat
(
user
:
User
,
message
:
string
):
void
{
this
.
broadcast
(
new
RoomChatMessage
(
message
,
user
.
username
),
user
);
}
public
getData
():
RoomData
{
return
{
uuid
:
this
.
uuid
,
...
...
Please
register
or
login
to post a comment