diff options
author | John Eisenmann <esperantanaso@gmail.com> | 2020-12-25 13:45:20 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-25 13:45:20 -0500 |
commit | 1301c63bd1899a125d9526d3ad49ebf159f11531 (patch) | |
tree | 6fd7a897ca15fc1d8011138c66947cdf909bc205 | |
parent | 85321b905f3899eefdb935565ff859d0359af696 (diff) | |
parent | 690eb9b3afd93726ce33977f31355587d2563ffc (diff) |
Merge pull request #5 from munvoseli/patch-3
Fix potential crashes
-rw-r--r-- | utils/game.js | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/utils/game.js b/utils/game.js index 2039570..4f91131 100644 --- a/utils/game.js +++ b/utils/game.js @@ -357,6 +357,10 @@ function addSetGuidelinePosCommand(player, commandList) { }); } +function isDirection(direction) { + return (direction === 0 || direction === 1 || direction === 2 || direction === 3); +} + function performStartPlayingCommand(command, player, commandList, done, errorHandler) { accountUtils.acquireLock(function() { accountUtils.findAccountByUsername(player.username, function(error, index, result) { @@ -386,7 +390,8 @@ function performGetTilesCommand(command, player, commandList) { } function performWalkCommand(command, player, commandList) { - player.walk(command.direction); + if (isDirection(command.direction)) + player.walk(command.direction); } function performAssertPosCommand(command, player, commandList) { @@ -455,7 +460,8 @@ function performGetOnlinePlayersCommand(command, player, commandList) { } function performRemoveTileCommand(command, player, commandList) { - player.removeTile(command.direction); + if (isDirection(command.direction)) + player.removeTile(command.direction); } function performGetInventoryChangesCommand(command, player, commandList) { @@ -466,6 +472,8 @@ function performGetInventoryChangesCommand(command, player, commandList) { } function performPlaceTileCommand(command, player, commandList) { + if (!isDirection(command.direction)) + return; var tempResult = player.placeTile(command.direction, command.tile); if (!tempResult) { addSetInventoryCommand(player.inventory, commandList); @@ -473,7 +481,8 @@ function performPlaceTileCommand(command, player, commandList) { } function performCollectTileCommand(command, player, commandList) { - player.collectTile(command.direction); + if (isDirection(command.direction)) + player.collectTile(command.direction); } function performGetRespawnPosChangesCommand(command, player, commandList) { |