コード例 #1
0
ファイル: Handshake.cs プロジェクト: Roger-luo/OpenRA
		public string Serialize()
		{
			var data = new List<MiniYamlNode>();
			data.Add(new MiniYamlNode("Handshake", null,
				new string[] { "Mod", "Version", "Password" }.Select(p => FieldSaver.SaveField(this, p)).ToList()));
			data.Add(new MiniYamlNode("Client", FieldSaver.Save(Client)));

			return data.WriteToString();
		}
コード例 #2
0
ファイル: GameInformation.cs プロジェクト: Berzeger/OpenRA
		public string Serialize()
		{
			var nodes = new List<MiniYamlNode>();

			nodes.Add(new MiniYamlNode("Root", FieldSaver.Save(this)));

			for (var i=0; i<Players.Count; i++)
				nodes.Add(new MiniYamlNode("Player@{0}".F(i), FieldSaver.Save(Players[i])));

			return nodes.WriteToString();
		}
コード例 #3
0
ファイル: Session.cs プロジェクト: pdovy/OpenRA
        public string Serialize()
        {
            var clientData = new List<MiniYamlNode>();

            foreach( var client in Clients )
                clientData.Add( new MiniYamlNode( "Client@{0}".F( client.Index ), FieldSaver.Save( client ) ) );

            foreach( var slot in Slots )
                clientData.Add( new MiniYamlNode( "Slot@{0}".F( slot.Index ), FieldSaver.Save( slot ) ) );

            clientData.Add( new MiniYamlNode( "GlobalSettings", FieldSaver.Save( GlobalSettings ) ) );

            return clientData.WriteToString();
        }
コード例 #4
0
ファイル: Server.cs プロジェクト: wytsep/OpenRA
        public void SyncClientPing()
        {
            // TODO: split this further into per client ping orders
            var clientPings = new List <MiniYamlNode>();

            foreach (var ping in LobbyInfo.ClientPings)
            {
                clientPings.Add(ping.Serialize());
            }

            DispatchOrders(null, 0,
                           new ServerOrder("SyncClientPings", clientPings.WriteToString()).Serialize());

            foreach (var t in serverTraits.WithInterface <INotifySyncLobbyInfo>())
            {
                t.LobbyInfoSynced(this);
            }
        }
コード例 #5
0
        public void SyncLobbyGlobalSettings()
        {
            if (State != ServerState.WaitingPlayers)
            {
                return;
            }

            var sessionData = new List <MiniYamlNode> {
                LobbyInfo.GlobalSettings.Serialize()
            };

            DispatchOrders(null, 0, new ServerOrder("SyncLobbyGlobalSettings", sessionData.WriteToString()).Serialize());

            foreach (var t in serverTraits.WithInterface <INotifySyncLobbyInfo>())
            {
                t.LobbyInfoSynced(this);
            }
        }
コード例 #6
0
ファイル: Session.cs プロジェクト: watsoncui/OpenRA
        public string Serialize()
        {
            var clientData = new List <MiniYamlNode>();

            foreach (var client in Clients)
            {
                clientData.Add(new MiniYamlNode("Client@{0}".F(client.Index), FieldSaver.Save(client)));
            }

            foreach (var slot in Slots)
            {
                clientData.Add(new MiniYamlNode("Slot@{0}".F(slot.Key), FieldSaver.Save(slot.Value)));
            }

            clientData.Add(new MiniYamlNode("GlobalSettings", FieldSaver.Save(GlobalSettings)));

            return(clientData.WriteToString());
        }
コード例 #7
0
ファイル: Session.cs プロジェクト: AttacqueSuperior/Engine
        public string Serialize()
        {
            var sessionData = new List <MiniYamlNode>()
            {
                new MiniYamlNode("DisabledSpawnPoints", FieldSaver.FormatValue(DisabledSpawnPoints))
            };

            foreach (var client in Clients)
            {
                sessionData.Add(client.Serialize());
            }

            foreach (var slot in Slots)
            {
                sessionData.Add(slot.Value.Serialize());
            }

            sessionData.Add(GlobalSettings.Serialize());

            return(sessionData.WriteToString());
        }
コード例 #8
0
ファイル: Server.cs プロジェクト: ushalin/OpenRA
        public void SyncLobbySlots()
        {
            if (State != ServerState.WaitingPlayers)
            {
                return;
            }

            // TODO: don't sync all the slots if just one changed
            var slotData = new List <MiniYamlNode>();

            foreach (var slot in LobbyInfo.Slots)
            {
                slotData.Add(slot.Value.Serialize());
            }

            DispatchOrders(null, 0,
                           new ServerOrder("SyncLobbySlots", slotData.WriteToString()).Serialize());

            foreach (var t in serverTraits.WithInterface <INotifySyncLobbyInfo>())
            {
                t.LobbyInfoSynced(this);
            }
        }
コード例 #9
0
ファイル: Session.cs プロジェクト: reaperrr/OpenRA
        public string Serialize()
        {
            var sessionData = new List <MiniYamlNode>();

            foreach (var client in Clients)
            {
                sessionData.Add(client.Serialize());
            }

            foreach (var clientPing in ClientPings)
            {
                sessionData.Add(clientPing.Serialize());
            }

            foreach (var slot in Slots)
            {
                sessionData.Add(slot.Value.Serialize());
            }

            sessionData.Add(GlobalSettings.Serialize());

            return(sessionData.WriteToString());
        }
コード例 #10
0
ファイル: Server.cs プロジェクト: ushalin/OpenRA
        public void SyncLobbyClients()
        {
            if (State != ServerState.WaitingPlayers)
            {
                return;
            }

            // TODO: only need to sync the specific client that has changed to avoid conflicts
            var clientData = new List <MiniYamlNode>();

            foreach (var client in LobbyInfo.Clients)
            {
                clientData.Add(client.Serialize());
            }

            DispatchOrders(null, 0,
                           new ServerOrder("SyncLobbyClients", clientData.WriteToString()).Serialize());

            foreach (var t in serverTraits.WithInterface <INotifySyncLobbyInfo>())
            {
                t.LobbyInfoSynced(this);
            }
        }
コード例 #11
0
        public void RequestGameSave(string filename)
        {
            // Allow traits to save arbitrary data that will be passed back via IGameSaveTraitData.ResolveTraitData
            // at the end of the save restoration
            // TODO: This will need to be generalized to a request / response pair for multiplayer game saves
            var i = 0;

            foreach (var tp in TraitDict.ActorsWithTrait <IGameSaveTraitData>())
            {
                var data = tp.Trait.IssueTraitData(tp.Actor);
                if (data != null)
                {
                    var yaml = new List <MiniYamlNode>()
                    {
                        new MiniYamlNode(i.ToString(), new MiniYaml("", data))
                    };
                    IssueOrder(Order.FromTargetString("GameSaveTraitData", yaml.WriteToString(), true));
                }

                i++;
            }

            IssueOrder(Order.FromTargetString("CreateGameSave", filename, true));
        }
コード例 #12
0
ファイル: Map.cs プロジェクト: zhangolove/OpenRA
        public void Save(string toPath)
        {
            MapFormat = 7;

            var root   = new List <MiniYamlNode>();
            var fields = new[]
            {
                "MapFormat",
                "RequiresMod",
                "Title",
                "Description",
                "Author",
                "Tileset",
                "MapSize",
                "Bounds",
                "Visibility",
                "Type",
            };

            foreach (var field in fields)
            {
                var f = this.GetType().GetField(field);
                if (f.GetValue(this) == null)
                {
                    continue;
                }
                root.Add(new MiniYamlNode(field, FieldSaver.FormatValue(this, f)));
            }

            root.Add(new MiniYamlNode("Videos", FieldSaver.SaveDifferences(Videos, new MapVideos())));

            root.Add(new MiniYamlNode("Options", FieldSaver.SaveDifferences(Options, new MapOptions())));

            root.Add(new MiniYamlNode("Players", null, PlayerDefinitions));

            root.Add(new MiniYamlNode("Actors", null, ActorDefinitions));
            root.Add(new MiniYamlNode("Smudges", null, SmudgeDefinitions));
            root.Add(new MiniYamlNode("Rules", null, RuleDefinitions));
            root.Add(new MiniYamlNode("Sequences", null, SequenceDefinitions));
            root.Add(new MiniYamlNode("VoxelSequences", null, VoxelSequenceDefinitions));
            root.Add(new MiniYamlNode("Weapons", null, WeaponDefinitions));
            root.Add(new MiniYamlNode("Voices", null, VoiceDefinitions));
            root.Add(new MiniYamlNode("Music", null, MusicDefinitions));
            root.Add(new MiniYamlNode("Notifications", null, NotificationDefinitions));
            root.Add(new MiniYamlNode("Translations", null, TranslationDefinitions));

            var entries = new Dictionary <string, byte[]>();

            entries.Add("map.bin", SaveBinaryData());
            var s = root.WriteToString();

            entries.Add("map.yaml", Encoding.UTF8.GetBytes(s));

            // Add any custom assets
            if (Container != null)
            {
                foreach (var file in Container.AllFileNames())
                {
                    if (file == "map.bin" || file == "map.yaml")
                    {
                        continue;
                    }

                    entries.Add(file, Container.GetContent(file).ReadAllBytes());
                }
            }

            // Saving the map to a new location
            if (toPath != Path || Container == null)
            {
                Path = toPath;

                // Create a new map package
                Container = GlobalFileSystem.CreatePackage(Path, int.MaxValue, entries);
            }

            // Update existing package
            Container.Write(entries);

            // Update UID to match the newly saved data
            Uid = ComputeHash();
        }
コード例 #13
0
ファイル: Handshake.cs プロジェクト: Generalcamo/OpenRA
 public string Serialize()
 {
     var data = new List<MiniYamlNode>();
     data.Add(new MiniYamlNode("Handshake", FieldSaver.Save(this)));
     return data.WriteToString();
 }
コード例 #14
0
        public void Save(string toPath)
        {
            MapFormat = 6;

            var root   = new List <MiniYamlNode>();
            var fields = new[]
            {
                "Selectable",
                "MapFormat",
                "RequiresMod",
                "Title",
                "Description",
                "Author",
                "Tileset",
                "MapSize",
                "Bounds",
                "UseAsShellmap",
                "Type",
            };

            foreach (var field in fields)
            {
                var f = this.GetType().GetField(field);
                if (f.GetValue(this) == null)
                {
                    continue;
                }
                root.Add(new MiniYamlNode(field, FieldSaver.FormatValue(this, f)));
            }

            root.Add(new MiniYamlNode("Options", FieldSaver.SaveDifferences(Options, new MapOptions())));

            root.Add(new MiniYamlNode("Players", null,
                                      Players.Select(p => new MiniYamlNode("PlayerReference@{0}".F(p.Key), FieldSaver.SaveDifferences(p.Value, new PlayerReference()))).ToList())
                     );

            root.Add(new MiniYamlNode("Actors", null,
                                      Actors.Value.Select(x => new MiniYamlNode(x.Key, x.Value.Save())).ToList())
                     );

            root.Add(new MiniYamlNode("Smudges", MiniYaml.FromList <SmudgeReference>(Smudges.Value)));
            root.Add(new MiniYamlNode("Rules", null, RuleDefinitions));
            root.Add(new MiniYamlNode("Sequences", null, SequenceDefinitions));
            root.Add(new MiniYamlNode("VoxelSequences", null, VoxelSequenceDefinitions));
            root.Add(new MiniYamlNode("Weapons", null, WeaponDefinitions));
            root.Add(new MiniYamlNode("Voices", null, VoiceDefinitions));
            root.Add(new MiniYamlNode("Notifications", null, NotificationDefinitions));
            root.Add(new MiniYamlNode("Translations", null, TranslationDefinitions));

            var entries = new Dictionary <string, byte[]>();

            entries.Add("map.bin", SaveBinaryData());
            var s = root.WriteToString();

            entries.Add("map.yaml", Encoding.UTF8.GetBytes(s));

            // Add any custom assets
            if (Container != null)
            {
                foreach (var file in Container.AllFileNames())
                {
                    if (file == "map.bin" || file == "map.yaml")
                    {
                        continue;
                    }

                    entries.Add(file, Container.GetContent(file).ReadAllBytes());
                }
            }

            // Saving the map to a new location
            if (toPath != Path)
            {
                Path = toPath;

                // Create a new map package
                Container = GlobalFileSystem.CreatePackage(Path, int.MaxValue, entries);
            }

            // Update existing package
            Container.Write(entries);
        }
コード例 #15
0
ファイル: Session.cs プロジェクト: CH4Code/OpenRA
        public string Serialize()
        {
            var sessionData = new List<MiniYamlNode>();

            foreach (var client in Clients)
                sessionData.Add(client.Serialize());

            foreach (var clientPing in ClientPings)
                sessionData.Add(clientPing.Serialize());

            foreach (var slot in Slots)
                sessionData.Add(slot.Value.Serialize());

            sessionData.Add(GlobalSettings.Serialize());

            return sessionData.WriteToString();
        }
コード例 #16
0
ファイル: Map.cs プロジェクト: TiriliPiitPiit/OpenRA
        public void Save(string toPath)
        {
            MapFormat = 5;

            var root = new List<MiniYamlNode>();
            var fields = new[]
            {
                "Selectable",
                "MapFormat",
                "RequiresMod",
                "Title",
                "Description",
                "Author",
                "Tileset",
                "Options",
                "MapSize",
                "Bounds",
                "UseAsShellmap",
                "Type",
            };

            foreach (var field in fields)
            {
                var f = this.GetType().GetField(field);
                if (f.GetValue(this) == null) continue;
                root.Add(new MiniYamlNode(field, FieldSaver.FormatValue(this, f)));
            }

            root.Add(new MiniYamlNode("Players", null,
                Players.Select(p => new MiniYamlNode("PlayerReference@{0}".F(p.Key), FieldSaver.SaveDifferences(p.Value, new PlayerReference()))).ToList()));

            root.Add(new MiniYamlNode("Actors", null,
                Actors.Value.Select(x => new MiniYamlNode(x.Key, x.Value.Save())).ToList()));

            root.Add(new MiniYamlNode("Smudges", MiniYaml.FromList<SmudgeReference>(Smudges.Value)));
            root.Add(new MiniYamlNode("Rules", null, Rules));
            root.Add(new MiniYamlNode("Sequences", null, Sequences));
            root.Add(new MiniYamlNode("VoxelSequences", null, VoxelSequences));
            root.Add(new MiniYamlNode("Weapons", null, Weapons));
            root.Add(new MiniYamlNode("Voices", null, Voices));
            root.Add(new MiniYamlNode("Notifications", null, Notifications));

            var entries = new Dictionary<string, byte[]>();
            entries.Add("map.bin", SaveBinaryData());
            var s = root.WriteToString();
            entries.Add("map.yaml", Encoding.UTF8.GetBytes(s));

            // Saving the map to a new location
            if (toPath != Path)
            {
                Path = toPath;

                // Create a new map package
                // TODO: Add other files (custom assets) to the entries list
                container = FileSystem.CreatePackage(Path, int.MaxValue, entries);
            }

            // Update existing package
            container.Write(entries);
        }
コード例 #17
0
ファイル: Map.cs プロジェクト: ushardul/OpenRA
        public void Save(string toPath)
        {
            MapFormat = 7;

            var root = new List<MiniYamlNode>();
            var fields = new[]
            {
                "MapFormat",
                "RequiresMod",
                "Title",
                "Description",
                "Author",
                "Tileset",
                "MapSize",
                "Bounds",
                "Visibility",
                "Type",
            };

            foreach (var field in fields)
            {
                var f = this.GetType().GetField(field);
                if (f.GetValue(this) == null)
                    continue;
                root.Add(new MiniYamlNode(field, FieldSaver.FormatValue(this, f)));
            }

            root.Add(new MiniYamlNode("Videos", FieldSaver.SaveDifferences(Videos, new MapVideos())));

            root.Add(new MiniYamlNode("Options", FieldSaver.SaveDifferences(Options, new MapOptions())));

            root.Add(new MiniYamlNode("Players", null, PlayerDefinitions));

            root.Add(new MiniYamlNode("Actors", null, ActorDefinitions));
            root.Add(new MiniYamlNode("Smudges", null, SmudgeDefinitions));
            root.Add(new MiniYamlNode("Rules", null, RuleDefinitions));
            root.Add(new MiniYamlNode("Sequences", null, SequenceDefinitions));
            root.Add(new MiniYamlNode("VoxelSequences", null, VoxelSequenceDefinitions));
            root.Add(new MiniYamlNode("Weapons", null, WeaponDefinitions));
            root.Add(new MiniYamlNode("Voices", null, VoiceDefinitions));
            root.Add(new MiniYamlNode("Notifications", null, NotificationDefinitions));
            root.Add(new MiniYamlNode("Translations", null, TranslationDefinitions));

            var entries = new Dictionary<string, byte[]>();
            entries.Add("map.bin", SaveBinaryData());
            var s = root.WriteToString();
            entries.Add("map.yaml", Encoding.UTF8.GetBytes(s));

            // Add any custom assets
            if (Container != null)
            {
                foreach (var file in Container.AllFileNames())
                {
                    if (file == "map.bin" || file == "map.yaml")
                        continue;

                    entries.Add(file, Container.GetContent(file).ReadAllBytes());
                }
            }

            // Saving the map to a new location
            if (toPath != Path)
            {
                Path = toPath;

                // Create a new map package
                Container = GlobalFileSystem.CreatePackage(Path, int.MaxValue, entries);
            }

            // Update existing package
            Container.Write(entries);
        }
コード例 #18
0
ファイル: Server.cs プロジェクト: pchote/OpenRA
        public void SyncLobbyGlobalSettings()
        {
            if (State != ServerState.WaitingPlayers)
                return;

            var sessionData = new List<MiniYamlNode> { LobbyInfo.GlobalSettings.Serialize() };

            DispatchOrders(null, 0, new ServerOrder("SyncLobbyGlobalSettings", sessionData.WriteToString()).Serialize());

            foreach (var t in serverTraits.WithInterface<INotifySyncLobbyInfo>())
                t.LobbyInfoSynced(this);
        }
コード例 #19
0
ファイル: Server.cs プロジェクト: RunCraze/OpenRA
        public void SyncClientPing()
        {
            // TODO: split this further into per client ping orders
            var clientPings = new List<MiniYamlNode>();
            foreach (var ping in LobbyInfo.ClientPings)
                clientPings.Add(ping.Serialize());

            DispatchOrders(null, 0,
                new ServerOrder("SyncClientPings", clientPings.WriteToString()).Serialize());

            foreach (var t in serverTraits.WithInterface<INotifySyncLobbyInfo>())
                t.LobbyInfoSynced(this);
        }
コード例 #20
0
ファイル: Server.cs プロジェクト: RunCraze/OpenRA
        public void SyncLobbyClients()
        {
            if (State != ServerState.WaitingPlayers)
                return;

            // TODO: only need to sync the specific client that has changed to avoid conflicts
            var clientData = new List<MiniYamlNode>();
            foreach (var client in LobbyInfo.Clients)
                clientData.Add(client.Serialize());

            DispatchOrders(null, 0,
                new ServerOrder("SyncLobbyClients", clientData.WriteToString()).Serialize());

            foreach (var t in serverTraits.WithInterface<INotifySyncLobbyInfo>())
                t.LobbyInfoSynced(this);
        }
コード例 #21
0
ファイル: Server.cs プロジェクト: RunCraze/OpenRA
        public void SyncLobbySlots()
        {
            if (State != ServerState.WaitingPlayers)
                return;

            // TODO: don't sync all the slots if just one changed
            var slotData = new List<MiniYamlNode>();
            foreach (var slot in LobbyInfo.Slots)
                slotData.Add(slot.Value.Serialize());

            DispatchOrders(null, 0,
                new ServerOrder("SyncLobbySlots", slotData.WriteToString()).Serialize());

            foreach (var t in serverTraits.WithInterface<INotifySyncLobbyInfo>())
                t.LobbyInfoSynced(this);
        }
コード例 #22
0
ファイル: Map.cs プロジェクト: pchote/OpenRA
        public void Save(IReadWritePackage toPackage)
        {
            MapFormat = SupportedMapFormat;

            var root = new List<MiniYamlNode>();
            foreach (var field in YamlFields)
                field.Serialize(this, root);

            // Saving to a new package: copy over all the content from the map
            if (Package != null && toPackage != Package)
                foreach (var file in Package.Contents)
                    toPackage.Update(file, Package.GetStream(file).ReadAllBytes());

            if (!LockPreview)
                toPackage.Update("map.png", SavePreview());

            // Update the package with the new map data
            var s = root.WriteToString();
            toPackage.Update("map.yaml", Encoding.UTF8.GetBytes(s));
            toPackage.Update("map.bin", SaveBinaryData());
            Package = toPackage;

            // Update UID to match the newly saved data
            Uid = ComputeUID(toPackage);
        }