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
88f25a67
Commit
88f25a67
authored
Aug 31, 2023
by
SuperChrisBoy
Browse files
Options
Downloads
Plain Diff
Merge branch 'main' into chris
parents
df139b85
b4fa4b8c
No related branches found
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
+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
env.json
+3
-0
3 additions, 0 deletions
env.json
with
46 additions
and
4 deletions
app/login.js
+
9
−
1
View file @
88f25a67
...
@@ -16,6 +16,7 @@ initSqlJs().then(function (SQL) {
...
@@ -16,6 +16,7 @@ initSqlJs().then(function (SQL) {
const
filebuffer
=
fs
.
readFileSync
(
db_path
);
const
filebuffer
=
fs
.
readFileSync
(
db_path
);
db
=
new
SQL
.
Database
(
filebuffer
);
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 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
data
=
db
.
export
();
const
buffer
=
Buffer
.
from
(
data
);
const
buffer
=
Buffer
.
from
(
data
);
fs
.
writeFileSync
(
env
[
"
db_path
"
],
buffer
);
fs
.
writeFileSync
(
env
[
"
db_path
"
],
buffer
);
...
@@ -51,6 +52,13 @@ function writeUser(user, hash) {
...
@@ -51,6 +52,13 @@ function writeUser(user, hash) {
fs
.
writeFileSync
(
env
[
"
db_path
"
],
buffer
);
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
)
{
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-20 characters
"
};
return
{
"
code
"
:
400
,
"
error
"
:
"
Username should be 2-20 characters
"
};
...
@@ -79,4 +87,4 @@ async function login(user, pass) {
...
@@ -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 @
88f25a67
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
</head>
</head>
<body>
<body>
<h1>
2doku
</h1>
<h1>
2doku
</h1>
<div
id=
"error-container"
></div>
<div
id=
"player-info-container"
>
<div
id=
"player-info-container"
>
<h2
id=
"score-header"
>
Player Scores
</h2>
<h2
id=
"score-header"
>
Player Scores
</h2>
</div>
</div>
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
BOARD1
.
updateBoard
(
args
.
boardDisplay
,
args
.
boardLock
,
args
.
boardColors
);
BOARD1
.
updateBoard
(
args
.
boardDisplay
,
args
.
boardLock
,
args
.
boardColors
);
displayPlayerScores
(
args
.
playerScores
);
displayPlayerScores
(
args
.
playerScores
);
hideJoinButton
();
hideJoinButton
();
socket
.
emit
(
"
verify solution
"
,
{
board
:
args
.
boardDisplay
,
playerScores
:
args
.
playerScores
});
});
});
socket
.
on
(
"
game stop
"
,
()
=>
{
socket
.
on
(
"
game stop
"
,
()
=>
{
...
@@ -41,7 +42,13 @@
...
@@ -41,7 +42,13 @@
});
});
document
.
querySelector
(
"
#join-game
"
).
onclick
=
()
=>
{
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
();
hideJoinButton
();
}
}
...
...
This diff is collapsed.
Click to expand it.
app/server.js
+
25
−
1
View file @
88f25a67
...
@@ -200,6 +200,13 @@ function ensureAuth(req, res, fn) {
...
@@ -200,6 +200,13 @@ function ensureAuth(req, res, fn) {
fn
(
user
);
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
)
=>
{
app
.
get
(
"
/
"
,
(
req
,
res
)
=>
{
clearBadToken
(
req
,
res
);
clearBadToken
(
req
,
res
);
return
res
.
sendFile
(
__dirname
+
"
/semipublic/index.html
"
);
return
res
.
sendFile
(
__dirname
+
"
/semipublic/index.html
"
);
...
@@ -297,10 +304,26 @@ io.on("connection", (socket) => {
...
@@ -297,10 +304,26 @@ io.on("connection", (socket) => {
game
.
sendBoard
();
game
.
sendBoard
();
});
});
socket
.
on
(
"
join game
"
,
()
=>
{
socket
.
on
(
"
join game
"
,
(
_
,
fn
)
=>
{
if
(
!
game
.
playerUsers
.
includes
(
user
))
{
if
(
!
game
.
playerUsers
.
includes
(
user
))
{
game
.
userJoin
(
socketId
,
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
"
,
()
=>
{
socket
.
on
(
"
disconnect
"
,
()
=>
{
...
@@ -310,6 +333,7 @@ io.on("connection", (socket) => {
...
@@ -310,6 +333,7 @@ io.on("connection", (socket) => {
});
});
});
});
httpServer
.
listen
(
port
,
hostname
,
()
=>
{
httpServer
.
listen
(
port
,
hostname
,
()
=>
{
console
.
log
(
`http://
${
hostname
}
:
${
port
}
`
);
console
.
log
(
`http://
${
hostname
}
:
${
port
}
`
);
});
});
This diff is collapsed.
Click to expand it.
env.json
0 → 100644
+
3
−
0
View file @
88f25a67
{
"db_path"
:
"../login.sqlite"
}
\ No newline at end of file
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