Skip to content

Expand copilot-instructions: code style, module organization, and safety model#17

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/add-copilot-instructions-file
Draft

Expand copilot-instructions: code style, module organization, and safety model#17
Copilot wants to merge 3 commits intomainfrom
copilot/add-copilot-instructions-file

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 18, 2026

The instructions were thin on three topics contributors need to reason about correctly: code style conventions, how modules are structured, and how client input is validated. Also corrects the false claim that there are no unit tests.

Code Style

  • Documents glob import conventions (enums::*, error::*, PacketID::*) and when to use them
  • Naming: Rust snake_case/PascalCase vs. FusionFall Hungarian notation on packet fields; #[allow(non_snake_case)] pattern
  • Casting: infallible as for well-bounded protocol fields, try_into()? for enums or out-of-range values
  • Immediately-invoked closure pattern for handlers that must produce SUCC or FAIL response packets

Module Organization

  • Library (src/lib.rs) vs. binary (src/bin/) separation and what belongs where
  • Private-module + pub use * re-export pattern (mod ffclient; pub use ffclient::*;)
  • Global singletons via OnceLock/LazyLock (config_get(), tdata_get(), db_get()); mutable game state stays in ShardServerState/LoginServerState
  • Handler files grouped by feature domain; file-local mod helpers { … } submodule at bottom of file

Safety — Trust-but-Verify

Documents the four validation layers every packet passes through:

  1. Connection-level filtering (can_send_packet): unknown clients may only send a 3-packet whitelist; all others filtered by direction bitmask
  2. Structural deserialization (pkt.get()): alignment + size checked before transmute; misaligned data returns FFError, not UB
  3. Semantic validation in handlers: enum fields via try_into()?, slot bounds, target count caps, entity lookups returning FFResult, resource/currency checks, validate_perms() guard on all GM handlers
  4. Session guard: serial-key handshake + pending_entering_uids prevent replay and double-enter races

Also documents why the single unsafe block in bytes_to_struct is sound and points to the net/mod.rs unit tests that cover it.

Unit Tests

Corrects the erroneous "no unit tests" statement. Tests exist in util, config, chunk, net/mod, net/crypto, entity/mod, and tabledata.

Copilot AI and others added 3 commits April 18, 2026 15:52
… safety sections

Agent-Logs-Url: https://github.com/yungcomputerchair/RustyFusion/sessions/2d2c844b-70af-4a2d-9d4b-078923c6b7c2

Co-authored-by: yungcomputerchair <5123173+yungcomputerchair@users.noreply.github.com>
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