sendgc
#103
Closed
andy
wants to merge 5 commits from sendgc
into master
pull from: sendgc
merge into: jake:master
jake:andy/add-patch-log-dir
jake:andy/clamp-mag-feed
jake:andy/directories
jake:andy/map-objects
jake:andy/update-rust
jake:expsteal
jake:fuckin_andy_making_me_do_this_now
jake:kill_counters
jake:map_objects
jake:master
jake:morfin/test
jake:move_stuff_to_libpso
jake:pbs
jake:presents
jake:set_char_exp
jake:teams
jake:techs
jake:traps
jake:unitxt
10 changed files with 121 additions and 18 deletions
-
2Cargo.lock
-
2Cargo.toml
-
27src/entity/account.rs
-
4src/entity/gateway/entitygateway.rs
-
23src/entity/gateway/inmemory.rs
-
3src/entity/gateway/postgres/postgres.rs
-
4src/login/character.rs
-
14src/ship/packet/handler/communication.rs
-
5src/ship/ship.rs
-
55tests/test_communication.rs
@ -1,6 +1,7 @@ |
|||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||
use libpso::character::settings;
|
use libpso::character::settings;
|
||||
use libpso::character::guildcard;
|
use libpso::character::guildcard;
|
||||
|
use libpso::packet::ship::{GuildcardAccept};
|
||||
|
|
||||
pub const USERFLAG_NEWCHAR: u32 = 0x00000001;
|
pub const USERFLAG_NEWCHAR: u32 = 0x00000001;
|
||||
pub const USERFLAG_DRESSINGROOM: u32 = 0x00000002;
|
pub const USERFLAG_DRESSINGROOM: u32 = 0x00000002;
|
||||
@ -9,9 +10,13 @@ pub const USERFLAG_DRESSINGROOM: u32 = 0x00000002; |
|||||
pub struct UserAccountId(pub u32);
|
pub struct UserAccountId(pub u32);
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct UserSettingsId(pub u32);
|
pub struct UserSettingsId(pub u32);
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
|
||||
pub struct GuildCardDataId(pub u32);
|
|
||||
|
|
||||
|
#[derive(Debug)]
|
||||
jake
commented 3 years ago
Review
TODO: remove TODO TODO: remove TODO
|
|||||
|
pub enum GuildcardError {
|
||||
|
GuildcardAlreadyFriend(UserAccountId),
|
||||
|
GuildcardAlreadyBlocked(UserAccountId),
|
||||
|
GuildcardListFull,
|
||||
|
}
|
||||
|
|
||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||
pub struct NewUserAccountEntity {
|
pub struct NewUserAccountEntity {
|
||||
@ -124,20 +129,26 @@ impl NewGuildCardDataEntity { |
|||||
}
|
}
|
||||
}
|
}
|
||||
|
|
||||
// TODO: implement this properly
|
|
||||
#[derive(Clone)]
|
|
||||
|
#[derive(Clone, Debug)]
|
||||
pub struct GuildCardDataEntity {
|
pub struct GuildCardDataEntity {
|
||||
pub id: GuildCardDataId,
|
|
||||
pub user_id: UserAccountId,
|
pub user_id: UserAccountId,
|
||||
pub guildcard: guildcard::GuildCardData,
|
|
||||
|
pub guildcard_data: Box<guildcard::GuildCardData>,
|
||||
}
|
}
|
||||
|
|
||||
impl GuildCardDataEntity {
|
impl GuildCardDataEntity {
|
||||
pub fn new(user_id: UserAccountId) -> GuildCardDataEntity {
|
pub fn new(user_id: UserAccountId) -> GuildCardDataEntity {
|
||||
GuildCardDataEntity {
|
GuildCardDataEntity {
|
||||
id: GuildCardDataId(0),
|
|
||||
user_id,
|
user_id,
|
||||
guildcard: guildcard::GuildCardData::default(),
|
|
||||
|
guildcard_data: Box::new(guildcard::GuildCardData::default()),
|
||||
}
|
}
|
||||
}
|
}
|
||||
|
|
||||
|
pub fn add_friend(&mut self, new_friend: &GuildcardAccept) -> Result<(), GuildcardError> {
|
||||
|
let next_open_spot = self.guildcard_data.friends
|
||||
|
.iter()
|
||||
|
.position(|&g| g.id == 0)
|
||||
|
.ok_or(GuildcardError::GuildcardListFull)?;
|
||||
|
self.guildcard_data.friends[next_open_spot] = guildcard::GuildCard::from(new_friend);
|
||||
|
Ok(()) // TODO: implement a real error
|
||||
|
}
|
||||
}
|
}
|
@ -0,0 +1,55 @@ |
|||||
|
use elseware::common::serverstate::{ClientId, ServerState};
|
||||
|
use elseware::entity::gateway::{EntityGateway, InMemoryGateway};
|
||||
|
use elseware::ship::ship::{ShipServerState, RecvShipPacket};
|
||||
|
use libpso::packet::ship::*;
|
||||
|
|
||||
|
#[path = "common.rs"]
|
||||
|
mod common;
|
||||
|
use common::*;
|
||||
|
|
||||
|
#[async_std::test]
|
||||
|
async fn test_guildcard_add_friend() {
|
||||
|
let mut entity_gateway = InMemoryGateway::default();
|
||||
|
let (user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
||||
|
|
||||
|
let mut ship = Box::new(ShipServerState::builder()
|
||||
|
.gateway(entity_gateway.clone())
|
||||
|
.build());
|
||||
|
|
||||
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
||||
|
join_lobby(&mut ship, ClientId(1)).await;
|
||||
|
|
||||
|
// Accept friend request from "Test Char 2"
|
||||
|
ship.handle(ClientId(1), &RecvShipPacket::GuildcardAccept(GuildcardAccept {
|
||||
|
id: 2,
|
||||
|
name: [84, 101, 115, 116, 32, 67, 104, 97, 114, 32, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
|
team: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
|
desc: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
|
one: 1,
|
||||
|
language: 0,
|
||||
|
section_id: 0,
|
||||
|
class: 0,
|
||||
|
})).await.unwrap().for_each(drop);
|
||||
|
|
||||
|
let friendlist = entity_gateway.get_guild_card_data_by_user(&user1).await.unwrap();
|
||||
|
|
||||
|
assert!(friendlist.guildcard_data.friends[0].name == [84, 101, 115, 116, 32, 67, 104, 97, 114, 32, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
||||
|
}
|
||||
|
|
||||
|
|
||||
|
/*
|
||||
|
TODO: actually write these tests at some point. also add a test for transmute/repr(C)?
|
||||
|
|
||||
|
#[async_std::test]
|
||||
|
async fn test_guildcard_block_rival() {}
|
||||
|
|
||||
|
#[async_std::test]
|
||||
|
async fn test_guildcard_write_comment() {}
|
||||
|
|
||||
|
#[async_std::test]
|
||||
|
async fn test_player_chat() {}
|
||||
|
|
||||
|
#[async_std::test]
|
||||
|
async fn test_update_infoboard() {}
|
||||
|
|
||||
|
*/
|
Reference in new issue
merge this in libpso