diff -r bbec6b28d072 -r f43ab2bd76ae rust/hedgewars-server/src/server/core.rs --- a/rust/hedgewars-server/src/server/core.rs Tue Apr 09 00:45:14 2019 +0200 +++ b/rust/hedgewars-server/src/server/core.rs Tue Apr 09 21:08:35 2019 +0300 @@ -2,13 +2,14 @@ client::HWClient, coretypes::{ClientId, RoomId}, indexslab::IndexSlab, - io::HWServerIO, room::HWRoom, }; use crate::utils; use log::*; use slab; +use std::fs::{File, OpenOptions}; +use std::io::{Read, Write}; use std::{borrow::BorrowMut, iter, num::NonZeroU16}; type Slab = slab::Slab; @@ -16,7 +17,6 @@ pub struct HWAnteClient { pub nick: Option, pub protocol_number: Option, - pub web_password: Option, pub server_salt: String, } @@ -35,20 +35,12 @@ nick: None, protocol_number: None, server_salt: salt, - web_password: None, }; self.clients.insert(client_id, client); } pub fn remove_client(&mut self, client_id: ClientId) -> Option { let mut client = self.clients.remove(client_id); - if let Some(HWAnteClient { - web_password: Some(ref mut password), - .. - }) = client - { - password.replace_range(.., "🦔🦔🦔🦔🦔🦔🦔🦔"); - } client } } @@ -213,3 +205,48 @@ } } } + +pub trait HWServerIO { + fn write_file(&mut self, name: &str, content: &str) -> std::io::Result<()>; + fn read_file(&mut self, name: &str) -> std::io::Result; +} + +pub struct EmptyServerIO {} + +impl EmptyServerIO { + pub fn new() -> Self { + Self {} + } +} + +impl HWServerIO for EmptyServerIO { + fn write_file(&mut self, _name: &str, _content: &str) -> std::io::Result<()> { + Ok(()) + } + + fn read_file(&mut self, _name: &str) -> std::io::Result { + Ok("".to_string()) + } +} + +pub struct FileServerIO {} + +impl FileServerIO { + pub fn new() -> Self { + Self {} + } +} + +impl HWServerIO for FileServerIO { + fn write_file(&mut self, name: &str, content: &str) -> std::io::Result<()> { + let mut writer = OpenOptions::new().create(true).write(true).open(name)?; + writer.write_all(content.as_bytes()) + } + + fn read_file(&mut self, name: &str) -> std::io::Result { + let mut reader = File::open(name)?; + let mut result = String::new(); + reader.read_to_string(&mut result)?; + Ok(result) + } +}