Browse Source

echo Message packets to other clients in the room

pbs
jake 5 years ago
parent
commit
11b51e97a2
  1. 5
      src/ship/location.rs
  2. 17
      src/ship/ship.rs

5
src/ship/location.rs

@ -1,6 +1,7 @@
use crate::common::serverstate::ClientId;
// TODO: room passwords?
// TODO: remove clients from areas (or upon insert, remove that id from anywhere else)
#[derive(Copy, Clone)]
pub struct ClientArea<const N: usize> {
@ -52,12 +53,12 @@ pub struct ClientLocation {
}
enum JoinRoomError {
pub enum JoinRoomError {
RoomDoesNotExist,
RoomFull,
}
enum JoinLobbyError {
pub enum JoinLobbyError {
LobbyDoesNotExist,
LobbyFull,
}

17
src/ship/ship.rs

@ -4,6 +4,7 @@ use rand::Rng;
use libpso::packet::ship::*;
use libpso::packet::login::{Login, LoginResponse, AccountStatus, Session};
use libpso::packet::messages::*;
use libpso::{PacketParseError, PSOPacket};
use libpso::crypto::bb::PSOBBCipher;
use libpso::character::character;
@ -32,6 +33,7 @@ pub enum RecvShipPacket {
Login(Login),
MenuSelect(MenuSelect),
CharData(CharData),
Message(Message),
}
impl RecvServerPacket for RecvShipPacket {
@ -40,6 +42,7 @@ impl RecvServerPacket for RecvShipPacket {
0x93 => Ok(RecvShipPacket::Login(Login::from_bytes(data)?)),
0x10 => Ok(RecvShipPacket::MenuSelect(MenuSelect::from_bytes(data)?)),
0x61 => Ok(RecvShipPacket::CharData(CharData::from_bytes(data)?)),
0x60 => Ok(RecvShipPacket::Message(Message::from_bytes(data)?)),
_ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec()))
}
}
@ -53,6 +56,7 @@ pub enum SendShipPacket {
FullCharacter(FullCharacter),
CharDataRequest(CharDataRequest),
JoinLobby(JoinLobby),
Message(Message),
}
impl SendServerPacket for SendShipPacket {
@ -64,6 +68,7 @@ impl SendServerPacket for SendShipPacket {
SendShipPacket::FullCharacter(pkt) => pkt.as_bytes(),
SendShipPacket::CharDataRequest(pkt) => pkt.as_bytes(),
SendShipPacket::JoinLobby(pkt) => pkt.as_bytes(),
SendShipPacket::Message(pkt) => pkt.as_bytes(),
}
}
}
@ -176,12 +181,19 @@ impl<EG: EntityGateway> ShipServerState<EG> {
}
]
};
self.client_location.add_to_lobby(id, 0);
Ok(vec![
SendShipPacket::JoinLobby(joinlobby)
])
}
fn message(&mut self, id: ClientId, msg: &Message) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)>> {
let cmsg = msg.clone();
Box::new(self.client_location.get_client_neighbors(id).into_iter().map(move |client| {
(client, SendShipPacket::Message(cmsg.clone()))
}))
}
}
@ -218,6 +230,9 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
},
RecvShipPacket::CharData(chardata) => {
Box::new(self.send_player_to_lobby(id, chardata)?.into_iter().map(move |pkt| (id, pkt)))
},
RecvShipPacket::Message(msg) => {
self.message(id, msg)
}
})
}

Loading…
Cancel
Save