public override void ProcessPacket(FactoryLoadRequest packet, NebulaConnection conn)
        {
            if (IsClient)
            {
                return;
            }

            PlanetData    planet  = GameMain.galaxy.PlanetById(packet.PlanetID);
            PlanetFactory factory = GameMain.data.GetOrCreateFactory(planet);

            using (BinaryUtils.Writer writer = new BinaryUtils.Writer())
            {
                factory.Export(writer.BinaryWriter);
                byte[] data = writer.CloseAndGetBytes();
                Log.Info($"Sent {data.Length} bytes of data for PlanetFactory {planet.name} (ID: {planet.id})");
                conn.SendPacket(new FactoryData(packet.PlanetID, data, planet.data.modData));
            }

            // Add requesting client to connected player, so he can receive following update
            IPlayerManager playerManager = Multiplayer.Session.Network.PlayerManager;
            INebulaPlayer  player        = playerManager.GetSyncingPlayer(conn);

            if (player != null)
            {
                player.Data.LocalPlanetId = packet.PlanetID;
                player.Data.LocalStarId   = GameMain.galaxy.PlanetById(packet.PlanetID).star.id;
                using (playerManager.GetConnectedPlayers(out System.Collections.Generic.Dictionary <INebulaConnection, INebulaPlayer> connectedPlayers))
                {
                    connectedPlayers.Add(player.Connection, player);
                }
            }
        }
Ejemplo n.º 2
0
        public void ProcessPacket(FactoryLoadRequest packet, NebulaConnection conn)
        {
            PlanetData    planet  = GameMain.galaxy.PlanetById(packet.PlanetID);
            PlanetFactory factory = GameMain.data.GetOrCreateFactory(planet);

            using (BinaryUtils.Writer writer = new BinaryUtils.Writer())
            {
                factory.Export(writer.BinaryWriter);
                conn.SendPacket(new FactoryData(packet.PlanetID, writer.CloseAndGetBytes()));
            }
            conn.SendPacket(StatisticsManager.instance.GetFactoryPlanetIds());
        }
Ejemplo n.º 3
0
        public void ProcessPacket(FactoryLoadRequest packet, NebulaConnection conn)
        {
            PlanetData    planet  = GameMain.galaxy.PlanetById(packet.PlanetID);
            PlanetFactory factory = GameMain.data.GetOrCreateFactory(planet);

            using (MemoryStream ms = new MemoryStream())
            {
                using (LZ4Stream ls = new LZ4Stream(ms, CompressionMode.Compress))
                    using (BufferedStream bs = new BufferedStream(ls, 8192))
                        using (BinaryWriter bw = new BinaryWriter(bs))
                        {
                            factory.Export(bw);
                        }

                conn.SendPacket(new FactoryData(packet.PlanetID, ms.ToArray()));
            }
        }