|
@ -21,6 +21,7 @@ pub struct InMemoryGateway { |
|
|
equips: Arc<Mutex<BTreeMap<CharacterEntityId, EquippedEntity>>>,
|
|
|
equips: Arc<Mutex<BTreeMap<CharacterEntityId, EquippedEntity>>>,
|
|
|
mag_modifiers: Arc<Mutex<BTreeMap<ItemEntityId, Vec<mag::MagModifier>>>>,
|
|
|
mag_modifiers: Arc<Mutex<BTreeMap<ItemEntityId, Vec<mag::MagModifier>>>>,
|
|
|
weapon_modifiers: Arc<Mutex<BTreeMap<ItemEntityId, Vec<weapon::WeaponModifier>>>>,
|
|
|
weapon_modifiers: Arc<Mutex<BTreeMap<ItemEntityId, Vec<weapon::WeaponModifier>>>>,
|
|
|
|
|
|
guildcard_entities: Arc<Mutex<BTreeMap<UserAccountId, GuildCardDataEntity>>>,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl Default for InMemoryGateway {
|
|
|
impl Default for InMemoryGateway {
|
|
@ -37,6 +38,7 @@ impl Default for InMemoryGateway { |
|
|
equips: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
equips: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
mag_modifiers: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
mag_modifiers: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
weapon_modifiers: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
weapon_modifiers: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
|
|
|
guildcard_entities: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@ -101,6 +103,7 @@ impl InMemoryGateway { |
|
|
impl EntityGateway for InMemoryGateway {
|
|
|
impl EntityGateway for InMemoryGateway {
|
|
|
async fn create_user(&mut self, user: NewUserAccountEntity) -> Result<UserAccountEntity, GatewayError> {
|
|
|
async fn create_user(&mut self, user: NewUserAccountEntity) -> Result<UserAccountEntity, GatewayError> {
|
|
|
let mut users = self.users.lock().unwrap();
|
|
|
let mut users = self.users.lock().unwrap();
|
|
|
|
|
|
let mut guildcards = self.guildcard_entities.lock().unwrap();
|
|
|
let id = users
|
|
|
let id = users
|
|
|
.iter()
|
|
|
.iter()
|
|
|
.fold(0, |sum, (i, _)| std::cmp::max(sum, i.0))
|
|
|
.fold(0, |sum, (i, _)| std::cmp::max(sum, i.0))
|
|
@ -109,7 +112,7 @@ impl EntityGateway for InMemoryGateway { |
|
|
id: UserAccountId(id),
|
|
|
id: UserAccountId(id),
|
|
|
username: user.username,
|
|
|
username: user.username,
|
|
|
password: user.password,
|
|
|
password: user.password,
|
|
|
guildcard: user.guildcard,
|
|
|
|
|
|
|
|
|
guildcard: id,
|
|
|
team_id: user.team_id,
|
|
|
team_id: user.team_id,
|
|
|
banned_until: user.banned_until,
|
|
|
banned_until: user.banned_until,
|
|
|
muted_until: user.muted_until,
|
|
|
muted_until: user.muted_until,
|
|
@ -120,7 +123,11 @@ impl EntityGateway for InMemoryGateway { |
|
|
at_character: false,
|
|
|
at_character: false,
|
|
|
at_ship: false,
|
|
|
at_ship: false,
|
|
|
};
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let guildcard = GuildCardDataEntity::new(UserAccountId(id)); // TODO: NewGuildcardDataEntity ?
|
|
|
users.insert(user.id, user.clone());
|
|
|
users.insert(user.id, user.clone());
|
|
|
|
|
|
guildcards.insert(user.id, guildcard.clone());
|
|
|
|
|
|
|
|
|
Ok(user)
|
|
|
Ok(user)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
@ -213,8 +220,14 @@ impl EntityGateway for InMemoryGateway { |
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: ok_or a real error ?
|
|
|
async fn get_guild_card_data_by_user(&self, user: &UserAccountEntity) -> Result<GuildCardDataEntity, GatewayError> {
|
|
|
async fn get_guild_card_data_by_user(&self, user: &UserAccountEntity) -> Result<GuildCardDataEntity, GatewayError> {
|
|
|
Ok(GuildCardDataEntity::new(user.id))
|
|
|
|
|
|
|
|
|
let guildcards = self.guildcard_entities.lock().unwrap();
|
|
|
|
|
|
guildcards
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.find(|(_, g)| g.user_id == user.id)
|
|
|
|
|
|
.map(|(_, g)| g.clone())
|
|
|
|
|
|
.ok_or(GatewayError::Error)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn create_item(&mut self, item: NewItemEntity) -> Result<ItemEntity, GatewayError> {
|
|
|
async fn create_item(&mut self, item: NewItemEntity) -> Result<ItemEntity, GatewayError> {
|
|
@ -347,4 +360,10 @@ impl EntityGateway for InMemoryGateway { |
|
|
Err(GatewayError::Error)
|
|
|
Err(GatewayError::Error)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn set_guild_card(&mut self, id: UserAccountId, gc_data: GuildCardDataEntity) -> Result<(), GatewayError> {
|
|
|
|
|
|
let mut guildcard = self.guildcard_entities.lock().unwrap();
|
|
|
|
|
|
guildcard.insert(id, gc_data);
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|