notherbase-fs 1.5.3 → 2.0.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.
Files changed (52) hide show
  1. package/controllers/creation.js +90 -0
  2. package/controllers/spirit-world.js +110 -0
  3. package/controllers/spirits/attribute.js +47 -0
  4. package/controllers/spirits/contact.js +16 -0
  5. package/controllers/spirits/inventory.js +71 -0
  6. package/controllers/spirits/item.js +41 -0
  7. package/controllers/spirits/serve.js +33 -0
  8. package/controllers/spirits/user.js +130 -0
  9. package/controllers/spirits/util.js +39 -0
  10. package/models/index.js +130 -14
  11. package/models/spirit.js +159 -0
  12. package/notherbase-fs.js +23 -73
  13. package/package.json +2 -2
  14. package/public/js/commune.js +22 -0
  15. package/public/js/establishment.js +44 -0
  16. package/public/js/memories.js +29 -30
  17. package/public/styles/main.css +9 -99
  18. package/test/explorer/coast/tall-beach/nono-cove/server-scripts/emailTime.js +7 -3
  19. package/test/explorer/coast/tall-beach/nono-cove/views/index.ejs +38 -60
  20. package/test/pages/server-scripts/emailTime.js +15 -0
  21. package/test/pages/test.ejs +30 -3
  22. package/test/the-front/server-scripts/emailTime.js +7 -3
  23. package/test/the-front/server-scripts/migrateBig.js +3 -0
  24. package/test/the-front/views/check.ejs +88 -2
  25. package/test/the-front/views/index.ejs +43 -101
  26. package/test-index.js +5 -0
  27. package/views/account.ejs +25 -36
  28. package/views/explorer.ejs +48 -1
  29. package/views/inventory.ejs +41 -99
  30. package/views/menu.ejs +8 -2
  31. package/views/more.ejs +8 -14
  32. package/views/player.ejs +37 -24
  33. package/controllers/authCheck.js +0 -18
  34. package/controllers/contact.js +0 -22
  35. package/controllers/explorer.js +0 -150
  36. package/controllers/game.js +0 -59
  37. package/controllers/index.js +0 -10
  38. package/controllers/inventory.js +0 -116
  39. package/controllers/item.js +0 -70
  40. package/controllers/pages.js +0 -33
  41. package/controllers/the-front.js +0 -70
  42. package/controllers/user.js +0 -413
  43. package/controllers/void.js +0 -16
  44. package/models/chat.js +0 -9
  45. package/models/contact.js +0 -14
  46. package/models/detail.js +0 -16
  47. package/models/game.js +0 -8
  48. package/models/inventory.js +0 -19
  49. package/models/item.js +0 -12
  50. package/models/page.js +0 -14
  51. package/models/user.js +0 -25
  52. package/test/test-index.js +0 -5
package/views/account.ejs CHANGED
@@ -56,27 +56,23 @@
56
56
  this.$passwordInput = this.$passwordEdit.find("input");
57
57
 
58
58
  this.$info = $(".content#account #info");
59
-
59
+
60
60
  <% if (user) { %>
61
+ this.username = "<%= user.username %>";
62
+ this.email = "<%= user.email %>";
63
+
61
64
  this.refresh();
62
65
  <% } %>
63
66
  }
64
67
 
65
68
  async refresh() {
66
- try {
67
- $.get("/user/basic", (data) => {
68
- this.$email.text(data.email);
69
- this.$emailInput.val(data.email);
70
- this.$username.text(data.username);
71
- this.$usernameInput.val(data.username);
72
-
73
- $(".content#account .settings").removeClass("invisible");
74
- $(".content#account #please-login").addClass("invisible");
75
- });
76
- }
77
- catch(err) {
78
- this.$info.text(err);
79
- }
69
+ this.$email.text(this.email);
70
+ this.$emailInput.val(this.email);
71
+ this.$username.text(this.username);
72
+ this.$usernameInput.val(this.username);
73
+
74
+ $(".content#account .settings").removeClass("invisible");
75
+ $(".content#account #please-login").addClass("invisible");
80
76
  }
81
77
 
82
78
  editEmail() {
@@ -91,16 +87,13 @@
91
87
  }
92
88
 
93
89
  async updateEmail() {
94
- try {
95
- await $.post("/user/email", { email: this.$emailInput.val() }, (data) => {
96
- this.$email.text(this.$emailInput.val());
97
- this.cancelEmail();
98
- this.$info.text("Email Updated!");
99
- });
100
- }
101
- catch(err) {
102
- this.$info.text(err);
103
- }
90
+ let response = await commune("changeUserEmail", { email: this.$emailInput.val() });
91
+
92
+ this.$email.text(this.$emailInput.val());
93
+ this.cancelEmail();
94
+ this.$info.text("Email Updated!");
95
+
96
+ location.reload();
104
97
  }
105
98
 
106
99
  editUsername() {
@@ -115,17 +108,13 @@
115
108
  }
116
109
 
117
110
  async updateUsername() {
118
- try {
119
- await $.post("/user/username", { username: this.$usernameInput.val() }, (data) => {
120
- this.$username.text(this.$usernameInput.val());
121
- this.cancelUsername();
122
- this.$info.text("Username Updated!");
123
- });
124
- }
125
- catch(err) {
126
- if (err.status === 401) this.$info.text("Username already taken!");
127
- else this.$info.text("Server Error");
128
- }
111
+ let response = await commune("changeUsername", { username: this.$usernameInput.val() });
112
+
113
+ this.$username.text(this.$usernameInput.val());
114
+ this.cancelUsername();
115
+ this.$info.text("Username Updated!");
116
+
117
+ location.reload();
129
118
  }
130
119
  }
131
120
 
@@ -3,11 +3,58 @@
3
3
  <script>
4
4
  const currentRoute = "<%- route %>";
5
5
  </script>
6
+ <script src="/js/commune.js"></script>
6
7
  <script src="/socket.io/socket.io.js"></script>
7
8
  <script src="/js/memories.js"></script>
9
+ <script src="/js/establishment.js"></script>
8
10
 
9
11
  <main class="override">
10
- <%- include(`${main}.ejs`); %>
12
+ <% if (requireUser && !user) { %>
13
+ <div class="login-cover">
14
+ <a href="/">
15
+ <h1>NotherBase</h1>
16
+ </a>
17
+ <h3>Login to Your Account</h3>
18
+ <input type="email" placeholder="user@email.com" id="email">
19
+ <input type="password" placeholder="password" id="pass">
20
+ <button id="login" onclick="attemptLogin()">Login</button>
21
+ <button id="reset" onclick="resetPassword()">Reset Password</button>
22
+ <p class="info"></p>
23
+ </div>
24
+ <script>
25
+ const $loginEmail = $(".login-cover #email");
26
+ const $loginPassword = $(".login-cover #pass");
27
+ const $loginInfo = $(".login-cover .info");
28
+
29
+ const attemptLogin = async () => {
30
+ return $.post("/s", JSON.stringify({
31
+ action: "login",
32
+ data: {
33
+ email: $loginEmail.val(),
34
+ password: $loginPassword.val()
35
+ }
36
+ }), (data) => {
37
+ if (data.status === "success") {
38
+ $loginInfo.text("You've logged in.");
39
+ location.reload();
40
+ }
41
+ else $loginInfo.text(data.message);
42
+ });
43
+ };
44
+
45
+ const resetPassword = async () => {
46
+ return $.post("/s", JSON.stringify({
47
+ action: "sendPasswordReset",
48
+ data: { email: $loginEmail.val() }
49
+ }), (data) => {
50
+ if (data.status === "success") $loginInfo.text("A reset code has been sent to your email.");
51
+ else $loginInfo.text(data.message);
52
+ });
53
+ }
54
+ </script>
55
+ <% } else { %>
56
+ <%- include(`${main}.ejs`); %>
57
+ <% } %>
11
58
  </main>
12
59
 
13
60
  <div class="ui">
@@ -3,13 +3,6 @@
3
3
  Please login to view your inventory.
4
4
  </div>
5
5
 
6
- <div class="item-spawner invisible">
7
- <input type="text" class="search">
8
- <div class="search-results">
9
-
10
- </div>
11
- </div>
12
-
13
6
  <div class="item-list">
14
7
  </div>
15
8
  </div>
@@ -25,74 +18,49 @@
25
18
  this.$error = $("#inventory #error");
26
19
  this.items = [];
27
20
 
28
- this.$search.on("keyup", () => {
29
- let searchString = this.$search.val();
30
-
31
- $.get(`/item`, { name: searchString }, (data) => {
32
- this.renderSearchResults(data.foundItems);
33
- });
34
- });
35
-
36
21
  this.refresh();
37
-
38
- setInterval(this.update, this.updateCooldown);
39
22
  }
40
23
 
41
24
  async change(itemName, amount) {
42
25
  let change = {
43
- item: itemName,
26
+ name: itemName,
44
27
  amount: amount
45
28
  }
46
29
 
47
- try {
48
- let data = null;
49
- let status = null;
50
-
51
- await $.post("/inventory", change, (d, s) => {
52
- data = d;
53
- status = s;
54
- });
55
-
56
- if (status === "notmodified") {
57
- return false;
58
- }
59
- else {
60
- let holding = false;
61
-
62
- for (let i = 0; i < this.items.length; i++) {
63
- if (this.items[i].item._id === data.item._id) {
64
- this.items[i].amount = data.amount;
65
- holding = true;
30
+ let response = await commune("updateItemInInventory", change);
66
31
 
67
- if (data.amount <= 0) this.items.splice(i, 1);
68
- }
69
- }
70
-
71
- if (!holding && data.amount > 0 && data.item) {
72
- this.items.push(data);
32
+ if (response.status === "success") {
33
+ let holding = false;
34
+
35
+ for (let i = 0; i < this.items.length; i++) {
36
+ if (this.items[i].name === response.data.name) {
37
+ this.items[i].amount = response.data.amount;
38
+ holding = true;
39
+
40
+ if (response.data.amount <= 0) this.items.splice(i, 1);
73
41
  }
74
-
75
- this.render();
76
- return true;
77
42
  }
43
+
44
+ if (!holding && response.data.amount > 0 && response.data.name) {
45
+ this.items.push(response.data);
46
+ }
47
+
48
+ this.render();
49
+
50
+ return true;
78
51
  }
79
- catch(err) {
80
- console.log(err);
81
- return false;
82
- }
52
+ else return false;
83
53
  }
84
54
 
85
55
  async getData() {
86
- try {
87
- await $.get("/inventory", (data) => {
88
- if (data.foundInventory) this.items = data.foundInventory.items;
56
+ await $.post("/s", JSON.stringify({ action: "getUserInventory" }), (res) => {
57
+ if (res.status === "success") {
58
+ this.items = res.data;
89
59
 
90
60
  this.clearError();
91
- });
92
- }
93
- catch(err) {
94
-
95
- }
61
+ }
62
+ else console.log(res);
63
+ });
96
64
  }
97
65
 
98
66
  render() {
@@ -101,34 +69,28 @@
101
69
  for (let i = 0; i < this.items.length; i++) {
102
70
  let $new = this.$list.append(
103
71
  `<div class="item-card">
104
- <h5>${this.items[i].item.name}</h5>
72
+ <h5>${this.items[i].name}</h5>
105
73
  <button id="${i}">X</button>
106
74
  <hr>
107
75
  <p>${this.items[i].amount}</p>
108
- </div>`
109
- ).children().last();
110
-
111
- $new.find("button").on("click", (e) => {
112
- let which = parseInt(e.currentTarget.id);
113
-
114
- this.change({
115
- item: this.items[which].item._id,
116
- amount: -1
117
- });
76
+ </div>`
77
+ ).children().last();
118
78
 
119
- this.clearError();
120
- });
121
- }
79
+ $new.find("button").on("click", this.reduceItem);
122
80
  }
81
+ }
82
+
83
+ reduceItem = (e) => {
84
+ let which = parseInt(e.currentTarget.id);
85
+
86
+ this.change(this.items[which].name, -1);
87
+
88
+ this.clearError();
89
+ }
123
90
 
124
91
  async refresh() {
125
- try {
126
- await this.getData();
127
- this.render();
128
- }
129
- catch(err) {
130
-
131
- }
92
+ await this.getData();
93
+ this.render();
132
94
  }
133
95
 
134
96
  clearError() {
@@ -140,26 +102,6 @@
140
102
  this.$error.removeClass("invisible");
141
103
  }
142
104
 
143
- renderSearchResults(results) {
144
- this.$searchResults.empty();
145
- this.searchResults = results;
146
-
147
- for (let i = 0; i < this.searchResults.length; i++) {
148
- let $new = this.$searchResults.append(
149
- `<p id="${i}">${this.searchResults[i].name}</p>`
150
- ).children().last();
151
-
152
- $new.on("click", (e) => {
153
- let which = parseInt(e.currentTarget.id);
154
-
155
- this.change({
156
- item: this.searchResults[which]._id,
157
- amount: 1
158
- });
159
- });
160
- }
161
- }
162
-
163
105
  hasItem(itemName, minAmount = 1) {
164
106
  for (let i = 0; i < this.items.length; i++) {
165
107
  if (this.items[i].item.name === itemName) {
package/views/menu.ejs CHANGED
@@ -25,11 +25,11 @@
25
25
  <div id="content-window">
26
26
  <%- include("./inventory.ejs"); %>
27
27
  <%- include("./player.ejs"); %>
28
- <%- include("./account.ejs"); %>
28
+ <%- include("./account.ejs", { user: user }); %>
29
29
  <%- include("./more.ejs"); %>
30
30
  </div>
31
31
 
32
- <a href="/user/logout" id="logout">Logout</a>
32
+ <button onclick="logout()">Logout</button>
33
33
  </div>
34
34
 
35
35
  <button id="menu"><i class="fas fa-cog"></i></button>
@@ -75,5 +75,11 @@
75
75
  $(`.menu .tabs #${id}`).addClass("selected");
76
76
  }
77
77
 
78
+ let logout = () => {
79
+ $.post("/s", JSON.stringify({
80
+ action: "logout"
81
+ }), () => {location.reload();});
82
+ }
83
+
78
84
  switchTab("inventory");
79
85
  </script>
package/views/more.ejs CHANGED
@@ -1,22 +1,16 @@
1
1
  <div class="content invisible" id="more">
2
2
  <h4>Message Nother</h4>
3
3
  <textarea id="content"></textarea>
4
- <button id="send">Send Message</button>
4
+ <button id="send" onclick="sendMessageToNother()">Send Message</button>
5
5
  </div>
6
6
 
7
7
  <script>
8
- $("#contact").on("click", (e) => {
9
- $("#contact-form").toggleClass("invisible");
10
- });
11
-
12
- $("#send").on("click", (e) => {
13
- $.post("/contact",
14
- {
15
- location: currentRoute,
16
- content: $("#content").val(),
17
- },
18
- function () {
19
- $("#content").val("");
8
+ let sendMessageToNother = async () => {
9
+ await commune("contactNother", {
10
+ content: $(".menu .content#more #content").val(),
11
+ route: currentRoute
20
12
  });
21
- });
13
+
14
+ $(".menu .content#more #content").val("");
15
+ }
22
16
  </script>
package/views/player.ejs CHANGED
@@ -6,39 +6,52 @@
6
6
  class PlayerAttributes {
7
7
  constructor() {
8
8
  this.$content = $(".content#player");
9
+ this.attributes = [];
9
10
 
10
11
  <% if (user) { %>
11
12
  this.refresh();
12
13
  <% } %>
13
14
  }
14
15
 
15
- async setAtt(change, to) {
16
- await $.post("/user/attributes", { change: change, to: to }, async (data) => {
17
- await this.refresh();
18
- });
16
+ async set(change, to) {
17
+ let response = await commune("setAttribute", { change: change, to: to });
18
+ this.attributes = response.data;
19
+ await this.render();
20
+ }
21
+
22
+ async increment(which) {
23
+ let response = await commune("incrementAttribute", { change: which, max: 20 });
24
+ this.attributes[which] = response.data;
25
+ await this.render();
26
+ }
27
+
28
+ async check(which, against) {
29
+ let response = await commune("checkAttribute", { check: which, against: against });
30
+ await this.render();
19
31
  }
20
32
 
21
33
  async refresh() {
22
- try {
23
- await $.get("/user/attributes", (data) => {
24
- this.$content.empty();
25
- for (const [key, value] of Object.entries(data)) {
26
- <% if (user) {
27
- if (user.authLevels.includes("Creator")) { %>
28
- this.$content.append(`<h3 id="${key}">
29
- ${key}: ${value}
30
- <input type="number"></input>
31
- <button onclick="playerAttributes.setAtt('${key}', $('.content#player h3#${key} input').val())">Set</button>
32
- </h3>`);
33
- <% }
34
- } else { %>
35
- this.$content.append(`<h3 id="${key}">${key}: ${value}</h3>`);
36
- <% } %>
37
- }
38
- });
39
- }
40
- catch(err) {
41
- console.log(err);
34
+ let response = await commune("attributes");
35
+ this.attributes = response.data;
36
+
37
+ this.render();
38
+ }
39
+
40
+ render() {
41
+ this.$content.empty();
42
+
43
+ for (const [key, value] of Object.entries(this.attributes)) {
44
+ <% if (user && user.authLevels.includes("Creator")) { %>
45
+ this.$content.append(`<h3 id="${key}">
46
+ ${key}: ${value}
47
+ <input type="number"></input>
48
+ <button onclick="playerAttributes.set('${key}', $('.content#player h3#${key} input').val())">Set</button>
49
+ <button onclick="playerAttributes.increment('${key}')">+</button>
50
+ <button onclick="playerAttributes.check('${key}', $('.content#player h3#${key} input').val())">Check</button>
51
+ </h3>`);
52
+ <% } else { %>
53
+ this.$content.append(`<h3 id="${key}">${key}: ${value}</h3>`);
54
+ <% } %>
42
55
  }
43
56
  }
44
57
  }
@@ -1,18 +0,0 @@
1
- import { connectionSuccess } from "../models/index.js";
2
-
3
- const authCheck = async function authCheck(req, res, next){
4
- if (connectionSuccess) {
5
- if (req.session.currentUser) {
6
- next();
7
- }
8
- else {
9
- res.redirect("/the-front");
10
- }
11
- }
12
- else {
13
- console.log("AuthCheck failed: not connected to db");
14
- res.redirect("/the-front");
15
- }
16
- }
17
-
18
- export default authCheck;
@@ -1,22 +0,0 @@
1
- import express from "express";
2
- const router = express.Router();
3
-
4
- import contact from "../models/contact.js";
5
-
6
- router.post("/", async function(req, res) {
7
- try {
8
- await contact.create({
9
- user: req.session.currentUser,
10
- location: req.body.location,
11
- content: req.body.content
12
- });
13
-
14
- res.status(200).end();
15
- }
16
- catch(err) {
17
- res.status(500).end();
18
- console.log(err);
19
- }
20
- });
21
-
22
- export default router;
@@ -1,150 +0,0 @@
1
- import express from "express";
2
- import fs from 'fs';
3
-
4
- let router = express.Router();
5
-
6
- router.post(`/:region/:area/:poi/:detail/serve/:script`, async function(req, res) {
7
- try {
8
- let currentAreaRoute = `${req.params.region}/${req.params.area}/${req.params.poi}`;
9
- let currentRoute = `${req.params.region}/${req.params.area}/${req.params.poi}/${req.params.detail}`;
10
- const foundUser = await req.db.user.findById(req.session.currentUser);
11
-
12
- let script = await import(`${req.worldDir}/${currentAreaRoute}/server-scripts/${req.params.script}.js`);
13
- let scriptResult = await script.default(req.db, currentRoute, foundUser, req.body);
14
- res.send({ scriptResult: scriptResult });
15
- }
16
- catch(err) {
17
- console.log(err);
18
- res.status(500).end();
19
- }
20
- });
21
-
22
- router.get(`/recall`, async function(req, res) {
23
- try {
24
- let exists = await req.db.detail.exists({
25
- route: req.query.route,
26
- service: req.query.service,
27
- scope: "local",
28
- user: req.session.currentUser
29
- });
30
-
31
- if (!exists) {
32
- await req.db.detail.create({
33
- _lastUpdate: Date.now(),
34
- route: req.query.route,
35
- service: req.query.service,
36
- scope: "local",
37
- user: req.session.currentUser,
38
- data: {}
39
- });
40
- }
41
-
42
- let found = await req.db.detail.findOne({
43
- route: req.query.route,
44
- service: req.query.service,
45
- scope: "local",
46
- user: req.session.currentUser
47
- });
48
-
49
- if (new Date(found._lastUpdate) > new Date(req.query._lastUpdate)) {
50
- res.send({
51
- isUpToDate: false,
52
- data: found.data
53
- });
54
- }
55
- else res.send({
56
- isUpToDate: true,
57
- data: null
58
- });
59
- }
60
- catch(err) {
61
- console.log(err);
62
- res.status(500).end();
63
- }
64
- });
65
-
66
- router.post(`/commit`, async function(req, res) {
67
- try {
68
- await req.db.detail.updateOne({
69
- route: req.body.route,
70
- service: req.body.service,
71
- scope: "local",
72
- user: req.session.currentUser
73
- }, {
74
- route: req.body.route,
75
- service: req.body.service,
76
- scope: "local",
77
- user: req.session.currentUser,
78
- _lastUpdate: req.body.time,
79
- data: req.body.data
80
- }, {
81
- upsert: true
82
- });
83
-
84
- res.send("Update successful!");
85
- }
86
- catch(err) {
87
- console.log(err);
88
- res.status(500).end();
89
- }
90
- });
91
-
92
- router.get(`/:region/:area/:poi/:detail`, async function(req, res, next) {
93
- try {
94
- let main = `${req.worldDir}/${req.params.region}/${req.params.area}/${req.params.poi}/views/${req.params.detail}`;
95
-
96
- if (fs.existsSync(main + ".ejs")) {
97
- const foundUser = await req.db.user.findById(req.session.currentUser);
98
- const foundInventory = await req.db.inventory.findOne({ user: req.session.currentUser }).populate("items.item");
99
-
100
- let context = {
101
- siteTitle: `NotherBase - ${req.params.detail}`,
102
- user: foundUser,
103
- main: main,
104
- pov: req.query.pov,
105
- inventory: foundInventory,
106
- query: req.query,
107
- dir: req.worldDir,
108
- route: `/${req.params.region}/${req.params.area}/${req.params.poi}/${req.params.detail}`
109
- }
110
-
111
- await res.render(`explorer`, context);
112
- }
113
- else next();
114
- }
115
- catch(err) {
116
- console.log(err);
117
- res.status(500).end();
118
- }
119
- });
120
-
121
- router.get(`/:region/:area/:poi`, async function(req, res, next) {
122
- try {
123
- let main = `${req.worldDir}/${req.params.region}/${req.params.area}/${req.params.poi}/views/index`;
124
-
125
- if (fs.existsSync(main + ".ejs")) {
126
- const foundUser = await req.db.user.findById(req.session.currentUser);
127
- const foundInventory = await req.db.inventory.findOne({ user: req.session.currentUser }).populate("items.item");
128
-
129
- let context = {
130
- siteTitle: `NotherBase - ${req.params.poi}`,
131
- user: foundUser,
132
- main: main,
133
- pov: req.query.pov,
134
- inventory: foundInventory,
135
- query: req.query,
136
- dir: req.worldDir,
137
- route: `/${req.params.region}/${req.params.area}/${req.params.poi}`
138
- }
139
-
140
- await res.render(`explorer`, context);
141
- }
142
- else next();
143
- }
144
- catch(err) {
145
- console.log(err);
146
- res.status(500).end();
147
- }
148
- });
149
-
150
- export default router;