notherbase-fs 1.1.35 → 1.1.36
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 +36 -28
- package/controllers/game.js +59 -0
- package/controllers/the-front.js +5 -5
- package/controllers/user.js +11 -12
- package/models/game.js +11 -0
- package/models/index.js +1 -0
- package/models/start-mongoose.js +29 -33
- package/package.json +1 -1
- package/test/coast/tall-beach/nono-cove/local-scripts/game.js +7 -0
- package/test/coast/tall-beach/nono-cove/server-scripts/game.js +31 -0
- package/test/coast/tall-beach/nono-cove/views/index.ejs +16 -1
- package/test/test-index.js +4 -1
- package/test/views/index.ejs +20 -1
- package/views/explorer.ejs +2 -2
package/controllers/explorer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const inventory = require("../models
|
|
1
|
+
const { inventory, game, item } = require("../models");
|
|
2
2
|
|
|
3
3
|
let router = require("express").Router();;
|
|
4
4
|
let dir = "";
|
|
@@ -24,11 +24,13 @@ let complete = function complete(explorerBuild) {
|
|
|
24
24
|
let detail = poi.details[l];
|
|
25
25
|
|
|
26
26
|
let currentDir = `${dir}/${currentRegion}/${currentArea}/${currentPoi}`;
|
|
27
|
+
let currentRoute = `/${currentRegion}/${currentArea}/${currentPoi}/${detail.name}`;
|
|
27
28
|
|
|
28
29
|
detail.options = {
|
|
29
30
|
styles: [],
|
|
30
31
|
externalStyles: [],
|
|
31
|
-
|
|
32
|
+
localScripts: [],
|
|
33
|
+
serverScripts: [],
|
|
32
34
|
needsKey: "",
|
|
33
35
|
dropOff: "",
|
|
34
36
|
...detail.options
|
|
@@ -44,52 +46,58 @@ let complete = function complete(explorerBuild) {
|
|
|
44
46
|
return style;
|
|
45
47
|
});
|
|
46
48
|
|
|
47
|
-
detail.options.
|
|
49
|
+
detail.options.localScripts = detail.options.localScripts.map(script => {
|
|
48
50
|
script = `${currentDir}/local-scripts/${script}`;
|
|
49
51
|
return script;
|
|
50
52
|
});
|
|
53
|
+
|
|
54
|
+
detail.options.serverScripts = detail.options.serverScripts.map(script => {
|
|
55
|
+
script = require(`${currentDir}/server-scripts/${script}`);
|
|
56
|
+
return script;
|
|
57
|
+
});
|
|
51
58
|
|
|
52
59
|
detail.options.main = "index";
|
|
53
60
|
if (detail.name !== "") detail.options.main = detail.name;
|
|
54
61
|
detail.options.main = `${currentDir}/views/${detail.options.main}`;
|
|
55
62
|
|
|
56
|
-
router.get(
|
|
63
|
+
router.get(currentRoute, async function(req, res) {
|
|
57
64
|
try {
|
|
58
65
|
const foundInventory = await inventory.findOne({ user: req.session.currentUser }).populate("items.item");
|
|
59
66
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
else res.render(`explorer`,
|
|
69
|
-
{
|
|
70
|
-
siteTitle: "NotherBase",
|
|
71
|
-
user: req.session.currentUserFull,
|
|
72
|
-
styles: detail.options.styles,
|
|
73
|
-
externalStyles: detail.options.externalStyles,
|
|
74
|
-
main: detail.options.main,
|
|
75
|
-
scripts: detail.options.scripts,
|
|
76
|
-
pov: req.query.pov,
|
|
77
|
-
inventory: foundInventory,
|
|
78
|
-
query: req.query
|
|
79
|
-
});
|
|
67
|
+
let serverScriptReturns = [];
|
|
68
|
+
|
|
69
|
+
for (let m = 0; m < detail.options.serverScripts.length; m++) {
|
|
70
|
+
serverScriptReturns.push(await detail.options.serverScripts[m]({
|
|
71
|
+
game: game,
|
|
72
|
+
inventory: inventory,
|
|
73
|
+
item: item
|
|
74
|
+
}));
|
|
80
75
|
}
|
|
81
|
-
|
|
82
|
-
{
|
|
76
|
+
|
|
77
|
+
let context = {
|
|
83
78
|
siteTitle: "NotherBase",
|
|
84
79
|
user: req.session.currentUserFull,
|
|
85
80
|
styles: detail.options.styles,
|
|
86
81
|
externalStyles: detail.options.externalStyles,
|
|
87
82
|
main: detail.options.main,
|
|
88
|
-
|
|
83
|
+
localScripts: detail.options.localScripts,
|
|
84
|
+
serverScriptReturns: serverScriptReturns,
|
|
89
85
|
pov: req.query.pov,
|
|
90
86
|
inventory: foundInventory,
|
|
91
87
|
query: req.query
|
|
92
|
-
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (detail.options.needsKey !== "" && foundInventory) {
|
|
91
|
+
let hasKey = false;
|
|
92
|
+
|
|
93
|
+
for (let i = 0; i < foundInventory.items.length; i++) {
|
|
94
|
+
if (foundInventory.items[i].item.name === detail.options.needsKey) hasKey = true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (!hasKey) res.redirect(detail.options.dropOff);
|
|
98
|
+
else res.render(`explorer`, context);
|
|
99
|
+
}
|
|
100
|
+
else res.render(`explorer`, context);
|
|
93
101
|
}
|
|
94
102
|
catch(err) {
|
|
95
103
|
console.log(err);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const express = require("express");
|
|
2
|
+
const router = express.Router();
|
|
3
|
+
|
|
4
|
+
// Import my Data
|
|
5
|
+
const { game } = require("../models");
|
|
6
|
+
|
|
7
|
+
router.get("/all", async function(req, res) {
|
|
8
|
+
try {
|
|
9
|
+
let foundGames = await game.find({game: req.query.game});
|
|
10
|
+
|
|
11
|
+
res.status(200).send({ foundGames: foundGames });
|
|
12
|
+
}
|
|
13
|
+
catch(err) {
|
|
14
|
+
res.status(500).end();
|
|
15
|
+
console.log(err);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
router.get("/one", async function(req, res) {
|
|
20
|
+
try {
|
|
21
|
+
let foundGame = await game.findOne({_id: req.query._id});
|
|
22
|
+
|
|
23
|
+
if (!foundGame) res.status(404).end();
|
|
24
|
+
else res.status(200).send({ foundGame: foundGame });
|
|
25
|
+
}
|
|
26
|
+
catch(err) {
|
|
27
|
+
res.status(500).end();
|
|
28
|
+
console.log(err);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
router.post("/", async function(req, res) {
|
|
33
|
+
try {
|
|
34
|
+
let foundGame = await game.findOne({_id: req.query._id});
|
|
35
|
+
|
|
36
|
+
if (!foundGame) {
|
|
37
|
+
await game.create({
|
|
38
|
+
name: req.body.name,
|
|
39
|
+
shortDescription: req.body.shortDescription,
|
|
40
|
+
fullDescription: req.body.fullDescription
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
res.status(200).end();
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
foundGame.data = req.query.data;
|
|
47
|
+
foundGame.markModified("data");
|
|
48
|
+
await foundGame.save();
|
|
49
|
+
|
|
50
|
+
res.status(200).send();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch(err) {
|
|
54
|
+
res.status(500).end();
|
|
55
|
+
console.log(err);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
module.exports = router;
|
package/controllers/the-front.js
CHANGED
|
@@ -7,7 +7,7 @@ let front = function front(detail) {
|
|
|
7
7
|
detail.options = {
|
|
8
8
|
styles: [],
|
|
9
9
|
externalStyles: [],
|
|
10
|
-
|
|
10
|
+
localScripts: [],
|
|
11
11
|
needsKey: "",
|
|
12
12
|
dropOff: "",
|
|
13
13
|
...detail.options
|
|
@@ -23,7 +23,7 @@ let front = function front(detail) {
|
|
|
23
23
|
return style;
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
detail.options.
|
|
26
|
+
detail.options.localScripts = detail.options.localScripts.map(script => {
|
|
27
27
|
script = `${dir}/local-scripts/${script}`;
|
|
28
28
|
return script;
|
|
29
29
|
});
|
|
@@ -52,7 +52,7 @@ let front = function front(detail) {
|
|
|
52
52
|
styles: detail.options.styles,
|
|
53
53
|
externalStyles: detail.options.externalStyles,
|
|
54
54
|
main: detail.options.main,
|
|
55
|
-
|
|
55
|
+
localScripts: detail.options.localScripts,
|
|
56
56
|
inventory: foundInventory,
|
|
57
57
|
query: req.query
|
|
58
58
|
});
|
|
@@ -64,7 +64,7 @@ let front = function front(detail) {
|
|
|
64
64
|
styles: detail.options.styles,
|
|
65
65
|
externalStyles: detail.options.externalStyles,
|
|
66
66
|
main: detail.options.main,
|
|
67
|
-
|
|
67
|
+
localScripts: detail.options.localScripts,
|
|
68
68
|
inventory: foundInventory,
|
|
69
69
|
query: req.query
|
|
70
70
|
});
|
|
@@ -83,7 +83,7 @@ let front = function front(detail) {
|
|
|
83
83
|
styles: detail.options.styles,
|
|
84
84
|
externalStyles: detail.options.externalStyles,
|
|
85
85
|
main: detail.options.main,
|
|
86
|
-
|
|
86
|
+
localScripts: detail.options.localScripts,
|
|
87
87
|
inventory: null,
|
|
88
88
|
query: req.query
|
|
89
89
|
});
|
package/controllers/user.js
CHANGED
|
@@ -3,20 +3,19 @@ const router = express.Router();
|
|
|
3
3
|
const bcrypt = require("bcrypt");
|
|
4
4
|
|
|
5
5
|
// Import my Data
|
|
6
|
-
const
|
|
7
|
-
const inventory = require("../models/inventory");
|
|
6
|
+
const { user, inventory } = require("../models");
|
|
8
7
|
|
|
9
8
|
const authCheck = require("./authCheck");
|
|
10
9
|
|
|
11
10
|
router.post("/register", async function(req, res) {
|
|
12
11
|
try {
|
|
13
|
-
const foundAccount = await
|
|
12
|
+
const foundAccount = await user.findOne({ username: req.body.username });
|
|
14
13
|
|
|
15
14
|
if (!foundAccount) {
|
|
16
15
|
const salt = await bcrypt.genSalt(10);
|
|
17
16
|
const hash = await bcrypt.hash(req.body.password, salt);
|
|
18
17
|
|
|
19
|
-
let qAuth = await
|
|
18
|
+
let qAuth = await user.create({
|
|
20
19
|
username: req.body.username,
|
|
21
20
|
password: hash,
|
|
22
21
|
email: "temp@example.com",
|
|
@@ -33,7 +32,7 @@ router.post("/register", async function(req, res) {
|
|
|
33
32
|
res.status(200).send("Registration Successful!");
|
|
34
33
|
}
|
|
35
34
|
else {
|
|
36
|
-
res.status(400).send("Registration Failed:
|
|
35
|
+
res.status(400).send("Registration Failed: username taken!");
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
catch(err) {
|
|
@@ -45,12 +44,12 @@ router.post("/register", async function(req, res) {
|
|
|
45
44
|
|
|
46
45
|
router.post("/login", async function(req, res) {
|
|
47
46
|
try {
|
|
48
|
-
const foundAccount = await
|
|
47
|
+
const foundAccount = await user.findOne({ username: req.body.username });
|
|
49
48
|
|
|
50
49
|
if (foundAccount) {
|
|
51
50
|
if (await bcrypt.compare(req.body.password, foundAccount.password)) {
|
|
52
|
-
req.session.
|
|
53
|
-
req.session.
|
|
51
|
+
req.session.currentuser = { _id: foundAccount._id };
|
|
52
|
+
req.session.currentuserFull = foundAccount;
|
|
54
53
|
|
|
55
54
|
res.status(200).send("Login successful!");
|
|
56
55
|
}
|
|
@@ -59,7 +58,7 @@ router.post("/login", async function(req, res) {
|
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
else {
|
|
62
|
-
res.status(401).send("Login Failed:
|
|
61
|
+
res.status(401).send("Login Failed: username not found!");
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
64
|
catch(err) {
|
|
@@ -82,9 +81,9 @@ router.get("/logout", authCheck, async function(req, res) {
|
|
|
82
81
|
|
|
83
82
|
router.get("/all", authCheck, async function(req, res) {
|
|
84
83
|
try {
|
|
85
|
-
let
|
|
84
|
+
let foundusers = await user.find({}, 'username coin home authLevels location');
|
|
86
85
|
|
|
87
|
-
res.status(200).send({
|
|
86
|
+
res.status(200).send({ foundusers: foundusers });
|
|
88
87
|
}
|
|
89
88
|
catch(err) {
|
|
90
89
|
res.status(500).end();
|
|
@@ -94,7 +93,7 @@ router.get("/all", authCheck, async function(req, res) {
|
|
|
94
93
|
|
|
95
94
|
router.delete("/", authCheck, async function(req, res) {
|
|
96
95
|
try {
|
|
97
|
-
const found = await
|
|
96
|
+
const found = await user.findByIdAndDelete(req.session.currentuser);
|
|
98
97
|
|
|
99
98
|
if (!found) console.log("Could not find account. No deletion!");
|
|
100
99
|
|
package/models/game.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This allows us to use Mongoose to connect to MongoDB
|
|
2
|
+
const mongoose = require("mongoose");
|
|
3
|
+
|
|
4
|
+
const game = new mongoose.Schema({
|
|
5
|
+
name: String,
|
|
6
|
+
data: {}
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// This tells Mongoose to use the exampleSchema to access the examples collection
|
|
10
|
+
// in our db and then exports the model so we can use it.
|
|
11
|
+
module.exports = mongoose.model('games', game);
|
package/models/index.js
CHANGED
package/models/start-mongoose.js
CHANGED
|
@@ -1,40 +1,36 @@
|
|
|
1
1
|
require("dotenv").config();
|
|
2
2
|
const mongoose = require("mongoose");
|
|
3
3
|
|
|
4
|
-
let success =
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
success = false;
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
catch (err) {
|
|
33
|
-
console.log(`Mongoose on connect: ${err}`);
|
|
34
|
-
success = false;
|
|
35
|
-
}
|
|
4
|
+
let success = null;
|
|
5
|
+
|
|
6
|
+
//handlers
|
|
7
|
+
mongoose.connection.on('connected', (err) => {
|
|
8
|
+
console.log(`Mongoose connected to db`);
|
|
9
|
+
success = true;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
mongoose.connection.on('error', (err) => {
|
|
13
|
+
console.log(`Mongoose ${err}`);
|
|
14
|
+
success = false;
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
mongoose.connection.on('disconnected', () => {
|
|
18
|
+
console.log('Mongoose disconnected');
|
|
19
|
+
success = false;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
mongoose.connect(process.env.MONGODB_URI, {
|
|
24
|
+
useNewUrlParser: true,
|
|
25
|
+
useUnifiedTopology: true
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
success = true;
|
|
36
29
|
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
console.log(`Mongoose on connect: ${err}`);
|
|
37
32
|
|
|
38
|
-
|
|
33
|
+
success = false;
|
|
34
|
+
}
|
|
39
35
|
|
|
40
36
|
module.exports = success;
|
package/package.json
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const req = require("express/lib/request");
|
|
2
|
+
|
|
3
|
+
module.exports = async function gameServerScript(db) {
|
|
4
|
+
try {
|
|
5
|
+
let foundGame = await db.game.findOne({ name: "test" });
|
|
6
|
+
|
|
7
|
+
if (!foundGame) {
|
|
8
|
+
await db.game.create({
|
|
9
|
+
name: "test",
|
|
10
|
+
data: {
|
|
11
|
+
count: 0
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return 0;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
let newCount = foundGame.data.count + 1;
|
|
19
|
+
foundGame.data = {
|
|
20
|
+
count: newCount
|
|
21
|
+
}
|
|
22
|
+
foundGame.markModified("data");
|
|
23
|
+
await foundGame.save();
|
|
24
|
+
|
|
25
|
+
return newCount;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch(err) {
|
|
29
|
+
console.log(err);
|
|
30
|
+
}
|
|
31
|
+
}
|
package/test/test-index.js
CHANGED
package/test/views/index.ejs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<p>
|
|
2
|
-
|
|
2
|
+
Welcome to The Front.
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
<hr>
|
|
@@ -13,9 +13,26 @@
|
|
|
13
13
|
<p id="login-info"></p>
|
|
14
14
|
</div>
|
|
15
15
|
|
|
16
|
+
<hr>
|
|
17
|
+
|
|
18
|
+
<div class="locked to nother-base">
|
|
19
|
+
Go to Nono Cove
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<a href="/coast/tall-beach/nono-cove" class="invisible to nother-base">
|
|
23
|
+
Go to Nono Cove
|
|
24
|
+
</a>
|
|
25
|
+
|
|
16
26
|
<script>
|
|
17
27
|
let $loginButton = $("#login-button");
|
|
18
28
|
let $loginInfo = $("#login-info");
|
|
29
|
+
let $toNonoButton = $(".locked.to.nother-base");
|
|
30
|
+
let $toNonoLink = $(".invisible.to.nother-base");
|
|
31
|
+
|
|
32
|
+
<% if (user) { %>
|
|
33
|
+
$toNonoButton.addClass("invisible");
|
|
34
|
+
$toNonoLink.removeClass("invisible");
|
|
35
|
+
<% } %>
|
|
19
36
|
|
|
20
37
|
$loginButton.on("click", async function () {
|
|
21
38
|
try {
|
|
@@ -24,6 +41,8 @@
|
|
|
24
41
|
password: $("#login-pass").val()
|
|
25
42
|
}, (data) => {
|
|
26
43
|
$loginInfo.text("To your right you hear the sound of a bang against a chain-link fence. You've logged in.");
|
|
44
|
+
$toNonoButton.addClass("invisible");
|
|
45
|
+
$toNonoLink.removeClass("invisible");
|
|
27
46
|
});
|
|
28
47
|
} catch (error) {
|
|
29
48
|
//console.log(error);
|
package/views/explorer.ejs
CHANGED