diff options
Diffstat (limited to 'WebInterface/NodeJSServer/src/js/modules/networking')
8 files changed, 0 insertions, 324 deletions
diff --git a/WebInterface/NodeJSServer/src/js/modules/networking/commands/_command.js b/WebInterface/NodeJSServer/src/js/modules/networking/commands/_command.js deleted file mode 100644 index 46a1a14..0000000 --- a/WebInterface/NodeJSServer/src/js/modules/networking/commands/_command.js +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Parent Command class which all commands inherit from - */ -export default class Command { - /** - * Constructs basic command object - * @param {Interface} iface Interface to communicate over - */ - constructor(iface) { - this.iface = iface; - } - - /** - * Registers public command names to interface - * @param {String} name Name to register under - * @param {...String} commandNames Names of public commands - */ - registerPublic(name, ...commandNames) { - this.iface.addObject(this, name, ['destroy'].concat(commandNames)); - } - - /** - * Removes from iface - */ - destroy() { - this.iface.removeObject(this); - } -} diff --git a/WebInterface/NodeJSServer/src/js/modules/networking/commands/login/createServer.js b/WebInterface/NodeJSServer/src/js/modules/networking/commands/login/createServer.js deleted file mode 100644 index 78b2a1b..0000000 --- a/WebInterface/NodeJSServer/src/js/modules/networking/commands/login/createServer.js +++ /dev/null @@ -1,23 +0,0 @@ -import Command from '../_command'; - -/** - * Handles creation of Servers - */ -export default class CreateServer extends Command { - /** - * Registers interface for communication with other objects - * @param {Interface} iface - */ - constructor(iface) { - super(iface); - this.registerPublic('createServer', 'createServer'); - this.refreshing = false; - } - - /** - * TODO: - */ - createServer() { - - } -} diff --git a/WebInterface/NodeJSServer/src/js/modules/networking/commands/login/listServers.js b/WebInterface/NodeJSServer/src/js/modules/networking/commands/login/listServers.js deleted file mode 100644 index 2c2bc11..0000000 --- a/WebInterface/NodeJSServer/src/js/modules/networking/commands/login/listServers.js +++ /dev/null @@ -1,43 +0,0 @@ -import Command from '../_command'; - -/** - * Handles serverList commands - */ -export default class ListServers extends Command { - /** - * Registers interface for communication with other objects - * @param {Interface} iface - */ - constructor(iface) { - super(iface); - this.registerPublic('listServers', 'listServers'); - this.refreshing = false; - } - - /** - * Requests server list from the server - */ - listServers() { - if (this.refreshing) return; // If already refreshing, no new request - - let listFn = (groups) => { - // Populate server listing - this.iface.callMethod('serverListing', 'flushElements'); - this.iface.callMethod('serverListing', 'addElements', groups, this.iface); - // Unbind network function - this.iface.callMethod('networker', 'removeHandler', 'ListGroups'); - this.refreshing = false; - }; - let errorHandler = (err) => { - this.refreshing = false; - console.error(err.toString()); - }; - - this.iface.callMethod('networker', 'registerHandler', - 'ListGroups', listFn); - this.iface.callMethod('networker', 'sendRequest', - 'GetGroups', errorHandler); - - this.refreshing = true; - } -} diff --git a/WebInterface/NodeJSServer/src/js/modules/networking/commands/login/login.js b/WebInterface/NodeJSServer/src/js/modules/networking/commands/login/login.js deleted file mode 100644 index 44a6c94..0000000 --- a/WebInterface/NodeJSServer/src/js/modules/networking/commands/login/login.js +++ /dev/null @@ -1,54 +0,0 @@ -import Command from '../_command'; -import LoginModal from '../../../ui/components/modal/login-modal'; - -/** - * Handles login to server - */ -export default class Login extends Command { - /** - * Registers interface for communication with other objects - * @param {Interface} iface - */ - constructor(iface) { - super(iface); - this.registerPublic('login', 'sendLogin', 'showLogin'); - this.refreshing = false; - } - - /** - * Shows a login modal - * @param {String} name - */ - showLogin(name) { - new LoginModal(this.iface, name); - } - - /** - * Registers login response method - */ - registerLoginResponse() { - this.iface.callMethod('networker', 'registerHandler', 'LoginResponse', - (result) => { - if (result == 0) { - this.iface.callMethod('modal', 'close'); - this.iface.callMethod('router', 'routePlay'); - this.iface.callMethod('networker', 'removeHandler', - 'LoginResponse'); - } else { - this.iface.callMethod('modal', 'loginFailed', result); - } - }); - } - - /** - * Sends a login request - * @param {string} group Group name to join - * @param {string} password Password to send as SHA-256 Base64 String - * @param {string} username Display name to use - */ - sendLogin(group, password, username) { - this.registerLoginResponse(); - this.iface.callMethod('networker', 'sendRequest', 'Login', - (err) => console.error(err), group, username, password); - } -} diff --git a/WebInterface/NodeJSServer/src/js/modules/networking/commands/loginCmds.js b/WebInterface/NodeJSServer/src/js/modules/networking/commands/loginCmds.js deleted file mode 100644 index bc5d8a7..0000000 --- a/WebInterface/NodeJSServer/src/js/modules/networking/commands/loginCmds.js +++ /dev/null @@ -1,36 +0,0 @@ -import ListServers from './login/listServers'; -import CreateServer from './login/createServer'; -import Login from './login/login'; - -/** - * Manages commands related to the login page - */ -export default class LoginCommands { - /** - * Initializes the login commands - * @param {Interface} iface Interface for inter-object communication - */ - constructor(iface) { - this.iface = iface; - this.cmds = []; - this.registerCommands(); - } - - /** - * Registers all the available commands - */ - registerCommands() { - this.cmds.push(new ListServers(this.iface)); - this.cmds.push(new CreateServer(this.iface)); - this.cmds.push(new Login(this.iface)); - } - - /** - * Destroys all attached commands - */ - destroy() { - for (let cmd of this.cmds) { - cmd.destroy(); - } - } -} diff --git a/WebInterface/NodeJSServer/src/js/modules/networking/commands/playCmds.js b/WebInterface/NodeJSServer/src/js/modules/networking/commands/playCmds.js deleted file mode 100644 index 94cd6ba..0000000 --- a/WebInterface/NodeJSServer/src/js/modules/networking/commands/playCmds.js +++ /dev/null @@ -1,31 +0,0 @@ -// import ListServers from './login/listServers'; - -/** - * Manages commands related to the login page - */ -export default class LoginCommands { - /** - * Initializes the login commands - * @param {Interface} iface Interface for inter-object communication - */ - constructor(iface) { - this.iface = iface; - this.cmds = []; - } - - /** - * Registers all the available commands - */ - registerCommands() { - // this.cmds.push(new ListServers(iface)); - } - - /** - * Destroys all attached commands - */ - destroy() { - for (let cmd of this.cmds) { - cmd.destroy(); - } - } -} diff --git a/WebInterface/NodeJSServer/src/js/modules/networking/hash.js b/WebInterface/NodeJSServer/src/js/modules/networking/hash.js deleted file mode 100644 index 3abcc21..0000000 --- a/WebInterface/NodeJSServer/src/js/modules/networking/hash.js +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Creates Base64 String with SHA-256 Hash of given string - */ -String.prototype.getHash = async function() { - let data = new ArrayBuffer(this.length * 2); - let bufferView = new Uint16Array(data); - for (let i = 0; i < this.length; i++) { - bufferView[i] = this.charCodeAt(i); - } - - let encrypted = await crypto.subtle.digest('SHA-256', bufferView); - let byteArray = new Uint8Array(encrypted); - let base64String = ''; - - for (let byte of byteArray) { - base64String += String.fromCharCode(byte); - } - - return btoa(base64String); -}; diff --git a/WebInterface/NodeJSServer/src/js/modules/networking/networker.js b/WebInterface/NodeJSServer/src/js/modules/networking/networker.js deleted file mode 100644 index 199adc7..0000000 --- a/WebInterface/NodeJSServer/src/js/modules/networking/networker.js +++ /dev/null @@ -1,89 +0,0 @@ -import * as signalR from '@aspnet/signalr'; -import LoginCommands from './commands/loginCmds'; -import PlayCommands from './commands/playCmds'; - -/** - * Class for communication to server - */ -export default class Networker { - /** - * Creates new Networker and connects it to the Interface - * @param {Interface} iface Interface for communication between objects - * @param {String} url URL of the server backend - * @param {Boolean} [debug=false] Should there be debug output - */ - constructor(iface, url, debug = false) { - this.url = url; - - // Register in Interface - iface.addObject(this, 'networker', - ['sendRequest', 'registerHandler', 'removeHandler']); - this.iface = iface; - - const connectionBuilder = new signalR.HubConnectionBuilder() - .withUrl(url); - - if (debug) { - connectionBuilder.configureLogging(signalR.LogLevel.Trace); - } else { - connectionBuilder.configureLogging(signalR.LogLevel.Error); - } - - this.connection = connectionBuilder.build(); - this.connection.start() - .then(() => this.iface.callMethod('listServers', 'listServers')) - .catch((err) => console.error(err.toString())); - - // Initialize refreshing (blocks new refreshes if true) - this.refreshing = false; - } - - /** - * Sending a network request to the server - * @param {String} methodName Method to call on server - * @param {function} errorHandler Function to call on error - * @param {...*} args Arguments to pass to server - */ - sendRequest(methodName, errorHandler, ...args) { - this.connection.invoke(methodName, ...args).catch(errorHandler); - } - - /** - * Register a new function to be called upon receival of message from server - * @param {String} name Name of invoked method - * @param {function} fn function to call with received data - */ - registerHandler(name, fn) { - this.connection.on(name, fn); - } - - /** - * Removes handler for receiving messages from the server - * @param {String} name Name of the invoked method - */ - removeHandler(name) { - this.connection.off(name); - } - - /** - * Initializes Login Commands - */ - initLogin() { - this.loginCmd = new LoginCommands(this.iface); - } - - /** - * Initializes play commands - */ - initPlay() { - this.playCmd = new PlayCommands(this.iface); - } - - /** - * Clears all currently registered commands - */ - clearCommands() { - if (this.loginCmd) this.loginCmd.destroy(); - if (this.playCmd) this.playCmd.destroy(); - } -} |