rust/hedgewars-server/src/server/io.rs
changeset 14802 01f8ab45f806
parent 14801 65861ba8b4e8
child 14806 a1077e8d26f4
equal deleted inserted replaced
14801:65861ba8b4e8 14802:01f8ab45f806
     7 
     7 
     8 use crate::server::{
     8 use crate::server::{
     9     database::Database,
     9     database::Database,
    10     handlers::{IoResult, IoTask},
    10     handlers::{IoResult, IoTask},
    11 };
    11 };
       
    12 use log::*;
    12 use mio::{Evented, Poll, PollOpt};
    13 use mio::{Evented, Poll, PollOpt};
    13 use mio_extras::channel;
    14 use mio_extras::channel;
    14 use log::*;
       
    15 
    15 
    16 pub type RequestId = u32;
    16 pub type RequestId = u32;
    17 
    17 
    18 pub struct IOThread {
    18 pub struct IOThread {
    19     core_tx: mpsc::Sender<(RequestId, IoTask)>,
    19     core_tx: mpsc::Sender<(RequestId, IoTask)>,
    43                             protocol,
    43                             protocol,
    44                             &password_hash,
    44                             &password_hash,
    45                             &client_salt,
    45                             &client_salt,
    46                             &server_salt,
    46                             &server_salt,
    47                         ) {
    47                         ) {
    48                             Ok(account) => {
    48                             Ok(account) => IoResult::Account(account),
    49                                 IoResult::Account(account)
       
    50                             }
       
    51                             Err(..) => {
    49                             Err(..) => {
    52                                 warn!("Unable to get account data: {}", 0);
    50                                 warn!("Unable to get account data: {}", 0);
    53                                 IoResult::Account(None)
    51                                 IoResult::Account(None)
    54                             }
    52                             }
    55                         }
    53                         }
    56                     },
    54                     }
    57 
    55 
    58                     IoTask::SaveRoom { room_id, filename, contents} => {
    56                     IoTask::SaveRoom {
       
    57                         room_id,
       
    58                         filename,
       
    59                         contents,
       
    60                     } => {
    59                         let result = match save_file(&filename, &contents) {
    61                         let result = match save_file(&filename, &contents) {
    60                             Ok(()) => true,
    62                             Ok(()) => true,
    61                             Err(e) => {
    63                             Err(e) => {
    62                                 warn!(
    64                                 warn!(
    63                                     "Error while writing the room config file \"{}\": {}",
    65                                     "Error while writing the room config file \"{}\": {}",
    64                                     filename, e
    66                                     filename, e
    65                                 );
    67                                 );
    66                                 false
    68                                 false
    67                            }
    69                             }
    68                         };
    70                         };
    69                         IoResult::SaveRoom(room_id, result)
    71                         IoResult::SaveRoom(room_id, result)
    70                     },
    72                     }
    71 
    73 
    72                     IoTask::LoadRoom {room_id, filename} => {
    74                     IoTask::LoadRoom { room_id, filename } => {
    73                         let result = match load_file(&filename) {
    75                         let result = match load_file(&filename) {
    74                             Ok(contents) => Some(contents),
    76                             Ok(contents) => Some(contents),
    75                             Err(e) => {
    77                             Err(e) => {
    76                                 warn!(
    78                                 warn!(
    77                                     "Error while writing the room config file \"{}\": {}",
    79                                     "Error while writing the room config file \"{}\": {}",