rust/hedgewars-server/src/server/handlers/inroom.rs
changeset 14780 65861ba8b4e8
parent 14697 f64e21f164a5
child 14781 01f8ab45f806
equal deleted inserted replaced
14779:f43ab2bd76ae 14780:65861ba8b4e8
   335             room.save_config(name, location);
   335             room.save_config(name, location);
   336         }
   336         }
   337         SaveRoom(filename) => {
   337         SaveRoom(filename) => {
   338             if client.is_admin() {
   338             if client.is_admin() {
   339                 match room.get_saves() {
   339                 match room.get_saves() {
   340                     Ok(text) => match server.io.write_file(&filename, &text) {
   340                     Ok(contents) =>
   341                         Ok(_) => response.add(
   341                         response.request_io(super::IoTask::SaveRoom {
   342                             server_chat("Room configs saved successfully.".to_string()).send_self(),
   342                             room_id, filename, contents
   343                         ),
   343                         }),
   344                         Err(e) => {
       
   345                             warn!(
       
   346                                 "Error while writing the config file \"{}\": {}",
       
   347                                 filename, e
       
   348                             );
       
   349                             response.add(
       
   350                                 Warning("Unable to save the room configs.".to_string()).send_self(),
       
   351                             );
       
   352                         }
       
   353                     },
       
   354                     Err(e) => {
   344                     Err(e) => {
   355                         warn!("Error while serializing the room configs: {}", e);
   345                         warn!("Error while serializing the room configs: {}", e);
   356                         response.add(
   346                         response.add(
   357                             Warning("Unable to serialize the room configs.".to_string())
   347                             Warning("Unable to serialize the room configs.".to_string())
   358                                 .send_self(),
   348                                 .send_self(),
   361                 }
   351                 }
   362             }
   352             }
   363         }
   353         }
   364         LoadRoom(filename) => {
   354         LoadRoom(filename) => {
   365             if client.is_admin() {
   355             if client.is_admin() {
   366                 match server.io.read_file(&filename) {
   356                 response.request_io(super::IoTask::LoadRoom {
   367                     Ok(text) => match room.set_saves(&text) {
   357                     room_id,
   368                         Ok(_) => response.add(
   358                     filename
   369                             server_chat("Room configs loaded successfully.".to_string())
   359                 });
   370                                 .send_self(),
       
   371                         ),
       
   372                         Err(e) => {
       
   373                             warn!("Error while deserializing the room configs: {}", e);
       
   374                             response.add(
       
   375                                 Warning("Unable to deserialize the room configs.".to_string())
       
   376                                     .send_self(),
       
   377                             );
       
   378                         }
       
   379                     },
       
   380                     Err(e) => {
       
   381                         warn!(
       
   382                             "Error while reading the config file \"{}\": {}",
       
   383                             filename, e
       
   384                         );
       
   385                         response.add(
       
   386                             Warning("Unable to load the room configs.".to_string()).send_self(),
       
   387                         );
       
   388                     }
       
   389                 }
       
   390             }
   360             }
   391         }
   361         }
   392         Delete(name) => {
   362         Delete(name) => {
   393             if !room.delete_config(&name) {
   363             if !room.delete_config(&name) {
   394                 response.add(Warning(format!("Save doesn't exist: {}", name)).send_self());
   364                 response.add(Warning(format!("Save doesn't exist: {}", name)).send_self());