Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Commit

Permalink
Merge pull request #6 from Firstbloodio/develop
Browse files Browse the repository at this point in the history
See comment
  • Loading branch information
zackcoburn authored Oct 30, 2018
2 parents f182999 + 2facbc2 commit 64aae3a
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 54 deletions.
2 changes: 1 addition & 1 deletion dapp/app/frontend/modules/common/views/left_side_menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
<li><a class="link-logout" data-keyboard="true" data-toggle="modal" data-target="#logout"></a></li>
</ul>
<span class="txt-version txt-synced">Synced blocks<em>{{blockrange.minBlock}} - {{blockrange.maxBlock}}</em></span>
<span class="txt-version">Version 1.0.2</span>
<span class="txt-version">Version 1.0.3</span>
</aside>
126 changes: 80 additions & 46 deletions dapp/app/resources/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,57 +10,91 @@ const app = express();
const tables = require('./routes/tables');
const constant = require('./routes/constant.js');
const morgan = require('morgan');
require('dotenv').config()
const fs = require('fs');
const rp = require('request-promise');
require('dotenv').config();

app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(expressValidator());
app.use(cookieParser());
app.use(session({secret: 'krunal', saveUninitialized: false, resave: false}));
app.use(express.static(path.join(__dirname, 'assets')));
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', '*');
res.header('Access-Control-Allow-Headers', '*');
next();
}
app.use(allowCrossDomain);
app.disable('etag');
const getSteamServers = () => new Promise((resolve, reject) => {
rp('https://api.steampowered.com/ISteamDirectory/GetCMList/v1/?format=json&cellid=0')
.then((res) => {
try {
const serverList = JSON.parse(res).response.serverlist;
const servers = serverList.map(x => {
const spl = x.split(':');
return {
host: spl[0],
port: spl[1],
};
});
fs.writeFile(`${process.cwd()}/servers.json`, JSON.stringify(servers), (err) => {
if (err) {
reject(`Error saving Steam servers: ${err}`);
} else {
resolve('Saved Steam servers');
}
});
} catch (err) {
resolve(`Error parsing Steam servers: ${err}`);
}
})
.catch((err) => {
reject(`Failed to get Steam servers: ${err}`);
});
});

app.use(morgan(':method :url :status :res[content-length] - :response-time ms'));
getSteamServers().then((result) => {
console.log(result);
}).catch((err) => {
console.log(err);
}).then(() => {
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(expressValidator());
app.use(cookieParser());
app.use(session({secret: 'krunal', saveUninitialized: false, resave: false}));
app.use(express.static(path.join(__dirname, 'assets')));
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', '*');
res.header('Access-Control-Allow-Headers', '*');
next();
}
app.use(allowCrossDomain);
app.disable('etag');

const configRouter = require('./routes/configuration');
const infuraRouter = require('./routes/infura');
const challengeRouter = require('./routes/challenge');
const metamaskRouter = require('./routes/metamask');
const cronRouter = require('./routes/cron');
const witnessRouter = require('./routes/witness');
const findmatchRouter = require('./routes/findmatch');
app.use(morgan(':method :url :status :res[content-length] - :response-time ms'));

app.use('/', configRouter);
app.use('/infura', infuraRouter);
app.use('/challenge', challengeRouter);
app.use('/metamask', metamaskRouter);
app.use('/cron', cronRouter);
app.use('/witness', witnessRouter);
app.use('/findmatch', findmatchRouter);
const configRouter = require('./routes/configuration');
const infuraRouter = require('./routes/infura');
const challengeRouter = require('./routes/challenge');
const metamaskRouter = require('./routes/metamask');
const cronRouter = require('./routes/cron');
const witnessRouter = require('./routes/witness');
const findmatchRouter = require('./routes/findmatch');

// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
app.use('/', configRouter);
app.use('/infura', infuraRouter);
app.use('/challenge', challengeRouter);
app.use('/metamask', metamaskRouter);
app.use('/cron', cronRouter);
app.use('/witness', witnessRouter);
app.use('/findmatch', findmatchRouter);

// error handler
app.use(function(err, req, res, next) {
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
res.status(err.status || 500);
res.send('error')
});
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});

var listener = app.listen(constant.port, function() {
console.log("server started at port ", listener.address().port);
});
// error handler
app.use(function(err, req, res, next) {
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
res.status(err.status || 500);
res.send('error')
});

module.exports = app;
var listener = app.listen(constant.port, function() {
console.log("server started at port ", listener.address().port);
});
});
1 change: 1 addition & 0 deletions dapp/app/resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"morgan": "^1.9.1",
"node-rest-client": "^3.1.0",
"rebuild": "^0.1.2",
"request": "^2.88.0",
"request-promise": "^4.2.2",
"solc": "^0.4.24",
"sqlite3": "^4.0.2",
Expand Down
30 changes: 24 additions & 6 deletions dapp/app/resources/routes/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ const sqlite3 = require('sqlite3').verbose();
var db = "";
var isWin = process.platform === "win32";

try {
Steam.servers = JSON.parse(fs.readFileSync(`${process.cwd()}/servers.json`));
} catch (err) {
console.log(`Error reading servers.json: ${err}`);
}

if(isWin){
db = new sqlite3.Database('firstblood.db');
}else{
Expand Down Expand Up @@ -132,7 +138,9 @@ router.post('/login', [
return new Promise((resolve, reject) => {
validateName(value, req, 'player').then(result => {
if (!result) {
reject("There's no such player username available.");
const err = "There's no such player username available.";
console.log(err);
reject(err);
} else {
resolve(true);
}
Expand All @@ -151,7 +159,9 @@ router.post('/login', [
return new Promise((resolve, reject) => {
validateAddress(value).then(result => {
if (!result) {
reject("Referrer Ethereum Address is invalid.");
const err = "Referrer Ethereum Address is invalid.";
console.log(err);
reject(err);
} else {
resolve(true);
}
Expand All @@ -170,7 +180,9 @@ router.post('/login', [
return new Promise((resolve, reject) => {
validateKey(value).then(result => {
if (!result) {
reject('Ethereum Private Key is invalid.');
const err = 'Ethereum Private Key is invalid.';
console.log(err);
reject(err);
} else {
resolve(true);
}
Expand All @@ -189,7 +201,9 @@ router.post('/login', [
return new Promise((resolve, reject) => {
validateName(value, req, 'witness').then(result => {
if (!result) {
reject("There's no such witness username available.");
const err = "There's no such witness username available.";
console.log(err);
reject(err);
} else {
resolve(true);
}
Expand All @@ -208,7 +222,9 @@ router.post('/login', [
return new Promise((resolve, reject) => {
validateWitness(value, req.body.steamPassword).then(result => {
if (result != 1) {
reject("There's no Steam User associated with the provided detail.");
const err = "There's no Steam User associated with the provided detail.";
console.log(err);
reject(err);
} else {
resolve(true);
}
Expand Down Expand Up @@ -308,6 +324,7 @@ function validateName(userName, req, type) {
*/
function validateWitness(witnessName, steamPassword) {
return new Promise((resolve, reject) => {
console.log(`Attempting to login to Steam: ${witnessName}`);
var steamClient = new Steam.SteamClient();
var steamUser = new Steam.SteamUser(steamClient);
steamClient.connect();
Expand All @@ -325,7 +342,8 @@ function validateWitness(witnessName, steamPassword) {
}
});

steamClient.on('error', function onSteamError() {
steamClient.on('error', function onSteamError(err) {
console.log(`Steam login error: ${err}`);
resolve(false);
});

Expand Down
7 changes: 7 additions & 0 deletions dapp/app/resources/routes/cron.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ const contracts = require('../assets/files/compiled.json').contracts;
const Tx = require('ethereumjs-tx');
const notifier = require('node-notifier');
const sqlite3 = require('sqlite3').verbose();
const fs = require('fs');
var db = "";
var isWin = process.platform === "win32";

try {
Steam.servers = JSON.parse(fs.readFileSync(`${process.cwd()}/servers.json`));
} catch (err) {
console.log(`Error reading servers.json: ${err}`);
}

if(isWin){
db = new sqlite3.Database('firstblood.db');
}else{
Expand Down
6 changes: 6 additions & 0 deletions dapp/app/resources/routes/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ const sqlite3 = require('sqlite3').verbose();
var db = "";
var isWin = process.platform === "win32";

try {
steam.servers = JSON.parse(fs.readFileSync(`${process.cwd()}/servers.json`));
} catch (err) {
console.log(`Error reading servers.json: ${err}`);
}

if(isWin){
db = new sqlite3.Database('firstblood.db');
}else{
Expand Down
2 changes: 1 addition & 1 deletion dapp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "FirstBlood",
"version": "1.0.2",
"version": "1.0.3",
"main": "main.js",
"license": "MIT",
"private": true,
Expand Down
1 change: 1 addition & 0 deletions dapp/servers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"host":"162.254.193.6","port":"27017"},{"host":"162.254.193.7","port":"27018"},{"host":"162.254.193.6","port":"27019"},{"host":"162.254.193.46","port":"27018"},{"host":"162.254.193.47","port":"27018"},{"host":"162.254.193.46","port":"27017"},{"host":"162.254.193.46","port":"27019"},{"host":"162.254.193.47","port":"27019"},{"host":"162.254.193.6","port":"27018"},{"host":"162.254.193.7","port":"27019"},{"host":"162.254.193.7","port":"27017"},{"host":"162.254.193.47","port":"27017"},{"host":"162.254.195.46","port":"27018"},{"host":"162.254.195.44","port":"27017"},{"host":"162.254.195.47","port":"27017"},{"host":"162.254.195.45","port":"27017"},{"host":"162.254.195.44","port":"27019"},{"host":"162.254.195.44","port":"27018"},{"host":"162.254.195.45","port":"27019"},{"host":"162.254.195.47","port":"27018"},{"host":"162.254.195.45","port":"27018"},{"host":"162.254.195.47","port":"27019"},{"host":"205.196.6.67","port":"27018"},{"host":"155.133.254.132","port":"27017"},{"host":"155.133.254.133","port":"27018"},{"host":"155.133.254.133","port":"27019"},{"host":"162.254.195.46","port":"27017"},{"host":"162.254.192.100","port":"27019"},{"host":"155.133.254.132","port":"27019"},{"host":"162.254.195.46","port":"27019"},{"host":"205.196.6.75","port":"27019"},{"host":"205.196.6.75","port":"27018"},{"host":"162.254.192.101","port":"27017"},{"host":"162.254.192.108","port":"27018"},{"host":"162.254.192.101","port":"27019"},{"host":"162.254.192.109","port":"27019"},{"host":"155.133.254.132","port":"27018"},{"host":"205.196.6.67","port":"27017"},{"host":"162.254.192.109","port":"27018"},{"host":"205.196.6.67","port":"27019"},{"host":"205.196.6.75","port":"27017"},{"host":"162.254.192.100","port":"27018"},{"host":"162.254.192.100","port":"27017"},{"host":"162.254.192.101","port":"27018"},{"host":"162.254.192.108","port":"27017"},{"host":"155.133.254.133","port":"27017"},{"host":"162.254.192.109","port":"27017"},{"host":"162.254.192.108","port":"27019"},{"host":"162.254.196.67","port":"27019"},{"host":"162.254.196.83","port":"27017"},{"host":"162.254.196.83","port":"27019"},{"host":"162.254.196.67","port":"27017"},{"host":"162.254.196.83","port":"27018"},{"host":"162.254.196.67","port":"27018"},{"host":"162.254.196.84","port":"27019"},{"host":"162.254.196.84","port":"27018"},{"host":"162.254.196.68","port":"27019"},{"host":"162.254.196.68","port":"27018"},{"host":"162.254.196.84","port":"27017"},{"host":"162.254.196.68","port":"27017"},{"host":"155.133.248.53","port":"27019"},{"host":"155.133.248.50","port":"27018"},{"host":"155.133.248.50","port":"27019"},{"host":"155.133.248.53","port":"27018"},{"host":"155.133.248.52","port":"27018"},{"host":"155.133.248.53","port":"27017"},{"host":"155.133.248.51","port":"27019"},{"host":"155.133.248.50","port":"27017"},{"host":"155.133.248.51","port":"27017"},{"host":"155.133.248.52","port":"27019"},{"host":"155.133.248.51","port":"27018"},{"host":"155.133.248.52","port":"27017"},{"host":"155.133.246.69","port":"27019"},{"host":"155.133.242.8","port":"27017"},{"host":"155.133.246.68","port":"27017"},{"host":"155.133.246.68","port":"27019"},{"host":"155.133.246.69","port":"27017"},{"host":"146.66.152.11","port":"27019"},{"host":"162.254.197.40","port":"27017"},{"host":"155.133.242.9","port":"27019"},{"host":"185.25.180.15","port":"27018"},{"host":"155.133.242.9","port":"27017"},{"host":"185.25.180.14","port":"27019"},{"host":"155.133.242.8","port":"27019"},{"host":"155.133.246.69","port":"27018"},{"host":"146.66.152.11","port":"27018"},{"host":"146.66.152.10","port":"27017"},{"host":"162.254.197.42","port":"27019"},{"host":"162.254.197.180","port":"27018"},{"host":"162.254.197.42","port":"27017"},{"host":"185.25.180.15","port":"27019"},{"host":"185.25.180.15","port":"27017"},{"host":"146.66.152.11","port":"27017"},{"host":"146.66.152.10","port":"27018"},{"host":"162.254.197.40","port":"27019"},{"host":"162.254.197.180","port":"27017"},{"host":"162.254.197.181","port":"27017"},{"host":"162.254.197.180","port":"27019"},{"host":"155.133.246.68","port":"27018"},{"host":"146.66.152.10","port":"27019"}]

0 comments on commit 64aae3a

Please sign in to comment.