This repository has been archived on 2024-04-29. You can view files and clone it, but cannot push or open issues or pull requests.
node-fftcg/server.js

63 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-09-30 18:21:59 +00:00
// libraries
var
http = require('http'),
socketio = require('socket.io'),
2018-10-04 00:27:49 +00:00
mysql = require('mysql'),
bcrypt = require('bcrypt'),
2018-09-30 21:23:05 +00:00
express = require('express'),
2018-10-02 00:17:04 +00:00
gulp = global.gulp = require('gulp'),
helmet = require('helmet');
2018-09-30 21:23:05 +00:00
// gulp the sources
require('./gulpfile');
gulp.start('default');
2018-09-30 18:21:59 +00:00
// socket.io framework
let app = express();
let web = http.Server(app);
let io = socketio(web);
// Listen server
web.listen(8080, function () {
console.log('Node.js listening on port 8080');
2018-09-30 18:21:59 +00:00
});
2018-10-02 00:17:04 +00:00
app.use(helmet());
2018-09-30 18:21:59 +00:00
// Static content
app.use(express.static(__dirname + '/static'));
2018-10-04 00:27:49 +00:00
var con = mysql.createConnection({
host: "tcgsql",
user: "fftcg",
database: "fftcg",
password: "juchie5OhH6eiQuujaoquievezoe9iXe",
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected to TCGSQL!");
});
2018-09-30 18:21:59 +00:00
// Server logic
io.on('connection', function (socket) {
console.log('a user connected');
socket.on('disconnect', function(){
// console.log('user disconnected');
});
socket.on('login', function(msg){
console.log('message:', msg.uname, msg.password);
2018-10-04 00:27:49 +00:00
const saltRounds = 13;
bcrypt.hash(msg.password, saltRounds, function(err, hash) {
con.query('INSERT INTO `users` (nick, pwd_hash) VALUES (\'' + msg.uname + '\', \'' + hash + '\');', function (err, result) {
if (err) throw err;
console.log("Result: " + result);
});
});
});
2018-09-30 18:21:59 +00:00
});