public void ProcessPacket(DysonSphereAddNodePacket packet, NebulaConnection conn)
        {
            Player player = playerManager.GetPlayer(conn);

            if (player != null)
            {
                playerManager.SendPacketToOtherPlayers(packet, player);

                using (DysonSphere_Manager.IncomingDysonSpherePacket.On())
                {
                    GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId)?.NewDysonNode(packet.NodeProtoId, DataStructureExtensions.ToVector3(packet.Position));
                    DysonSphereLayer dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId);

                    // DysonSphereLayer is missing, we can't do anything now.
                    if (dsl == null)
                    {
                        NebulaModel.Logger.Log.Warn("Could not add Dyson Sphere Node, DysonSphereLayer is null.");
                        return;
                    }

                    //Try to add queued Dyson Frames that failed due to the missing nodes
                    DysonSphereAddFramePacket queuedPacked;
                    for (int i = DysonSphere_Manager.QueuedAddFramePackets.Count - 1; i >= 0; i--)
                    {
                        queuedPacked = DysonSphere_Manager.QueuedAddFramePackets[i];
                        if (dsl.nodePool[queuedPacked.NodeAId].id != 0 && dsl.nodePool[queuedPacked.NodeBId].id != 0)
                        {
                            dsl.NewDysonFrame(queuedPacked.ProtoId, queuedPacked.NodeAId, queuedPacked.NodeBId, queuedPacked.Euler);
                            DysonSphere_Manager.QueuedAddFramePackets.RemoveAt(i);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void ProcessPacket(DysonSphereAddNodePacket packet, NebulaConnection conn)
        {
            Log.Info($"Processing DysonSphere Add Node notification for system {GameMain.data.galaxy.stars[packet.StarIndex].name} (Index: {GameMain.data.galaxy.stars[packet.StarIndex].index})");
            Player player = playerManager.GetPlayer(conn);

            if (player != null)
            {
                playerManager.SendPacketToOtherPlayers(packet, player);
                DysonSphere_Manager.IncomingDysonSpherePacket = true;
                GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId)?.NewDysonNode(packet.NodeProtoId, DataStructureExtensions.ToUnity(packet.Position));
                DysonSphereLayer dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId);
                //Try to add queued Dyson Frames that failed due to the missing nodes
                DysonSphereAddFramePacket queuedPacked;
                for (int i = DysonSphere_Manager.QueuedAddFramePackets.Count - 1; i >= 0; i--)
                {
                    queuedPacked = DysonSphere_Manager.QueuedAddFramePackets[i];
                    if (dsl?.nodePool[queuedPacked.NodeAId]?.id != 0 && dsl?.nodePool[queuedPacked.NodeBId]?.id != 0)
                    {
                        dsl.NewDysonFrame(queuedPacked.ProtoId, queuedPacked.NodeAId, queuedPacked.NodeBId, queuedPacked.Euler);
                        DysonSphere_Manager.QueuedAddFramePackets.RemoveAt(i);
                    }
                }
                DysonSphere_Manager.IncomingDysonSpherePacket = false;
            }
        }
        public override void ProcessPacket(DysonSphereAddFramePacket packet, NebulaConnection conn)
        {
            bool valid = true;

            if (IsHost)
            {
                Player player = playerManager.GetPlayer(conn);
                if (player != null)
                {
                    playerManager.SendPacketToOtherPlayers(packet, player);
                }
                else
                {
                    valid = false;
                }
            }

            if (valid)
            {
                using (DysonSphereManager.IsIncomingRequest.On())
                {
                    DysonSphereLayer dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId);
                    //Check if target nodes exists (if not, assume that AddNode packet is on the way)
                    if (DysonSphereManager.CanCreateFrame(packet.NodeAId, packet.NodeBId, dsl))
                    {
                        dsl.NewDysonFrame(packet.ProtoId, packet.NodeAId, packet.NodeBId, packet.Euler);
                    }
                    else
                    {
                        DysonSphereManager.QueuedAddFramePackets.Add(packet);
                    }
                }
            }
        }
 public void ProcessPacket(DysonSphereAddFramePacket packet, NebulaConnection conn)
 {
     using (DysonSphere_Manager.IncomingDysonSpherePacket.On())
     {
         DysonSphereLayer dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId);
         //Check if target nodes exists (if not, assume that AddNode packet is on the way)
         if (DysonSphere_Manager.CanCreateFrame(packet.NodeAId, packet.NodeBId, dsl))
         {
             dsl.NewDysonFrame(packet.ProtoId, packet.NodeAId, packet.NodeBId, packet.Euler);
         }
         else
         {
             DysonSphere_Manager.QueuedAddFramePackets.Add(packet);
         }
     }
 }
        public void ProcessPacket(DysonSphereAddFramePacket packet, NebulaConnection conn)
        {
            Log.Info($"Processing DysonSphere Add Frame notification for system {GameMain.data.galaxy.stars[packet.StarIndex].name} (Index: {GameMain.data.galaxy.stars[packet.StarIndex].index})");
            DysonSphere_Manager.IncomingDysonSpherePacket = true;
            DysonSphereLayer dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId);

            //Check if target nodes exists (if not, assume that AddNode packet is on the way)
            if (DysonSphere_Manager.CanCreateFrame(packet.NodeAId, packet.NodeBId, dsl))
            {
                dsl.NewDysonFrame(packet.ProtoId, packet.NodeAId, packet.NodeBId, packet.Euler);
            }
            else
            {
                DysonSphere_Manager.QueuedAddFramePackets.Add(packet);
            }
            DysonSphere_Manager.IncomingDysonSpherePacket = false;
        }
 public void ProcessPacket(DysonSphereAddNodePacket packet, NebulaConnection conn)
 {
     using (DysonSphere_Manager.IncomingDysonSpherePacket.On())
     {
         int?addedID = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId)?.NewDysonNode(packet.NodeProtoId, DataStructureExtensions.ToVector3(packet.Position));
         //Try to add frames that failed due to the missing nodes
         DysonSphereLayer          dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId);
         DysonSphereAddFramePacket queuedPacked;
         for (int i = DysonSphere_Manager.QueuedAddFramePackets.Count - 1; i >= 0; i--)
         {
             queuedPacked = DysonSphere_Manager.QueuedAddFramePackets[i];
             if (dsl?.nodePool[queuedPacked.NodeAId]?.id != 0 && dsl?.nodePool[queuedPacked.NodeBId]?.id != 0)
             {
                 dsl.NewDysonFrame(queuedPacked.ProtoId, queuedPacked.NodeAId, queuedPacked.NodeBId, queuedPacked.Euler);
                 DysonSphere_Manager.QueuedAddFramePackets.RemoveAt(i);
             }
         }
     }
 }
        public override void ProcessPacket(DysonSphereAddFramePacket packet, NebulaConnection conn)
        {
            DysonSphereLayer layer = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId);

            if (layer == null)
            {
                return;
            }
            using (Multiplayer.Session.DysonSpheres.IsIncomingRequest.On())
            {
                int frameId = layer.frameRecycleCursor > 0 ? layer.frameRecycle[layer.frameRecycleCursor - 1] : layer.frameCursor;
                if (frameId != packet.FrameId || layer.NewDysonFrame(packet.ProtoId, packet.NodeAId, packet.NodeBId, packet.Euler) == 0)
                {
                    Log.Warn($"Cannnot add frame[{packet.FrameId}] on layer[{layer.id}], starIndex[{packet.StarIndex}]");
                    Multiplayer.Session.DysonSpheres.HandleDesync(packet.StarIndex, conn);
                    return;
                }
            }
            if (IsHost)
            {
                Multiplayer.Session.DysonSpheres.SendPacketToDysonSphereExcept(packet, packet.StarIndex, conn);
            }
        }