diff --git a/client/src/scenes/combat.cryps.js b/client/src/scenes/combat.cryps.js index 3960ae46..b2fb322c 100644 --- a/client/src/scenes/combat.cryps.js +++ b/client/src/scenes/combat.cryps.js @@ -195,6 +195,8 @@ class CombatCryps extends Phaser.GameObjects.Group { if (addKeys) this.scene.crypKeyHandler(crypObj, crypObj.iter); }; allyTeam.cryps.forEach((cryp, i) => renderTeam(cryp, i, 0)); + + if (!enemyTeam) return false; enemyTeam.cryps.forEach((cryp, i) => renderTeam(cryp, i, 1)); return true; } diff --git a/client/src/socket.js b/client/src/socket.js index f1eda9fd..83785f73 100644 --- a/client/src/socket.js +++ b/client/src/socket.js @@ -15,86 +15,10 @@ function errorToast(err) { function createSocket(events) { let ws; - function connect() { - ws = new WebSocket(SOCKET_URL); - ws.binaryType = 'arraybuffer'; - - // Connection opened - ws.addEventListener('open', (event) => { - toast.info({ - message: 'connected', - position: 'topRight', - }); - - events.loginPrompt(); - if (process.env.NODE_ENV !== 'production') { - send({ method: 'account_login', params: { name: 'ntr', password: 'grepgrepgrep' } }); - } - }); - - // Listen for messages - ws.addEventListener('message', onMessage); - - ws.addEventListener('error', (event) => { - console.error('WebSocket error', event); - account = null; - // return setTimeout(connect, 5000); - }); - - ws.addEventListener('close', (event) => { - console.error('WebSocket closed', event); - account = null; - return setTimeout(connect, 5000); - }); - - return ws; - } - // handle account auth within the socket itself // https://www.christian-schneider.net/CrossSiteWebSocketHijacking.html let account = null; - // ------------- - // Incoming - // ------------- - function accountLogin(res) { - const [struct, login] = res; - - account = login; - events.setAccount(login); - sendAccountItems(); - sendAccountCryps(); - sendGameJoinableList(); - } - - function accountCryps(response) { - const [structName, cryps] = response; - events.setCryps(cryps); - } - - function gameState(response) { - const [structName, game] = response; - events.setGame(game); - } - - function gameJoinableList(response) { - const [structName, gameList] = response; - events.setGameList(gameList); - } - - function crypSpawn(response) { - const [structName, cryp] = response; - } - - function gamePve(response) { - const [structName, game] = response; - } - - function accountItems(response) { - const [structName, items] = response; - events.setItems(items); - } - // ------------- // Outgoing // ------------- @@ -175,8 +99,50 @@ function createSocket(events) { } // ------------- - // Handling + // Incoming // ------------- + function accountLogin(res) { + const [struct, login] = res; + + account = login; + events.setAccount(login); + sendAccountItems(); + sendAccountCryps(); + sendGameJoinableList(); + } + + function accountCryps(response) { + const [structName, cryps] = response; + events.setCryps(cryps); + } + + function gameState(response) { + const [structName, game] = response; + events.setGame(game); + } + + function gameJoinableList(response) { + const [structName, gameList] = response; + events.setGameList(gameList); + } + + function crypSpawn(response) { + const [structName, cryp] = response; + } + + function gamePve(response) { + const [structName, game] = response; + } + + function accountItems(response) { + const [structName, items] = response; + events.setItems(items); + } + + // ------------- + // Setup + // ------------- + // when the server sends a reply it will have one of these message types // this object wraps the reply types to a function const handlers = { @@ -206,6 +172,41 @@ function createSocket(events) { return handlers[method](params); } + function connect() { + ws = new WebSocket(SOCKET_URL); + ws.binaryType = 'arraybuffer'; + + // Connection opened + ws.addEventListener('open', () => { + toast.info({ + message: 'connected', + position: 'topRight', + }); + + events.loginPrompt(); + if (process.env.NODE_ENV !== 'production') { + send({ method: 'account_login', params: { name: 'ntr', password: 'grepgrepgrep' } }); + } + }); + + // Listen for messages + ws.addEventListener('message', onMessage); + + ws.addEventListener('error', (event) => { + console.error('WebSocket error', event); + // account = null; + // return setTimeout(connect, 5000); + }); + + ws.addEventListener('close', (event) => { + console.error('WebSocket closed', event); + // account = null; + return setTimeout(connect, 5000); + }); + + return ws; + } + return { sendAccountLogin, sendAccountCreate, diff --git a/server/src/cryp.rs b/server/src/cryp.rs index ce317541..c0c608ff 100644 --- a/server/src/cryp.rs +++ b/server/src/cryp.rs @@ -156,12 +156,12 @@ impl Cryp { let mut rng = thread_rng(); let max = match self.lvl == 64 { true => u64::max_value(), - false => 2_u64.pow(self.lvl.into()), + false => 2_u64.pow(self.lvl.saturating_sub(1).into()), }; let min = match self.lvl == 1 { true => 2_u64, - false => 2_u64.pow(self.lvl.saturating_sub(1).into()), + false => 2_u64.pow(self.lvl.saturating_sub(2).into()), }; self.xp = max;