Files
raven a8755bd3de Add comprehensive documentation and unit tests
Documentation:
- Add detailed README files for all services (auth, character, database, launcher, packet, utils, world)
- Create API documentation for the database service with detailed endpoint specifications
- Document database schema and relationships
- Add service architecture overviews and configuration instructions

Unit Tests:
- Implement comprehensive test suite for database repositories (user, character, session)
- Add gRPC service tests for database interactions
- Create tests for packet service components (bufferpool, connection, packets)
- Add utility service tests (health check, logging, load balancer, redis cache, service discovery)
- Implement auth service user tests
- Add character service tests

Code Structure:
- Reorganize test files into a more consistent structure
- Create a dedicated tests crate for integration testing
- Add test helpers and mock implementations for easier testing
2025-04-09 13:29:53 -04:00

3.1 KiB

Packet Service

The Packet Service handles communication between game clients and the MMORPG server using a custom binary packet protocol.

Overview

The Packet Service is responsible for:

  • Accepting TCP connections from game clients
  • Parsing binary packet data
  • Routing packets to appropriate handlers
  • Sending response packets back to clients
  • Managing client connection state

Architecture

The service is built using the following components:

  • TCP Server: Accepts client connections
  • Buffer Pool: Efficiently manages memory for packet processing
  • Packet Router: Routes packets to appropriate handlers
  • Connection Service: Manages client connection state
  • Packet Handlers: Process specific packet types
  • Auth/Character Clients: Communicate with other services

Packet Structure

Each packet follows a standard binary format:

+----------------+----------------+----------------+----------------+
| Packet Size    | Packet Type    | Packet CRC     | Payload        |
| (2 bytes)      | (2 bytes)      | (2 bytes)      | (variable)     |
+----------------+----------------+----------------+----------------+
  • Packet Size: Total size of the packet in bytes (including header)
  • Packet Type: Identifies the packet type (see packet_type.rs)
  • Packet CRC: Checksum for packet validation
  • Payload: Packet-specific data

Packet Types

The service supports numerous packet types for different game operations:

  • Authentication: Login, logout, server selection
  • Character: Character creation, deletion, selection
  • Chat: Normal chat, whispers, shouts, party chat
  • Movement: Position updates, teleportation
  • Combat: Attacks, skills, damage
  • Items: Inventory management, equipment
  • Party: Party formation, invitations
  • Trade: Item trading between players
  • Shop: NPC shop interactions

See packet_type.rs for a complete list of supported packet types.

Connection State

The service maintains state for each client connection, including:

  • User ID
  • Session ID
  • Character ID
  • Character list
  • Additional session data

Metrics

The service exposes Prometheus metrics for monitoring:

  • Active connections
  • Packets received/sent
  • Packet processing time

Configuration

The service can be configured using environment variables:

  • LISTEN_ADDR: The address to listen on (default: "0.0.0.0")
  • SERVICE_PORT: The port to listen on (default: "29000")
  • PACKET_METRICS_PORT: Port for Prometheus metrics (default: "9102")
  • MAX_CONCURRENT_CONNECTIONS: Maximum allowed concurrent connections
  • BUFFER_POOL_SIZE: Size of the packet buffer pool
  • LOG_LEVEL: Logging level (default: "info")

Running the Service

Local Development

cargo run

Docker

docker build -t packet-service .
docker run -p 29000:29000 -p 9102:9102 packet-service

Integration with External Systems

The Packet Service integrates with:

  • Auth Service: For user authentication and session validation
  • Character Service: For character management
  • World Service: For game world interactions