-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·102 lines (91 loc) · 2.62 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var express = require('express');
// var path = require('path');
var app = express();
var http = require('http').Server(app);
// var io = require('socket.io')(http);
// var mysql = require('mysql');
// // MySQL
// var dbconn = mysql.createConnection({
// host: "localhost",
// user: "root",
// password: "",
// database: "flappybunny"
// });
// dbconn.connect(function(err) {
// if (err) throw err;
// console.log("[SERVER] Database succesfully connected!");
// });
// Express
app.use(express.static(__dirname + '/public'));
app.get('/', function(req, res) {
res.sendFile(__dirname + '/public/index.html');
});
app.get('/statistics', function(req, res) {
res.sendFile(__dirname + '/public/statistics.html');
})
// Server port
var port = 3000;
http.listen(port, function() {
console.log('[SERVER] Successfully started! Running on port: ' + port);
});
// function sendData(socket) {
// var wins
// var loses
// var average
// let query = 'SELECT COUNT(*) as wins FROM result WHERE win LIKE TRUE'
// dbconn.query(query, function(err, result, fields) {
// wins = result
// wins = wins[0]
// wins = wins.wins
// query = 'SELECT COUNT(*) as loses FROM result WHERE win LIKE FALSE'
// dbconn.query(query, function(err, result, fields) {
// loses = result
// loses = loses[0]
// loses = loses.loses
// query = 'SELECT AVG(score) as average FROM result'
// dbconn.query(query, function(err, result, fields) {
// average = result
// average = average[0]
// average = average.average
// if (average == null) {
// average = 0
// }
// let data = {
// wins: wins,
// loses: loses,
// average: average
// }
// console.log(data)
// socket.emit('data', data)
// })
// })
// })
// }
// io.on('connection', function(socket) {
// socket.on('disconnect', function() {
// })
// socket.on('get data', function() {
// sendData(socket)
// })
// socket.on('reset', function() {
// dbconn.query('DELETE FROM result WHERE 1', function(err, result) {
// if (err) throw err
// sendData(socket)
// })
// })
// socket.on('game over', function(data) {
// let query = 'INSERT INTO result(score, win, date) VALUES(\''+data.score+'\', '+data.win+', NOW())'
// dbconn.query(query, function(err, result) {
// if (err) throw err
// let text = '[RESULTS] Score inserted: '
// if (data.win == 1) {
// text += '(win) '
// } else {
// text += '(lose) '
// }
// text += ' - ' + data.score
// console.log(text)
// sendData(io)
// })
// })
// })