Compare commits
2 commits
master
...
feature/vu
Author | SHA1 | Date | |
---|---|---|---|
a3fc829555 | |||
5e7868c8e8 |
44 changed files with 8329 additions and 416 deletions
|
@ -1,4 +1,4 @@
|
|||
FROM node:latest
|
||||
FROM node:latest as devStage
|
||||
|
||||
# some dir for our code
|
||||
WORKDIR /app
|
||||
|
@ -9,8 +9,5 @@ EXPOSE 3000
|
|||
COPY package*.json .
|
||||
RUN yarn
|
||||
|
||||
# copy code
|
||||
COPY . .
|
||||
|
||||
# this is how we start
|
||||
CMD ["yarn", "start"]
|
||||
CMD ["yarn", "watch"]
|
108
backend/inc/fftcgdb.coffee
Normal file
108
backend/inc/fftcgdb.coffee
Normal file
|
@ -0,0 +1,108 @@
|
|||
# libraries
|
||||
bcrypt = (require 'bcrypt')
|
||||
sqlite3 = (require 'sqlite3').verbose()
|
||||
|
||||
# bruteforce countermeasure
|
||||
saltRounds = 13
|
||||
|
||||
FFTCGDB = (filename) ->
|
||||
@filename = filename
|
||||
|
||||
@db = new sqlite3.Database @filename, (err) ->
|
||||
if err
|
||||
console.error err.message
|
||||
|
||||
@db.run """
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
login text NOT NULL COLLATE NOCASE,
|
||||
pwdhash text NOT NULL,
|
||||
UNIQUE(login)
|
||||
);
|
||||
"""
|
||||
|
||||
console.log "[FFTCGDB] Connected to '#{@filename}'"
|
||||
return
|
||||
|
||||
FFTCGDB::close = ->
|
||||
new Promise (resolve, reject) ->
|
||||
@db.close (err) ->
|
||||
if err
|
||||
resolve "[FFTCGDB] Error closing: '#{err.message}'"
|
||||
else
|
||||
reject "[FFTCGDB] Closed '#{@filename}'"
|
||||
|
||||
FFTCGDB::register = (login, password) ->
|
||||
that = @
|
||||
|
||||
new Promise (resolve, reject) ->
|
||||
# validate user input
|
||||
if login == '' or password == ''
|
||||
# no user name or password given
|
||||
console.log "[FFTCGDB] reg: user name '#{login}' or password empty"
|
||||
reject 'invalid'
|
||||
|
||||
# hash password
|
||||
bcrypt.hash password, saltRounds, (err, hash) ->
|
||||
if err
|
||||
console.log "[FFTCGDB] reg: hash fail for name '#{login}'"
|
||||
reject 'hash'
|
||||
|
||||
# try creating row in users table
|
||||
stmt = that.db.prepare 'INSERT INTO users (login, pwdhash) VALUES (?, ?)'
|
||||
stmt.run [login, hash], (err) ->
|
||||
if err
|
||||
console.log "[FFTCGDB] reg: DB fail '#{err.code}' for name '#{login}'"
|
||||
stmt.finalize()
|
||||
# reduce attack surface, don't disclose user names
|
||||
reject 'db' # user already exists
|
||||
|
||||
else
|
||||
console.log "[FFTCGDB] reg: OK '#{login}'"
|
||||
stmt.finalize()
|
||||
# registration successful
|
||||
resolve
|
||||
uid: @lastID
|
||||
login: login
|
||||
|
||||
FFTCGDB::login = (login, password) ->
|
||||
that = @
|
||||
|
||||
new Promise (resolve, reject) ->
|
||||
# get users table row
|
||||
stmt = that.db.prepare 'SELECT rowid, login, pwdhash FROM users WHERE login = ?'
|
||||
stmt.get [login], (err, row) ->
|
||||
if err
|
||||
console.log "[FFTCGDB] login: DB fail '#{err.code}' for name '#{login}'"
|
||||
stmt.finalize()
|
||||
reject 'db'
|
||||
|
||||
else if not row
|
||||
# hash the password for timing attack reasons
|
||||
bcrypt.hash password, saltRounds, (err, hash) ->
|
||||
console.log "[FFTCGDB] login: nonexistent '#{login}'"
|
||||
stmt.finalize()
|
||||
# reduce attack surface, don't disclose user names
|
||||
reject 'login' # user doesnt exist
|
||||
|
||||
else
|
||||
bcrypt.compare password, row.pwdhash, (err, res) ->
|
||||
if err
|
||||
console.log "[FFTCGDB] login: hash fail for name '#{login}'"
|
||||
reject 'hash'
|
||||
|
||||
if res == true
|
||||
console.log "[FFTCGDB] login: OK '#{row.login}'"
|
||||
stmt.finalize()
|
||||
# login successful
|
||||
resolve
|
||||
uid: row.rowid
|
||||
login: row.login
|
||||
|
||||
else
|
||||
console.log "[FFTCGDB] login: wrong password for '#{login}'"
|
||||
stmt.finalize()
|
||||
# login failed
|
||||
reject 'login'
|
||||
|
||||
|
||||
module.exports = FFTCGDB
|
|
@ -3,26 +3,14 @@ express = (require 'express')
|
|||
path = (require 'path')
|
||||
|
||||
# my libraries
|
||||
FFTCGDB = (require './db')
|
||||
FFTCGLOG = new (require './console')('FFTCGROUTER')
|
||||
FFTCGDB = (require './fftcgdb')
|
||||
|
||||
# open fftcg db
|
||||
fftcgdb = new FFTCGDB path.resolve(__dirname, '../fftcg.db')
|
||||
|
||||
# create router
|
||||
FFTCGROUTER = express.Router()
|
||||
|
||||
# request logging
|
||||
FFTCGROUTER.use (req, res, next) ->
|
||||
if req.session.user
|
||||
FFTCGLOG.log "user '#{req.session.user.login}' requested '#{req.url}'"
|
||||
else
|
||||
FFTCGLOG.log "requested '#{req.url}'"
|
||||
|
||||
next()
|
||||
|
||||
# static content
|
||||
FFTCGROUTER.use express.static path.resolve(__dirname, '../public_html')
|
||||
# FFTCGROUTER.use express.static path.resolve(__dirname, '../public_html')
|
||||
|
||||
# register user
|
||||
FFTCGROUTER.post '/register', (req, res) ->
|
||||
|
@ -31,7 +19,7 @@ FFTCGROUTER.post '/register', (req, res) ->
|
|||
# registration successful, return JSON status
|
||||
res.json
|
||||
status: 'ok'
|
||||
user: user.user
|
||||
uid: user.id
|
||||
login: user.login
|
||||
|
||||
.catch (err) ->
|
||||
|
@ -51,7 +39,7 @@ FFTCGROUTER.post '/login', (req, res) ->
|
|||
# return JSON status
|
||||
res.json
|
||||
status: 'ok'
|
||||
user: user.user
|
||||
uid: user.uid
|
||||
login: user.login
|
||||
|
||||
.catch (err) ->
|
||||
|
@ -60,23 +48,4 @@ FFTCGROUTER.post '/login', (req, res) ->
|
|||
status: 'fail'
|
||||
text: err
|
||||
|
||||
# Templates
|
||||
FFTCGROUTER.get '/:template.html', (req, res) ->
|
||||
# redirect logged-in users to user cp
|
||||
if req.session.user and req.params.template == 'index'
|
||||
return res.redirect '/usercp.html'
|
||||
|
||||
# render requested template
|
||||
res.render (req.params.template + '.pug'), (err, html) ->
|
||||
# redirect invalid requests to index
|
||||
if err
|
||||
return res.redirect '/index.html'
|
||||
|
||||
# actual response
|
||||
res.send html
|
||||
|
||||
# default route
|
||||
FFTCGROUTER.use (req, res) ->
|
||||
return res.redirect '/index.html'
|
||||
|
||||
module.exports = FFTCGROUTER
|
|
@ -1,7 +1,6 @@
|
|||
# node libraries
|
||||
socketio = (require 'socket.io')
|
||||
path = (require 'path')
|
||||
FFTCGLOG = new (require './console')('FFTCGSOCKET')
|
||||
|
||||
# my libraries
|
||||
|
||||
|
@ -15,17 +14,17 @@ FFTCGSOCKET = (http, session) ->
|
|||
# on new connection
|
||||
@io.on 'connection', (socket) ->
|
||||
@session = socket.handshake.session
|
||||
FFTCGLOG.log "session '#{@session.id}' connected"
|
||||
FFTCGLOG.log "is user '#{@session.userID}'" if @session.userID
|
||||
console.log "session '#{@session.id}' connected"
|
||||
console.log "is user '#{@session.userID}'" if @session.userID
|
||||
|
||||
socket.on 'disconnect', ->
|
||||
FFTCGLOG.log "session '#{that.session.id}' disconnected"
|
||||
FFTCGLOG.log "is user '#{that.session.userID}'" if that.session.userID
|
||||
console.log "session '#{that.session.id}' disconnected"
|
||||
console.log "is user '#{that.session.userID}'" if that.session.userID
|
||||
|
||||
return
|
||||
|
||||
FFTCGSOCKET::close = ->
|
||||
FFTCGLOG.log 'shutting down'
|
||||
console.log '[FFTCGSOCKET] shutting down'
|
||||
if @db
|
||||
@db.close()
|
||||
.then (msg) ->
|
34
backend/package.json
Normal file
34
backend/package.json
Normal file
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"name": "yvk-fftcg-backend",
|
||||
"version": "0.1.0",
|
||||
|
||||
"description": "FFTCG online using Socket.IO and CraftyJS on Node.js on Docker",
|
||||
"author": "JMM <jmm@yavook.de>",
|
||||
|
||||
"main": "server.coffee",
|
||||
"private": true,
|
||||
"license": "UNLICENSED",
|
||||
|
||||
"scripts": {
|
||||
"start": "coffee server.coffee",
|
||||
"watch": "nodemon server.coffee",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
|
||||
"dependencies": {
|
||||
"bcrypt": "^3.0.2",
|
||||
"body-parser": "^1.18.3",
|
||||
"coffeescript": "^2.3.2",
|
||||
"connect-redis": "^3.4.0",
|
||||
"express": "^4.16.4",
|
||||
"express-session": "^1.15.6",
|
||||
"express-socket.io-session": "^1.3.5",
|
||||
"helmet": "^3.15.0",
|
||||
"socket.io": "^2.2.0",
|
||||
"sqlite3": "^4.0.4"
|
||||
},
|
||||
|
||||
"devDependencies": {
|
||||
"nodemon": "^1.18.9"
|
||||
}
|
||||
}
|
|
@ -7,10 +7,9 @@ http = (require 'http')
|
|||
path = (require 'path')
|
||||
|
||||
# my libraries
|
||||
FFTCGSOCKET = (require './inc/socket')
|
||||
FFTCGSESSION = (require './inc/session')
|
||||
FFTCGROUTER = (require './inc/router')
|
||||
FFTCGLOG = new (require './inc/console')('FFTCG')
|
||||
FFTCGSOCKET = (require './inc/fftcgsocket')
|
||||
FFTCGSESSION = (require './inc/fftcgsession')
|
||||
FFTCGROUTER = (require './inc/fftcgrouter')
|
||||
|
||||
# express framework
|
||||
app = express()
|
||||
|
@ -25,16 +24,23 @@ app.use sessionMiddleware
|
|||
# routes
|
||||
app.use FFTCGROUTER
|
||||
|
||||
# Templates
|
||||
app.set 'view engine', 'pug'
|
||||
app.get '/:template.html', (req, res) ->
|
||||
if req.session.user
|
||||
console.log "[FFTCG] user is '#{req.session.user.login}'"
|
||||
res.render (req.params.template + '.pug')
|
||||
|
||||
# socket.io
|
||||
web = http.Server app
|
||||
socket = new FFTCGSOCKET web, sharedSession sessionMiddleware
|
||||
|
||||
# Create server
|
||||
web.listen 3000, ->
|
||||
FFTCGLOG.log 'Listening on port 3000 ...'
|
||||
console.log '[FFTCG] Listening on port 3000 ...'
|
||||
|
||||
# Handle termination
|
||||
process.on 'SIGINT', ->
|
||||
socket.close()
|
||||
FFTCGLOG.log 'shutting down after SIGINT'
|
||||
console.log '[FFTCG] shutting down after SIGINT'
|
||||
process.exit()
|
|
@ -1,20 +1,18 @@
|
|||
version: "2"
|
||||
|
||||
services:
|
||||
fftcg:
|
||||
build: .
|
||||
command: "yarn debug"
|
||||
restart: "no"
|
||||
volumes:
|
||||
- "${PWD}/src:/app/src"
|
||||
- "${PWD}/views:/app/views:ro"
|
||||
- "${PWD}/public_html:/app/public_html"
|
||||
- "${PWD}/inc:/app/inc:ro"
|
||||
- "${PWD}/server.coffee:/app/server.coffee:ro"
|
||||
# - "${PWD}/fftcg.db:/app/fftcg.db"
|
||||
ports:
|
||||
- "3000:3000"
|
||||
|
||||
redis:
|
||||
image: redis:alpine
|
||||
restart: "no"
|
||||
|
||||
backend:
|
||||
build:
|
||||
context: ./backend
|
||||
target: devStage
|
||||
restart: "no"
|
||||
volumes:
|
||||
- "${PWD}/backend/inc:/app/inc:ro"
|
||||
- "${PWD}/backend/server.coffee:/app/server.coffee:ro"
|
||||
# - "${PWD}/backend/fftcg.db:/app/fftcg.db"
|
||||
ports:
|
||||
- "3000:3000"
|
||||
|
|
3
frontend/.browserslistrc
Normal file
3
frontend/.browserslistrc
Normal file
|
@ -0,0 +1,3 @@
|
|||
> 1%
|
||||
last 2 versions
|
||||
not ie <= 8
|
17
frontend/.eslintrc.js
Normal file
17
frontend/.eslintrc.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
module.exports = {
|
||||
root: true,
|
||||
env: {
|
||||
node: true
|
||||
},
|
||||
'extends': [
|
||||
'plugin:vue/essential',
|
||||
'eslint:recommended'
|
||||
],
|
||||
rules: {
|
||||
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
|
||||
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
|
||||
},
|
||||
parserOptions: {
|
||||
parser: 'babel-eslint'
|
||||
}
|
||||
}
|
21
frontend/.gitignore
vendored
Normal file
21
frontend/.gitignore
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
.DS_Store
|
||||
node_modules
|
||||
/dist
|
||||
|
||||
# local env files
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# Log files
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Editor directories and files
|
||||
.idea
|
||||
.vscode
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw*
|
29
frontend/README.md
Normal file
29
frontend/README.md
Normal file
|
@ -0,0 +1,29 @@
|
|||
# frontend
|
||||
|
||||
## Project setup
|
||||
```
|
||||
yarn install
|
||||
```
|
||||
|
||||
### Compiles and hot-reloads for development
|
||||
```
|
||||
yarn run serve
|
||||
```
|
||||
|
||||
### Compiles and minifies for production
|
||||
```
|
||||
yarn run build
|
||||
```
|
||||
|
||||
### Run your tests
|
||||
```
|
||||
yarn run test
|
||||
```
|
||||
|
||||
### Lints and fixes files
|
||||
```
|
||||
yarn run lint
|
||||
```
|
||||
|
||||
### Customize configuration
|
||||
See [Configuration Reference](https://cli.vuejs.org/config/).
|
5
frontend/babel.config.js
Normal file
5
frontend/babel.config.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
module.exports = {
|
||||
presets: [
|
||||
'@vue/app'
|
||||
]
|
||||
}
|
38
frontend/package.json
Normal file
38
frontend/package.json
Normal file
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"name": "yvk-fftcg-frontend",
|
||||
"version": "0.1.0",
|
||||
|
||||
"description": "FFTCG online using Socket.IO and CraftyJS on Node.js on Docker",
|
||||
"author": "JMM <jmm@yavook.de>",
|
||||
|
||||
"private": true,
|
||||
"license": "UNLICENSED",
|
||||
|
||||
"scripts": {
|
||||
"serve": "vue-cli-service serve",
|
||||
"build": "vue-cli-service build",
|
||||
"lint": "vue-cli-service lint"
|
||||
},
|
||||
|
||||
"dependencies": {
|
||||
"vue": "^2.5.21"
|
||||
},
|
||||
|
||||
"devDependencies": {
|
||||
"craftyjs": "^0.9.0",
|
||||
"bootstrap": "^4.1.3",
|
||||
"jquery": "^3.3.1",
|
||||
"popper.js": "^1.14.5",
|
||||
"socket.io-client": "^2.2.0",
|
||||
|
||||
"@vue/cli-plugin-babel": "^3.3.0",
|
||||
"@vue/cli-plugin-eslint": "^3.3.0",
|
||||
"@vue/cli-service": "^3.3.0",
|
||||
"babel-eslint": "^10.0.1",
|
||||
"eslint": "^5.8.0",
|
||||
"eslint-plugin-vue": "^5.0.0",
|
||||
"pug": "^2.0.3",
|
||||
"pug-plain-loader": "^1.0.0",
|
||||
"vue-template-compiler": "^2.5.21"
|
||||
}
|
||||
}
|
5
frontend/postcss.config.js
Normal file
5
frontend/postcss.config.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
module.exports = {
|
||||
plugins: {
|
||||
autoprefixer: {}
|
||||
}
|
||||
}
|
BIN
frontend/public/favicon.ico
Normal file
BIN
frontend/public/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
17
frontend/public/index.html
Normal file
17
frontend/public/index.html
Normal file
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
|
||||
<title>frontend</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>
|
||||
<strong>We're sorry but frontend doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
||||
</noscript>
|
||||
<div id="app"></div>
|
||||
<!-- built files will be auto injected -->
|
||||
</body>
|
||||
</html>
|
Before Width: | Height: | Size: 610 KiB After Width: | Height: | Size: 610 KiB |
Before Width: | Height: | Size: 615 KiB After Width: | Height: | Size: 615 KiB |
28
frontend/src/App.vue
Normal file
28
frontend/src/App.vue
Normal file
|
@ -0,0 +1,28 @@
|
|||
<template>
|
||||
<div id="app">
|
||||
<img alt="Vue logo" src="./assets/logo.png">
|
||||
<HelloWorld msg="Welcome to Your Vue.js App"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import HelloWorld from './components/HelloWorld.vue'
|
||||
|
||||
export default {
|
||||
name: 'app',
|
||||
components: {
|
||||
HelloWorld
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
#app {
|
||||
font-family: 'Avenir', Helvetica, Arial, sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
text-align: center;
|
||||
color: #2c3e50;
|
||||
margin-top: 60px;
|
||||
}
|
||||
</style>
|
BIN
frontend/src/assets/logo.png
Normal file
BIN
frontend/src/assets/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.7 KiB |
58
frontend/src/components/HelloWorld.vue
Normal file
58
frontend/src/components/HelloWorld.vue
Normal file
|
@ -0,0 +1,58 @@
|
|||
<template>
|
||||
<div class="hello">
|
||||
<h1>{{ msg }}</h1>
|
||||
<p>
|
||||
For a guide and recipes on how to configure / customize this project,<br>
|
||||
check out the
|
||||
<a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
|
||||
</p>
|
||||
<h3>Installed CLI Plugins</h3>
|
||||
<ul>
|
||||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
|
||||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener">eslint</a></li>
|
||||
</ul>
|
||||
<h3>Essential Links</h3>
|
||||
<ul>
|
||||
<li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
|
||||
<li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
|
||||
<li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
|
||||
<li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
|
||||
<li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
|
||||
</ul>
|
||||
<h3>Ecosystem</h3>
|
||||
<ul>
|
||||
<li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
|
||||
<li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
|
||||
<li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
|
||||
<li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
|
||||
<li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'HelloWorld',
|
||||
props: {
|
||||
msg: String
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||
<style scoped>
|
||||
h3 {
|
||||
margin: 40px 0 0;
|
||||
}
|
||||
ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
||||
li {
|
||||
display: inline-block;
|
||||
margin: 0 10px;
|
||||
}
|
||||
a {
|
||||
color: #42b983;
|
||||
}
|
||||
</style>
|
8
frontend/src/main.js
Normal file
8
frontend/src/main.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
import Vue from 'vue'
|
||||
import App from './App.vue'
|
||||
|
||||
Vue.config.productionTip = false
|
||||
|
||||
new Vue({
|
||||
render: h => h(App),
|
||||
}).$mount('#app')
|
|
@ -49,7 +49,6 @@ $ ->
|
|||
if data.status == 'ok'
|
||||
that.fullReset()
|
||||
showAlert 'success', "successfully logged in '#{data.login}'"
|
||||
location.reload()
|
||||
|
||||
else
|
||||
switch data.text
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
html, body {
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
|
|
@ -5,8 +5,7 @@ module.exports = {
|
|||
|
||||
entry: {
|
||||
index: './src/index.coffee',
|
||||
game: './src/game.coffee',
|
||||
usercp: './src/usercp.coffee'
|
||||
game: './src/game.coffee'
|
||||
},
|
||||
|
||||
devtool: 'inline-source-map',
|
7920
frontend/yarn.lock
Normal file
7920
frontend/yarn.lock
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,11 +0,0 @@
|
|||
FFTCGLOG = (unit) ->
|
||||
@unit = unit
|
||||
return
|
||||
|
||||
FFTCGLOG::log = (msg) ->
|
||||
console.log "[#{@unit}] #{msg}"
|
||||
|
||||
FFTCGLOG::error = (msg) ->
|
||||
console.error "[#{@unit}] #{msg}"
|
||||
|
||||
module.exports = FFTCGLOG
|
222
inc/db.coffee
222
inc/db.coffee
|
@ -1,222 +0,0 @@
|
|||
# libraries
|
||||
bcrypt = (require 'bcrypt')
|
||||
sqlite3 = (require 'sqlite3').verbose()
|
||||
FFTCGLOG = new (require './console')('FFTCGDB')
|
||||
|
||||
# bruteforce countermeasure
|
||||
saltRounds = 13
|
||||
|
||||
FFTCGDB = (filename, truncate) ->
|
||||
that = @
|
||||
@filename = filename
|
||||
|
||||
@db = new sqlite3.Database @filename, (err) ->
|
||||
if err
|
||||
FFTCGLOG.error err.message
|
||||
|
||||
else
|
||||
FFTCGLOG.log "Connected to '#{that.filename}'"
|
||||
|
||||
that.db.run 'PRAGMA foreign_keys = ON;', (err) ->
|
||||
FFTCGLOG.error err.message if err
|
||||
|
||||
if truncate == true
|
||||
that.db.run 'DROP TABLE IF EXISTS users;', (err) ->
|
||||
FFTCGLOG.error err.message if err
|
||||
that.db.run '''
|
||||
CREATE TABLE users (
|
||||
user integer PRIMARY KEY,
|
||||
login text NOT NULL COLLATE NOCASE,
|
||||
pwdhash text NOT NULL,
|
||||
UNIQUE(login)
|
||||
);
|
||||
''', (err) ->
|
||||
FFTCGLOG.error err.message if err
|
||||
|
||||
that.db.run 'DROP TABLE IF EXISTS decks;', (err) ->
|
||||
FFTCGLOG.error err.message if err
|
||||
that.db.run '''
|
||||
CREATE TABLE decks (
|
||||
deck integer PRIMARY KEY,
|
||||
user integer NOT NULL,
|
||||
json text,
|
||||
FOREIGN KEY (user) REFERENCES users (user)
|
||||
ON DELETE CASCADE
|
||||
);
|
||||
''', (err) ->
|
||||
FFTCGLOG.error err.message if err
|
||||
|
||||
FFTCGLOG.log 'recreated DB'
|
||||
|
||||
return
|
||||
|
||||
FFTCGDB::close = ->
|
||||
new Promise (resolve, reject) ->
|
||||
@db.close (err) ->
|
||||
if err
|
||||
FFTCGLOG.log "Error closing: '#{err.message}'"
|
||||
resolve 'ok'
|
||||
else
|
||||
FFTCGLOG.error "Closed '#{@filename}'"
|
||||
reject 'db'
|
||||
|
||||
FFTCGDB::register = (login, password) ->
|
||||
that = @
|
||||
|
||||
new Promise (resolve, reject) ->
|
||||
# validate user input
|
||||
if login == '' or password == ''
|
||||
# no user name or password given
|
||||
FFTCGLOG.log "reg: user name '#{login}' or password empty"
|
||||
reject 'invalid'
|
||||
|
||||
# hash password
|
||||
bcrypt.hash password, saltRounds, (err, hash) ->
|
||||
if err
|
||||
FFTCGLOG.log "reg: hash fail for name '#{login}'"
|
||||
reject 'hash'
|
||||
|
||||
# try creating row in users table
|
||||
stmt = that.db.prepare 'INSERT INTO users (login, pwdhash) VALUES (?, ?)'
|
||||
stmt.run [login, hash], (err) ->
|
||||
if err
|
||||
FFTCGLOG.log "reg: DB fail '#{err.code}' for name '#{login}'"
|
||||
stmt.finalize()
|
||||
# reduce attack surface, don't disclose user names
|
||||
reject 'db' # user already exists
|
||||
|
||||
else
|
||||
FFTCGLOG.log "reg: OK '#{login}'"
|
||||
stmt.finalize()
|
||||
# registration successful
|
||||
resolve
|
||||
user: @lastID
|
||||
login: login
|
||||
|
||||
FFTCGDB::login = (login, password) ->
|
||||
that = @
|
||||
|
||||
new Promise (resolve, reject) ->
|
||||
# get users table row
|
||||
stmt = that.db.prepare 'SELECT user, login, pwdhash FROM users WHERE login = ?'
|
||||
stmt.get [login], (err, row) ->
|
||||
if err
|
||||
FFTCGLOG.log "login: DB fail '#{err.code}' for name '#{login}'"
|
||||
stmt.finalize()
|
||||
reject 'db'
|
||||
|
||||
else if not row
|
||||
# hash the password for timing attack reasons
|
||||
bcrypt.hash password, saltRounds, (err, hash) ->
|
||||
FFTCGLOG.log "login: nonexistent '#{login}'"
|
||||
stmt.finalize()
|
||||
# reduce attack surface, don't disclose user names
|
||||
reject 'login' # user doesnt exist
|
||||
|
||||
else
|
||||
bcrypt.compare password, row.pwdhash, (err, res) ->
|
||||
if err
|
||||
FFTCGLOG.log "login: hash fail for name '#{login}'"
|
||||
reject 'hash'
|
||||
|
||||
if res == true
|
||||
FFTCGLOG.log "login: OK '#{row.login}'"
|
||||
stmt.finalize()
|
||||
# login successful
|
||||
resolve
|
||||
user: row.user
|
||||
login: row.login
|
||||
|
||||
else
|
||||
FFTCGLOG.log "login: wrong password for '#{login}'"
|
||||
stmt.finalize()
|
||||
# login failed
|
||||
reject 'login'
|
||||
|
||||
FFTCGDB::addDeck = (user, deckCards) ->
|
||||
that = @
|
||||
|
||||
new Promise (resolve, reject) ->
|
||||
# try creating row in decks table
|
||||
stmt = that.db.prepare 'INSERT INTO decks (user, json) VALUES (?, ?)'
|
||||
stmt.run [user, JSON.stringify deckCards], (err) ->
|
||||
if err
|
||||
FFTCGLOG.log "addDeck: DB fail '#{err.code}' for id '#{user}'"
|
||||
stmt.finalize()
|
||||
reject 'db'
|
||||
|
||||
else
|
||||
stmt.finalize()
|
||||
# deck added successfully, now add cards
|
||||
that.modDeck(@lastID, deckCards)
|
||||
.then (deckID) ->
|
||||
resolve deckID
|
||||
.catch (error) ->
|
||||
reject error
|
||||
|
||||
FFTCGDB::modDeck = (deckID, deckCards) ->
|
||||
that = @
|
||||
|
||||
new Promise (resolve, reject) ->
|
||||
# delete old deck cards
|
||||
stmt = that.db.prepare 'DELETE FROM decks_cards WHERE deck = ?'
|
||||
stmt.run [deckID], (err) ->
|
||||
stmt.finalize()
|
||||
if err
|
||||
FFTCGLOG.log "modDeck: DB fail '#{err.code}' for deck '#{deckID}'"
|
||||
reject 'db'
|
||||
else
|
||||
stmt = that.db.prepare 'INSERT INTO decks_cards (deck, card, quant) VALUES (?, ?, ?)'
|
||||
# add new cards
|
||||
that.db.parallelize ->
|
||||
# needs to be done in several queries
|
||||
promiseCount = deckCards.length
|
||||
deckCards.forEach (card) ->
|
||||
stmt.run [deckID, card.id, card.quant], (err) ->
|
||||
if err
|
||||
FFTCGLOG.log "modDeck: DB fail '#{err.code}' for card '#{deckID}', '#{card.id}', '#{card.quant}'"
|
||||
stmt.finalize()
|
||||
reject 'db'
|
||||
else
|
||||
# check if all queries are done
|
||||
promiseCount -= 1
|
||||
if promiseCount == 0
|
||||
FFTCGLOG.log "modDeck: OK '#{deckID}'"
|
||||
stmt.finalize()
|
||||
resolve deckID
|
||||
|
||||
FFTCGDB::getDecks = (user) ->
|
||||
that = @
|
||||
|
||||
new Promise (resolve, reject) ->
|
||||
# try deleting correct row in decks table
|
||||
decks = {}
|
||||
stmt = that.db.prepare 'SELECT decks.deck, decks.json FROM decks INNER JOIN users ON decks.user = users.user WHERE users.user = ?'
|
||||
stmt.all [user], (err, rows) ->
|
||||
stmt.finalize()
|
||||
if err
|
||||
FFTCGLOG.log "getDeck: DB fail '#{err.code}' for deck '#{deckID}'"
|
||||
reject 'db'
|
||||
else
|
||||
FFTCGLOG.log "getDeck: OK '#{deckID}'"
|
||||
for row in rows
|
||||
decks[row.deck] = JSON.parse row.json
|
||||
resolve decks
|
||||
|
||||
FFTCGDB::delDeck = (deckID) ->
|
||||
that = @
|
||||
|
||||
new Promise (resolve, reject) ->
|
||||
# try deleting correct row in decks table
|
||||
stmt = that.db.prepare 'DELETE FROM decks WHERE deck = ?'
|
||||
stmt.run [deckID], (err) ->
|
||||
stmt.finalize()
|
||||
if err
|
||||
FFTCGLOG.log "delDeck: DB fail '#{err.code}' for deck '#{deckID}'"
|
||||
reject 'db'
|
||||
else
|
||||
FFTCGLOG.log "delDeck: OK '#{deckID}'"
|
||||
resolve deckID
|
||||
|
||||
|
||||
module.exports = FFTCGDB
|
57
package.json
57
package.json
|
@ -1,57 +0,0 @@
|
|||
{
|
||||
"name": "node-fftcg",
|
||||
"version": "0.0.3",
|
||||
|
||||
"description": "FFTCG online using Socket.IO and CraftyJS on Node.js on Docker",
|
||||
"author": "JMM <jmm@yavook.de>",
|
||||
|
||||
"main": "server.coffee",
|
||||
"private": true,
|
||||
"license": "UNLICENSED",
|
||||
|
||||
"scripts": {
|
||||
"build": "webpack",
|
||||
"watch": "webpack --watch",
|
||||
"start": "webpack && coffee server.coffee",
|
||||
"debug": "webpack --watch & nodemon server.coffee",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.1.6",
|
||||
"@babel/preset-env": "^7.1.6",
|
||||
"coffee-loader": "^0.9.0",
|
||||
|
||||
"autoprefixer": "^9.3.1",
|
||||
"css-loader": "^1.0.1",
|
||||
"postcss-loader": "^3.0.0",
|
||||
"node-sass": "^4.10.0",
|
||||
"precss": "^3.1.2",
|
||||
"sass-loader": "^7.1.0",
|
||||
"style-loader": "^0.23.1",
|
||||
|
||||
"nodemon": "^1.18.9",
|
||||
"webpack": "^4.25.1",
|
||||
"webpack-cli": "^3.1.2",
|
||||
|
||||
"bootstrap": "^4.1.3",
|
||||
"craftyjs": "^0.9.0",
|
||||
"jquery": "^3.3.1",
|
||||
"popper.js": "^1.14.5"
|
||||
},
|
||||
|
||||
"dependencies": {
|
||||
"bcrypt": "^3.0.2",
|
||||
"body-parser": "^1.18.3",
|
||||
"coffeescript": "^2.3.2",
|
||||
"connect-redis": "^3.4.0",
|
||||
"express": "^4.16.4",
|
||||
"express-session": "^1.15.6",
|
||||
"express-socket.io-session": "^1.3.5",
|
||||
"helmet": "^3.15.0",
|
||||
"pug": "^2.0.3",
|
||||
"socket.io": "^2.2.0",
|
||||
"socket.io-client": "^2.2.0",
|
||||
"sqlite3": "^4.0.4"
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
# libs
|
||||
window.$ = require('jquery')
|
||||
|
||||
# import bootstrap
|
||||
require './style/custom.scss'
|
||||
require 'bootstrap/js/dist/alert'
|
||||
require 'bootstrap/js/dist/collapse'
|
||||
|
||||
# on load
|
||||
$ ->
|
||||
return
|
|
@ -1,45 +0,0 @@
|
|||
doctype html
|
||||
html
|
||||
head
|
||||
title Crafty Things
|
||||
script(src='/usercp.bundle.js')
|
||||
body
|
||||
|
||||
header.jumbotron.jumbotron-fluid.py-4.bg-primary.text-light.text-center
|
||||
div.container
|
||||
h1 Hello World!
|
||||
h2 App under development, please don't submit any valuable data!
|
||||
|
||||
div.container.bg-light
|
||||
h3 Yavook!FFTCG
|
||||
div#alert-area
|
||||
div.row
|
||||
div.col-md-8
|
||||
h4 My Decks
|
||||
ul.list-group#my-decks
|
||||
li.list-group-item
|
||||
div.row
|
||||
div.col-3.btn-group(role="group")
|
||||
button.btn.btn-secondary(data-toggle="collapse" data-target="#modDeck0") Edit
|
||||
button.btn.btn-secondary#delDeck0 Delete
|
||||
div.col-9.align-self-center item1
|
||||
|
||||
form.collapse.pt-2#modDeck0(name="modDeck0")
|
||||
div.form-group
|
||||
label(for="deck") Decklist:
|
||||
textarea.form-control.form-control-sm.text-monospace(name="deck" rows="20" required)
|
||||
|
||||
div.form-group
|
||||
button.btn.btn-primary.w-100(type="submit") Confirm
|
||||
|
||||
p Hello
|
||||
|
||||
div.col-md-4
|
||||
h4 New Deck
|
||||
form(name="addDeck")
|
||||
div.form-group
|
||||
label(for="deck") Paste decklist:
|
||||
textarea.form-control.form-control-sm.text-monospace(name="deck" rows="20" required)
|
||||
|
||||
div.form-group
|
||||
button.btn.btn-primary.w-100(type="submit") Add
|
Reference in a new issue