Exemplo n.º 1
0
        private void OnReceivedSchematic(SchematicJsonPacket message)
        {
            bool allow = capi.Settings.Bool["allowSaveFilesFromServer"];

            if (!allow)
            {
                capi.ShowChatMessage("Server tried to send a schematic file, but it was rejected for safety reasons. To accept, set allowSaveFilesFromServer to true in clientsettings.json, or type '.clientconfigcreate allowSavefilesFromServer bool true' but be aware of potential security implications!");
                return;
            }

            try
            {
                string exportFolderPath = capi.GetOrCreateDataPath("WorldEdit");
                string outfilepath      = Path.Combine(exportFolderPath, Path.GetFileName(message.Filename));

                if (!outfilepath.EndsWith(".json"))
                {
                    outfilepath += ".json";
                }

                using (TextWriter textWriter = new StreamWriter(outfilepath))
                {
                    textWriter.Write(message.JsonCode);
                    textWriter.Close();
                }

                capi.ShowChatMessage(string.Format("Schematic file {0} received and saved", message.Filename));
            }
            catch (IOException e)
            {
                capi.ShowChatMessage("Server sent a schematic file, but failed to save it: " + e.Message);
            }
        }