- add: Character service now loads the data from the database and sends it in the character list packet

- add: character id list to the connection state for tracking the real character database id's for when the client requests actions on the character
- fix: sql error when trying to create a character
This commit is contained in:
2025-01-07 22:16:47 -05:00
parent cb6ee657f0
commit db868cc1ac
9 changed files with 117 additions and 62 deletions

View File

@@ -27,44 +27,24 @@ impl CharacterService for MyCharacterService {
let user_id = req.user_id;
debug!("Character list for User ID: {}", user_id);
// todo: get the data from the database
// self.character_db_client.as_ref();
// Simulated database fetch for characters
let characters = vec![
Character {
character_id: "1".to_string(),
name: "Warrior123".to_string(),
last_played: 1633017600,
delete_time: 0,
stats: Option::from(Stats {
job: 0,
level: 0,
}),
looks: Option::from(Looks {
race: 0,
hair: 0,
face: 0,
}),
items: vec![],
},
Character {
character_id: "2".to_string(),
name: "Mage123".to_string(),
last_played: 1633017600,
delete_time: 0,
stats: Option::from(Stats {
job: 211,
level: 20,
}),
looks: Option::from(Looks {
race: 1,
hair: 0,
face: 1,
}),
items: vec![],
},
];
let character_list = self.character_db_client.as_ref().clone().get_character_list(&user_id).await
.map_err(|_| Status::aborted("Unable to get character list"))?;
debug!("{:?}", character_list.characters);
let mut characters: Vec<Character> = vec![];
for character in character_list.characters {
characters.push(
Character {
character_id: character.id.to_string(),
name: character.name,
last_played: 0,
delete_time: 0,
stats: serde_json::from_str(&character.stats).unwrap(),
looks: serde_json::from_str(&character.looks).unwrap(),
items: serde_json::from_str(&character.inventory).unwrap(),
}
)
}
let response = GetCharacterListResponse { characters };
Ok(Response::new(response))