rust/hedgewars-server/src/server/handlers.rs
changeset 14780 65861ba8b4e8
parent 14779 f43ab2bd76ae
child 14781 01f8ab45f806
--- a/rust/hedgewars-server/src/server/handlers.rs	Tue Apr 09 21:08:35 2019 +0300
+++ b/rust/hedgewars-server/src/server/handlers.rs	Tue Apr 09 23:03:12 2019 +0300
@@ -4,11 +4,11 @@
 use super::{
     actions::{Destination, DestinationRoom},
     core::HWServer,
-    coretypes::ClientId,
+    coretypes::{ClientId, RoomId},
     room::RoomSave,
 };
 use crate::{
-    protocol::messages::{HWProtocolMessage, HWServerMessage, HWServerMessage::*},
+    protocol::messages::{HWProtocolMessage, HWServerMessage, HWServerMessage::*, server_chat},
     server::actions::PendingMessage,
     utils,
 };
@@ -58,10 +58,21 @@
         client_salt: String,
         server_salt: String,
     },
+    SaveRoom {
+        room_id: RoomId,
+        filename: String,
+        contents: String,
+    },
+    LoadRoom {
+        room_id: RoomId,
+        filename: String
+    }
 }
 
 pub enum IoResult {
     Account(Option<AccountInfo>),
+    SaveRoom(RoomId, bool),
+    LoadRoom(RoomId, Option<String>)
 }
 
 pub struct Response {
@@ -250,5 +261,35 @@
             response.add(Error("Authentication failed.".to_string()).send_self());
             response.remove_client(client_id);
         }
+        IoResult::SaveRoom(_, true) => {
+            response.add(server_chat("Room configs saved successfully.".to_string()).send_self());
+        }
+        IoResult::SaveRoom(_, false) => {
+            response.add(
+                Warning("Unable to save the room configs.".to_string()).send_self(),
+            );
+        }
+        IoResult::LoadRoom(room_id, Some(contents)) => {
+            if let Some(ref mut room) = server.rooms.get_mut(room_id) {
+                match room.set_saves(&contents) {
+                    Ok(_) => response.add(
+                        server_chat("Room configs loaded successfully.".to_string())
+                            .send_self(),
+                    ),
+                    Err(e) => {
+                        warn!("Error while deserializing the room configs: {}", e);
+                        response.add(
+                            Warning("Unable to deserialize the room configs.".to_string())
+                                .send_self(),
+                        );
+                    }
+                }
+            }
+        }
+        IoResult::LoadRoom(_,None) => {
+            response.add(
+                Warning("Unable to load the room configs.".to_string()).send_self(),
+            );
+        }
     }
 }