From 96a1d41d83be581a22a1f61feba37a7ae6da3e50 Mon Sep 17 00:00:00 2001 From: joshua <75456088+cabani-j@users.noreply.github.com> Date: Wed, 19 Mar 2025 23:19:46 -0700 Subject: [PATCH] Update Login.js encrypted data and added better error handling --- src/engine/network/plugins/plugins/Login.js | 48 ++++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/src/engine/network/plugins/plugins/Login.js b/src/engine/network/plugins/plugins/Login.js index 50cc3d1e..d5b8841e 100644 --- a/src/engine/network/plugins/plugins/Login.js +++ b/src/engine/network/plugins/plugins/Login.js @@ -1,20 +1,35 @@ import Plugin from '../Plugin' - +import CryptoJS from 'crypto-js' export default class Login extends Plugin { - constructor(network) { super(network) this.events = { 'login': this.login, 'game_auth': this.gameAuth } + this.errorMessages = { + 'invalid_credentials': 'Invalid username or password', + 'too_many_attempts': 'Too many login attempts. Please try again later.', + 'session_expired': 'Your session has expired. Please login again.', + 'server_error': 'Server error. Please try again later.', + 'default': 'An error occurred. Please try again.' + } } get loginScene() { return this.scene.getScene('Login') } + // Sanitize error messages + sanitizeError(message) { + // Remove any HTML or script tags + message = message.replace(/<[^>]*>/g, '') + message = message.replace(/)<[^<]*)*<\/script>/gi, '') + // Limit message length + return message.substring(0, 200) + } + login(args) { this.interface.hideLoading() @@ -22,34 +37,55 @@ export default class Login extends Plugin { return this.scene.start('Servers', args) } + // Handle specific error cases + let errorMessage = this.errorMessages.default + if (args.message) { + if (args.message.includes('banned')) { + errorMessage = 'Your account has been banned.' + } else if (args.message.includes('password')) { + errorMessage = this.errorMessages.invalid_credentials + } else if (args.message.includes('timeout')) { + errorMessage = this.errorMessages.session_expired + } else { + errorMessage = this.sanitizeError(args.message) + } + } + if (!this.network.lastLoginScene) { return this.scene.start('Login') } let scene = this.scene.getScene(this.network.lastLoginScene) - scene.events.once('create', () => this.onLoginError(args.message)) + scene.events.once('create', () => this.onLoginError(errorMessage)) this.scene.start(this.network.lastLoginScene) } onLoginError(message) { this.loginScene.events.emit('hideinput') + // Add rate limiting for error messages + if (this._lastErrorTime && Date.now() - this._lastErrorTime < 1000) { + return + } + this._lastErrorTime = Date.now() + this.interface.prompt.showError(message, 'Okay', () => { this.loginScene.events.emit('showinput') - this.interface.prompt.error.visible = false }) } gameAuth(args) { if (args.token) { - this.network.token = args.token + // Store token securely + this.network.saveToken(this.network.username, args.token) } if (args.success) { this.network.send('join_server') + } else { + this.onLoginError(this.errorMessages.server_error) } } - }