|
@ -19,10 +19,10 @@ pub struct Client<P, E> { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl<P: ServerPacket + std::fmt::Debug, E: std::fmt::Debug> Client<P, E> {
|
|
|
impl<P: ServerPacket + std::fmt::Debug, E: std::fmt::Debug> Client<P, E> {
|
|
|
pub fn new(socket: net::TcpStream, state: Box<dyn ServerState<Packet = P, PacketError = E>>) -> Client<P, E> {
|
|
|
|
|
|
|
|
|
pub fn new(socket: mio::tcp::TcpStream, state: Box<dyn ServerState<Packet = P, PacketError = E>>) -> Client<P, E> {
|
|
|
let mut client = Client {
|
|
|
let mut client = Client {
|
|
|
running: true,
|
|
|
running: true,
|
|
|
socket: mio::tcp::TcpStream::from_stream(socket).expect("could not convert socket to nonblocking"),
|
|
|
|
|
|
|
|
|
socket: socket,
|
|
|
cipher_in: Box::new(NullCipher {}),
|
|
|
cipher_in: Box::new(NullCipher {}),
|
|
|
cipher_out: Box::new(NullCipher {}),
|
|
|
cipher_out: Box::new(NullCipher {}),
|
|
|
state: state,
|
|
|
state: state,
|
|
@ -62,7 +62,6 @@ impl<P: ServerPacket + std::fmt::Debug, E: std::fmt::Debug> Client<P, E> { |
|
|
// TODO: this may need to pad to 8 bytes for bb cipher
|
|
|
// TODO: this may need to pad to 8 bytes for bb cipher
|
|
|
fn send(&mut self, pkt: &dyn PSOPacket) {
|
|
|
fn send(&mut self, pkt: &dyn PSOPacket) {
|
|
|
let buf = pkt.as_bytes();
|
|
|
let buf = pkt.as_bytes();
|
|
|
println!("[send]: {:X?}", buf);
|
|
|
|
|
|
let mut cbuf = self.cipher_out.encrypt(&buf).unwrap();
|
|
|
let mut cbuf = self.cipher_out.encrypt(&buf).unwrap();
|
|
|
self.send_buffer.append(&mut cbuf);
|
|
|
self.send_buffer.append(&mut cbuf);
|
|
|
self.send_data();
|
|
|
self.send_data();
|
|
@ -97,7 +96,6 @@ impl<P: ServerPacket + std::fmt::Debug, E: std::fmt::Debug> Client<P, E> { |
|
|
}
|
|
|
}
|
|
|
},
|
|
|
},
|
|
|
Err(err) => {
|
|
|
Err(err) => {
|
|
|
println!("error recv-ing packet with {:?}: {:?}", self.socket, err);
|
|
|
|
|
|
match err {
|
|
|
match err {
|
|
|
PacketNetworkError::ClientDisconnected => self.running = false,
|
|
|
PacketNetworkError::ClientDisconnected => self.running = false,
|
|
|
_ => println!("error recv-ing packet with {:?}: {:?}", self.socket, err),
|
|
|
_ => println!("error recv-ing packet with {:?}: {:?}", self.socket, err),
|
|
|