From 758b2e5ebc3032add9629920906b2ba8800165e3 Mon Sep 17 00:00:00 2001 From: Jake Probst Date: Tue, 20 Aug 2019 17:55:19 -0700 Subject: [PATCH] use pktvec in patch --- src/patch/main.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/patch/main.rs b/src/patch/main.rs index 91de59f..81a1e68 100644 --- a/src/patch/main.rs +++ b/src/patch/main.rs @@ -4,16 +4,17 @@ use std::net; use std::thread; use std::fs; use std::io; -use std::io::{Read, Write}; +use std::io::{Read}; use std::path::{Path, PathBuf, Components}; use std::convert::AsRef; -use mio::{Events, Poll, Token, Ready, PollOpt}; use rand::{Rng, RngCore}; use crc::{crc32, Hasher32}; use libpso::{PacketParseError, PSOPacket}; use libpso::packet::patch::*; use libpso::crypto::pc::PSOPCCipher; -use elseware::common::network::{send_packet, recv_packet, PacketNetworkError}; +use elseware::pktvec; +use elseware::common::pktvec::PktVec; +use elseware::common::network::{PacketNetworkError}; use elseware::common::client::Client; use elseware::common::serverstate::{ServerPacket, ServerState, OnConnect}; @@ -143,14 +144,13 @@ impl ServerState for PatchServerState { fn handle(&mut self, pkt: &PatchPacket) -> Box>> { match pkt { PatchPacket::PatchWelcomeReply(_pkt) => { - let p: Vec> = vec![Box::new(RequestLogin {})]; - Box::new(p.into_iter()) + pktvec![RequestLogin {}] }, PatchPacket::LoginReply(_pkt) => { - let mut p: Vec> = vec![Box::new(Message::new("hello player".to_string()))]; - p.append(&mut get_file_list_packets(&self.patch_file_tree)); + let mut p = pktvec![Message::new("hello player".to_string())]; + p.append(get_file_list_packets(&self.patch_file_tree)); p.push(Box::new(PatchEndList {})); - Box::new(p.into_iter()) + p }, PatchPacket::FileInfoReply(pkt) => { self.patch_file_info.push(pkt.clone()); @@ -164,10 +164,10 @@ impl ServerState for PatchServerState { let total_size = need_update.iter().fold(0, |a, file_info| a + file_info.size); let total_files = need_update.len() as u32; - let p: Vec> = vec![Box::new(FilesToPatchMetadata::new(total_size, total_files)), - Box::new(PatchStartList {}), + let p = pktvec![FilesToPatchMetadata::new(total_size, total_files), + PatchStartList {} ]; - Box::new(p.into_iter().chain(SendFileIterator::new(&self))) + Box::new(p.chain(SendFileIterator::new(&self))) } } } @@ -263,10 +263,10 @@ struct SendFileIterator { impl SendFileIterator { fn new(state: &PatchServerState) -> SendFileIterator { - let need_update = state.patch_file_info.iter() + let file_ids_to_update = state.patch_file_info.iter() .filter(|file_info| does_file_need_updating(file_info, &state.patch_file_lookup)) - .collect::>(); - let file_ids_to_update = need_update.iter().map(|k| k.id).collect::>(); + .map(|k| k.id) + .collect::>(); SendFileIterator { done: false,