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-06-09 22:08:47 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
42b9c8ceabda458e15bfa99c4d91b74b5097a767
42b9c8ce
1 parent
723137f5
자유로운 이름으로 입장할 수 있도록 닉네임 구현
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
5 deletions
common/dataType.ts
common/message.ts
server/connection/Connection.ts
server/room/Room.ts
server/user/User.ts
common/dataType.ts
View file @
42b9c8c
...
...
@@ -38,6 +38,7 @@ export const RoomInfoRecord = Record({
users
:
Array
(
Record
({
username
:
String
,
nickname
:
String
,
admin
:
Boolean
,
ready
:
Boolean
,
})
...
...
common/message.ts
View file @
42b9c8c
...
...
@@ -22,7 +22,7 @@ import {
// 'result' 속성은 서버 요청 결과에만 포함되는 특별한 속성입니다.
export
class
ServerInboundMessageRecordMap
{
// 로그인을 시도합니다.
login
=
Record
({
username
:
String
});
login
=
Record
({
nickname
:
String
,
result
:
String
});
// 방 목록을 요청합니다.
roomList
=
Record
({
...
...
@@ -94,6 +94,7 @@ interface ServerOutboundMessageMap {
state
:
"added"
|
"updated"
|
"removed"
;
user
:
{
username
:
string
;
nickname
:
string
;
admin
:
boolean
;
ready
:
boolean
;
};
...
...
server/connection/Connection.ts
View file @
42b9c8c
...
...
@@ -77,7 +77,7 @@ export class Connection {
private
handleLogin
(
message
:
ServerInboundMessage
<
"login"
>
):
ServerResponse
<
"login"
>
{
this
.
user
=
new
User
(
message
.
user
name
,
this
);
this
.
user
=
new
User
(
message
.
nick
name
,
this
);
// console.log(`User ${message.username} has logged in!`);
return
{
ok
:
true
};
...
...
server/room/Room.ts
View file @
42b9c8c
...
...
@@ -106,6 +106,7 @@ export class Room {
state
:
"added"
,
user
:
{
username
:
user
.
username
,
nickname
:
user
.
nickname
,
admin
:
user
===
this
.
admin
,
ready
:
this
.
usersReady
.
includes
(
user
),
},
...
...
@@ -128,6 +129,7 @@ export class Room {
state
:
"removed"
,
user
:
{
username
:
user
.
username
,
nickname
:
user
.
nickname
,
admin
:
user
===
this
.
admin
,
ready
:
this
.
usersReady
.
includes
(
user
),
},
...
...
@@ -221,6 +223,7 @@ export class Room {
state
:
"updated"
,
user
:
{
username
:
user
.
username
,
nickname
:
user
.
nickname
,
admin
:
this
.
isAdmin
(
user
),
ready
:
this
.
isReady
(
user
),
},
...
...
@@ -244,6 +247,7 @@ export class Room {
users
:
this
.
users
.
map
((
u
)
=>
{
return
{
username
:
u
.
username
,
nickname
:
u
.
nickname
,
admin
:
this
.
isAdmin
(
u
),
ready
:
this
.
usersReady
.
includes
(
u
),
};
...
...
server/user/User.ts
View file @
42b9c8c
...
...
@@ -3,9 +3,11 @@ import { Connection } from "../connection/Connection";
import
{
MessageHandler
}
from
"../message/MessageHandler"
;
import
{
Room
}
from
"../room/Room"
;
import
{
RoomManager
}
from
"../room/RoomManager"
;
import
{
v4
as
uuidv4
}
from
"uuid"
;
export
class
User
{
public
readonly
username
:
string
;
public
readonly
username
:
string
;
// TODO: 실제 역할은 uuid임
public
readonly
nickname
:
string
;
public
readonly
connection
:
Connection
;
...
...
@@ -13,8 +15,9 @@ export class User {
public
handler
:
MessageHandler
;
constructor
(
username
:
string
,
connection
:
Connection
)
{
this
.
username
=
username
;
constructor
(
nickname
:
string
,
connection
:
Connection
)
{
this
.
username
=
uuidv4
();
this
.
nickname
=
nickname
;
this
.
connection
=
connection
;
this
.
handler
=
new
MessageHandler
({
roomList
:
(
user
,
message
)
=>
{
...
...
Please
register
or
login
to post a comment