@@ -168,6 +168,11 @@ | |||
"resolved": "https://registry.npmjs.org/blob/-/blob-0.0.5.tgz", | |||
"integrity": "sha512-gaqbzQPqOoamawKg0LGVd7SzLgXS+JH61oWprSLH+P+abTczqJbhTR8CmJ2u9/bUYNmHTGJx/UEmn6doAvvuig==" | |||
}, | |||
"bluebird": { | |||
"version": "2.11.0", | |||
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-2.11.0.tgz", | |||
"integrity": "sha1-U0uQM8AiyVecVro7Plpcqvu2UOE=" | |||
}, | |||
"body-parser": { | |||
"version": "1.18.3", | |||
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.3.tgz", | |||
@@ -1396,6 +1401,14 @@ | |||
} | |||
} | |||
}, | |||
"rethinkdb": { | |||
"version": "2.3.3", | |||
"resolved": "https://registry.npmjs.org/rethinkdb/-/rethinkdb-2.3.3.tgz", | |||
"integrity": "sha1-PcZYbiL6HavuDSVOZL0ON5+tL3I=", | |||
"requires": { | |||
"bluebird": ">= 2.3.2 < 3" | |||
} | |||
}, | |||
"rimraf": { | |||
"version": "2.6.3", | |||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", | |||
@@ -9,6 +9,7 @@ | |||
"express-minify": "^1.0.0", | |||
"google-spreadsheet": "^2.0.7", | |||
"less-middleware": "^3.1.0", | |||
"rethinkdb": "^2.3.3", | |||
"socket.io": "^2.2.0", | |||
"sqlite3": "^4.0.6" | |||
}, | |||
@@ -1,13 +1,12 @@ | |||
let fs = require('fs'); | |||
let util = require('util'); | |||
let firebase = null; | |||
let rethink = null; | |||
const useFirebase = false; | |||
const doConvert = false; | |||
const useRethink = true; | |||
if (useFirebase) | |||
firebase = require('./ioFirebase'); | |||
if (useRethink) | |||
rethink = require('./ioRethink'); | |||
module.exports = { | |||
db: null, | |||
@@ -32,12 +31,11 @@ module.exports = { | |||
accountInfo: null | |||
}, | |||
init: function (cbReady) { | |||
if (useFirebase && !doConvert) { | |||
firebase.init(this, false); | |||
cbReady(); | |||
return; | |||
} | |||
init: async function (cbReady) { | |||
if (rethink) | |||
await rethink.init(this); | |||
//cbReady(); | |||
//return; | |||
let sqlite = require('sqlite3').verbose(); | |||
this.exists = fs.existsSync(this.file); | |||
@@ -54,8 +52,6 @@ module.exports = { | |||
`, scope.onTableCreated.bind(scope, t)); | |||
} | |||
if (useFirebase) | |||
firebase.init(this, true); | |||
cbReady(); | |||
}, this); | |||
@@ -172,12 +168,9 @@ module.exports = { | |||
_.log(e); | |||
_.log(e); | |||
if (!doConvert) | |||
this.buffer.splice(0, 0, next); | |||
else { | |||
next.resolve(null); | |||
return; | |||
} | |||
this.buffer.splice(0, 0, next); | |||
setTimeout(this.process.bind(this), 10); | |||
return; | |||
} | |||
@@ -0,0 +1,77 @@ | |||
let r = require('rethinkdb'); | |||
const tables = [ | |||
'character', | |||
'characterList', | |||
'stash', | |||
'skins', | |||
'login', | |||
'leaderboard', | |||
'customMap', | |||
'mail', | |||
'customChannels', | |||
'error', | |||
'modLog', | |||
'accountInfo' | |||
]; | |||
module.exports = { | |||
connection: null, | |||
useDb: 'dev', | |||
init: async function () { | |||
this.connection = await r.connect({ | |||
host: 'localhost', | |||
port: 28015 | |||
}); | |||
await this.connection.use(this.useDb); | |||
await this.create(); | |||
this.bindHandlers(); | |||
}, | |||
create: async function () { | |||
try { | |||
await r.dbCreate('dev').run(this.connection); | |||
} catch (e) { | |||
} | |||
for (const table of tables) { | |||
try { | |||
await r.tableCreate(table).run(this.connection); | |||
} catch (e) { | |||
if (!e.msg.includes('already exists')) | |||
console.log(e); | |||
} | |||
} | |||
}, | |||
bindHandlers: function () { | |||
io.getAsync = this.getAsync.bind(this); | |||
io.setAsync = this.setAsync.bind(this); | |||
}, | |||
getAsync: async function ({ | |||
table, | |||
key | |||
}) { | |||
let res = await r.table(table) | |||
.get(key) | |||
.run(this.connection); | |||
}, | |||
setAsync: async function ({ | |||
table, | |||
key, | |||
value | |||
}) { | |||
await r.table(table) | |||
.insert({ | |||
index: key, | |||
value | |||
}) | |||
.run(this.connection); | |||
} | |||
}; |