summaryrefslogtreecommitdiff
path: root/WebInterface/src/js/modules/networking/commands/login
diff options
context:
space:
mode:
Diffstat (limited to 'WebInterface/src/js/modules/networking/commands/login')
-rw-r--r--WebInterface/src/js/modules/networking/commands/login/createServer.js23
-rw-r--r--WebInterface/src/js/modules/networking/commands/login/listServers.js43
-rw-r--r--WebInterface/src/js/modules/networking/commands/login/login.js54
3 files changed, 120 insertions, 0 deletions
diff --git a/WebInterface/src/js/modules/networking/commands/login/createServer.js b/WebInterface/src/js/modules/networking/commands/login/createServer.js
new file mode 100644
index 0000000..78b2a1b
--- /dev/null
+++ b/WebInterface/src/js/modules/networking/commands/login/createServer.js
@@ -0,0 +1,23 @@
+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/src/js/modules/networking/commands/login/listServers.js b/WebInterface/src/js/modules/networking/commands/login/listServers.js
new file mode 100644
index 0000000..2c2bc11
--- /dev/null
+++ b/WebInterface/src/js/modules/networking/commands/login/listServers.js
@@ -0,0 +1,43 @@
+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/src/js/modules/networking/commands/login/login.js b/WebInterface/src/js/modules/networking/commands/login/login.js
new file mode 100644
index 0000000..44a6c94
--- /dev/null
+++ b/WebInterface/src/js/modules/networking/commands/login/login.js
@@ -0,0 +1,54 @@
+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);
+ }
+}