netplaySniff – Diff between revs 4 and 5

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 4 Rev 5
Line 13... Line 13...
13 const PROTOCOL = decoders.PROTOCOL 13 const PROTOCOL = decoders.PROTOCOL
14 const shortHash = require('short-hash') 14 const shortHash = require('short-hash')
15 const { exec } = require("child_process") 15 const { exec } = require("child_process")
16 const Inotify = require('inotify-remastered').Inotify 16 const Inotify = require('inotify-remastered').Inotify
17 const inotify = new Inotify() 17 const inotify = new Inotify()
18 const sqlite = require('sqlite') 18 const sqlite = require('sqlite3')
Line 19... Line 19...
19   19  
20 // load configuration file. 20 // load configuration file.
Line 21... Line 21...
21 let config = YAML.load('config.yml') 21 let config = YAML.load('config.yml')
Line 132... Line 132...
132 netplay.hash = shortHash(`${netplay.nick}${netplay.ip}`) 132 netplay.hash = shortHash(`${netplay.nick}${netplay.ip}`)
133 netplay.time = new Date().toISOString() 133 netplay.time = new Date().toISOString()
Line 134... Line 134...
134 134
Line 135... Line 135...
135 logger.info(`Player ${netplay.nick} joined via IP ${netplay.ip}`); 135 logger.info(`Player ${netplay.nick} joined via IP ${netplay.ip}`);
136 136
137 const db = new sqlite.Database({ filename: config.db.file }, sqlite.OPEN_CREATE | sqlite.OPEN_READWRITE | sqlite.OPEN_FULLMUTEX, (error) => { 137 const db = new sqlite.Database(config.db.file, sqlite.OPEN_CREATE | sqlite.OPEN_READWRITE | sqlite.OPEN_FULLMUTEX, (error) => {
138 if(error) { 138 if(error) {
139 logger.error(`failed to open database ${config.db.file}`) 139 logger.error(`failed to open database: ${config.db.file}`)
Line 140... Line 140...
140 return 140 return
141 } 141 }
142 142
143 db.run(`CREATE TABLE IF NOT EXISTS "players" ("nick" TEXT(15) NOT NULL, "ip" TEXT NOT NULL)`, (error, result) => { 143 db.run(`CREATE TABLE IF NOT EXISTS "players" ("nick" TEXT(15) NOT NULL, "ip" TEXT NOT NULL)`, (error, result) => {
144 if(error) { 144 if(error) {
145 logger.error(`could not create database table`); 145 logger.error(`could not create database table: ${error}`);
146 return 146 return
147 } 147 }
148 db.run(`INSERT INTO "players" ("nick", "ip") VALUES (:nick, :ip)`, { nick: netplay.nick, $ip: netplay.ip }, (error) => { 148 db.run(`INSERT INTO "players" ("nick", "ip") VALUES ($nick, $ip)`, { $nick: netplay.nick, $ip: netplay.ip }, (error) => {
149 if(error) { 149 if(error) {
Line 150... Line 150...
150 logger.error(`could not insert player and IP into database`) 150 logger.error(`could not insert player and IP into database: ${error}`)
151 return 151 return
152 } 152 }
153 153
Line 154... Line 154...
154 logger.info(`player added to database`) 154 logger.info(`player added to database`)
155 }) 155 })
156 }) 156 })
-   157 })
-   158  
Line 157... Line 159...
157 }) 159 // send data to MQTT server
158   160 const data = JSON.stringify(netplay, null, 4)
159 // send data to MQTT server 161 mqttClient.publish(`${config.mqtt.topic}`, data, (error, packet) => {
160 const data = JSON.stringify(netplay, null, 4) 162 logger.info(`player data sent to MQTT broker`)