You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
180 lines
6.1 KiB
180 lines
6.1 KiB
#![allow(dead_code)]
|
|
|
|
use networking::serverstate::{ClientId, ServerState};
|
|
use entity::gateway::EntityGateway;
|
|
use entity::account::{UserAccountEntity, NewUserAccountEntity, NewUserSettingsEntity};
|
|
use entity::character::{CharacterEntity, NewCharacterEntity, SectionID};
|
|
use entity::item::{Meseta, BankIdentifier};
|
|
use elseware::ship::ship::{ShipServerState, ShipServerStateBuilder, RecvShipPacket};
|
|
use maps::room::{RoomMode, Difficulty, Episode};
|
|
use maps::area::MapArea;
|
|
use maps::maps::null_free_roam_maps;
|
|
use maps::object::MapObject;
|
|
use maps::monster::MonsterType;
|
|
use quests::{QuestList, QuestLoadError};
|
|
use drops::{DropTable, ItemDropType};
|
|
|
|
use entity::item;
|
|
|
|
use libpso::packet::ship::*;
|
|
use libpso::packet::login::{Login, Session};
|
|
use libpso::{utf8_to_array, utf8_to_utf16_array};
|
|
|
|
fn null_quest_builder(_mode: RoomMode) -> Result<QuestList, QuestLoadError> {
|
|
Ok(Default::default())
|
|
}
|
|
|
|
struct NullDropTable;
|
|
|
|
impl DropTable for NullDropTable {
|
|
fn get_drop(&mut self, _map_area: &MapArea, _monster: &MonsterType) -> Option<ItemDropType> {
|
|
None
|
|
}
|
|
fn get_box_drop(&mut self, _map_area: &MapArea, _object: &MapObject) -> Option<ItemDropType> {
|
|
None
|
|
}
|
|
}
|
|
|
|
pub fn null_drop_table_builder(_episode: Episode, _difficult: Difficulty, _section_id: SectionID) -> Box<dyn DropTable + Send + Sync> {
|
|
Box::new(NullDropTable)
|
|
}
|
|
|
|
pub fn standard_ship_buildable<EG: EntityGateway + Clone>(gateway: EG) -> ShipServerStateBuilder<EG> {
|
|
ShipServerState::builder()
|
|
.gateway(gateway)
|
|
.standard_quest_builder(Box::new(null_quest_builder))
|
|
.government_quest_builder(Box::new(null_quest_builder))
|
|
.drop_table_builder(Box::new(null_drop_table_builder))
|
|
.map_builder(Box::new(null_free_roam_maps))
|
|
}
|
|
|
|
pub fn standard_ship<EG: EntityGateway + Clone>(gateway: EG) -> ShipServerState<EG> {
|
|
ShipServerState::builder()
|
|
.gateway(gateway)
|
|
.standard_quest_builder(Box::new(null_quest_builder))
|
|
.government_quest_builder(Box::new(null_quest_builder))
|
|
.drop_table_builder(Box::new(null_drop_table_builder))
|
|
.map_builder(Box::new(null_free_roam_maps))
|
|
.build()
|
|
}
|
|
|
|
//TODO: remove kb_conf_preset
|
|
pub async fn new_user_character<EG: EntityGateway + Clone>(entity_gateway: &mut EG, username: &str, password: &str, kb_conf_preset: usize) -> (UserAccountEntity, CharacterEntity) {
|
|
let new_user = NewUserAccountEntity {
|
|
email: format!("{}@pso.com", username),
|
|
username: username.into(),
|
|
password: bcrypt::hash(password, 5).unwrap(),
|
|
guildcard: 1,
|
|
activated: true,
|
|
..NewUserAccountEntity::default()
|
|
};
|
|
|
|
let user = entity_gateway.create_user(new_user).await.unwrap();
|
|
let new_settings = NewUserSettingsEntity::new(user.id);
|
|
let _settings = entity_gateway.create_user_settings(new_settings).await.unwrap();
|
|
let new_character = NewCharacterEntity::new(user.id);
|
|
let character = entity_gateway.create_character(new_character).await.unwrap();
|
|
entity_gateway.set_character_meseta(&character.id, Meseta(0)).await.unwrap();
|
|
entity_gateway.set_bank_meseta(&character.id, &BankIdentifier::Character, Meseta(0)).await.unwrap();
|
|
|
|
(user, character)
|
|
}
|
|
|
|
pub async fn log_in_char<EG: EntityGateway + Clone>(ship: &mut ShipServerState<EG>, id: ClientId, username: &str, password: &str) {
|
|
let username = username.to_string();
|
|
let password = password.to_string();
|
|
ship.handle(id, RecvShipPacket::Login(Login {
|
|
tag: 0,
|
|
guildcard: 0,
|
|
version: 0,
|
|
unknown1: [0; 6],
|
|
team: 0,
|
|
username: utf8_to_array!(username, 16),
|
|
unknown2: [0; 32],
|
|
password: utf8_to_array!(password, 16),
|
|
unknown3: [0; 40],
|
|
hwinfo: [0; 8],
|
|
session: Session::new(),
|
|
})).await.unwrap();
|
|
}
|
|
|
|
pub async fn join_lobby<EG: EntityGateway + Clone>(ship: &mut ShipServerState<EG>, id: ClientId) {
|
|
ship.handle(id, RecvShipPacket::CharData(CharData {
|
|
_unknown: [0; 0x828]
|
|
})).await.unwrap();
|
|
}
|
|
|
|
pub async fn create_room<EG: EntityGateway + Clone>(ship: &mut ShipServerState<EG>, id: ClientId, name: &str, password: &str) {
|
|
create_room_with_difficulty(ship, id, name, password, Difficulty::Normal).await;
|
|
}
|
|
|
|
pub async fn leave_room<EG: EntityGateway + Clone>(ship: &mut ShipServerState<EG>, id: ClientId) {
|
|
ship.handle(id, RecvShipPacket::LobbySelect(LobbySelect {
|
|
menu: 3,
|
|
lobby: 0,
|
|
})).await.unwrap();
|
|
}
|
|
|
|
pub async fn create_room_with_difficulty<EG: EntityGateway + Clone>(ship: &mut ShipServerState<EG>, id: ClientId, name: &str, password: &str, difficulty: Difficulty) {
|
|
ship.handle(id, RecvShipPacket::CreateRoom(CreateRoom {
|
|
unknown: [0; 2],
|
|
name: utf8_to_utf16_array!(name, 16),
|
|
password: utf8_to_utf16_array!(password, 16),
|
|
difficulty: difficulty.into(),
|
|
battle: 0,
|
|
challenge: 0,
|
|
episode: 1,
|
|
single_player: 0,
|
|
padding: [0; 3],
|
|
})).await.unwrap();
|
|
ship.handle(id, RecvShipPacket::DoneBursting(DoneBursting {})).await.unwrap();
|
|
}
|
|
|
|
pub async fn join_room<EG: EntityGateway + Clone>(ship: &mut ShipServerState<EG>, id: ClientId, room_id: u32) {
|
|
ship.handle(id, RecvShipPacket::MenuSelect(MenuSelect {
|
|
menu: ROOM_MENU_ID,
|
|
item: room_id,
|
|
})).await.unwrap();
|
|
ship.handle(id, RecvShipPacket::DoneBursting(DoneBursting {})).await.unwrap();
|
|
}
|
|
|
|
|
|
|
|
pub struct WeaponBuilder {
|
|
weapon: item::weapon::WeaponType,
|
|
grind: u8,
|
|
}
|
|
|
|
impl WeaponBuilder {
|
|
pub fn grind(self, grind: u8) -> WeaponBuilder {
|
|
WeaponBuilder {
|
|
grind,
|
|
..self
|
|
}
|
|
}
|
|
|
|
pub fn as_new(self) -> item::NewItemEntity {
|
|
item::NewItemEntity {
|
|
item: item::ItemDetail::Weapon(
|
|
item::weapon::Weapon {
|
|
weapon: self.weapon,
|
|
grind: self.grind,
|
|
special: None,
|
|
attrs: [None, None, None],
|
|
tekked: true,
|
|
}
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct ItemBuilder;
|
|
|
|
impl ItemBuilder {
|
|
pub fn weapon(weapon: item::weapon::WeaponType) -> WeaponBuilder {
|
|
WeaponBuilder {
|
|
weapon,
|
|
grind: 0,
|
|
}
|
|
}
|
|
}
|