diff --git a/.gitignore b/.gitignore
index f2fe600..a201c14 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,2 @@
client/node_modules/
-catalogue_server/node_modules/
+server/node_modules/
diff --git a/client/public/index.html b/client/public/index.html
index 6dcbea5..4c34c17 100644
--- a/client/public/index.html
+++ b/client/public/index.html
@@ -7,11 +7,17 @@
+
+
awaiting client id
-
+
diff --git a/client/public/index.js b/client/public/index.js
index 1c49fe5..0abd603 100644
--- a/client/public/index.js
+++ b/client/public/index.js
@@ -1,7 +1,28 @@
-(()=>{
- const username = prompt('Username:');
+const UsernameForm = document.querySelector('#input-username');
+const UsernameInput = document.querySelector('#input-text-username');
+UsernameForm.addEventListener('submit', onUsernameSubmit);
- console.log(username);
+(()=>{
+
+ // Presettup
})()
+
+// User submits their desired username
+function onUsernameSubmit(e)
+{
+ // Stop form refreshing page
+ e.preventDefault();
+
+ const chosenUsername = UsernameInput.value;
+
+ const req = {
+ username: chosenUsername
+ };
+
+
+
+ console.log(chosenUsername);
+
+}
diff --git a/game_server/index.js b/game_server/index.js
deleted file mode 100644
index e69de29..0000000
diff --git a/client/launchserver.js b/server/index.js
similarity index 54%
rename from client/launchserver.js
rename to server/index.js
index 7b6aa51..c8de907 100644
--- a/client/launchserver.js
+++ b/server/index.js
@@ -1,15 +1,13 @@
const Express = require('express');
const App = Express();
-const Port = 8080;
+const Port = 8081;
-const CATALOUGE_SERVER = 'localhost:8081';
-
-App.use(Express.static('public'));
+App.use(Express.static('../client/public'));
App.get('catalogue', async (req, res, next) => {
res.end({server: CATALOUGE_SERVER});
});
App.listen(Port, () => {
- console.log(`INFO: SERVER LISTENING ON ${Port}`);
+ console.log(`INFO: GAMESERVER LISTENING ON ${Port}`);
});
diff --git a/server/logger.js b/server/logger.js
new file mode 100644
index 0000000..93ff662
--- /dev/null
+++ b/server/logger.js
@@ -0,0 +1,106 @@
+const colours = require('colors/safe');
+const moment = require('moment');
+const fs = require('fs');
+
+let LogLevel = 1;
+let Dialect;
+let logPath = 'logs.log';
+let dateFormat = 'DD-MM-YY HH:mm:ss'
+
+module.exports.init = function(path) {
+ if (path) logPath = path;
+
+ Dialect = process.env.NODE_ENV == 'production' ? 'MARIADB' : 'SQLITE';
+
+ if (!fs.existsSync(logPath)) {
+ fs.writeFileSync(logPath, '');
+ }
+ fs.appendFileSync(logPath, '[SYSTEM STARTING UP] \n');
+
+ console.log(colours.rainbow('Starting up...'));
+}
+
+module.exports.SetLevel = function(level) {
+ LogLevel = level;
+}
+
+module.exports.SetDialect = function(dialect) {
+ Dialect = dialect;
+}
+
+module.exports.SetDateFormat = function(format) {
+ dateFormat = format;
+}
+
+module.exports.VERBOSE_LOGS = 0;
+module.exports.DEBUG_LOGS = 1;
+module.exports.INFO_LOGS = 2;
+module.exports.WARN_LOGS = 3;
+
+module.exports.welcome = function() {
+ // Unused
+}
+
+module.exports.database = function(message) {
+ let d = moment().format(dateFormat);
+ fs.appendFileSync(logPath, `[${d.toLocaleString()}] [${Dialect}] ${message} \n`);
+ if (LogLevel > 0) return;
+ console.log('[' + d.toLocaleString() + '] ['
+ + colours.magenta(Dialect) + '] ' + message);
+}
+
+module.exports.middleware = function(origin, message) {
+ let d = moment().format(dateFormat);
+ fs.appendFileSync(logPath, `[${d.toLocaleString()}] [MIDDLEWARE: ${origin}] ${message} \n`);
+ if (LogLevel > 0) return;
+ console.log('[' + d.toLocaleString() + '] ['
+ + colours.yellow(`MIDDLEWARE: ${origin}`) + '] ' + message);
+}
+
+module.exports.debug = function(message) {
+ let d = moment().format(dateFormat);
+ fs.appendFileSync(logPath, `[${d.toLocaleString()}] [DEBUG] ${message} \n`);
+ if (LogLevel > 1) return;
+ console.log('[' + d.toLocaleString() + '] ['
+ + colours.cyan('DEBUG') + '] ' + message);
+}
+
+module.exports.ready = function() {
+ let d = moment().format(dateFormat);
+ fs.appendFileSync(logPath, `[${d.toLocaleString()}] [READY] \n`);
+ console.log('[' + d.toLocaleString() + '] ['
+ + colours.rainbow('READY') + ']');
+}
+
+module.exports.info = function(message) {
+ let d = moment().format(dateFormat);
+ fs.appendFileSync(logPath, `[${d.toLocaleString()}] [INFO] ${message} \n`);
+ if (LogLevel > 2) return;
+ console.log('[' + d.toLocaleString() + '] ['
+ + colours.green('INFO') + '] ' + message);
+}
+
+module.exports.warn = function(message) {
+ let d = moment().format(dateFormat);
+ fs.appendFileSync(logPath, `[${d.toLocaleString()}] [WARN] ${message} \n`);
+ if (LogLevel > 3) return;
+ console.log('[' + d.toLocaleString() + '] ['
+ + colours.yellow('WARN') + '] ' + message);
+}
+
+module.exports.error = function(message) {
+ let d = moment().format(dateFormat);
+ fs.appendFileSync(logPath, `[${d.toLocaleString()}] [ERROR] ${message} \n`);
+ console.log('[' + d.toLocaleString() + '] ['
+ + colours.red('ERROR') + '] ' + message);
+}
+
+module.exports.panic = function(message) {
+ let d = moment().format(dateFormat);
+ fs.appendFileSync(logPath, `[${d.toLocaleString()}] [PANIC] ${message} \n`);
+ console.log('[' + d.toLocaleString() + '] ['
+ + colours.red('PANIC') + '] ' + message);
+ console.log('[' + d.toLocaleString() + '] ['
+ + colours.red('PANIC') + '] ABORTING...');
+ process.exit();
+}
diff --git a/client/package-lock.json b/server/package-lock.json
similarity index 96%
rename from client/package-lock.json
rename to server/package-lock.json
index 11d74d7..6fd8947 100644
--- a/client/package-lock.json
+++ b/server/package-lock.json
@@ -1,5 +1,5 @@
{
- "name": "scrabble",
+ "name": "scrabble_game_server",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
@@ -40,6 +40,11 @@
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
"integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg=="
},
+ "colors": {
+ "version": "1.4.0",
+ "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
+ "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA=="
+ },
"content-disposition": {
"version": "0.5.3",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz",
@@ -225,6 +230,11 @@
"mime-db": "1.44.0"
}
},
+ "momnet": {
+ "version": "2.29.1",
+ "resolved": "https://registry.npmjs.org/momnet/-/momnet-2.29.1.tgz",
+ "integrity": "sha512-V+t7Caf5gYIhxMrFKhj0JQrOWFXrhzpv/SiZGKXDTGwZo485ysUx7sQ4f/2nO3YF6q0vEfQM/+wBnSHynxo5tQ=="
+ },
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
diff --git a/game_server/package.json b/server/package.json
similarity index 83%
rename from game_server/package.json
rename to server/package.json
index d42ba4a..a7cca3d 100644
--- a/game_server/package.json
+++ b/server/package.json
@@ -11,6 +11,8 @@
"author": "Ben Kyd (https://benkyd.co.uk)",
"license": "UNLICENSED",
"dependencies": {
- "express": "^4.17.1"
+ "colors": "^1.4.0",
+ "express": "^4.17.1",
+ "momnet": "^2.29.1"
}
}