notherbase-fs 1.1.33 → 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.
@@ -4,7 +4,7 @@ const authCheck = async function authCheck(req, res, next){
4
4
  if (connectionSuccess) {
5
5
  try {
6
6
  if (req.session.currentUser) {
7
- const foundAccount = await User.findById(req.session.currentUser);
7
+ const foundAccount = await user.findById(req.session.currentUser);
8
8
 
9
9
  if (foundAccount) {
10
10
  req.session.currentUserFull = foundAccount;
@@ -26,7 +26,6 @@ const authCheck = async function authCheck(req, res, next){
26
26
  }
27
27
  else {
28
28
  console.log("AuthCheck failed: not connected to db");
29
- req.session.currentUserFull = null;
30
29
  res.redirect("/the-front");
31
30
  }
32
31
  }
@@ -1,4 +1,4 @@
1
- const inventory = require("../models/inventory");
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
- scripts: [],
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.scripts = detail.options.scripts.map(script => {
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(`/${currentRegion}/${currentArea}/${currentPoi}/${detail.name}`, async function(req, res) {
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
- if (detail.options.needsKey !== "" && foundInventory) {
61
- let hasKey = false;
62
-
63
- for (let i = 0; i < foundInventory.items.length; i++) {
64
- if (foundInventory.items[i].item.name === detail.options.needsKey) hasKey = true;
65
- }
66
-
67
- if (!hasKey) res.redirect(detail.options.dropOff);
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
- else res.render(`explorer`,
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
- scripts: detail.options.scripts,
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;
@@ -7,7 +7,7 @@ let front = function front(detail) {
7
7
  detail.options = {
8
8
  styles: [],
9
9
  externalStyles: [],
10
- scripts: [],
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.scripts = detail.options.scripts.map(script => {
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
- scripts: detail.options.scripts,
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
- scripts: detail.options.scripts,
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
- scripts: detail.options.scripts,
86
+ localScripts: detail.options.localScripts,
87
87
  inventory: null,
88
88
  query: req.query
89
89
  });
@@ -3,20 +3,19 @@ const router = express.Router();
3
3
  const bcrypt = require("bcrypt");
4
4
 
5
5
  // Import my Data
6
- const User = require("../models/user");
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 User.findOne({ username: req.body.username });
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 User.create({
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: Username taken!");
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 User.findOne({ username: req.body.username });
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.currentUser = { _id: foundAccount._id };
53
- req.session.currentUserFull = foundAccount;
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: Username not found!");
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 foundUsers = await User.find({}, 'username coin home authLevels location');
84
+ let foundusers = await user.find({}, 'username coin home authLevels location');
86
85
 
87
- res.status(200).send({ foundUsers: foundUsers });
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 User.findByIdAndDelete(req.session.currentUser);
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
@@ -5,4 +5,5 @@ module.exports = {
5
5
  user: require("./user"),
6
6
  contact: require("./contact"),
7
7
  inventory: require("./inventory"),
8
+ game: require("./game")
8
9
  }
@@ -1,40 +1,36 @@
1
1
  require("dotenv").config();
2
2
  const mongoose = require("mongoose");
3
3
 
4
- let success = false;
5
-
6
- //connect mongoose and mongo
7
- let init = async function init() {
8
- try {
9
- await mongoose.connect(process.env.MONGODB_URI, {
10
- useNewUrlParser: true,
11
- useUnifiedTopology: true
12
- });
13
-
14
- success = true;
15
-
16
- //handlers
17
- mongoose.connection.on('connected', (err) => {
18
- console.log(`Mongoose connected to db`);
19
- success = true;
20
- });
21
-
22
- mongoose.connection.on('error', (err) => {
23
- console.log(`Mongoose ${err}`);
24
- success = false;
25
- });
26
-
27
- mongoose.connection.on('disconnected', () => {
28
- console.log('Mongoose disconnected');
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
- init();
33
+ success = false;
34
+ }
39
35
 
40
36
  module.exports = success;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notherbase-fs",
3
- "version": "1.1.33",
3
+ "version": "1.1.36",
4
4
  "description": "Functions to help make developing for NotherBase easier.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,7 @@
1
+ let $game = $(".game");
2
+ let $text = $(".game h3");
3
+ let $button = $(".game button");
4
+
5
+ $button.on("click", function () {
6
+ $text.text(`${$text.text()} clicked`);
7
+ });
@@ -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
+ }
@@ -1 +1,16 @@
1
- nono
1
+ <p>
2
+ nono
3
+ </p>
4
+
5
+ <hr>
6
+
7
+ <div class="game">
8
+ <h3><%= serverScriptReturns[0] %>Text</h3>
9
+ <button>Click</button>
10
+ </div>
11
+
12
+ <hr>
13
+
14
+ <a href="/the-front">
15
+ Go to The Front
16
+ </a>
@@ -24,7 +24,10 @@ const world = {
24
24
  details: [
25
25
  {
26
26
  name: "",
27
- options: {}
27
+ options: {
28
+ localScripts: ["game"],
29
+ serverScripts: ["game"]
30
+ }
28
31
  }
29
32
  ]
30
33
  }
@@ -1,5 +1,5 @@
1
1
  <p>
2
- A random nono washes up on shore. Will you solve it?
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);
@@ -19,8 +19,8 @@
19
19
  </div>
20
20
 
21
21
  <script>
22
- <% for (let i = 0; i < scripts.length; i++) { %>
23
- <%- include(`${scripts[i]}.js`); %>
22
+ <% for (let i = 0; i < localScripts.length; i++) { %>
23
+ <%- include(`${localScripts[i]}.js`); %>
24
24
  <% } %>
25
25
  </script>
26
26