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
888e17c9
Commit
888e17c9
authored
Aug 29, 2023
by
SuperChrisBoy
Browse files
Options
Downloads
Plain Diff
Some changes from main
parents
85de6f85
5c06f34e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
app/login.js
+1
-1
1 addition, 1 deletion
app/login.js
app/semipublic/game.html
+11
-0
11 additions, 0 deletions
app/semipublic/game.html
app/semipublic/signup.html
+1
-1
1 addition, 1 deletion
app/semipublic/signup.html
app/server.js
+22
-16
22 additions, 16 deletions
app/server.js
with
35 additions
and
18 deletions
app/login.js
+
1
−
1
View file @
888e17c9
...
@@ -53,7 +53,7 @@ function writeUser(user, hash) {
...
@@ -53,7 +53,7 @@ function writeUser(user, hash) {
async
function
signup
(
user
,
pass
)
{
async
function
signup
(
user
,
pass
)
{
if
(
user
.
length
<
2
||
user
.
length
>
20
)
if
(
user
.
length
<
2
||
user
.
length
>
20
)
return
{
"
code
"
:
400
,
"
error
"
:
"
Username should be 2-
16
characters
"
};
return
{
"
code
"
:
400
,
"
error
"
:
"
Username should be 2-
20
characters
"
};
if
(
pass
.
length
<
8
||
pass
.
length
>
32
)
if
(
pass
.
length
<
8
||
pass
.
length
>
32
)
return
{
"
code
"
:
400
,
"
error
"
:
"
Password should be 8-32 characters
"
};
return
{
"
code
"
:
400
,
"
error
"
:
"
Password should be 8-32 characters
"
};
if
(
userExists
(
user
))
if
(
userExists
(
user
))
...
...
This diff is collapsed.
Click to expand it.
app/semipublic/game.html
+
11
−
0
View file @
888e17c9
...
@@ -16,6 +16,11 @@
...
@@ -16,6 +16,11 @@
<script
src=
"/socket.io/socket.io.js"
></script>
<script
src=
"/socket.io/socket.io.js"
></script>
<script
src=
"/game_render.js"
></script>
<script
src=
"/game_render.js"
></script>
<script>
<script>
function
hideJoinButton
()
{
document
.
querySelector
(
"
#join-game
"
).
style
.
display
=
"
none
"
;
}
const
socket
=
io
({
const
socket
=
io
({
query
:
{
query
:
{
gameId
:
window
.
location
.
href
.
split
(
"
/
"
).
filter
(
e
=>
e
.
length
>
0
).
pop
()
gameId
:
window
.
location
.
href
.
split
(
"
/
"
).
filter
(
e
=>
e
.
length
>
0
).
pop
()
...
@@ -28,12 +33,18 @@
...
@@ -28,12 +33,18 @@
BOARD1
=
new
SudokuBoard
(
"
board-container
"
,
updateToServer
);
BOARD1
=
new
SudokuBoard
(
"
board-container
"
,
updateToServer
);
BOARD1
.
updateBoard
(
args
.
boardDisplay
,
args
.
boardLock
,
args
.
boardColors
);
BOARD1
.
updateBoard
(
args
.
boardDisplay
,
args
.
boardLock
,
args
.
boardColors
);
displayPlayerScores
(
args
.
playerScores
);
displayPlayerScores
(
args
.
playerScores
);
hideJoinButton
();
});
});
socket
.
on
(
"
game stop
"
,
()
=>
{
socket
.
on
(
"
game stop
"
,
()
=>
{
window
.
location
.
href
=
"
/
"
;
window
.
location
.
href
=
"
/
"
;
});
});
document
.
querySelector
(
"
#join-game
"
).
onclick
=
()
=>
{
socket
.
emit
(
"
join game
"
);
hideJoinButton
();
}
function
updateToServer
(
x
,
y
,
num
)
{
function
updateToServer
(
x
,
y
,
num
)
{
socket
.
emit
(
"
cell input
"
,
{
"
x
"
:
x
,
"
y
"
:
y
,
"
num
"
:
num
});
socket
.
emit
(
"
cell input
"
,
{
"
x
"
:
x
,
"
y
"
:
y
,
"
num
"
:
num
});
}
}
...
...
This diff is collapsed.
Click to expand it.
app/semipublic/signup.html
+
1
−
1
View file @
888e17c9
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
<a
href=
"/"
><-
Back
</
a
><br>
<a
href=
"/"
><-
Back
</
a
><br>
<a
href=
"/login"
>
Login
</a>
<a
href=
"/login"
>
Login
</a>
<h1>
Create Account
</h1>
<h1>
Create Account
</h1>
<label
for=
"username"
>
Username (2-
16
characters):
</label>
<label
for=
"username"
>
Username (2-
20
characters):
</label>
<input
type=
"text"
id=
"username"
name=
"username"
/><br><br>
<input
type=
"text"
id=
"username"
name=
"username"
/><br><br>
<label
for=
"password"
>
Password (8-32 characters):
</label>
<label
for=
"password"
>
Password (8-32 characters):
</label>
<input
type=
"password"
id=
"password"
name=
"password"
/><br><br>
<input
type=
"password"
id=
"password"
name=
"password"
/><br><br>
...
...
This diff is collapsed.
Click to expand it.
app/server.js
+
22
−
16
View file @
888e17c9
...
@@ -61,15 +61,19 @@ class Game {
...
@@ -61,15 +61,19 @@ class Game {
this
.
sendBoard
();
this
.
sendBoard
();
}
}
sendBoard
()
{
packageBoardState
()
{
// do not send board state if game is not in progress
return
{
if
(
this
.
state
===
ROOM_PLAYING
)
{
this
.
sendAll
(
"
board state
"
,
{
boardDisplay
:
this
.
boardDisplay
,
boardDisplay
:
this
.
boardDisplay
,
boardLock
:
this
.
boardLock
,
boardLock
:
this
.
boardLock
,
boardColors
:
this
.
boardColors
,
boardColors
:
this
.
boardColors
,
playerScores
:
this
.
playerScores
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 {
...
@@ -94,10 +98,6 @@ class Game {
return
true
;
return
true
;
}
}
validateCell
(
args
)
{
return
this
.
boardSolution
[
args
.
y
][
args
.
x
]
===
args
.
num
;
}
userJoin
(
clientId
,
user
)
{
userJoin
(
clientId
,
user
)
{
if
(
this
.
state
===
ROOM_OPEN
&&
this
.
playerUsers
.
length
<
2
)
{
if
(
this
.
state
===
ROOM_OPEN
&&
this
.
playerUsers
.
length
<
2
)
{
this
.
playerUsers
.
push
(
user
);
this
.
playerUsers
.
push
(
user
);
...
@@ -131,15 +131,13 @@ class Game {
...
@@ -131,15 +131,13 @@ class Game {
userLeave
(
client
,
user
)
{
userLeave
(
client
,
user
)
{
this
.
usersToClients
.
delete
(
user
);
this
.
usersToClients
.
delete
(
user
);
if
(
this
.
playerUsers
.
includes
(
user
))
{
if
(
this
.
connectedClients
.
includes
(
client
))
{
this
.
kill
();
}
else
if
(
this
.
connectedClients
.
includes
(
client
))
{
this
.
connectedClients
.
splice
(
this
.
connectedClients
.
indexOf
(
client
),
1
);
this
.
connectedClients
.
splice
(
this
.
connectedClients
.
indexOf
(
client
),
1
);
}
}
}
}
send
All
(
name
,
message
=
null
)
{
send
(
name
,
clients
,
message
=
null
)
{
for
(
let
clientId
of
this
.
connectedC
lients
)
{
for
(
let
clientId
of
c
lients
)
{
io
.
in
(
clientId
).
fetchSockets
().
then
(
sockets
=>
{
io
.
in
(
clientId
).
fetchSockets
().
then
(
sockets
=>
{
sockets
.
forEach
(
socket
=>
{
sockets
.
forEach
(
socket
=>
{
socket
.
emit
(
name
,
message
)
socket
.
emit
(
name
,
message
)
...
@@ -148,6 +146,10 @@ class Game {
...
@@ -148,6 +146,10 @@ class Game {
}
}
}
}
sendAll
(
name
,
message
=
null
)
{
this
.
send
(
name
,
this
.
connectedClients
,
message
);
}
constructor
(
id
,
difficulty
)
{
constructor
(
id
,
difficulty
)
{
this
.
id
=
id
;
this
.
id
=
id
;
this
.
difficulty
=
difficulty
;
this
.
difficulty
=
difficulty
;
...
@@ -156,9 +158,9 @@ class Game {
...
@@ -156,9 +158,9 @@ class Game {
this
.
boardLock
=
[];
this
.
boardLock
=
[];
this
.
boardColors
=
[];
this
.
boardColors
=
[];
this
.
connectedClients
=
[];
this
.
connectedClients
=
[];
this
.
usersToClients
=
new
Map
();
this
.
playerUsers
=
[];
this
.
playerUsers
=
[];
this
.
playerScores
=
{};
this
.
playerScores
=
{};
this
.
usersToClients
=
new
Map
();
this
.
state
=
ROOM_OPEN
;
this
.
state
=
ROOM_OPEN
;
}
}
}
}
...
@@ -284,6 +286,10 @@ io.on("connection", (socket) => {
...
@@ -284,6 +286,10 @@ io.on("connection", (socket) => {
game
.
clientJoin
(
socketId
);
game
.
clientJoin
(
socketId
);
console
.
log
(
`Client connected:
${
socketId
}
to game
${
gameId
}
`
);
console
.
log
(
`Client connected:
${
socketId
}
to game
${
gameId
}
`
);
if
(
game
.
playerUsers
.
includes
(
user
))
{
socket
.
emit
(
"
board state
"
,
game
.
packageBoardState
());
}
socket
.
on
(
"
cell input
"
,
args
=>
{
socket
.
on
(
"
cell input
"
,
args
=>
{
if
(
game
.
playerUsers
.
includes
(
user
))
{
if
(
game
.
playerUsers
.
includes
(
user
))
{
game
.
input
(
socketId
,
user
,
args
.
x
,
args
.
y
,
args
.
num
);
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