Skip to content

Fix crashes#289

Merged
sorokya merged 20 commits intomasterfrom
fix-crashes
Apr 15, 2026
Merged

Fix crashes#289
sorokya merged 20 commits intomasterfrom
fix-crashes

Conversation

@sorokya
Copy link
Copy Markdown
Owner

@sorokya sorokya commented Apr 15, 2026

This pull request introduces several important improvements and fixes across the codebase, focusing on input validation, UTF-8 string handling, dependency updates, and error handling. The most notable changes are enhanced validation for account and character names, improved handling of multibyte strings, removal of a redundant save command, and updates to dependencies for better compatibility and security.

Input validation and normalization:

  • Added normalization and validation for emails and account names during account creation and login, ensuring only valid inputs are accepted and stored in lowercase (src/player/player/handlers/account.rs) [1] [2] [3] [4] [5] [6] [7].
  • Added validation for character name fields (fiance, partner) and enforced character title length using chars().count() for proper Unicode support (src/map/map/character/set_character_property.rs) [1] [2].

UTF-8/multibyte string handling:

  • Improved truncation logic for board post subjects and bodies to handle multibyte characters safely, using a new truncate_to_chars utility (src/map/map/board/create_board_post.rs) [1] [2].
  • Refactored text_cap to properly handle multibyte strings and prevent panics, and added a test to verify correct behavior (src/map/map/utils/show_info_box.rs) [1] [2].

Error handling and code cleanup:

  • Refactored map leave logic to return Result, propagating errors up and handling them gracefully in player logic (src/map/map_handle.rs, src/player/player/arena_die.rs, src/player/player/close.rs, src/player/player/die.rs) [1] [2] [3] [4].
  • Removed the unused synchronous Save command in favor of the async variant, simplifying the command interface (src/map/command.rs, src/map/map.rs, src/map/map_handle.rs) [1] [2] [3].

Dependency and configuration updates:

  • Updated several dependencies (tokio-tungstenite, rusqlite, regex) to newer versions and bumped the crate version to 1.16.0 (Cargo.toml) [1] [2].
  • Added min_name_length to character configuration for stricter name validation (config/Config.toml).

Protocol and packet handling:

  • Added support for new reply codes in account and character server packets, improving client-server communication (src/player/player/handlers/account.rs, src/player/player/handlers/character.rs) [1] [2].
  • Improved packet handling to discard invalid (too short) packets early (src/player/packet_bus.rs).

sorokya added 10 commits April 14, 2026 20:29
…uncate_to_chars` utility function for multi byte chars
- Added `emval` crate for email validation and normalization.
- Introduced `normalize_email` utility function to standardize email addresses.
- Implemented `validate_account_name` function to ensure usernames meet criteria.
- Updated account creation logic to validate email and username before proceeding.
- Added minimum name length configuration in `Config.toml` and updated character name validation to use configurable limits.
- Enhanced character creation logic to validate character names based on new rules.
- Replaced `emval` dependency with `regex` for email validation.
- Modified `normalize_email` function to use a regex for validating email format and return a more descriptive error using `anyhow`.
- Updated SQL query parameters in `account.rs` to convert `username` to a `String` to avoid type mismatches.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR focuses on preventing crashes and improving robustness by tightening input validation, making UTF-8 string operations safe, improving error propagation in map-leave flows, simplifying save commands, and updating dependencies/config.

Changes:

  • Added/centralized validation & normalization for account/character-related inputs (including new reply codes and config-driven min name length).
  • Fixed several UTF-8/multibyte string handling paths (safe truncation/capitalization/info-box text capping) and added targeted unit tests.
  • Refactored save + map leave behavior (async saves with batching; map leave now returns Result) and updated dependencies.

Reviewed changes

Copilot reviewed 26 out of 27 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/world/world/save.rs Removes sync save and batches async map saves to reduce concurrent load.
src/world/world.rs Routes Command::Save through async save.
src/utils/validate_character_name.rs Updates character name validation to use config-driven bounds.
src/utils/validate_account_name.rs Adds account name validation helper.
src/utils/truncate_to_chars.rs Adds safe character-count truncation utility with tests.
src/utils/normalize_email.rs Adds email normalization/validation helper.
src/utils/mod.rs Exposes new utility modules (truncate/email/account-name validation).
src/utils/capitalize.rs Fixes multibyte-safe capitalization and adds a test.
src/settings.rs Adds character.min_name_length to settings struct.
src/player/player/handlers/warp.rs Handles map leave errors instead of assuming success.
src/player/player/handlers/marriage.rs Normalizes/validates character names before marriage operations.
src/player/player/handlers/item.rs Enforces title length using Unicode character count.
src/player/player/handlers/character.rs Validates character name and sends NotApproved reply on invalid input.
src/player/player/handlers/account.rs Normalizes/validates usernames and emails; uses NotApproved reply code.
src/player/player/die.rs Handles map leave errors to avoid panics/unwrapping failures.
src/player/player/close.rs Updates close flow to handle leave() returning Result.
src/player/player/arena_die.rs Handles map leave errors to avoid panics/unwrapping failures.
src/player/packet_bus.rs Drops invalid too-short websocket packets early.
src/map/map_handle.rs Changes leave() to return anyhow::Result<Character> and removes sync save wrapper.
src/map/map/utils/show_info_box.rs Refactors text capping to be UTF-8 safe; adds a regression test.
src/map/map/character/set_character_property.rs Validates/normalizes fiance/partner fields; Unicode-safe title length check.
src/map/map/board/create_board_post.rs Uses character-aware truncation for subject/body.
src/map/map.rs Removes redundant Command::Save handling in favor of async variant.
src/map/command.rs Removes Save command variant (keeps SaveAsync).
config/Config.toml Adds character.min_name_length configuration.
Cargo.toml Bumps crate version and updates/adds dependencies (incl. regex).
Cargo.lock Updates lockfile to match dependency changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/player/player/close.rs Outdated
Comment thread src/player/player/handlers/account.rs
Comment thread src/utils/validate_account_name.rs Outdated
Comment thread src/utils/normalize_email.rs Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 26 out of 27 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/player/packet_bus.rs Outdated
Comment thread src/player/player/close.rs Outdated
Comment thread src/utils/validate_account_name.rs
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 42 out of 43 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/settings.rs
Comment thread src/player/player/handlers/account.rs
Comment thread src/player/player/handlers/account.rs
@sorokya sorokya merged commit 4dd9a12 into master Apr 15, 2026
11 checks passed
@sorokya sorokya deleted the fix-crashes branch April 15, 2026 04:48
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