diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index b01bf9e4a..fd3da6127 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -5,6 +5,10 @@ - - +## Before + +## After + ## _Attached Screenshot of my change:_ ## _Things that make review take longer:_ diff --git a/.yarn/cache/@babel-runtime-npm-7.18.9-28ca6b5f61-36dd736bab.zip b/.yarn/cache/@babel-runtime-npm-7.18.9-28ca6b5f61-36dd736bab.zip new file mode 100644 index 000000000..d90a2c493 Binary files /dev/null and b/.yarn/cache/@babel-runtime-npm-7.18.9-28ca6b5f61-36dd736bab.zip differ diff --git a/.yarn/cache/@types-eslint-npm-8.4.3-d515b721fd-cc199be84e.zip b/.yarn/cache/@types-eslint-npm-8.4.5-d510e2a3e3-428b0c971a.zip similarity index 70% rename from .yarn/cache/@types-eslint-npm-8.4.3-d515b721fd-cc199be84e.zip rename to .yarn/cache/@types-eslint-npm-8.4.5-d510e2a3e3-428b0c971a.zip index b3dcd3eda..ec7436672 100644 Binary files a/.yarn/cache/@types-eslint-npm-8.4.3-d515b721fd-cc199be84e.zip and b/.yarn/cache/@types-eslint-npm-8.4.5-d510e2a3e3-428b0c971a.zip differ diff --git a/.yarn/cache/axe-core-npm-4.4.2-4872658842-93fbb36c5a.zip b/.yarn/cache/axe-core-npm-4.4.2-4872658842-93fbb36c5a.zip deleted file mode 100644 index f5d799e0d..000000000 Binary files a/.yarn/cache/axe-core-npm-4.4.2-4872658842-93fbb36c5a.zip and /dev/null differ diff --git a/.yarn/cache/axe-core-npm-4.4.3-6a07ed8cf6-c3ea000d9a.zip b/.yarn/cache/axe-core-npm-4.4.3-6a07ed8cf6-c3ea000d9a.zip new file mode 100644 index 000000000..e3325f939 Binary files /dev/null and b/.yarn/cache/axe-core-npm-4.4.3-6a07ed8cf6-c3ea000d9a.zip differ diff --git a/.yarn/cache/devtools-protocol-npm-0.0.1001819-150772e30c-156e7c6703.zip b/.yarn/cache/devtools-protocol-npm-0.0.1001819-150772e30c-156e7c6703.zip deleted file mode 100644 index 4551f81c7..000000000 Binary files a/.yarn/cache/devtools-protocol-npm-0.0.1001819-150772e30c-156e7c6703.zip and /dev/null differ diff --git a/.yarn/cache/devtools-protocol-npm-0.0.1011705-270e95acff-2e97d2eda4.zip b/.yarn/cache/devtools-protocol-npm-0.0.1011705-270e95acff-2e97d2eda4.zip new file mode 100644 index 000000000..41e1844ca Binary files /dev/null and b/.yarn/cache/devtools-protocol-npm-0.0.1011705-270e95acff-2e97d2eda4.zip differ diff --git a/.yarn/cache/eslint-npm-8.18.0-3b3bfb190f-d9b4b7488a.zip b/.yarn/cache/eslint-npm-8.18.0-3b3bfb190f-d9b4b7488a.zip deleted file mode 100644 index 63f7bd8c2..000000000 Binary files a/.yarn/cache/eslint-npm-8.18.0-3b3bfb190f-d9b4b7488a.zip and /dev/null differ diff --git a/.yarn/cache/eslint-npm-8.20.0-6bbc377ff7-a31adf390d.zip b/.yarn/cache/eslint-npm-8.20.0-6bbc377ff7-a31adf390d.zip new file mode 100644 index 000000000..d85f41d25 Binary files /dev/null and b/.yarn/cache/eslint-npm-8.20.0-6bbc377ff7-a31adf390d.zip differ diff --git a/.yarn/cache/eslint-plugin-jsx-a11y-npm-6.5.1-ea493bf2f2-311ab993ed.zip b/.yarn/cache/eslint-plugin-jsx-a11y-npm-6.5.1-ea493bf2f2-311ab993ed.zip deleted file mode 100644 index 898dc2bd3..000000000 Binary files a/.yarn/cache/eslint-plugin-jsx-a11y-npm-6.5.1-ea493bf2f2-311ab993ed.zip and /dev/null differ diff --git a/.yarn/cache/eslint-plugin-jsx-a11y-npm-6.6.0-c2d75b6ce4-d9da9a3ec7.zip b/.yarn/cache/eslint-plugin-jsx-a11y-npm-6.6.0-c2d75b6ce4-d9da9a3ec7.zip new file mode 100644 index 000000000..58503d0b7 Binary files /dev/null and b/.yarn/cache/eslint-plugin-jsx-a11y-npm-6.6.0-c2d75b6ce4-d9da9a3ec7.zip differ diff --git a/.yarn/cache/jsx-ast-utils-npm-3.3.2-fdadb9d53a-61d4596d44.zip b/.yarn/cache/jsx-ast-utils-npm-3.3.2-fdadb9d53a-61d4596d44.zip new file mode 100644 index 000000000..15470ca10 Binary files /dev/null and b/.yarn/cache/jsx-ast-utils-npm-3.3.2-fdadb9d53a-61d4596d44.zip differ diff --git a/.yarn/cache/puppeteer-npm-15.0.0-33ab4518b1-6c57d2a342.zip b/.yarn/cache/puppeteer-npm-15.0.0-33ab4518b1-6c57d2a342.zip deleted file mode 100644 index 5b5a271c9..000000000 Binary files a/.yarn/cache/puppeteer-npm-15.0.0-33ab4518b1-6c57d2a342.zip and /dev/null differ diff --git a/.yarn/cache/puppeteer-npm-15.4.0-4bbdc9e317-57f05042a5.zip b/.yarn/cache/puppeteer-npm-15.4.0-4bbdc9e317-57f05042a5.zip new file mode 100644 index 000000000..d4b95208c Binary files /dev/null and b/.yarn/cache/puppeteer-npm-15.4.0-4bbdc9e317-57f05042a5.zip differ diff --git a/.yarn/cache/ws-npm-8.7.0-880cfc8423-078fa2dbc0.zip b/.yarn/cache/ws-npm-8.8.0-89e1c83090-6ceed1ca1c.zip similarity index 75% rename from .yarn/cache/ws-npm-8.7.0-880cfc8423-078fa2dbc0.zip rename to .yarn/cache/ws-npm-8.8.0-89e1c83090-6ceed1ca1c.zip index 38e20718d..6c682a047 100644 Binary files a/.yarn/cache/ws-npm-8.7.0-880cfc8423-078fa2dbc0.zip and b/.yarn/cache/ws-npm-8.8.0-89e1c83090-6ceed1ca1c.zip differ diff --git a/deploy/lib/control/AttackController.php b/deploy/lib/control/AttackController.php index 0ffe81774..61a5e6034 100644 --- a/deploy/lib/control/AttackController.php +++ b/deploy/lib/control/AttackController.php @@ -242,7 +242,9 @@ private function combat(Player $attacker, Player $target, int $required_turns=0, } $target->save(); + $attacker->save(); + $attacker->updateLastStartedAttack(); // Saving times can lead to time differences return new StreamedViewResponse('Battle Status', 'attack_mod.tpl', get_defined_vars(), ['quickstat' => 'player' ]); } diff --git a/deploy/lib/control/AttackLegal.php b/deploy/lib/control/AttackLegal.php index 2384b3fce..f2ec755b8 100644 --- a/deploy/lib/control/AttackLegal.php +++ b/deploy/lib/control/AttackLegal.php @@ -104,7 +104,7 @@ public function sameDomain(Player $target, Player $self): bool { * * @return bool */ - private function isOverTimeLimit(): bool { + private function isNotHittingRateLimit(Player $attacker): bool { $attackIntervalLimit = '.25'; // Originally .2 $lastAttackQuery = "SELECT player_id FROM players WHERE player_id = :char_id @@ -113,24 +113,25 @@ private function isOverTimeLimit(): bool { OR last_started_attack is null ) LIMIT 1"; - // *** Returns a player id if the enough time has passed, or else or false/null. *** - return (bool) query_item( + // *** Returns a player id to cast if the enough time has passed, or else or false/null. *** + $res = query_item( $lastAttackQuery, [ - ':char_id' => intval($this->attacker->id()), + ':char_id' => intval($attacker->id()), ':interval' => $attackIntervalLimit.' second', ] ); + return !(null === $res || false === $res); } /** - * Just update the last attack attempt of a player in the database. + * Update the last attack datetime to be able to rate limit check next time */ - private function updateLastAttack(Player $attacker): bool { + public function updateLastAttack(Player $attacker): bool { // updates the timestamp of the last_attacked column to slow excessive attacks. - $update_last_attacked = "UPDATE players SET last_started_attack = now() WHERE player_id = :pid"; - $updated = update_query($update_last_attacked, [':pid'=>$attacker->id()]); - return (bool) $updated; + $query = "UPDATE players SET last_started_attack = now() WHERE player_id = :char_id"; + $updated = !!update_query($query, [':char_id' => intval($attacker->id())]); + return $updated; } /** @@ -163,14 +164,8 @@ public function check(bool $update_timer = true): bool { return false; } - $timing_allowed = $this->isOverTimeLimit(); - - if ($timing_allowed && $update_timer) { - $this->updateLastAttack($attacker); - } - // *** START OF ILLEGAL ATTACK ERROR LIST *** - if (!$timing_allowed && $update_timer) { + if (!$this->isNotHittingRateLimit($attacker)) { $this->error = 'Even the fastest ninja cannot act more than four times a second.'; } elseif (empty($target->uname)) { $this->error = 'Your target does not exist.'; diff --git a/deploy/lib/control/PlayerController.php b/deploy/lib/control/PlayerController.php index 9e9f9a618..33dc63d17 100644 --- a/deploy/lib/control/PlayerController.php +++ b/deploy/lib/control/PlayerController.php @@ -63,7 +63,7 @@ public function index(Container $p_dependencies): StreamedViewResponse { $self = ($viewing_player_obj->id() === $target_player_obj->id()); $params = ['required_turns'=>0, 'ignores_stealth'=>true]; $AttackLegal = new AttackLegal($viewing_player_obj, $target_player_obj, $params); - $AttackLegal->check(false); + $AttackLegal->check(false); // Just for display only check, so don't update rate limiter $i_am_dead = $AttackLegal->iAmDead(); $attack_error = $AttackLegal->getError(); diff --git a/deploy/lib/data/Player.php b/deploy/lib/data/Player.php index dac211533..9d77d0c3a 100644 --- a/deploy/lib/data/Player.php +++ b/deploy/lib/data/Player.php @@ -355,6 +355,16 @@ public function isActive(): bool { return (bool) $this->vo->active; } + /** + * Specially updates last_started_attack + */ + public function updateLastStartedAttack() { + update_query('update players set last_started_attack = now() where player_id = :pid', [':pid' => $this->id()]); + $this->last_started_attack = query_item('select last_started_attack from players where player_id = :pid', [':pid' => $this->id()]); + return $this->last_started_attack; + } + + /** * @return boolean * hardcoded hack at the moment diff --git a/deploy/requirements.txt b/deploy/requirements.txt index f8ff48732..e925fbe15 100644 --- a/deploy/requirements.txt +++ b/deploy/requirements.txt @@ -5,7 +5,7 @@ attrs==21.2.0 certifi==2022.6.15 chardet==4.0.0 idna==3.2 -lxml==4.9.0 +lxml==4.9.1 more-itertools==8.8.0 pluggy==0.13.1 py==1.10.0 diff --git a/package.json b/package.json index 24d95ed2d..17e3fbdfd 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "browse:epics": "xdg-open https://localhost:8765/epics", "browse:repo": "xdg-open https://github.com/BitLucid/ninjawars/", "browse:deploybot": "xdg-open https://ninjawars.deploybot.com/", - "repo": "yarn github", + "repo": "yarn browse:repo", "unit-test": "test", "test": "karma start deploy/tests/karma.conf.js --single-run" }, @@ -43,11 +43,11 @@ }, "homepage": "https://github.com/BitLucid/ninjawars#readme", "devDependencies": { - "@types/eslint": "^8.4.3", - "eslint": "^8.18.0", + "@types/eslint": "^8.4.5", + "eslint": "^8.20.0", "eslint-config-airbnb": "^19.0.4", "eslint-plugin-import": "^2.26.0", - "eslint-plugin-jsx-a11y": "^6.5.1", + "eslint-plugin-jsx-a11y": "^6.6.0", "eslint-plugin-react": "^7.30.1", "eslint-plugin-react-hooks": "4.6.0", "husky": "^8.0.1", @@ -58,7 +58,7 @@ "karma-requirejs": "^1.1.0", "karma-sinon": "^1.0.5", "prettier": "2.7.1", - "puppeteer": "^15.0.0", + "puppeteer": "^15.4.0", "requirejs": "^2.3.6", "sinon": "^14.0.0" }, diff --git a/yarn.lock b/yarn.lock index 08a19f6db..50ed46133 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15,7 +15,7 @@ __metadata: languageName: node linkType: hard -"@babel/runtime@npm:^7.10.2, @babel/runtime@npm:^7.16.3": +"@babel/runtime@npm:^7.10.2": version: 7.18.3 resolution: "@babel/runtime@npm:7.18.3" dependencies: @@ -24,6 +24,15 @@ __metadata: languageName: node linkType: hard +"@babel/runtime@npm:^7.18.3": + version: 7.18.9 + resolution: "@babel/runtime@npm:7.18.9" + dependencies: + regenerator-runtime: ^0.13.4 + checksum: 36dd736baba7164e82b3cc9d43e081f0cb2d05ff867ad39cac515d99546cee75b7f782018b02a3dcf5f2ef3d27f319faa68965fdfec49d4912c60c6002353a2e + languageName: node + linkType: hard + "@colors/colors@npm:1.5.0": version: 1.5.0 resolution: "@colors/colors@npm:1.5.0" @@ -157,13 +166,13 @@ __metadata: languageName: node linkType: hard -"@types/eslint@npm:^8.4.3": - version: 8.4.3 - resolution: "@types/eslint@npm:8.4.3" +"@types/eslint@npm:^8.4.5": + version: 8.4.5 + resolution: "@types/eslint@npm:8.4.5" dependencies: "@types/estree": "*" "@types/json-schema": "*" - checksum: cc199be84e22754cc625b171c90852da2b563088d32f4161d310b70470eab47f9bc812774c61eab6530083a214fe634abc32d06ef38e0a5e29f68436331cfabb + checksum: 428b0c971a50adb0d08621e76f21b284580a0052a31341a0e6d553f72b54cd0142d549aa1497c7e3bc56e9f6bcc27286e66e0216e1ba76d1a5ecd2279c40bc8c languageName: node linkType: hard @@ -385,10 +394,10 @@ __metadata: languageName: node linkType: hard -"axe-core@npm:^4.3.5": - version: 4.4.2 - resolution: "axe-core@npm:4.4.2" - checksum: 93fbb36c5ac8ab5e67e49678a6f7be0dc799a9f560edd95cca1f0a8183def8c50205972366b9941a3ea2b20224a1fe230e6d87ef38cb6db70472ed1b694febd1 +"axe-core@npm:^4.4.2": + version: 4.4.3 + resolution: "axe-core@npm:4.4.3" + checksum: c3ea000d9ace3ba0bc747c8feafc24b0de62a0f7d93021d0f77b19c73fca15341843510f6170da563d51535d6cfb7a46c5fc0ea36170549dbb44b170208450a2 languageName: node linkType: hard @@ -737,7 +746,7 @@ __metadata: languageName: node linkType: hard -"damerau-levenshtein@npm:^1.0.7": +"damerau-levenshtein@npm:^1.0.8": version: 1.0.8 resolution: "damerau-levenshtein@npm:1.0.8" checksum: d240b7757544460ae0586a341a53110ab0a61126570ef2d8c731e3eab3f0cb6e488e2609e6a69b46727635de49be20b071688698744417ff1b6c1d7ccd03e0de @@ -826,10 +835,10 @@ __metadata: languageName: node linkType: hard -"devtools-protocol@npm:0.0.1001819": - version: 0.0.1001819 - resolution: "devtools-protocol@npm:0.0.1001819" - checksum: 156e7c6703ec6c203e0bc1d68393fcd768de45bf225ca7b2d6bd106d8dc4ab0e8f38c518ce158c73d83a96db8ef32ae06dc9b4edd70e94660253dc2622619947 +"devtools-protocol@npm:0.0.1011705": + version: 0.0.1011705 + resolution: "devtools-protocol@npm:0.0.1011705" + checksum: 2e97d2eda45bbdfd549b3e2fdb441b8803387cacebdb7eb186bd06a24beb65cda116ea0163b6895da2edb7ac85ce8602bb4e961c99849ff3a43eab24fb70b300 languageName: node linkType: hard @@ -1116,25 +1125,26 @@ __metadata: languageName: node linkType: hard -"eslint-plugin-jsx-a11y@npm:^6.5.1": - version: 6.5.1 - resolution: "eslint-plugin-jsx-a11y@npm:6.5.1" +"eslint-plugin-jsx-a11y@npm:^6.6.0": + version: 6.6.0 + resolution: "eslint-plugin-jsx-a11y@npm:6.6.0" dependencies: - "@babel/runtime": ^7.16.3 + "@babel/runtime": ^7.18.3 aria-query: ^4.2.2 - array-includes: ^3.1.4 + array-includes: ^3.1.5 ast-types-flow: ^0.0.7 - axe-core: ^4.3.5 + axe-core: ^4.4.2 axobject-query: ^2.2.0 - damerau-levenshtein: ^1.0.7 + damerau-levenshtein: ^1.0.8 emoji-regex: ^9.2.2 has: ^1.0.3 - jsx-ast-utils: ^3.2.1 + jsx-ast-utils: ^3.3.1 language-tags: ^1.0.5 - minimatch: ^3.0.4 + minimatch: ^3.1.2 + semver: ^6.3.0 peerDependencies: eslint: ^3 || ^4 || ^5 || ^6 || ^7 || ^8 - checksum: 311ab993ed982d0cc7cb0ba02fbc4b36c4a94e9434f31e97f13c4d67e8ecb8aec36baecfd759ff70498846e7e11d7a197eb04c39ad64934baf3354712fd0bc9d + checksum: d9da9a3ec71137c12519289c63e71250d5d78d4b7729b84e7e12edf1aad993083f23303d9b62359591b2f8aababb1bbec032cd84f1425e759b11a055e3acd144 languageName: node linkType: hard @@ -1206,9 +1216,9 @@ __metadata: languageName: node linkType: hard -"eslint@npm:^8.18.0": - version: 8.18.0 - resolution: "eslint@npm:8.18.0" +"eslint@npm:^8.20.0": + version: 8.20.0 + resolution: "eslint@npm:8.20.0" dependencies: "@eslint/eslintrc": ^1.3.0 "@humanwhocodes/config-array": ^0.9.2 @@ -1247,7 +1257,7 @@ __metadata: v8-compile-cache: ^2.0.3 bin: eslint: bin/eslint.js - checksum: d9b4b7488a9cee97608343cbb5ac652d3f316436f95ef0800cd9497c1c6f877b655a3275817989c02f1ff0d5dfd1959c5092af9251c7e3fcf60659da37752a10 + checksum: a31adf390d71d916925586bc8467b48f620e93dd0416bc1e897d99265af88b48d4eba3985b5ff4653ae5cc46311a360d373574002277e159bb38a4363abf9228 languageName: node linkType: hard @@ -2093,7 +2103,7 @@ __metadata: languageName: node linkType: hard -"jsx-ast-utils@npm:^2.4.1 || ^3.0.0, jsx-ast-utils@npm:^3.2.1": +"jsx-ast-utils@npm:^2.4.1 || ^3.0.0": version: 3.3.0 resolution: "jsx-ast-utils@npm:3.3.0" dependencies: @@ -2103,6 +2113,16 @@ __metadata: languageName: node linkType: hard +"jsx-ast-utils@npm:^3.3.1": + version: 3.3.2 + resolution: "jsx-ast-utils@npm:3.3.2" + dependencies: + array-includes: ^3.1.5 + object.assign: ^4.1.2 + checksum: 61d4596d44480afc03ae0a7ebb272aa6603dc4c3645805dea0fc8d9f0693542cd0959f3ba7c0c9b16c13dd5a900c7c4310108bada273132a8355efe3fed22064 + languageName: node + linkType: hard + "just-extend@npm:^4.0.2": version: 4.2.1 resolution: "just-extend@npm:4.2.1" @@ -2507,11 +2527,11 @@ __metadata: version: 0.0.0-use.local resolution: "ninjawars@workspace:." dependencies: - "@types/eslint": ^8.4.3 - eslint: ^8.18.0 + "@types/eslint": ^8.4.5 + eslint: ^8.20.0 eslint-config-airbnb: ^19.0.4 eslint-plugin-import: ^2.26.0 - eslint-plugin-jsx-a11y: ^6.5.1 + eslint-plugin-jsx-a11y: ^6.6.0 eslint-plugin-react: ^7.30.1 eslint-plugin-react-hooks: 4.6.0 husky: ^8.0.1 @@ -2522,7 +2542,7 @@ __metadata: karma-requirejs: ^1.1.0 karma-sinon: ^1.0.5 prettier: 2.7.1 - puppeteer: ^15.0.0 + puppeteer: ^15.4.0 requirejs: ^2.3.6 sinon: ^14.0.0 languageName: unknown @@ -2939,13 +2959,13 @@ __metadata: languageName: node linkType: hard -"puppeteer@npm:^15.0.0": - version: 15.0.0 - resolution: "puppeteer@npm:15.0.0" +"puppeteer@npm:^15.4.0": + version: 15.4.0 + resolution: "puppeteer@npm:15.4.0" dependencies: cross-fetch: 3.1.5 debug: 4.3.4 - devtools-protocol: 0.0.1001819 + devtools-protocol: 0.0.1011705 extract-zip: 2.0.1 https-proxy-agent: 5.0.1 pkg-dir: 4.2.0 @@ -2954,8 +2974,8 @@ __metadata: rimraf: 3.0.2 tar-fs: 2.1.1 unbzip2-stream: 1.4.3 - ws: 8.7.0 - checksum: 6c57d2a34239b418d9499875d20b842c8055e51cd02a24d38f7605414ef5ee54a8b0c031711c1edddc0344336ee2eb9db811033e5699cc734d06ec4d03ee39eb + ws: 8.8.0 + checksum: 57f05042a58e5b5b6b9457da8b88680a0db170f9a6cd44153a8da03d5888ff0d9fcfc0bb1c4e72e1e3f19cb7707091e883ec5a7d0a2172ee36e29741ab8d7288 languageName: node linkType: hard @@ -3763,9 +3783,9 @@ __metadata: languageName: node linkType: hard -"ws@npm:8.7.0": - version: 8.7.0 - resolution: "ws@npm:8.7.0" +"ws@npm:8.8.0": + version: 8.8.0 + resolution: "ws@npm:8.8.0" peerDependencies: bufferutil: ^4.0.1 utf-8-validate: ^5.0.2 @@ -3774,7 +3794,7 @@ __metadata: optional: true utf-8-validate: optional: true - checksum: 078fa2dbc06b31a45e0057b19e2930d26c222622e355955afe019c9b9b25f62eb2a8eff7cceabdad04910ecd2bd6ef4fa48e6f3673f2fdddff02a6e4c2459584 + checksum: 6ceed1ca1cb800ef60c7fc8346c7d5d73d73be754228eb958765abf5d714519338efa20ffe674167039486eb3a813aae5a497f8d319e16b4d96216a31df5bd95 languageName: node linkType: hard