gameServer2/src/server/handlers/inroom.rs
changeset 14413 e335b3120f59
parent 14395 e5db279308d7
--- a/gameServer2/src/server/handlers/inroom.rs	Sun Dec 09 00:53:05 2018 +0100
+++ b/gameServer2/src/server/handlers/inroom.rs	Sun Dec 09 04:09:38 2018 +0300
@@ -18,8 +18,7 @@
     utils::is_name_illegal
 };
 use std::{
-    mem::swap, fs::{File, OpenOptions},
-    io::{Read, Write, Result, Error, ErrorKind}
+    mem::swap
 };
 use base64::{encode, decode};
 use super::common::rnd_reply;
@@ -101,18 +100,6 @@
     }
 }
 
-fn read_file(filename: &str) -> Result<String> {
-    let mut reader = File::open(filename)?;
-    let mut result = String::new();
-    reader.read_to_string(&mut result)?;
-    Ok(result)
-}
-
-fn write_file(filename: &str, content: &str) -> Result<()> {
-    let mut writer = OpenOptions::new().create(true).write(true).open(filename)?;
-    writer.write_all(content.as_bytes())
-}
-
 pub fn handle(server: &mut HWServer, client_id: ClientId, room_id: RoomId, message: HWProtocolMessage) {
     use crate::protocol::messages::HWProtocolMessage::*;
     match message {
@@ -315,7 +302,7 @@
         SaveRoom(filename) => {
             if server.clients[client_id].is_admin() {
                 let actions = match server.rooms[room_id].get_saves() {
-                    Ok(text) => match write_file(&filename, &text) {
+                    Ok(text) => match server.io.write_file(&filename, &text) {
                         Ok(_) => vec![server_chat("Room configs saved successfully.".to_string())
                             .send_self().action()],
                         Err(e) => {
@@ -333,7 +320,7 @@
         }
         LoadRoom(filename) => {
             if server.clients[client_id].is_admin() {
-                let actions = match read_file(&filename) {
+                let actions = match server.io.read_file(&filename) {
                     Ok(text) => match server.rooms[room_id].set_saves(&text) {
                         Ok(_) => vec![server_chat("Room configs loaded successfully.".to_string())
                             .send_self().action()],