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
This commit is contained in:
95
world-service/README.md
Normal file
95
world-service/README.md
Normal file
@@ -0,0 +1,95 @@
|
||||
# World Service
|
||||
|
||||
The World Service manages the game world state and character interactions in the MMORPG server architecture.
|
||||
|
||||
## Overview
|
||||
|
||||
The World Service is responsible for:
|
||||
- Managing character positions and movement
|
||||
- Handling map changes
|
||||
- Processing character interactions
|
||||
- Managing NPCs, monsters, and objects
|
||||
- Handling combat and skills
|
||||
|
||||
## Architecture
|
||||
|
||||
The service is built using the following components:
|
||||
|
||||
- **gRPC Server**: Exposes world management endpoints
|
||||
- **World State Manager**: Maintains the current state of the game world
|
||||
- **Map Manager**: Handles map data and transitions
|
||||
- **Entity Manager**: Manages characters, NPCs, and monsters
|
||||
|
||||
## Service Endpoints
|
||||
|
||||
The World Service exposes the following gRPC endpoints:
|
||||
|
||||
### GetCharacter
|
||||
Retrieves a character's world state.
|
||||
|
||||
```protobuf
|
||||
rpc GetCharacter(CharacterRequest) returns (CharacterResponse);
|
||||
```
|
||||
|
||||
### ChangeMap
|
||||
Handles a character changing maps.
|
||||
|
||||
```protobuf
|
||||
rpc ChangeMap(ChangeMapRequest) returns (ChangeMapResponse);
|
||||
```
|
||||
|
||||
### MoveCharacter
|
||||
Updates a character's position.
|
||||
|
||||
```protobuf
|
||||
rpc MoveCharacter(CharacterMoveRequest) returns (CharacterMoveResponse);
|
||||
```
|
||||
|
||||
### GetTargetHp
|
||||
Retrieves an object's current HP.
|
||||
|
||||
```protobuf
|
||||
rpc GetTargetHp(ObjectHpRequest) returns (ObjectHpResponse);
|
||||
```
|
||||
|
||||
## World Data Structure
|
||||
|
||||
The world consists of:
|
||||
|
||||
- **Maps**: Different areas with unique IDs
|
||||
- **Spawn Points**: Locations where characters can appear
|
||||
- **NPCs**: Non-player characters with fixed positions
|
||||
- **Monsters**: Hostile entities that can move and attack
|
||||
- **Objects**: Interactive items in the world
|
||||
|
||||
## 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: "50054")
|
||||
- `LOG_LEVEL`: Logging level (default: "info")
|
||||
|
||||
## Running the Service
|
||||
|
||||
### Local Development
|
||||
|
||||
```bash
|
||||
cargo run
|
||||
```
|
||||
|
||||
### Docker
|
||||
|
||||
```bash
|
||||
docker build -t world-service .
|
||||
docker run -p 50054:50054 world-service
|
||||
```
|
||||
|
||||
## Integration with External Systems
|
||||
|
||||
The World Service integrates with:
|
||||
|
||||
- **Database Service**: For retrieving and storing world state
|
||||
- **Auth Service**: For user authentication and authorization
|
||||
- **Character Service**: For character data
|
||||
- **Packet Service**: For handling client requests related to the world
|
||||
@@ -11,9 +11,6 @@ fn main() {
|
||||
tonic_build::configure()
|
||||
.build_server(false) // Generate gRPC client code
|
||||
.compile_well_known_types(true)
|
||||
.compile_protos(
|
||||
&["../proto/user_db_api.proto", "../proto/auth.proto"],
|
||||
&["../proto"],
|
||||
)
|
||||
.compile_protos(&["../proto/user_db_api.proto", "../proto/auth.proto"], &["../proto"])
|
||||
.unwrap_or_else(|e| panic!("Failed to compile protos {:?}", e));
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use dotenv::dotenv;
|
||||
use std::env;
|
||||
use utils::{health_check, logging};
|
||||
use utils::service_discovery::{get_kube_service_endpoints_by_dns, get_service_endpoints_by_dns};
|
||||
use utils::{health_check, logging};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
@@ -12,7 +12,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Set the gRPC server address
|
||||
let addr = env::var("LISTEN_ADDR").unwrap_or_else(|_| "0.0.0.0".to_string());
|
||||
let port = env::var("SERVICE_PORT").unwrap_or_else(|_| "50054".to_string());
|
||||
let db_url = format!("http://{}",get_kube_service_endpoints_by_dns("database-service","tcp","database-service").await?.get(0).unwrap());
|
||||
let db_url = format!(
|
||||
"http://{}",
|
||||
get_kube_service_endpoints_by_dns("database-service", "tcp", "database-service")
|
||||
.await?
|
||||
.get(0)
|
||||
.unwrap()
|
||||
);
|
||||
|
||||
// Register service with Consul
|
||||
health_check::start_health_check(addr.as_str()).await?;
|
||||
|
||||
Reference in New Issue
Block a user