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-23 14:50:16 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d27f5f984a3028d4d121317c339a43265eb8b6ff
d27f5f98
1 parent
6921c1e6
기초적인 방 관리 로직 구현
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
85 additions
and
2 deletions
server/message/MessageHandlerRegistry.ts
server/package.json
server/room/Room.ts
server/room/RoomManager.ts
server/yarn.lock
server/message/MessageHandlerRegistry.ts
View file @
d27f5f9
import
{
Connection
}
from
"../connection/Connection"
;
import
{
loginHandler
}
from
"./handler/
L
oginHandler"
;
import
{
loginHandler
}
from
"./handler/
l
oginHandler"
;
import
{
MessageType
}
from
"./types"
;
export
class
MessageHandlerRegistry
{
...
...
server/package.json
View file @
d27f5f9
...
...
@@ -3,11 +3,13 @@
"@types/express"
:
"^4.17.11"
,
"@types/node"
:
"^15.3.1"
,
"@types/socket.io"
:
"^3.0.2"
,
"@types/uuid"
:
"^8.3.0"
,
"express"
:
"^4.17.1"
,
"nodemon"
:
"^2.0.7"
,
"socket.io"
:
"^4.1.2"
,
"ts-node"
:
"^9.1.1"
,
"typescript"
:
"^4.2.4"
"typescript"
:
"^4.2.4"
,
"uuid"
:
"^8.3.2"
},
"scripts"
:
{
"start"
:
"nodemon index.ts"
...
...
server/room/Room.ts
0 → 100644
View file @
d27f5f9
import
{
Connection
}
from
"../connection/Connection"
;
import
{
v4
as
uuidv4
}
from
"uuid"
;
export
class
Room
{
public
readonly
uuid
:
string
;
public
name
:
string
;
public
readonly
maxConnections
:
number
;
private
connections
:
Connection
[]
=
[];
private
closed
:
boolean
=
false
;
constructor
(
name
:
string
,
maxConnections
:
number
=
8
)
{
this
.
uuid
=
uuidv4
();
this
.
name
=
name
;
this
.
maxConnections
=
maxConnections
;
}
public
connect
(
connection
:
Connection
):
void
{
if
(
this
.
connections
.
includes
(
connection
)
||
this
.
connections
.
length
>=
this
.
maxConnections
)
{
return
;
}
this
.
connections
.
push
(
connection
);
}
public
disconnect
(
connection
:
Connection
):
void
{
const
index
=
this
.
connections
.
indexOf
(
connection
);
if
(
index
>
-
1
)
{
this
.
connections
.
splice
(
index
,
1
);
}
}
public
close
():
void
{
if
(
!
this
.
closed
)
{
// TODO
this
.
closed
=
true
;
}
}
}
server/room/RoomManager.ts
0 → 100644
View file @
d27f5f9
import
{
Room
}
from
"./Room"
;
export
class
RoomManager
{
private
rooms
:
Map
<
string
,
Room
>
;
constructor
()
{
this
.
rooms
=
new
Map
<
string
,
Room
>
();
}
public
create
(
name
:
string
,
maxConnections
:
number
):
Room
{
const
room
=
new
Room
(
name
,
maxConnections
);
this
.
rooms
.
set
(
name
,
room
);
return
room
;
}
public
get
(
uuid
:
string
):
Room
|
undefined
{
return
this
.
rooms
.
get
(
uuid
);
}
public
delete
(
uuid
:
string
):
void
{
const
room
=
this
.
get
(
uuid
);
if
(
room
!==
undefined
)
{
room
.
close
();
this
.
rooms
.
delete
(
uuid
);
}
}
}
server/yarn.lock
View file @
d27f5f9
...
...
@@ -103,6 +103,11 @@
dependencies:
socket.io "*"
"@types/uuid@^8.3.0":
version "8.3.0"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.0.tgz#215c231dff736d5ba92410e6d602050cce7e273f"
integrity sha512-eQ9qFW/fhfGJF8WKHGEHZEyVWfZxrT+6CLIJGBcZPfxUh/+BnEj+UCGYMlr9qZuX/2AltsvwrGqp0LhEW8D0zQ==
abbrev@1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8"
...
...
@@ -1349,6 +1354,11 @@ utils-merge@1.0.1:
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
integrity sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=
uuid@^8.3.2:
version "8.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
vary@^1, vary@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
...
...
Please
register
or
login
to post a comment