-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
76 lines (66 loc) · 1.79 KB
/
Copy pathserver.js
File metadata and controls
76 lines (66 loc) · 1.79 KB
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
/*
THESE ARE THE MYSQL VARIABLES THAT NEED TO BE MODIFIED
*/
var mysqlUser = "root", //put an appropriate MySQL username
mysqlPassword = "root", //put the password for the above user
mysqlDatabase = "ctf", //put the name of the database where the desired table is
tableToMirror = "TEAMS";//put the name of the table you want displayed
/*
END OF THE MYSQL VARIABLES THAT NEED TO BE MODIFIED
*/
//packages
var express = require("express");
var app = express();
var path = require('path');
var mysql = require("mysql");
var http = require('http').Server(app);
var io = require("socket.io")(http);
//express paths
app.use(express.static(path.join(__dirname, 'public')));
app.get("/", function (req, res) {
res.sendFile(__dirname + '/index.html');
});
//mysql connection
var db = mysql.createConnection({
host: 'localhost',
user: mysqlUser,
password: mysqlPassword,
database: mysqlDatabase
});
db.connect(function (err) {
if (err) console.log(err)
});
var users = 0,
results = [];
io.sockets.on('connection', function (socket) {
users++;
io.sockets.emit('users', users);
socket.on('disconnect', () => {
users--;
io.sockets.emit('users', users);
});
//query
db.query('SELECT * FROM ' + tableToMirror)
.on('result', (data) => {
results.push(data);
})
.on('end', () => {
socket.emit('results', results)
});
results = [];
});
http.listen(3000, function () {
console.log("Listening on 3000");
});
var ZongJi = require('zongji');
var zongji = new ZongJi({
host: 'localhost',
user: 'zongji', //this is the zongji user you can modify
password: 'zongji', //this is the zongji user's password that you can modify
});
zongji.start({
includeEvents: ['tablemap', 'writerows', 'updaterows', 'deleterows']
});
zongji.on('binlog', function (update) {
io.sockets.emit('update', update.rows);
});