Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
2doku
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
kes444
2doku
Commits
c39518bf
Commit
c39518bf
authored
Aug 29, 2023
by
AceZephyr
Browse files
Options
Downloads
Patches
Plain Diff
Reconnection
parent
a5c5bae8
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/semipublic/game.html
+7
-1
7 additions, 1 deletion
app/semipublic/game.html
app/server.js
+22
-16
22 additions, 16 deletions
app/server.js
with
29 additions
and
17 deletions
app/semipublic/game.html
+
7
−
1
View file @
c39518bf
...
...
@@ -23,6 +23,11 @@
.
filter
(
c
=>
c
[
0
]
===
"
token
"
)[
0
];
return
t
?
t
[
1
]
:
null
;
}
function
hideJoinButton
()
{
document
.
querySelector
(
"
#join-game
"
).
style
.
display
=
"
none
"
;
}
const
socket
=
io
({
query
:
{
gameId
:
window
.
location
.
href
.
split
(
"
/
"
).
filter
(
e
=>
e
.
length
>
0
).
pop
(),
...
...
@@ -37,6 +42,7 @@
BOARD1
.
updateBoard
(
args
.
boardDisplay
,
args
.
boardLock
,
args
.
boardColors
);
document
.
querySelector
(
"
#join-game
"
).
style
.
display
=
"
none
"
;
displayPlayerScores
(
args
.
playerScores
);
hideJoinButton
();
});
socket
.
on
(
"
game stop
"
,
()
=>
{
...
...
@@ -45,7 +51,7 @@
document
.
querySelector
(
"
#join-game
"
).
onclick
=
()
=>
{
socket
.
emit
(
"
join game
"
);
document
.
querySelector
(
"
#join-game
"
).
style
.
display
=
"
none
"
;
hideJoinButton
()
;
}
function
updateToServer
(
x
,
y
,
num
)
{
...
...
This diff is collapsed.
Click to expand it.
app/server.js
+
22
−
16
View file @
c39518bf
...
...
@@ -61,15 +61,19 @@ class Game {
this
.
sendBoard
();
}
sendBoard
()
{
// do not send board state if game is not in progress
if
(
this
.
state
===
ROOM_PLAYING
)
{
this
.
sendAll
(
"
board state
"
,
{
packageBoardState
()
{
return
{
boardDisplay
:
this
.
boardDisplay
,
boardLock
:
this
.
boardLock
,
boardColors
:
this
.
boardColors
,
playerScores
:
this
.
playerScores
});
};
}
sendBoard
()
{
// do not send board state if game is not in progress
if
(
this
.
state
===
ROOM_PLAYING
)
{
this
.
sendAll
(
"
board state
"
,
this
.
packageBoardState
());
}
}
...
...
@@ -94,10 +98,6 @@ class Game {
return
true
;
}
validateCell
(
args
)
{
return
this
.
boardSolution
[
args
.
y
][
args
.
x
]
===
args
.
num
;
}
userJoin
(
clientId
,
user
)
{
if
(
this
.
state
===
ROOM_OPEN
&&
this
.
playerUsers
.
length
<
2
)
{
this
.
playerUsers
.
push
(
user
);
...
...
@@ -131,15 +131,13 @@ class Game {
userLeave
(
client
,
user
)
{
this
.
usersToClients
.
delete
(
user
);
if
(
this
.
playerUsers
.
includes
(
user
))
{
this
.
kill
();
}
else
if
(
this
.
connectedClients
.
includes
(
client
))
{
if
(
this
.
connectedClients
.
includes
(
client
))
{
this
.
connectedClients
.
splice
(
this
.
connectedClients
.
indexOf
(
client
),
1
);
}
}
send
All
(
name
,
message
=
null
)
{
for
(
let
clientId
of
this
.
connectedC
lients
)
{
send
(
name
,
clients
,
message
=
null
)
{
for
(
let
clientId
of
c
lients
)
{
io
.
in
(
clientId
).
fetchSockets
().
then
(
sockets
=>
{
sockets
.
forEach
(
socket
=>
{
socket
.
emit
(
name
,
message
)
...
...
@@ -148,6 +146,10 @@ class Game {
}
}
sendAll
(
name
,
message
=
null
)
{
this
.
send
(
name
,
this
.
connectedClients
,
message
);
}
constructor
(
id
,
difficulty
)
{
this
.
id
=
id
;
this
.
difficulty
=
difficulty
;
...
...
@@ -156,9 +158,9 @@ class Game {
this
.
boardLock
=
[];
this
.
boardColors
=
[];
this
.
connectedClients
=
[];
this
.
usersToClients
=
new
Map
();
this
.
playerUsers
=
[];
this
.
playerScores
=
{};
this
.
usersToClients
=
new
Map
();
this
.
state
=
ROOM_OPEN
;
}
}
...
...
@@ -284,6 +286,10 @@ io.on("connection", (socket) => {
game
.
clientJoin
(
socketId
);
console
.
log
(
`Client connected:
${
socketId
}
to game
${
gameId
}
`
);
if
(
game
.
playerUsers
.
includes
(
user
))
{
socket
.
emit
(
"
board state
"
,
game
.
packageBoardState
());
}
socket
.
on
(
"
cell input
"
,
args
=>
{
if
(
game
.
playerUsers
.
includes
(
user
))
{
game
.
input
(
socketId
,
user
,
args
.
x
,
args
.
y
,
args
.
num
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment