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
176c5a18
Commit
176c5a18
authored
1 year ago
by
AceZephyr
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'origin/main' into main
parents
c5b32f11
b4fa4b8c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/login.js
+9
-1
9 additions, 1 deletion
app/login.js
app/semipublic/game.html
+9
-2
9 additions, 2 deletions
app/semipublic/game.html
app/server.js
+25
-1
25 additions, 1 deletion
app/server.js
with
43 additions
and
4 deletions
app/login.js
+
9
−
1
View file @
176c5a18
...
...
@@ -16,6 +16,7 @@ initSqlJs().then(function (SQL) {
const
filebuffer
=
fs
.
readFileSync
(
db_path
);
db
=
new
SQL
.
Database
(
filebuffer
);
db
.
run
(
"
CREATE TABLE IF NOT EXISTS users(username VARCHAR(20), pwhash VARCHAR(100));
"
);
db
.
run
(
"
CREATE TABLE IF NOT EXISTS leaderboard(username VARCHAR(20), score INT);
"
);
const
data
=
db
.
export
();
const
buffer
=
Buffer
.
from
(
data
);
fs
.
writeFileSync
(
env
[
"
db_path
"
],
buffer
);
...
...
@@ -51,6 +52,13 @@ function writeUser(user, hash) {
fs
.
writeFileSync
(
env
[
"
db_path
"
],
buffer
);
}
function
writeRecord
(
user
,
score
)
{
db
.
run
(
"
INSERT INTO leaderboard (username, score) VALUES (?, ?);
"
,
[
user
,
score
]);
const
data
=
db
.
export
();
const
buffer
=
Buffer
.
from
(
data
);
fs
.
writeFileSync
(
env
[
"
db_path
"
],
buffer
);
}
async
function
signup
(
user
,
pass
)
{
if
(
user
.
length
<
2
||
user
.
length
>
20
)
return
{
"
code
"
:
400
,
"
error
"
:
"
Username should be 2-20 characters
"
};
...
...
@@ -79,4 +87,4 @@ async function login(user, pass) {
}
}
module
.
exports
=
{
login
,
signup
,
getUserForToken
};
module
.
exports
=
{
login
,
signup
,
getUserForToken
,
writeRecord
};
This diff is collapsed.
Click to expand it.
app/semipublic/game.html
+
9
−
2
View file @
176c5a18
...
...
@@ -7,7 +7,7 @@
</head>
<body>
<h1>
2doku
</h1>
<div
id=
"error-container"
></div>
<div
id=
"player-info-container"
>
<h2
id=
"score-header"
>
Player Scores
</h2>
</div>
...
...
@@ -43,6 +43,7 @@
document
.
querySelector
(
"
#join-game
"
).
style
.
display
=
"
none
"
;
displayPlayerScores
(
args
.
playerScores
);
hideJoinButton
();
socket
.
emit
(
"
verify solution
"
,
{
board
:
args
.
boardDisplay
,
playerScores
:
args
.
playerScores
});
});
socket
.
on
(
"
game stop
"
,
()
=>
{
...
...
@@ -50,7 +51,13 @@
});
document
.
querySelector
(
"
#join-game
"
).
onclick
=
()
=>
{
socket
.
emit
(
"
join game
"
);
socket
.
emit
(
"
join game
"
,
null
,
(
duplicate
)
=>
{
if
(
duplicate
)
{
document
.
querySelector
(
"
#error-container
"
).
textContent
=
"
Already joined game.
"
;
document
.
querySelector
(
"
#player-info-container
"
).
style
.
display
=
"
none
"
;
document
.
querySelector
(
"
#board-container
"
).
style
.
display
=
"
none
"
;
}
});
hideJoinButton
();
}
...
...
This diff is collapsed.
Click to expand it.
app/server.js
+
25
−
1
View file @
176c5a18
...
...
@@ -200,6 +200,13 @@ function ensureAuth(req, res, fn) {
fn
(
user
);
}
function
writeUser
(
user
,
hash
)
{
db
.
run
(
"
INSERT INTO users (username, pwhash) VALUES (?, ?);
"
,
[
user
,
hash
]);
const
data
=
db
.
export
();
const
buffer
=
Buffer
.
from
(
data
);
fs
.
writeFileSync
(
env
[
"
db_path
"
],
buffer
);
}
app
.
get
(
"
/
"
,
(
req
,
res
)
=>
{
clearBadToken
(
req
,
res
);
return
res
.
sendFile
(
__dirname
+
"
/semipublic/index.html
"
);
...
...
@@ -303,10 +310,26 @@ io.on("connection", (socket) => {
game
.
sendBoard
();
});
socket
.
on
(
"
join game
"
,
()
=>
{
socket
.
on
(
"
join game
"
,
(
_
,
fn
)
=>
{
if
(
!
game
.
playerUsers
.
includes
(
user
))
{
game
.
userJoin
(
socketId
,
user
);
}
else
{
fn
(
"
duplicate
"
);
}
});
socket
.
on
(
"
verify solution
"
,
args
=>
{
const
{
board
,
playerScores
}
=
args
;
// Check for missing/incorrect answers
for
(
let
y
=
0
;
y
<
9
;
y
++
)
{
for
(
let
x
=
0
;
x
<
9
;
x
++
)
{
if
(
board
[
y
][
x
]
!==
game
.
boardSolution
[
y
][
x
])
{
return
;
}
}
}
// We solved the sudoku!
login
.
writeRecord
(
user
,
playerScores
[
user
]);
});
socket
.
on
(
"
disconnect
"
,
()
=>
{
...
...
@@ -316,6 +339,7 @@ io.on("connection", (socket) => {
});
});
httpServer
.
listen
(
port
,
hostname
,
()
=>
{
console
.
log
(
`http://
${
hostname
}
:
${
port
}
`
);
});
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
register
or
sign in
to comment