mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2025-01-31 21:40:38 +00:00
Merge branch 'master' of github.com:cblanc/sws_gathers
This commit is contained in:
commit
45a3a992e1
17 changed files with 1466 additions and 1070 deletions
18
README.md
18
README.md
|
@ -28,24 +28,6 @@ npm install
|
|||
npm start
|
||||
```
|
||||
|
||||
## Todo
|
||||
|
||||
Required for Production:
|
||||
|
||||
- Admin tools: Modify Messages
|
||||
- Admin tools: Remove gatherer
|
||||
- ENSL.org: Pull bans
|
||||
- ENSL.org: Archive gather on ensl.org
|
||||
|
||||
Nice to have:
|
||||
|
||||
- Hive.naturalselection2.com: Pull stats
|
||||
- Steam: Outbound steam messaging
|
||||
- Add sounds and configuration
|
||||
- Add user profile + backend store
|
||||
- Show online/away/offline status
|
||||
- Picking order
|
||||
|
||||
## License
|
||||
|
||||
MIT Licensed
|
||||
|
|
|
@ -7,6 +7,7 @@ var config = {
|
|||
},
|
||||
secret_token: "",
|
||||
session_store_name: "_ENSL_session_key_staging",
|
||||
hive_url: "http://hive.naturalselection2.com/",
|
||||
ensl_url: "http://staging.ensl.org/"
|
||||
};
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ var config = {
|
|||
},
|
||||
secret_token: "",
|
||||
session_store_name: "_ENSL_session_key",
|
||||
hive_url: "http://hive.naturalselection2.com/",
|
||||
ensl_url: "http://www.ensl.org/"
|
||||
};
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ var config = {
|
|||
},
|
||||
secret_token: "",
|
||||
session_store_name: "_ENSL_session_key_staging",
|
||||
hive_url: "http://hive.naturalselection2.com/",
|
||||
ensl_url: "http://staging.ensl.org/"
|
||||
};
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ var config = {
|
|||
},
|
||||
secret_token: "SUPERSECRETFOO",
|
||||
session_store_name: "_ENSL_session_key_staging",
|
||||
hive_url: "http://hive.naturalselection2.com/",
|
||||
ensl_url: "http://staging.ensl.org/"
|
||||
};
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ module.exports = io => {
|
|||
}
|
||||
|
||||
if (!session || typeof session.user !== 'number') {
|
||||
if (env === 'staging') {
|
||||
if (process.env.RANDOM_USER) {
|
||||
return assignRandomUser(socket, next);
|
||||
} else {
|
||||
return next(new Error("Authentication Failed"));
|
||||
|
|
30
lib/hive/client.js
Normal file
30
lib/hive/client.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
"use strict";
|
||||
|
||||
var path = require("path");
|
||||
var request = require("request");
|
||||
var logger = require("winston");
|
||||
var querystring = require('querystring');
|
||||
var config = require(path.join(__dirname, "../../config/config"));
|
||||
|
||||
function HiveClient (options) {
|
||||
if (!(this instanceof HiveClient)) {
|
||||
return new HiveClient(options);
|
||||
}
|
||||
|
||||
this.baseUrl = config.hive_url;
|
||||
}
|
||||
|
||||
HiveClient.prototype.getUserStats = (user, callback) => {
|
||||
if (!user || !user.hive.id) {
|
||||
return callback(new Error("Invalid user instance supplied"));
|
||||
}
|
||||
|
||||
var id = user.hive.id;
|
||||
var url = this.baseUrl + "api/get/playerData/" + id;
|
||||
return request({
|
||||
url: url,
|
||||
json: true
|
||||
}, callback);
|
||||
};
|
||||
|
||||
module.exports = HiveClient;
|
|
@ -634,13 +634,20 @@ var Gatherers = React.createClass({
|
|||
};
|
||||
|
||||
if (gatherer.user.profile.skill) {
|
||||
var skill = (<span className="label label-primary">{gatherer.user.profile.skill}</span>);
|
||||
var skill = (<span className="label label-default">{gatherer.user.profile.skill}</span>);
|
||||
}
|
||||
|
||||
var abilities = [];
|
||||
for (let attr in gatherer.user.profile.abilities) {
|
||||
if (gatherer.user.profile.abilities[attr]) abilities.push(_.capitalize(attr));
|
||||
}
|
||||
|
||||
if (gatherer.user.hive.skill) abilities.push("ELO: " + gatherer.user.hive.skill);
|
||||
|
||||
if (gatherer.user.hive.playTime) {
|
||||
abilities.push(Math.floor(gatherer.user.hive.playTime / 3600) + " Hours");
|
||||
}
|
||||
|
||||
var lifeform = (
|
||||
abilities.map(lifeform => {
|
||||
return (<span className="label label-default add-right"
|
||||
|
@ -650,7 +657,7 @@ var Gatherers = React.createClass({
|
|||
|
||||
var team;
|
||||
if (gatherer.user.team) {
|
||||
team = (<span className="label label-primary">{gatherer.user.team.name}</span>);
|
||||
team = (<span className="label label-default">{gatherer.user.team.name}</span>);
|
||||
}
|
||||
|
||||
var action;
|
||||
|
@ -685,8 +692,8 @@ var Gatherers = React.createClass({
|
|||
return (
|
||||
<tr key={gatherer.user.id} data-userid={gatherer.user.id}>
|
||||
<td className="col-md-9">
|
||||
<p className="gatherer">{gatherer.user.username}</p>
|
||||
<p className="gatherer">{country} {lifeform} {skill} {team}</p>
|
||||
<p className="gatherer">{country} {gatherer.user.username}</p>
|
||||
<p className="gatherer-ability">{lifeform} {skill} {team}</p>
|
||||
</td>
|
||||
<td className="col-md-3 text-right">{action} </td>
|
||||
</tr>
|
||||
|
|
|
@ -105,6 +105,7 @@ var ProfileModal = React.createClass({
|
|||
let abilities = {
|
||||
skulk: React.findDOMNode(this.refs.skulk).checked,
|
||||
lerk: React.findDOMNode(this.refs.lerk).checked,
|
||||
gorge: React.findDOMNode(this.refs.gorge).checked,
|
||||
fade: React.findDOMNode(this.refs.fade).checked,
|
||||
onos: React.findDOMNode(this.refs.onos).checked,
|
||||
commander: React.findDOMNode(this.refs.commander).checked
|
||||
|
|
|
@ -5,9 +5,13 @@
|
|||
*
|
||||
*/
|
||||
|
||||
var client = require("../ensl/client")();
|
||||
var _ = require("lodash");
|
||||
var async = require("async");
|
||||
var mongoose = require("mongoose");
|
||||
var Profile = mongoose.model("Profile");
|
||||
var steam = require('steamidconvert')();
|
||||
var enslClient = require("../ensl/client")();
|
||||
var hiveClient = require("../hive/client")();
|
||||
|
||||
function User (user) {
|
||||
this.id = user['id'];
|
||||
|
@ -15,24 +19,47 @@ function User (user) {
|
|||
this.username = user['username'];
|
||||
this.country = user['country'];
|
||||
this.time_zone = user['time_zone'];
|
||||
this.avatar = client.baseUrl + user['avatar'];
|
||||
this.avatar = enslClient.baseUrl + user['avatar'];
|
||||
this.admin = user['admin'];
|
||||
this.team = user['team'];
|
||||
this.bans = user['bans'];
|
||||
this.steam = {
|
||||
id: user['steam']['id'] || null,
|
||||
url: user['steam']['url'] || null,
|
||||
nickname: user['steam']['nickname'] || null
|
||||
};
|
||||
this.profile = null;
|
||||
this.hive = {
|
||||
id: null
|
||||
};
|
||||
|
||||
if (this.steam.url) {
|
||||
this.hive.id = this.getHiveId();
|
||||
}
|
||||
}
|
||||
|
||||
User.prototype.updateProfile = function (data, callback) {
|
||||
User.prototype.getSteamId = () => {
|
||||
if (this.steam.url === null) return null;
|
||||
var urlId = this.steam.url.match(/\d*$/);
|
||||
if (!urlId || urlId[0].length === 0) return null;
|
||||
return steam.convertToText(urlId[0]);
|
||||
};
|
||||
|
||||
User.prototype.getHiveId = () => {
|
||||
var steamId = this.steam.id;
|
||||
if (!steamId) return null;
|
||||
var index = steamId.match(/:0:/) ? 0 : 1;
|
||||
var tailId = parseInt(steamId.match(/\d*$/), 10);
|
||||
return index === 1 ? (tailId * 2) + 1 : tailId * 2;
|
||||
};
|
||||
|
||||
User.prototype.updateProfile = (data, callback) => {
|
||||
let self = this;
|
||||
Profile.update({
|
||||
userId: self.id
|
||||
}, data, function (error) {
|
||||
}, data, error => {
|
||||
if (error) return callback(error);
|
||||
Profile.findOne({userId: self.id}, function (error, profile) {
|
||||
Profile.findOne({userId: self.id}, (error, profile) => {
|
||||
if (error) return callback(error);
|
||||
self.profile = profile.toJson();
|
||||
return callback(error, profile);
|
||||
|
@ -41,17 +68,33 @@ User.prototype.updateProfile = function (data, callback) {
|
|||
};
|
||||
|
||||
User.find = (id, callback) => {
|
||||
client.getUserById({
|
||||
enslClient.getUserById({
|
||||
id: id
|
||||
}, (error, response, body) => {
|
||||
if (error) return callback(error);
|
||||
if (response.statusCode !== 200) return callback(new Error("Unable to auth user against API"));
|
||||
let user = new User(body);
|
||||
Profile.findOrCreate(user, function (error, profile) {
|
||||
async.parallel([
|
||||
// Retrieve or create user profile from local store
|
||||
callback => {
|
||||
Profile.findOrCreate(user, (error, profile) => {
|
||||
if (error) return callback(error);
|
||||
user.profile = profile.toJson();
|
||||
return callback(null, profile);
|
||||
});
|
||||
},
|
||||
// Retrive Hive Stats
|
||||
callback => {
|
||||
hiveClient.getUserStats(user, (error, response, body) => {
|
||||
if (error || response.statusCode !== 200 || body.id === null) return callback();
|
||||
_.assign(user.hive, body);
|
||||
return callback(null, body);
|
||||
});
|
||||
}
|
||||
], function (error, result) {
|
||||
if (error) return callback(error);
|
||||
user.profile = profile.toJson();
|
||||
return callback(null, user);
|
||||
});
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
|
|
2322
npm-shrinkwrap.json
generated
2322
npm-shrinkwrap.json
generated
File diff suppressed because it is too large
Load diff
|
@ -10,7 +10,7 @@
|
|||
"scripts": {
|
||||
"test": "NODE_ENV=test mocha --harmony spec/",
|
||||
"start": "npm run compile && node --harmony index.js",
|
||||
"watch": "node_modules/gulp/bin/gulp.js watch",
|
||||
"watch": "node_modules/gulp/bin/gulp.js && node_modules/gulp/bin/gulp.js watch",
|
||||
"compile": "node_modules/gulp/bin/gulp.js",
|
||||
"dev": "nodemon --harmony index.js"
|
||||
},
|
||||
|
@ -44,6 +44,8 @@
|
|||
"request": "~2.60.0",
|
||||
"serve-favicon": "~2.3.0",
|
||||
"socket.io": "~1.3.5",
|
||||
"steam": "^1.1.0",
|
||||
"steamidconvert": "^0.2.4",
|
||||
"winston": "~1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -7,10 +7,17 @@ html, body {
|
|||
}
|
||||
|
||||
.gatherer {
|
||||
margin-bottom: 3px;
|
||||
margin-bottom: 5px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
.gatherer-ability {
|
||||
font-size: 12px;
|
||||
line-height: 25px;
|
||||
padding: 0px;
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
#chatroom {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ var Gatherer = helpers.Gatherer = require(path.join(__dirname, "../../lib/gather
|
|||
|
||||
// ENSL Client
|
||||
var EnslClient = helpers.EnslClient = require(path.join(__dirname, "../../lib/ensl/client"));
|
||||
var HiveClient = helpers.HiveClient = require(path.join(__dirname, "../../lib/hive/client"));
|
||||
|
||||
// Mongo & Associated Models
|
||||
var db = require(path.join(__dirname, "../../db/index"));
|
||||
|
|
11
spec/hiveClient.js
Normal file
11
spec/hiveClient.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
"use strict";
|
||||
|
||||
var helper = require("./helpers/index.js");
|
||||
var HiveClient = helper.HiveClient;
|
||||
var assert = require("chai").assert;
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
|
||||
describe("Hive Client", function () {
|
||||
|
||||
});
|
58
spec/user.js
Normal file
58
spec/user.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
"use strict";
|
||||
|
||||
var helper = require("./helpers/index.js");
|
||||
var User = helper.User;
|
||||
var assert = require("chai").assert;
|
||||
var async = require("async");
|
||||
var userCount = 0;
|
||||
|
||||
describe("User", () => {
|
||||
var user, userAttributes;
|
||||
|
||||
before(() => {
|
||||
userCount++;
|
||||
userAttributes = {
|
||||
id: userCount,
|
||||
username: "FearLess90",
|
||||
country: "CA",
|
||||
time_zone: "Eastern Time (US & Canada)",
|
||||
avatar: "/images/icons/" + userCount + ".png",
|
||||
admin: false,
|
||||
steam: {
|
||||
url: "http://steamcommunity.com/profiles/76561198076460617",
|
||||
nickname: "FearLess90"
|
||||
},
|
||||
bans: {
|
||||
gather: false,
|
||||
mute: false,
|
||||
site: false
|
||||
},
|
||||
team: {
|
||||
id: 622,
|
||||
name: "National Gamers"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
describe("#getSteamId", () => {
|
||||
beforeEach(() => {
|
||||
user = new User(userAttributes);
|
||||
});
|
||||
it ("returns steamid", () => {
|
||||
assert.equal(user.getSteamId(), "STEAM_0:1:58097444");
|
||||
});
|
||||
it ("returns null if no steamid", () => {
|
||||
user.steam.url = null;
|
||||
assert.isNull(user.getSteamId());
|
||||
});
|
||||
});
|
||||
|
||||
describe("#getHiveId", () => {
|
||||
beforeEach(() => {
|
||||
user = new User(userAttributes);
|
||||
});
|
||||
it ("returns hive id", () => {
|
||||
console.log(user.getHiveId());
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue