public void ParseOrders(Session lobbyInfo, Action <int, int, byte[]> packetFn) { // Send the trait data first to guarantee that it is available when needed foreach (var kv in TraitData) { var data = new List <MiniYamlNode>() { new MiniYamlNode(kv.Key.ToString(), kv.Value) }.WriteToString(); packetFn(0, 0, Order.FromTargetString("SaveTraitData", data, true).Serialize()); } ordersStream.Seek(0, SeekOrigin.Begin); while (ordersStream.Position < ordersStream.Length) { var dataLength = ordersStream.ReadInt32() - 8; var frame = ordersStream.ReadInt32(); var slot = ordersStream.ReadInt32(); var data = ordersStream.ReadBytes(dataLength); // Remap bot orders to their controller client var clientIndex = clientsBySlotIndex[slot]; var client = lobbyInfo.ClientWithIndex(clientIndex); if (client.Bot != null) { clientIndex = client.BotControllerClientIndex; } packetFn(frame, clientIndex, data); } // Send sync hash to validate restore packetFn(LastSyncFrame, 0, lastSyncPacket); }
// Adds the player information at start-up. public void AddPlayer(OpenRA.Player runtimePlayer, Session lobbyInfo) { if (runtimePlayer == null) throw new ArgumentNullException("runtimePlayer"); if (lobbyInfo == null) throw new ArgumentNullException("lobbyInfo"); // We don't care about spectators and map players if (runtimePlayer.NonCombatant || !runtimePlayer.Playable) return; // Find the lobby client that created the runtime player var client = lobbyInfo.ClientWithIndex(runtimePlayer.ClientIndex); if (client == null) return; var player = new Player { ClientIndex = runtimePlayer.ClientIndex, Name = runtimePlayer.PlayerName, IsHuman = !runtimePlayer.IsBot, IsBot = runtimePlayer.IsBot, FactionName = runtimePlayer.Faction.Name, FactionId = runtimePlayer.Faction.InternalName, Color = runtimePlayer.Color, Team = client.Team, SpawnPoint = runtimePlayer.SpawnPoint, IsRandomFaction = runtimePlayer.Faction.InternalName != client.Race, IsRandomSpawnPoint = runtimePlayer.SpawnPoint != client.SpawnPoint }; playersByRuntime.Add(runtimePlayer, player); Players.Add(player); }