|
@ -4,16 +4,17 @@ use std::net; |
|
|
use std::thread;
|
|
|
use std::thread;
|
|
|
use std::fs;
|
|
|
use std::fs;
|
|
|
use std::io;
|
|
|
use std::io;
|
|
|
use std::io::{Read, Write};
|
|
|
|
|
|
|
|
|
use std::io::{Read};
|
|
|
use std::path::{Path, PathBuf, Components};
|
|
|
use std::path::{Path, PathBuf, Components};
|
|
|
use std::convert::AsRef;
|
|
|
use std::convert::AsRef;
|
|
|
use mio::{Events, Poll, Token, Ready, PollOpt};
|
|
|
|
|
|
use rand::{Rng, RngCore};
|
|
|
use rand::{Rng, RngCore};
|
|
|
use crc::{crc32, Hasher32};
|
|
|
use crc::{crc32, Hasher32};
|
|
|
use libpso::{PacketParseError, PSOPacket};
|
|
|
use libpso::{PacketParseError, PSOPacket};
|
|
|
use libpso::packet::patch::*;
|
|
|
use libpso::packet::patch::*;
|
|
|
use libpso::crypto::pc::PSOPCCipher;
|
|
|
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::client::Client;
|
|
|
use elseware::common::serverstate::{ServerPacket, ServerState, OnConnect};
|
|
|
use elseware::common::serverstate::{ServerPacket, ServerState, OnConnect};
|
|
|
|
|
|
|
|
@ -143,14 +144,13 @@ impl ServerState for PatchServerState { |
|
|
fn handle(&mut self, pkt: &PatchPacket) -> Box<dyn Iterator<Item = Box<dyn PSOPacket>>> {
|
|
|
fn handle(&mut self, pkt: &PatchPacket) -> Box<dyn Iterator<Item = Box<dyn PSOPacket>>> {
|
|
|
match pkt {
|
|
|
match pkt {
|
|
|
PatchPacket::PatchWelcomeReply(_pkt) => {
|
|
|
PatchPacket::PatchWelcomeReply(_pkt) => {
|
|
|
let p: Vec<Box<dyn PSOPacket>> = vec![Box::new(RequestLogin {})];
|
|
|
|
|
|
Box::new(p.into_iter())
|
|
|
|
|
|
|
|
|
pktvec![RequestLogin {}]
|
|
|
},
|
|
|
},
|
|
|
PatchPacket::LoginReply(_pkt) => {
|
|
|
PatchPacket::LoginReply(_pkt) => {
|
|
|
let mut p: Vec<Box<dyn PSOPacket>> = 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 {}));
|
|
|
p.push(Box::new(PatchEndList {}));
|
|
|
Box::new(p.into_iter())
|
|
|
|
|
|
|
|
|
p
|
|
|
},
|
|
|
},
|
|
|
PatchPacket::FileInfoReply(pkt) => {
|
|
|
PatchPacket::FileInfoReply(pkt) => {
|
|
|
self.patch_file_info.push(pkt.clone());
|
|
|
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_size = need_update.iter().fold(0, |a, file_info| a + file_info.size);
|
|
|
let total_files = need_update.len() as u32;
|
|
|
let total_files = need_update.len() as u32;
|
|
|
|
|
|
|
|
|
let p: Vec<Box<dyn PSOPacket>> = 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 {
|
|
|
impl SendFileIterator {
|
|
|
fn new(state: &PatchServerState) -> 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))
|
|
|
.filter(|file_info| does_file_need_updating(file_info, &state.patch_file_lookup))
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
let file_ids_to_update = need_update.iter().map(|k| k.id).collect::<HashSet<_>>();
|
|
|
|
|
|
|
|
|
.map(|k| k.id)
|
|
|
|
|
|
.collect::<HashSet<_>>();
|
|
|
|
|
|
|
|
|
SendFileIterator {
|
|
|
SendFileIterator {
|
|
|
done: false,
|
|
|
done: false,
|
|
|