notherbase-fs 1.2.14 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/controllers/explorer.js +93 -130
- package/controllers/game.js +2 -1
- package/controllers/inventory.js +9 -5
- package/controllers/item.js +24 -14
- package/controllers/the-front.js +73 -91
- package/models/index.js +2 -1
- package/models/poi.js +18 -0
- package/notherbase-fs.js +87 -0
- package/package.json +2 -2
- package/test/coast/tall-beach/nono-cove/local-scripts/items.js +162 -0
- package/test/coast/tall-beach/nono-cove/local-scripts/nono.js +2 -5
- package/test/coast/tall-beach/nono-cove/server-scripts/addToTimer.js +34 -0
- package/test/coast/tall-beach/nono-cove/server-scripts/getTimer.js +31 -0
- package/test/coast/tall-beach/nono-cove/styles/items-floor.css +92 -0
- package/test/coast/tall-beach/nono-cove/views/index.ejs +93 -5
- package/test/coast/tall-beach/nono-cove/views/nono-og.ejs +6 -0
- package/test/test-index.js +2 -64
- package/test/views/check.ejs +7 -0
- package/test/views/index.ejs +4 -0
- package/views/explorer.ejs +0 -29
- package/views/inventory.ejs +12 -7
- package/index.js +0 -22
- package/server.js +0 -83
package/controllers/explorer.js
CHANGED
|
@@ -1,150 +1,113 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
for (let k = 0; k < area.pois.length; k++) {
|
|
21
|
-
let poi = area.pois[k];
|
|
22
|
-
currentPoi = poi.name;
|
|
23
|
-
|
|
24
|
-
for (let l = 0; l < poi.details.length; l++) {
|
|
25
|
-
let detail = poi.details[l];
|
|
26
|
-
|
|
27
|
-
let currentDir = `${dir}/${currentRegion}/${currentArea}/${currentPoi}`;
|
|
28
|
-
let currentRoute = `/${currentRegion}/${currentArea}/${currentPoi}/${detail.name}`;
|
|
29
|
-
|
|
30
|
-
detail.options = {
|
|
31
|
-
styles: [],
|
|
32
|
-
externalStyles: [],
|
|
33
|
-
localScripts: [],
|
|
34
|
-
serverScripts: [],
|
|
35
|
-
requiredItems: [],
|
|
36
|
-
needsKey: "",
|
|
37
|
-
dropOff: "",
|
|
38
|
-
...detail.options
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
detail.options.styles = detail.options.styles.map(style => {
|
|
42
|
-
style = `${currentDir}/styles/${style}`;
|
|
43
|
-
return style;
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
detail.options.externalStyles = detail.options.externalStyles.map(style => {
|
|
47
|
-
style = `${currentDir}/${style}`;
|
|
48
|
-
return style;
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
detail.options.localScripts = detail.options.localScripts.map(script => {
|
|
52
|
-
script = `${currentDir}/local-scripts/${script}`;
|
|
53
|
-
return script;
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
detail.options.serverScripts = detail.options.serverScripts.map(script => {
|
|
57
|
-
script = require(`${currentDir}/server-scripts/${script}`);
|
|
58
|
-
return script;
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
detail.options.main = "index";
|
|
62
|
-
if (detail.name !== "") detail.options.main = detail.name;
|
|
63
|
-
detail.options.main = `${currentDir}/views/${detail.options.main}`;
|
|
64
|
-
|
|
65
|
-
router.get(currentRoute, async function(req, res) {
|
|
66
|
-
try {
|
|
67
|
-
const foundUser = await user.findById(req.session.currentUser);
|
|
68
|
-
const foundInventory = await inventory.findOne({ user: req.session.currentUser }).populate("items.item");
|
|
69
|
-
|
|
70
|
-
let serverScriptReturns = [];
|
|
71
|
-
|
|
72
|
-
for (let m = 0; m < detail.options.serverScripts.length; m++) {
|
|
73
|
-
serverScriptReturns.push(await detail.options.serverScripts[m]({
|
|
74
|
-
game: game,
|
|
75
|
-
inventory: inventory,
|
|
76
|
-
item: item
|
|
77
|
-
}));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
let foundItemIDs = [];
|
|
81
|
-
for (let m = 0; m < detail.options.requiredItems.length; m++) {
|
|
82
|
-
let foundItem = await item.findOne({name: detail.options.requiredItems[m]});
|
|
83
|
-
|
|
84
|
-
foundItemIDs.push(foundItem._id);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
let context = {
|
|
88
|
-
siteTitle: "NotherBase",
|
|
89
|
-
user: foundUser,
|
|
90
|
-
styles: detail.options.styles,
|
|
91
|
-
externalStyles: detail.options.externalStyles,
|
|
92
|
-
main: detail.options.main,
|
|
93
|
-
localScripts: detail.options.localScripts,
|
|
94
|
-
serverScriptReturns: serverScriptReturns,
|
|
95
|
-
itemIDs: foundItemIDs,
|
|
96
|
-
pov: req.query.pov,
|
|
97
|
-
inventory: foundInventory,
|
|
98
|
-
query: req.query,
|
|
99
|
-
dir: dir,
|
|
100
|
-
path: path
|
|
101
|
-
}
|
|
1
|
+
const explorer = async function explorer(worldPath, voidPath) {
|
|
2
|
+
const db = require("../models");
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
let router = require("express").Router();
|
|
6
|
+
|
|
7
|
+
router.post(`/:region/:area/:poi/:detail/serve/:script`, async function(req, res) {
|
|
8
|
+
try {
|
|
9
|
+
let currentAreaRoute = `${req.params.region}/${req.params.area}/${req.params.poi}`;
|
|
10
|
+
let currentRoute = `${req.params.region}/${req.params.area}/${req.params.poi}/${req.params.detail}`;
|
|
11
|
+
|
|
12
|
+
if (await db.poi.exists({ route: currentRoute, type: "global" }) === false) {
|
|
13
|
+
await db.poi.create({
|
|
14
|
+
route: currentRoute,
|
|
15
|
+
name: req.params.detail,
|
|
16
|
+
type: "global",
|
|
17
|
+
data: {}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
102
20
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
else res.render(`explorer`, context);
|
|
112
|
-
}
|
|
113
|
-
else res.render(`explorer`, context);
|
|
114
|
-
}
|
|
115
|
-
catch(err) {
|
|
116
|
-
console.log(err);
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}
|
|
21
|
+
if (await db.poi.exists({ route: currentRoute, user: req.session.currentUser }) === false) {
|
|
22
|
+
await db.poi.create({
|
|
23
|
+
route: currentRoute,
|
|
24
|
+
name: req.params.detail,
|
|
25
|
+
type: "local",
|
|
26
|
+
user: req.session.currentUser,
|
|
27
|
+
data: {}
|
|
28
|
+
});
|
|
120
29
|
}
|
|
30
|
+
|
|
31
|
+
let scriptResult = await require(`${worldPath}/${currentAreaRoute}/server-scripts/${req.params.script}.js`)(db, currentRoute, req.session.currentUser, req.body);
|
|
32
|
+
res.send({ scriptResult: scriptResult });
|
|
121
33
|
}
|
|
122
|
-
|
|
123
|
-
|
|
34
|
+
catch(err) {
|
|
35
|
+
console.log(err);
|
|
36
|
+
res.status(500).end();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
router.get(`/:region/:area/:poi/:detail`, async function(req, res) {
|
|
41
|
+
try {
|
|
42
|
+
const foundUser = await db.user.findById(req.session.currentUser);
|
|
43
|
+
const foundInventory = await db.inventory.findOne({ user: req.session.currentUser }).populate("items.item");
|
|
44
|
+
|
|
45
|
+
let main = `${worldPath}/${req.params.region}/${req.params.area}/${req.params.poi}/views/${req.params.detail}`;
|
|
46
|
+
|
|
47
|
+
let context = {
|
|
48
|
+
siteTitle: `NotherBase - ${req.params.detail}`,
|
|
49
|
+
user: foundUser,
|
|
50
|
+
main: main,
|
|
51
|
+
pov: req.query.pov,
|
|
52
|
+
inventory: foundInventory,
|
|
53
|
+
query: req.query,
|
|
54
|
+
dir: worldPath,
|
|
55
|
+
path: path
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
await res.render(`explorer`, context);
|
|
59
|
+
}
|
|
60
|
+
catch(err) {
|
|
61
|
+
console.log(err);
|
|
62
|
+
res.status(500).end();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
router.get(`/:region/:area/:poi`, async function(req, res) {
|
|
67
|
+
try {
|
|
68
|
+
const foundUser = await db.user.findById(req.session.currentUser);
|
|
69
|
+
const foundInventory = await db.inventory.findOne({ user: req.session.currentUser }).populate("items.item");
|
|
70
|
+
|
|
71
|
+
let main = `${worldPath}/${req.params.region}/${req.params.area}/${req.params.poi}/views/index`;
|
|
72
|
+
|
|
73
|
+
let context = {
|
|
74
|
+
siteTitle: `NotherBase - ${req.params.poi}`,
|
|
75
|
+
user: foundUser,
|
|
76
|
+
main: main,
|
|
77
|
+
pov: req.query.pov,
|
|
78
|
+
inventory: foundInventory,
|
|
79
|
+
query: req.query,
|
|
80
|
+
dir: worldPath,
|
|
81
|
+
path: path
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
await res.render(`explorer`, context);
|
|
85
|
+
}
|
|
86
|
+
catch(err) {
|
|
87
|
+
console.log(err);
|
|
88
|
+
res.status(500).end();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
124
92
|
// start location
|
|
125
93
|
router.get("/", function(req, res) {
|
|
126
94
|
res.redirect("/the-front");
|
|
127
95
|
});
|
|
128
|
-
|
|
96
|
+
|
|
129
97
|
//the void
|
|
130
98
|
router.use(function(req, res, next){
|
|
131
99
|
res.render(`explorer`,
|
|
132
100
|
{
|
|
133
101
|
siteTitle: "NotherBase | The Void",
|
|
134
102
|
user: null,
|
|
135
|
-
styles: [`${dir}/${explorerBuild.void}/styles/void`],
|
|
136
|
-
externalStyles: [],
|
|
137
|
-
localScripts: [],
|
|
138
103
|
inventory: null,
|
|
139
|
-
|
|
140
|
-
main: `${dir}/${explorerBuild.void}/index`,
|
|
104
|
+
main: `${voidPath}/index`,
|
|
141
105
|
dir: dir,
|
|
142
106
|
path: path
|
|
143
107
|
});
|
|
144
108
|
});
|
|
109
|
+
|
|
110
|
+
return router;
|
|
145
111
|
}
|
|
146
112
|
|
|
147
|
-
module.exports =
|
|
148
|
-
router: router,
|
|
149
|
-
complete: complete
|
|
150
|
-
}
|
|
113
|
+
module.exports = explorer;
|
package/controllers/game.js
CHANGED
|
@@ -47,11 +47,12 @@ router.post("/", async function(req, res) {
|
|
|
47
47
|
foundGame.markModified("data");
|
|
48
48
|
await foundGame.save();
|
|
49
49
|
|
|
50
|
-
res.status(200).
|
|
50
|
+
res.status(200).end();
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
catch(err) {
|
|
54
54
|
res.status(500).end();
|
|
55
|
+
console.log(req.query);
|
|
55
56
|
console.log(err);
|
|
56
57
|
}
|
|
57
58
|
});
|
package/controllers/inventory.js
CHANGED
|
@@ -30,13 +30,15 @@ router.post("/", async function(req, res) {
|
|
|
30
30
|
if (connectionSuccess) {
|
|
31
31
|
try {
|
|
32
32
|
if (req.body.item && req.body.amount) {
|
|
33
|
-
|
|
33
|
+
let foundItem = await item.findOne({name: req.body.item});
|
|
34
|
+
|
|
35
|
+
if (foundItem) {
|
|
34
36
|
let foundInventory = await inventory.findOne({user: req.session.currentUser}).populate("items.item");
|
|
35
37
|
|
|
36
38
|
let holding = false;
|
|
37
39
|
|
|
38
40
|
for (let j = 0; j < foundInventory.items.length; j++) {
|
|
39
|
-
if (foundInventory.items[j].item.
|
|
41
|
+
if (foundInventory.items[j].item.name === req.body.item) {
|
|
40
42
|
holding = true;
|
|
41
43
|
|
|
42
44
|
if (foundInventory.items[j].amount >= -Math.floor(req.body.amount)) {
|
|
@@ -74,7 +76,7 @@ router.post("/", async function(req, res) {
|
|
|
74
76
|
if (!holding) {
|
|
75
77
|
if (req.body.amount > 0) {
|
|
76
78
|
foundInventory.items.push({
|
|
77
|
-
item:
|
|
79
|
+
item: foundItem._id,
|
|
78
80
|
amount: req.body.amount
|
|
79
81
|
});
|
|
80
82
|
|
|
@@ -94,11 +96,13 @@ router.post("/", async function(req, res) {
|
|
|
94
96
|
};
|
|
95
97
|
}
|
|
96
98
|
else {
|
|
97
|
-
|
|
99
|
+
console.log(`${req.body.item} doesn't exist!`);
|
|
100
|
+
res.status(400).send(`${req.body.item} doesn't exist!`);
|
|
98
101
|
}
|
|
99
102
|
}
|
|
100
103
|
else {
|
|
101
|
-
|
|
104
|
+
console.log(`${req.body.item} ${req.body.amount} Check Input!`);
|
|
105
|
+
res.status(400).send(`${req.body.item} ${req.body.amount} Check Input!`);
|
|
102
106
|
}
|
|
103
107
|
}
|
|
104
108
|
catch(err) {
|
package/controllers/item.js
CHANGED
|
@@ -16,12 +16,11 @@ router.get("/all", async function(req, res) {
|
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
router.get("/
|
|
19
|
+
router.get("/", async function(req, res) {
|
|
20
20
|
try {
|
|
21
|
-
let foundItem = await items.findOne({name: req.query.name});
|
|
21
|
+
let foundItem = await items.findOne({ name: req.query.name });
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
else res.status(200).send({ foundItem: foundItem });
|
|
23
|
+
res.status(200).send({ foundItem: foundItem });
|
|
25
24
|
}
|
|
26
25
|
catch(err) {
|
|
27
26
|
res.status(500).end();
|
|
@@ -29,11 +28,27 @@ router.get("/findOne", async function(req, res) {
|
|
|
29
28
|
}
|
|
30
29
|
});
|
|
31
30
|
|
|
32
|
-
router.
|
|
31
|
+
router.post("/", async function(req, res) {
|
|
33
32
|
try {
|
|
34
|
-
|
|
33
|
+
if (!req.body.id) {
|
|
34
|
+
await items.create({
|
|
35
|
+
name: req.body.name,
|
|
36
|
+
shortDescription: req.body.shortDescription,
|
|
37
|
+
fullDescription: req.body.fullDescription
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
let foundItem = await items.findById(req.body.id);
|
|
35
42
|
|
|
36
|
-
|
|
43
|
+
if (foundItem) {
|
|
44
|
+
foundItem.name = req.body.name;
|
|
45
|
+
foundItem.shortDescription = req.body.shortDescription;
|
|
46
|
+
foundItem.fullDescription = req.body.fullDescription;
|
|
47
|
+
await foundItem.save();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
res.status(200).end();
|
|
37
52
|
}
|
|
38
53
|
catch(err) {
|
|
39
54
|
res.status(500).end();
|
|
@@ -41,13 +56,9 @@ router.get("/", async function(req, res) {
|
|
|
41
56
|
}
|
|
42
57
|
});
|
|
43
58
|
|
|
44
|
-
router.post("/", async function(req, res) {
|
|
59
|
+
router.post("/delete", async function(req, res) {
|
|
45
60
|
try {
|
|
46
|
-
await items.
|
|
47
|
-
name: req.body.name,
|
|
48
|
-
shortDescription: req.body.shortDescription,
|
|
49
|
-
fullDescription: req.body.fullDescription
|
|
50
|
-
});
|
|
61
|
+
await items.findByIdAndDelete(req.body.id);
|
|
51
62
|
|
|
52
63
|
res.status(200).end();
|
|
53
64
|
}
|
|
@@ -57,5 +68,4 @@ router.post("/", async function(req, res) {
|
|
|
57
68
|
}
|
|
58
69
|
});
|
|
59
70
|
|
|
60
|
-
|
|
61
71
|
module.exports = router;
|
package/controllers/the-front.js
CHANGED
|
@@ -1,104 +1,86 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
styles: [],
|
|
11
|
-
externalStyles: [],
|
|
12
|
-
localScripts: [],
|
|
13
|
-
requiredItems: [],
|
|
14
|
-
needsKey: "",
|
|
15
|
-
dropOff: "",
|
|
16
|
-
...detail.options
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
detail.options.styles = detail.options.styles.map(style => {
|
|
20
|
-
style = `${dir}/styles/${style}`;
|
|
21
|
-
return style;
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
detail.options.externalStyles = detail.options.externalStyles.map(style => {
|
|
25
|
-
style = `${dir}/${style}`;
|
|
26
|
-
return style;
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
detail.options.localScripts = detail.options.localScripts.map(script => {
|
|
30
|
-
script = `${dir}/local-scripts/${script}`;
|
|
31
|
-
return script;
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
router.get(`/${detail.name}`, async function(req, res) {
|
|
35
|
-
detail.options.main = "index";
|
|
36
|
-
if (detail.name !== "") detail.options.main = detail.name;
|
|
37
|
-
detail.options.main = `${dir}/views/${detail.options.main}`;
|
|
1
|
+
const front = async function front(dir) {
|
|
2
|
+
const db = require("../models");
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
let router = require("express").Router();
|
|
6
|
+
|
|
7
|
+
router.post(`/serve/:script`, async function(req, res) {
|
|
8
|
+
try {
|
|
9
|
+
let currentRoute = `/${req.params.region}/${req.params.area}/${req.params.poi}/${req.params.detail}`;
|
|
38
10
|
|
|
39
|
-
|
|
40
|
-
for (let m = 0; m < detail.options.requiredItems.length; m++) {
|
|
41
|
-
let foundItem = await item.findOne({name: detail.options.requiredItems[m]});
|
|
11
|
+
let foundPoi = await db.poi.findOne({ route: currentRoute, type: "global" });
|
|
42
12
|
|
|
43
|
-
|
|
13
|
+
if (foundPoi === null) {
|
|
14
|
+
db.poi.create({
|
|
15
|
+
route: currentRoute,
|
|
16
|
+
name: req.params.detail,
|
|
17
|
+
type: "global",
|
|
18
|
+
global: {}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let scriptResult = await require(`${worldPath}/${currentRoute}/server-scripts/${req.params.script}.js`)(db, currentRoute, req.session.currentUser, req.body);
|
|
23
|
+
res.send(scriptResult);
|
|
44
24
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
user: null,
|
|
49
|
-
styles: detail.options.styles,
|
|
50
|
-
externalStyles: detail.options.externalStyles,
|
|
51
|
-
main: detail.options.main,
|
|
52
|
-
localScripts: detail.options.localScripts,
|
|
53
|
-
itemIDs: foundItemIDs,
|
|
54
|
-
inventory: null,
|
|
55
|
-
query: req.query,
|
|
56
|
-
dir: dir,
|
|
57
|
-
path: path
|
|
25
|
+
catch(err) {
|
|
26
|
+
console.log(err);
|
|
27
|
+
res.status(500).end();
|
|
58
28
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (detail.options.needsKey !== "" && context.inventory) {
|
|
66
|
-
let hasKey = false;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
router.get(`/:detail`, async function(req, res) {
|
|
32
|
+
try {
|
|
33
|
+
const foundUser = await db.user.findById(req.session.currentUser);
|
|
34
|
+
const foundInventory = await db.inventory.findOne({ user: req.session.currentUser }).populate("items.item");
|
|
67
35
|
|
|
68
|
-
|
|
69
|
-
if (foundInventory.items[i].item.name === detail.options.needsKey) hasKey = true;
|
|
70
|
-
}
|
|
36
|
+
let main = `${dir}/views/${req.params.detail}`;
|
|
71
37
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
38
|
+
let context = {
|
|
39
|
+
siteTitle: `NotherBase - ${req.params.detail}`,
|
|
40
|
+
user: foundUser,
|
|
41
|
+
main: main,
|
|
42
|
+
pov: req.query.pov,
|
|
43
|
+
inventory: foundInventory,
|
|
44
|
+
query: req.query,
|
|
45
|
+
dir: dir,
|
|
46
|
+
path: path
|
|
76
47
|
}
|
|
77
|
-
|
|
78
|
-
|
|
48
|
+
|
|
49
|
+
await res.render(`explorer`, context);
|
|
50
|
+
}
|
|
51
|
+
catch(err) {
|
|
52
|
+
console.log(err);
|
|
53
|
+
res.status(500).end();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
router.get(`/`, async function(req, res) {
|
|
58
|
+
try {
|
|
59
|
+
const foundUser = await db.user.findById(req.session.currentUser);
|
|
60
|
+
const foundInventory = await db.inventory.findOne({ user: req.session.currentUser }).populate("items.item");
|
|
61
|
+
|
|
62
|
+
let main = `${dir}/views/index`;
|
|
63
|
+
|
|
64
|
+
let context = {
|
|
65
|
+
siteTitle: `NotherBase - The Front`,
|
|
66
|
+
user: foundUser,
|
|
67
|
+
main: main,
|
|
68
|
+
pov: req.query.pov,
|
|
69
|
+
inventory: foundInventory,
|
|
70
|
+
query: req.query,
|
|
71
|
+
dir: dir,
|
|
72
|
+
path: path
|
|
79
73
|
}
|
|
74
|
+
|
|
75
|
+
await res.render(`explorer`, context);
|
|
80
76
|
}
|
|
81
|
-
|
|
82
|
-
console.log(
|
|
83
|
-
|
|
84
|
-
res.render(`explorer`, context);
|
|
77
|
+
catch(err) {
|
|
78
|
+
console.log(err);
|
|
79
|
+
res.status(500).end();
|
|
85
80
|
}
|
|
86
81
|
});
|
|
82
|
+
|
|
83
|
+
return router;
|
|
87
84
|
}
|
|
88
85
|
|
|
89
|
-
|
|
90
|
-
dir = frontBuild.dirname;
|
|
91
|
-
|
|
92
|
-
for (let i = 0; i < frontBuild.details.length; i++) {
|
|
93
|
-
front(frontBuild.details[i]);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
module.exports = {
|
|
98
|
-
setDir: function setDir(newDir) {
|
|
99
|
-
dir = newDir;
|
|
100
|
-
},
|
|
101
|
-
router: router,
|
|
102
|
-
front: front,
|
|
103
|
-
complete: complete
|
|
104
|
-
}
|
|
86
|
+
module.exports = front;
|
package/models/index.js
CHANGED
package/models/poi.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// This allows us to use Mongoose to connect to MongoDB
|
|
2
|
+
const mongoose = require("mongoose");
|
|
3
|
+
|
|
4
|
+
const poi = new mongoose.Schema({
|
|
5
|
+
route: String,
|
|
6
|
+
name: String,
|
|
7
|
+
type: String,
|
|
8
|
+
user: {
|
|
9
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
10
|
+
ref: "users",
|
|
11
|
+
required: false
|
|
12
|
+
},
|
|
13
|
+
data: {}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// This tells Mongoose to use the exampleSchema to access the examples collection
|
|
17
|
+
// in our db and then exports the model so we can use it.
|
|
18
|
+
module.exports = mongoose.model('pois', poi);
|
package/notherbase-fs.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
require("dotenv").config();
|
|
2
|
+
|
|
3
|
+
class NotherBaseFS {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.express = require("express");
|
|
6
|
+
this.session = require('express-session');
|
|
7
|
+
this.methodOverride = require('method-override');
|
|
8
|
+
this.MongoStore = require('connect-mongo');
|
|
9
|
+
this.favicon = require('serve-favicon');
|
|
10
|
+
this.http = require('http');
|
|
11
|
+
this.app = this.express();
|
|
12
|
+
this.server = this.http.createServer(this.app);
|
|
13
|
+
this.io = new (require("socket.io").Server)(this.server);
|
|
14
|
+
this.db = require("./models");
|
|
15
|
+
this.started = false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async start(worldPath, voidPath, frontPath, pagesPath) {
|
|
19
|
+
if (!this.started) {
|
|
20
|
+
//set views path
|
|
21
|
+
this.app.set("view engine", "ejs");
|
|
22
|
+
this.app.set("views", `${__dirname}/views`);
|
|
23
|
+
|
|
24
|
+
// allows us to delete
|
|
25
|
+
this.app.use(this.methodOverride('_method'));
|
|
26
|
+
|
|
27
|
+
// allows us to use post body data
|
|
28
|
+
this.app.use(this.express.urlencoded({ extended: true }));
|
|
29
|
+
|
|
30
|
+
// allows us to get static files like css
|
|
31
|
+
this.app.use(this.express.static('public'));
|
|
32
|
+
this.app.use(this.express.static(`${__dirname}/public`));
|
|
33
|
+
|
|
34
|
+
// sets the favicon image
|
|
35
|
+
this.app.use(this.favicon(__dirname + '/public/img/logo.png'));
|
|
36
|
+
|
|
37
|
+
// Import my Controller
|
|
38
|
+
const controllers = require("./controllers");
|
|
39
|
+
|
|
40
|
+
//enable cookies
|
|
41
|
+
if (this.db.connectionSuccess) {
|
|
42
|
+
this.app.use(this.session({
|
|
43
|
+
store: this.MongoStore.create({ mongoUrl: process.env.MONGODB_URI }),
|
|
44
|
+
secret: process.env.SECRET || "won",
|
|
45
|
+
resave: false,
|
|
46
|
+
saveUninitialized: false
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
console.log("sessions enabled");
|
|
50
|
+
}
|
|
51
|
+
else console.log("sessions disabled");
|
|
52
|
+
|
|
53
|
+
this.io.on('connection', (socket) => {
|
|
54
|
+
socket.join(socket.handshake.query.room);
|
|
55
|
+
|
|
56
|
+
socket.on('disconnect', () => {});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
this.app.use("/user", controllers.user);
|
|
60
|
+
|
|
61
|
+
this.app.use("/chat", controllers.chat(this.io));
|
|
62
|
+
|
|
63
|
+
this.app.use("/contact", controllers.contact);
|
|
64
|
+
|
|
65
|
+
this.app.use("/game", controllers.game);
|
|
66
|
+
|
|
67
|
+
this.app.use("/inventory", controllers.authCheck, controllers.inventory);
|
|
68
|
+
|
|
69
|
+
this.app.use("/item", controllers.item);
|
|
70
|
+
|
|
71
|
+
this.app.use("/the-front", await controllers.front(frontPath));
|
|
72
|
+
|
|
73
|
+
this.app.use("/", controllers.pages(pagesPath));
|
|
74
|
+
|
|
75
|
+
this.app.use("/", controllers.authCheck, await controllers.explorer(worldPath, voidPath));
|
|
76
|
+
|
|
77
|
+
this.server.listen(process.env.PORT, function () {
|
|
78
|
+
console.log(`Server started at ${process.env.PORT}`);
|
|
79
|
+
this.started = true;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
else console.log("Server already started!");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = new NotherBaseFS();
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "notherbase-fs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Functions to help make developing for NotherBase easier.",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "notherbase-fs.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "nodemon test/test-index.js",
|
|
8
8
|
"gmail-auth": "node gmail-auth.js",
|