Browse Source

first work

tags/v0.1.10^2
Big Bad Waffle 6 years ago
parent
commit
1754ef2be5
6 changed files with 655 additions and 81 deletions
  1. +1
    -0
      .gitignore
  2. +10
    -26
      src/server/config/roles.js
  3. +582
    -53
      src/server/package-lock.json
  4. +1
    -0
      src/server/package.json
  5. +56
    -0
      src/server/security/sheets.js
  6. +5
    -2
      src/server/startup.js

+ 1
- 0
.gitignore View File

@@ -3,4 +3,5 @@ storage.db
*.sublime-project
*.sublime-workspace
*.css
creds.js
!helpers/item-tooltip/styles.css

+ 10
- 26
src/server/config/roles.js View File

@@ -1,27 +1,16 @@
define([
'./roleSkins'
'security/sheets'
], function (
roleSkins
sheets
) {
return {
accounts: {
waffle: {
level: 10,
messageStyle: 'color-cyan',
messagePrefix: '(dev) ',
items: [{
type: 'key',
name: 'Key to the world',
sprite: [12, 0],
keyId: 'world'
}],
skins: []
}
getAccount: function (name) {
return sheets.getRecord(name);
},

onBeforePlayerEnterGame: function (obj, blueprint) {
var account = obj.account;
var config = this.accounts[account] || {};
var config = this.getAccount(account) || {};
if (config.items) {
var blueprintInventory = blueprint.components.find(c => (c.type == 'inventory'));
if (!blueprintInventory) {
@@ -47,14 +36,14 @@ define([

getRoleLevel: function (player) {
var account = player.account;
var level = this.accounts[account] ? this.accounts[account].level : 0;
var level = this.getAccount(account) ? this.getAccount(account).level : 0;

return level;
},

isRoleLevel: function (player, requireLevel, message) {
var account = player.account;
var level = this.accounts[account] ? this.accounts[account].level : 0;
var level = this.getAccount(account) ? this.getAccount(account).level : 0;

var success = (level >= requireLevel);

@@ -66,28 +55,23 @@ define([

getRoleMessageStyle: function (player) {
var account = player.account;
return this.accounts[account] ? this.accounts[account].messageStyle : null;
return this.getAccount(account) ? this.getAccount(account).messageStyle : null;
},

getRoleMessagePrefix: function (player) {
var account = player.account;
return this.accounts[account] ? this.accounts[account].messagePrefix : null;
return this.getAccount(account) ? this.getAccount(account).messagePrefix : null;
},

getSkins: function (account) {
var skins = [];
var account = this.accounts[account] || {
var account = this.getAccount(account) || {
skins: []
};
(account.skins || []).forEach(function (s) {
skins.push(s);
});

var roleSkinList = roleSkins[account.level || 0];
roleSkinList.forEach(function (s) {
skins.push(s);
});

skins = skins.filter((s, i) => (skins.indexOf(s) == i));
return skins;
},


+ 582
- 53
src/server/package-lock.json
File diff suppressed because it is too large
View File


+ 1
- 0
src/server/package.json View File

@@ -6,6 +6,7 @@
"bcrypt-nodejs": "0.0.3",
"express": "^4.13.1",
"extend": "^3.0.0",
"google-spreadsheet": "^2.0.4",
"less-middleware": "^2.0.1",
"mysql": "^2.13.0",
"requirejs": "^2.2.0",


+ 56
- 0
src/server/security/sheets.js View File

@@ -0,0 +1,56 @@
define([
'google-spreadsheet',
'./creds'
], function (
googleSheets,
creds
) {
return {
doc: null,
sheet: null,

records: null,

init: function () {
this.doc = new googleSheets('1PhNFF8IbNX7uecFeWkFsoTZgDfLF-zWVibOTuutNy8c');
this.doc.useServiceAccountAuth(creds, this.onAuth.bind(this));
},

onAuth: function () {
this.doc.getInfo(this.onGetInfo.bind(this));
},

onGetInfo: function () {
this.sheet = this.doc.worksheets[0];

this.update();
},

getRecord: function (name) {
return (this.records || []).find(r => (r.username == name));
},

onGetRows: function (err, rows) {
this.records = rows.map(function (r) {
var o = {};
Object.keys(r).forEach(function (p) {
if (['id', 'app:edited', '_links', '_xml', 'save', 'del'].indexOf(p) > -1)
return;

o[p] = r[p];
});

o.items = JSON.parse(o.items);
o.skins = JSON.parse(o.skins);

return o;
});

setTimeout(this.update.bind(this), 10000)
},

update: function () {
this.sheet.getRows({}, this.onGetRows.bind(this));
}
};
});

+ 5
- 2
src/server/startup.js View File

@@ -13,7 +13,8 @@ define([
'config/classes',
'config/spellsConfig',
'config/spells',
'items/config/types'
'items/config/types',
'security/sheets'
], function (
globals,
server,
@@ -29,7 +30,8 @@ define([
classes,
spellsConfig,
spells,
itemTypes
itemTypes,
sheets
) {
return {
init: function () {
@@ -65,6 +67,7 @@ define([
onServerReady: function () {
atlas.init();
leaderboard.init();
sheets.init();
},

onError: function (e) {


Loading…
Cancel
Save