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:
@@ -7,16 +7,15 @@ use crate::enums::ItemType;
|
||||
use crate::packet::{send_packet, Packet, PacketPayload};
|
||||
use crate::packet_type::PacketType;
|
||||
use crate::packets::*;
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::error::Error;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::sync::Arc;
|
||||
use tokio::net::TcpStream;
|
||||
use tokio::sync::Mutex;
|
||||
use tonic::{Code, Status};
|
||||
use tracing::{debug, error, info, warn};
|
||||
use utils::null_string::NullTerminatedString;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
|
||||
|
||||
fn string_to_u32(s: &str) -> u32 {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
@@ -80,20 +79,16 @@ pub(crate) async fn handle_char_list_req(
|
||||
let request = CliCharListReq::decode(packet.payload.as_slice());
|
||||
debug!("{:?}", request);
|
||||
|
||||
let mut user_id= "".to_string();
|
||||
let mut user_id = "".to_string();
|
||||
let session_id;
|
||||
if let Some(mut state) = connection_service.get_connection(&connection_id) {
|
||||
user_id = state.user_id.expect("Missing user id in connection state");
|
||||
session_id = state
|
||||
.session_id
|
||||
.expect("Missing session id in connection state");
|
||||
session_id = state.session_id.expect("Missing session id in connection state");
|
||||
}
|
||||
|
||||
// query the character service for the character list for this user
|
||||
let mut character_client = character_client.lock().await;
|
||||
let character_list = character_client
|
||||
.get_character_list(&user_id)
|
||||
.await?;
|
||||
let character_list = character_client.get_character_list(&user_id).await?;
|
||||
let mut characters = vec![];
|
||||
let mut character_id_list: Vec<u32> = Vec::new();
|
||||
for character in character_list.characters {
|
||||
@@ -154,9 +149,7 @@ pub(crate) async fn handle_create_char_req(
|
||||
let session_id;
|
||||
if let Some(mut state) = connection_service.get_connection(&connection_id) {
|
||||
user_id = state.user_id.expect("Missing user id in connection state");
|
||||
session_id = state
|
||||
.session_id
|
||||
.expect("Missing session id in connection state");
|
||||
session_id = state.session_id.expect("Missing session id in connection state");
|
||||
}
|
||||
|
||||
// send the data to the character service to create the character
|
||||
@@ -181,10 +174,7 @@ pub(crate) async fn handle_create_char_req(
|
||||
_ => srv_create_char_reply::Result::Failed,
|
||||
};
|
||||
|
||||
let data = SrvCreateCharReply {
|
||||
result,
|
||||
platininum: 0,
|
||||
};
|
||||
let data = SrvCreateCharReply { result, platininum: 0 };
|
||||
let response_packet = Packet::new(PacketType::PakccCreateCharReply, &data)?;
|
||||
send_packet(stream, &response_packet).await?;
|
||||
|
||||
@@ -209,9 +199,7 @@ pub(crate) async fn handle_delete_char_req(
|
||||
|
||||
if let Some(mut state) = connection_service.get_connection(&connection_id) {
|
||||
user_id = state.user_id.expect("Missing user id in connection state");
|
||||
session_id = state
|
||||
.session_id
|
||||
.expect("Missing session id in connection state");
|
||||
session_id = state.session_id.expect("Missing session id in connection state");
|
||||
character_id_list = state.character_list.expect("Missing character id list");
|
||||
}
|
||||
|
||||
@@ -256,10 +244,7 @@ pub(crate) async fn handle_select_char_req(
|
||||
let mut character_id_list: Vec<u32> = Vec::new();
|
||||
if let Some(mut state) = connection_service.get_connection_mut(&connection_id) {
|
||||
user_id = state.user_id.clone().expect("Missing user id in connection state");
|
||||
character_id_list = state
|
||||
.character_list
|
||||
.clone()
|
||||
.expect("Missing character id list");
|
||||
character_id_list = state.character_list.clone().expect("Missing character id list");
|
||||
state.character_id = Some(request.char_id as i8);
|
||||
}
|
||||
|
||||
@@ -274,10 +259,7 @@ pub(crate) async fn handle_select_char_req(
|
||||
|
||||
let mut character_client = character_client.lock().await;
|
||||
let character_data = character_client
|
||||
.get_character(
|
||||
&user_id.to_string(),
|
||||
character_id_list[request.char_id as usize] as u8,
|
||||
)
|
||||
.get_character(&user_id.to_string(), character_id_list[request.char_id as usize] as u8)
|
||||
.await?;
|
||||
|
||||
let character = character_data.character.unwrap_or_default();
|
||||
@@ -332,8 +314,7 @@ pub(crate) async fn handle_select_char_req(
|
||||
|
||||
let mut effect_list: [StatusEffect; (MAX_STATUS_EFFECTS as usize)] =
|
||||
core::array::from_fn(|i| StatusEffect::default());
|
||||
let mut hotbar_list: [HotbarItem; (MAX_HOTBAR_ITEMS as usize)] =
|
||||
core::array::from_fn(|i| HotbarItem::default());
|
||||
let mut hotbar_list: [HotbarItem; (MAX_HOTBAR_ITEMS as usize)] = core::array::from_fn(|i| HotbarItem::default());
|
||||
let data = SrvSelectCharReply {
|
||||
race: looks.race as u8,
|
||||
map: position.map_id as u16,
|
||||
|
||||
Reference in New Issue
Block a user