Browse Source

initial room creation logic

pbs
jake 5 years ago
committed by Jake Probst
parent
commit
3fd89664d7
  1. 1
      src/ship/mod.rs
  2. 53
      src/ship/ship.rs

1
src/ship/mod.rs

@ -1,3 +1,4 @@
pub mod ship;
pub mod location;
pub mod character;
pub mod room;

53
src/ship/ship.rs

@ -21,6 +21,7 @@ use crate::entity::item::ItemLocation;
use crate::login::login::get_login_status;
use crate::ship::location::{ClientLocation, LobbyId, RoomId};
use crate::ship::character::{CharacterBuilder, FullCharacterBuilder};
use crate::ship::room;
pub const SHIP_PORT: u16 = 23423;
@ -39,6 +40,7 @@ pub enum RecvShipPacket {
Message(Message),
DirectMessage(DirectMessage),
PlayerChat(PlayerChat),
CreateRoom(CreateRoom),
}
impl RecvServerPacket for RecvShipPacket {
@ -50,6 +52,7 @@ impl RecvServerPacket for RecvShipPacket {
0x60 => Ok(RecvShipPacket::Message(Message::from_bytes(data)?)),
0x62 => Ok(RecvShipPacket::DirectMessage(DirectMessage::from_bytes(data)?)),
0x06 => Ok(RecvShipPacket::PlayerChat(PlayerChat::from_bytes(data)?)),
0xC1 => Ok(RecvShipPacket::CreateRoom(CreateRoom::from_bytes(data)?)),
_ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec()))
}
}
@ -67,6 +70,9 @@ pub enum SendShipPacket {
Message(Message),
DirectMessage(DirectMessage),
PlayerChat(PlayerChat),
SmallDialog(SmallDialog),
JoinRoom(JoinRoom),
AddToRoom(AddToRoom),
}
impl SendServerPacket for SendShipPacket {
@ -82,6 +88,9 @@ impl SendServerPacket for SendShipPacket {
SendShipPacket::Message(pkt) => pkt.as_bytes(),
SendShipPacket::DirectMessage(pkt) => pkt.as_bytes(),
SendShipPacket::PlayerChat(pkt) => pkt.as_bytes(),
SendShipPacket::SmallDialog(pkt) => pkt.as_bytes(),
SendShipPacket::JoinRoom(pkt) => pkt.as_bytes(),
SendShipPacket::AddToRoom(pkt) => pkt.as_bytes(),
}
}
}
@ -325,6 +334,47 @@ impl<EG: EntityGateway> ShipServerState<EG> {
(client.client_id, SendShipPacket::PlayerChat(cmsg.clone()))
}).collect::<Vec<_>>().into_iter()))
}
fn create_room(&mut self, id: ClientId, create_room: &CreateRoom) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)>> {
let room_id = match self.client_location.new_room(id) {
Ok(room_id) => room_id,
Err(e) => return Box::new(vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("could not create room".to_owned())))].into_iter())
};
let room = room::RoomState::from_create_room(create_room).unwrap();
let client = self.clients.get_mut(&id).unwrap();//.ok_or(ShipError::ClientNotFound(id)).unwrap();
let players = [PlayerHeader {
tag: 0x00010000,
guildcard: client.user.id,
_unknown1: [0; 5],
client_id: 0,
name: client.character.character.name,
_unknown2: 2,
}, PlayerHeader::default(), PlayerHeader::default(), PlayerHeader::default()];
let join_room = JoinRoom {
flag: 1,
maps: room.maps,
players: players,
client_id: 0,
leader_id: 0,
one: 1,
difficulty: create_room.difficulty,
battle: create_room.battle,
event: 0,
section: 0, // TODO
challenge: create_room.challenge,
random_seed: 23, // TODO
episode: create_room.episode,
one2: 1,
single_player: create_room.single_player,
unknown: 0,
};
Box::new(vec![(id, SendShipPacket::JoinRoom(join_room))].into_iter())
//self.rooms.insert(room_id, room);
}
}
@ -372,6 +422,9 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
RecvShipPacket::PlayerChat(msg) => {
Box::new(self.player_chat(id, msg)?.into_iter())
},
RecvShipPacket::CreateRoom(create_room) => {
self.create_room(id, create_room)
}
})
}
}
Loading…
Cancel
Save