Skip to content

small changes#60

Merged
CLOEI merged 2 commits into
CLOEI:mainfrom
badewen:patches-1
Apr 26, 2026
Merged

small changes#60
CLOEI merged 2 commits into
CLOEI:mainfrom
badewen:patches-1

Conversation

@badewen

@badewen badewen commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Collect feature now supports optional per-call customization for collection radius and inter-packet delay parameters.
  • Chores

    • Updated game version to 5.46.

@coderabbitai

coderabbitai Bot commented Apr 26, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes update the game version to 5.46 and refactor the collect workflow to accept optional per-call overrides for collect radius and inter-packet delay, with the run-loop continuing to invoke collect(None, None) for default behavior.

Changes

Cohort / File(s) Summary
Collect Workflow Enhancement
src/bot/core.rs
Function signature updated to accept optional radius and delay parameters. Implementation now derives final values from provided options with fallback to clamped configured defaults. Added sleep_ms(delay) after each ItemActivateObjectRequest send. Script request handler updated to pass range and interval_ms through as overrides.
Version Bump
src/constants.rs
GAME_VER constant updated from "5.45" to "5.46".

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Hop-hop! The collect now flexes its might,
With radius and delays taking flight,
Parameters dance where defaults once stood,
Version 5.46 brings updates so good!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'small changes' is vague and generic, failing to convey meaningful information about the actual changeset which includes a collect function refactor and version bump. Replace with a more descriptive title that captures the main changes, such as 'Refactor collect function to accept optional overrides for radius and delay' or 'Update game version and refactor collect workflow'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/bot/core.rs`:
- Around line 2210-2215: The auto-collect fallback is incorrectly reusing
self.collect_interval as a per-packet delay causing long stalls; add a new field
(e.g., collect_packet_delay_ms: u64 with default 0 or small value) to the
struct/initializers and use it for per-packet pacing inside collect() instead of
delay.unwrap_or(self.collect_interval), keep self.collect_interval strictly as
the tick cadence used by run(), and ensure the radius override uses .clamp(1,5)
on the incoming radius (replace
radius.unwrap_or(self.collect_radius_tiles.clamp(1,5)) with clamping the
provided radius) so user-supplied values are bounded; retain MAX_PER_TICK but
honor the new collect_packet_delay_ms between ItemActivateObjectRequest packets
to avoid blocking run().
- Around line 2289-2291: The loop sends packets while holding the cap check
stale and sleeps after each packet, causing up to MAX_PER_TICK+1 sends and large
run-loop stalls; update the cap condition to use >= (change checks that read `if
sent > MAX_PER_TICK` to `if sent >= MAX_PER_TICK`) so you never exceed
MAX_PER_TICK, and move the sleep out of the inner per-uid loop in
send_game_packet/sleep_ms usage: perform sleep_ms(delay) only once per
tile-group (i.e., after finishing the group of uids) or after the outer loop
iteration rather than after every individual uid to avoid per-packet stalls
while keeping sent increment logic (sent variable and send_game_packet calls)
unchanged.
- Around line 2492-2494: The handler for Req::Collect is unsafely casting
ScriptRequest::Collect.range (f32) to u8, which can wrap or silently truncate;
update the code in the Req::Collect match arm so you first clamp the float into
the allowed numeric bounds and then convert to u8 before calling self.collect:
e.g. compute let clamped = range.clamp(1.0_f32, 5.0_f32); let radius = clamped
as u8; then call Rep::CollectCount(self.collect(Some(radius),
Some(interval_ms))); alternatively, if fractional semantics are required, apply
an explicit rounding method (floor/ceil/round) to clamped before casting, or
change the ScriptRequest::Collect.range type to u8 and validate at the script
boundary instead.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a64898d6-2a24-4643-a6d2-ea2bd7aacc47

📥 Commits

Reviewing files that changed from the base of the PR and between cf031a1 and cdf1a54.

📒 Files selected for processing (2)
  • src/bot/core.rs
  • src/constants.rs

Comment thread src/bot/core.rs
Comment on lines +2210 to +2215
let radius_tiles = radius.unwrap_or(self.collect_radius_tiles.clamp(1, 5));
let r_px = radius_tiles as f32 * 32.0;
const MAX_PER_TICK: usize = 32; // cap packets per call

let delay = delay.unwrap_or(self.collect_interval);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Default delay reuses collect_interval (the inter-tick interval), causing auto-collect to stall the bot for seconds.

self.collect_interval is documented as “Interval in ms between auto-collect ticks (default 500)” (line 174–175), not a per-packet pacing delay. With this fallback:

  • run() calls self.collect(None, None) (line 743), which now does sleep_ms(500) after every ItemActivateObjectRequest.
  • With MAX_PER_TICK = 32, a single auto-collect invocation can block for ~16 seconds.
  • During that block the run loop’s command intake, ping update, and reconnect_after checks at the top of run() are skipped (only service_once runs inside sleep_ms).
  • collect_timer is reset before the call (line 742), so the “every 500 ms” cadence is destroyed — the next tick effectively fires immediately after the previous one returns.

Also note the override path at line 2210 — radius.unwrap_or(self.collect_radius_tiles.clamp(1, 5)) — only clamps the configured value; a user-supplied radius is used unclamped (the Req::Collect path even truncates range as u8, so 256→0 silently).

Suggested direction: introduce a separate field (e.g. collect_packet_delay_ms, default 0 or a small value like 10–50) for the per-packet pacing, keep collect_interval as the tick cadence, and clamp the override.

🛠 Proposed fix sketch
-        let radius_tiles = radius.unwrap_or(self.collect_radius_tiles.clamp(1, 5));
+        let radius_tiles = radius
+            .unwrap_or(self.collect_radius_tiles)
+            .clamp(1, 5);
         let r_px = radius_tiles as f32 * 32.0;
         const MAX_PER_TICK: usize = 32; // cap packets per call
 
-        let delay = delay.unwrap_or(self.collect_interval);
+        // Per-packet pacing — separate from the auto-collect tick interval.
+        let delay = delay.unwrap_or(self.collect_packet_delay_ms);

And in the struct/initializers, add a new collect_packet_delay_ms: u64 (default e.g. 0) instead of overloading collect_interval.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/bot/core.rs` around lines 2210 - 2215, The auto-collect fallback is
incorrectly reusing self.collect_interval as a per-packet delay causing long
stalls; add a new field (e.g., collect_packet_delay_ms: u64 with default 0 or
small value) to the struct/initializers and use it for per-packet pacing inside
collect() instead of delay.unwrap_or(self.collect_interval), keep
self.collect_interval strictly as the tick cadence used by run(), and ensure the
radius override uses .clamp(1,5) on the incoming radius (replace
radius.unwrap_or(self.collect_radius_tiles.clamp(1,5)) with clamping the
provided radius) so user-supplied values are bounded; retain MAX_PER_TICK but
honor the new collect_packet_delay_ms between ItemActivateObjectRequest packets
to avoid blocking run().

Comment thread src/bot/core.rs
Comment on lines 2289 to 2291
self.send_game_packet(&pkt, true);
self.sleep_ms(delay);
sent += 1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Per-packet sleep_ms(delay) runs inside the inner per-object loop while holding the cap check stale.

Two related concerns at this site:

  1. The cap check uses if sent > MAX_PER_TICK (lines 2266, 2270). With > rather than >=, the loop can send MAX_PER_TICK + 1 = 33 packets before breaking. Pre-existing, but newly relevant because each excess packet now also sleeps for delay ms.
  2. Sleeping after every packet here (rather than between groups, or at the end) magnifies the stall noted in the comment on lines 2210–2215. Even a modest delay of 100 ms × 33 packets = 3.3 s of blocked run-loop work.

Consider >= for the cap, and/or sleeping only between distinct tile groups instead of after every individual uid.

♻️ Proposed cap fix
-            if sent > MAX_PER_TICK { break; }
+            if sent >= MAX_PER_TICK { break; }
 
             // fx, fy = the object actual coordinate
             for (fx, fy, uid, item_id) in objs {
-                if sent > MAX_PER_TICK { break; }
+                if sent >= MAX_PER_TICK { break; }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/bot/core.rs` around lines 2289 - 2291, The loop sends packets while
holding the cap check stale and sleeps after each packet, causing up to
MAX_PER_TICK+1 sends and large run-loop stalls; update the cap condition to use
>= (change checks that read `if sent > MAX_PER_TICK` to `if sent >=
MAX_PER_TICK`) so you never exceed MAX_PER_TICK, and move the sleep out of the
inner per-uid loop in send_game_packet/sleep_ms usage: perform sleep_ms(delay)
only once per tile-group (i.e., after finishing the group of uids) or after the
outer loop iteration rather than after every individual uid to avoid per-packet
stalls while keeping sent increment logic (sent variable and send_game_packet
calls) unchanged.

Comment thread src/bot/core.rs
Comment on lines 2492 to 2494
Req::Collect { range, interval_ms } => {
Rep::CollectCount(self.collect())
Rep::CollectCount(self.collect(Some(range as u8), Some(interval_ms)))
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect ScriptRequest::Collect to see the declared type of `range` and `interval_ms`.
fd -t f script_channel.rs --exec rg -nP -C2 'Collect\s*\{|CollectObject\s*\{' {}
echo "---"
# Show the full enum if found
fd -t f script_channel.rs --exec cat {}

Repository: CLOEI/Mori

Length of output: 3338


🏁 Script executed:

#!/bin/bash
# Find and inspect the collect method definition
rg -n "fn collect" src/bot/core.rs -A 10

Repository: CLOEI/Mori

Length of output: 1034


🏁 Script executed:

#!/bin/bash
# Search for collect_radius_tiles and related clamping logic
rg -n "collect_radius_tiles" src/bot/core.rs -B 2 -A 2
echo "---"
# Also search for SetCollectRange to see if there's validation
rg -n "SetCollectRange" src/bot/core.rs -B 2 -A 5

Repository: CLOEI/Mori

Length of output: 2871


Verify field type and address the unsafe as u8 cast—a safety net exists but incomplete.

ScriptRequest::Collect.range is f32, but the handler at lines 2492–2494 casts it as u8. This loses fractional values (e.g., 5.7 → 5) and causes wrapping (e.g., 256 → 0). While line 2210 includes clamp(1, 5) on the resulting u8, so 0 becomes 1, this doesn't fully salvage the intent: a script sending range = 256 silently becomes radius = 1 instead of clamping first.

Either cast and clamp before passing:

Some((range as u8).clamp(1, 5))

Or change the field to u8 with validation at the script boundary.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/bot/core.rs` around lines 2492 - 2494, The handler for Req::Collect is
unsafely casting ScriptRequest::Collect.range (f32) to u8, which can wrap or
silently truncate; update the code in the Req::Collect match arm so you first
clamp the float into the allowed numeric bounds and then convert to u8 before
calling self.collect: e.g. compute let clamped = range.clamp(1.0_f32, 5.0_f32);
let radius = clamped as u8; then call
Rep::CollectCount(self.collect(Some(radius), Some(interval_ms))); alternatively,
if fractional semantics are required, apply an explicit rounding method
(floor/ceil/round) to clamped before casting, or change the
ScriptRequest::Collect.range type to u8 and validate at the script boundary
instead.

@CLOEI

CLOEI commented Apr 26, 2026

Copy link
Copy Markdown
Owner

Thank you for your hard work!!

@CLOEI CLOEI merged commit d861ded into CLOEI:main Apr 26, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants