notherbase-fs 1.3.8 → 1.3.10

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,8 +4,6 @@ const router = express.Router();
4
4
  const getRouterWithIO = function getRouterWithIO(io) {
5
5
  router.post("/", async function(req, res) {
6
6
  try {
7
- //const foundAccount = await User.findOne({ _id: req.session.currentUser });
8
-
9
7
  if (req.session.currentUser) {
10
8
  io.to(req.body.room).emit('chat message', {
11
9
  name: req.session.currentUser,
@@ -42,7 +42,8 @@ const explorer = async function explorer(worldPath, voidPath) {
42
42
  try {
43
43
  let currentRoute = `${req.params.region}/${req.params.area}/${req.params.poi}/${req.params.detail}`;
44
44
 
45
- if (await db.poi.exists({ route: currentRoute, user: req.session.currentUser }) === false) {
45
+ let exists = await db.poi.exists({ route: currentRoute, user: req.session.currentUser });
46
+ if (!exists) {
46
47
  await db.poi.create({
47
48
  route: currentRoute,
48
49
  name: req.params.detail,
@@ -54,8 +55,7 @@ const explorer = async function explorer(worldPath, voidPath) {
54
55
 
55
56
  let found = await db.poi.findOne({ route: currentRoute, user: req.session.currentUser });
56
57
 
57
- if (found) res.send(found.data);
58
- else res.send("Found nothing.");
58
+ res.send(found.data);
59
59
  }
60
60
  catch(err) {
61
61
  console.log(err);
@@ -67,15 +67,14 @@ const explorer = async function explorer(worldPath, voidPath) {
67
67
  try {
68
68
  let currentRoute = `${req.params.region}/${req.params.area}/${req.params.poi}/${req.params.detail}`;
69
69
 
70
- if (await db.poi.exists({ route: currentRoute, user: req.session.currentUser }) === false) {
71
- await db.poi.create({
72
- route: currentRoute,
73
- name: req.params.detail,
74
- type: "user",
75
- user: req.session.currentUser,
76
- data: {}
77
- });
78
- }
70
+ let exists = await db.poi.exists({ route: currentRoute, user: req.session.currentUser });
71
+ if (!exists) await db.poi.create({
72
+ route: currentRoute,
73
+ name: req.params.detail,
74
+ type: "user",
75
+ user: req.session.currentUser,
76
+ data: {}
77
+ });
79
78
 
80
79
  await db.poi.updateOne({ route: currentRoute, user: req.session.currentUser }, { data: req.body });
81
80
 
@@ -2,10 +2,69 @@ const express = require("express");
2
2
  const router = express.Router();
3
3
  const fs = require('fs');
4
4
 
5
+ const page = require("../models").page;
6
+
5
7
  module.exports = function name(path)
6
8
  {
7
9
  let files = fs.readdirSync(path);
8
10
 
11
+ router.get('/pages/db', async function (req, res) {
12
+ try {
13
+ if (req.query.type === "global") {
14
+ let foundPage = await page.findOne({name: req.query.name, type: "global"});
15
+
16
+ if (!foundPage) res.status(404).end();
17
+ else res.status(200).send(foundPage);
18
+ }
19
+ else {
20
+ let foundPage = await page.findOne({name: req.query.name, user: req.session.currentUser});
21
+
22
+ if (!foundPage) res.status(404).end();
23
+ else res.status(200).send(foundPage);
24
+ }
25
+ }
26
+ catch(err) {
27
+ res.status(500).end();
28
+ console.log(err);
29
+ }
30
+ });
31
+
32
+ router.post('/pages/db', async function (req, res) {
33
+ try {
34
+ let foundPage;
35
+
36
+ if (req.query.type === "global") {
37
+ foundPage = await page.findOne({name: req.query.name, type: "global"});
38
+ }
39
+ else {
40
+ foundPage = await page.findOne({name: req.query.name, user: req.session.currentUser});
41
+ }
42
+
43
+ if (!foundGame) {
44
+ await game.create({
45
+ name: req.body.name,
46
+ type: req.query.type,
47
+ user: req.session.currentUser,
48
+ data: req.query.data
49
+ });
50
+
51
+ res.status(200).end();
52
+ }
53
+ else {
54
+ foundGame.data = req.query.data;
55
+ foundGame.markModified("data");
56
+ await foundGame.save();
57
+
58
+ res.status(200).end();
59
+ }
60
+ }
61
+ catch(err) {
62
+ res.status(500).end();
63
+ console.log(req.query);
64
+ console.log(err);
65
+ }
66
+ });
67
+
9
68
  files.forEach(file => {
10
69
  file = file.slice(0, -4);
11
70
 
package/models/index.js CHANGED
@@ -7,5 +7,6 @@ module.exports = {
7
7
  inventory: require("./inventory"),
8
8
  game: require("./game"),
9
9
  sendMail: require("./send-mail"),
10
- poi: require("./poi")
10
+ poi: require("./poi"),
11
+ page: require("./page")
11
12
  }
package/models/page.js ADDED
@@ -0,0 +1,14 @@
1
+ const mongoose = require("mongoose");
2
+
3
+ const page = new mongoose.Schema({
4
+ name: String,
5
+ type: String,
6
+ user: {
7
+ type: mongoose.Schema.Types.ObjectId,
8
+ ref: "users",
9
+ required: false
10
+ },
11
+ data: {}
12
+ });
13
+
14
+ module.exports = mongoose.model('pages', page);
package/notherbase-fs.js CHANGED
@@ -52,6 +52,10 @@ class NotherBaseFS {
52
52
 
53
53
  this.io.on('connection', (socket) => {
54
54
  socket.join(socket.handshake.query.room);
55
+
56
+ console.log(socket.rooms);
57
+
58
+ socket.to(socket.handshake.query.room).emit(`${socket.handshake.query.name} has joined the room`);
55
59
 
56
60
  socket.on('disconnect', () => {});
57
61
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notherbase-fs",
3
- "version": "1.3.8",
3
+ "version": "1.3.10",
4
4
  "description": "Functions to help make developing for NotherBase easier.",
5
5
  "main": "notherbase-fs.js",
6
6
  "scripts": {
@@ -0,0 +1,50 @@
1
+ class ChatBox {
2
+ constructor(name, box, room) {
3
+ this.socket = null;
4
+ import("/socket.io/socket.io.js").then(() => {
5
+ this.socket = io({
6
+ query: {
7
+ room: room,
8
+ name: name
9
+ }
10
+ });
11
+
12
+ this.socket.on('chat message', this.newMessage);
13
+ $(".chat-send").on("click", this.sendMessage);
14
+ this.$entry.on("keyup", function(e) {
15
+ if (e.keyCode == 13) sendMessage();
16
+ });
17
+ });
18
+
19
+ this.room = room;
20
+ this.$div = $(`.chat-box #${box}`)
21
+ this.$chatLog = this.$div.find(".chat-log");
22
+ this.$entry = this.$div.find(".chat-entry");
23
+ }
24
+
25
+ newMessage = (msg) => {
26
+ let time = new Date(msg.time);
27
+ this.$chatLog.append(`<p>[${time.toLocaleTimeString('en-US')}] ${msg.name}: ${msg.text}</p>`);
28
+ }
29
+
30
+ sendMessage = () => {
31
+ if (this.$entry.val() !== ""){
32
+ let val = this.$entry.val();
33
+ this.$entry.val("");
34
+
35
+ // $.post("/chat", {
36
+ // room: "<%= room %>",
37
+ // text: val
38
+ // }, function () {
39
+ // $chatLog.scrollTop($chatLog[0].scrollHeight);
40
+ // });
41
+
42
+ this.socket.emit('chat message', {
43
+ name: name,
44
+ time: Date.now(),
45
+ text: val
46
+ });
47
+ }
48
+ }
49
+ }
50
+
@@ -4,6 +4,19 @@
4
4
 
5
5
  <hr>
6
6
 
7
+ <div class="chat-box" id="test-box">
8
+ <div class="chat-name">Chatting using the name <%= user.username %>:</div>
9
+
10
+ <div class="chat-log">
11
+
12
+ </div>
13
+
14
+ <input autocomplete="off" type="text" name="text" class="chat-entry">
15
+ <div value="Send" class="chat-send">Send</div>
16
+ </div>
17
+
18
+ <hr>
19
+
7
20
  <h3>Game Test</h3>
8
21
 
9
22
  <button onclick="addToTime()">Add</button>
@@ -67,7 +80,11 @@
67
80
  Go to Nono Cove
68
81
  </a>
69
82
 
83
+
84
+ <script src="/js/chat-box.js"></script>
70
85
  <script>
86
+ let chatTest = new ChatBox("<%= user.username %>", "test-box", "testRoom");
87
+
71
88
  let bought = false;
72
89
 
73
90
  let tradeForDoll = async function tradeForDoll() {
package/views/head.ejs CHANGED
@@ -18,6 +18,7 @@
18
18
  <link rel="stylesheet" href="/styles/player.css">
19
19
  <link rel="stylesheet" href="/styles/account.css">
20
20
  <link rel="stylesheet" href="/styles/more.css">
21
+ <link rel="stylesheet" href="/styles/chat.css">
21
22
  </head>
22
23
 
23
24
  <body>
@@ -1,47 +0,0 @@
1
- <link rel="stylesheet" href="/styles/chat.css">
2
-
3
- <div class="chat-box">
4
- <div class="chat-name">Chatting using the name <%= user.username %>:</div>
5
-
6
- <div class="chat-log">
7
-
8
- </div>
9
- <input autocomplete="off" type="text" name="text" class="chat-entry">
10
- <div value="Send" class="chat-send">Send</div>
11
- </div>
12
-
13
- <script>
14
- <%- include("../node_modules/socket.io/client-dist/socket.io.js"); %>
15
-
16
- let socket = io({
17
- query: {
18
- room: "<%= room %>"
19
- }
20
- });
21
- let $chatLog = $(".chat-log");
22
- let $entry = $(".chat-entry");
23
-
24
- socket.on('chat message', function(msg) {
25
- let time = new Date(msg.time);
26
- $chatLog.append(`<p>[${time.toLocaleTimeString('en-US')}] ${msg.name}: ${msg.text}</p>`);
27
- });
28
-
29
- const sendMessage = function() {
30
- if ($entry.val() !== ""){
31
- let val = $entry.val();
32
- $entry.val("");
33
-
34
- $.post("/chat", {
35
- room: "<%= room %>",
36
- text: val
37
- }, function () {
38
- $chatLog.scrollTop($chatLog[0].scrollHeight);
39
- });
40
- }
41
- }
42
-
43
- $(".chat-send").on("click", sendMessage);
44
- $entry.on("keyup", function(e) {
45
- if (e.keyCode == 13) sendMessage();
46
- });
47
- </script>