Beispiel #1
0
        public override void ProcessPacket(DysonSphereRemoveShellPacket packet, NebulaConnection conn)
        {
            DysonSphereLayer layer = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId);

            if (layer == null)
            {
                return;
            }
            using (Multiplayer.Session.DysonSpheres.IsIncomingRequest.On())
            {
                if (packet.ShellId < 1 || packet.ShellId >= layer.shellCursor)
                {
                    Log.Warn($"Cannnot remove shell[{packet.ShellId}] on layer[{layer.id}], starIndex[{packet.StarIndex}]");
                    Multiplayer.Session.DysonSpheres.HandleDesync(packet.StarIndex, conn);
                    return;
                }
                //No need to remove if the shell is already null
                if (layer.shellPool[packet.ShellId] != null)
                {
                    layer.RemoveDysonShell(packet.ShellId);
                    NebulaWorld.Universe.DysonSphereManager.ClearSelection(packet.StarIndex, layer.id);
                }
            }
            if (IsHost)
            {
                Multiplayer.Session.DysonSpheres.SendPacketToDysonSphereExcept(packet, packet.StarIndex, conn);
            }
        }
Beispiel #2
0
 public void ProcessPacket(DysonSphereRemoveNodePacket packet, NebulaConnection conn)
 {
     Log.Info($"Processing DysonSphere Remove Node notification for system {GameMain.data.galaxy.stars[packet.StarIndex].name} (Index: {GameMain.data.galaxy.stars[packet.StarIndex].index})");
     using (DysonSphere_Manager.IncomingDysonSpherePacket.On())
     {
         DysonSphereLayer dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId);
         if (dsl != null)
         {
             int       num       = 0;
             DysonNode dysonNode = dsl.nodePool[packet.NodeId];
             //Remove all frames that are part of the node
             while (dysonNode.frames.Count > 0)
             {
                 dsl.RemoveDysonFrame(dysonNode.frames[0].id);
                 if (num++ > 4096)
                 {
                     Assert.CannotBeReached();
                     break;
                 }
             }
             //Remove all shells that are part of the node
             while (dysonNode.shells.Count > 0)
             {
                 dsl.RemoveDysonShell(dysonNode.shells[0].id);
                 if (num++ > 4096)
                 {
                     Assert.CannotBeReached();
                     break;
                 }
             }
             dsl.RemoveDysonNode(packet.NodeId);
         }
     }
 }
        public override void ProcessPacket(DysonSphereRemoveShellPacket 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);
                    if (DysonSphereManager.CanRemoveShell(packet.ShellId, dsl))
                    {
                        dsl.RemoveDysonShell(packet.ShellId);
                    }
                }
            }
        }
Beispiel #4
0
 public void ProcessPacket(DysonSphereRemoveShellPacket packet, NebulaConnection conn)
 {
     using (DysonSphere_Manager.IncomingDysonSpherePacket.On())
     {
         DysonSphereLayer dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId);
         if (DysonSphere_Manager.CanRemoveShell(packet.ShellId, dsl))
         {
             dsl.RemoveDysonShell(packet.ShellId);
         }
     }
 }
        public void ProcessPacket(DysonSphereRemoveShellPacket packet, NebulaConnection conn)
        {
            Log.Info($"Processing DysonSphere remove shell 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);

            if (DysonSphere_Manager.CanRemoveShell(packet.ShellId, dsl))
            {
                dsl.RemoveDysonShell(packet.ShellId);
            }
            DysonSphere_Manager.IncomingDysonSpherePacket = false;
        }
        public override void ProcessPacket(DysonSphereRemoveNodePacket 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);
                    if (dsl != null)
                    {
                        int       num       = 0;
                        DysonNode dysonNode = dsl.nodePool[packet.NodeId];
                        //Remove all frames that are part of the node
                        while (dysonNode.frames.Count > 0)
                        {
                            dsl.RemoveDysonFrame(dysonNode.frames[0].id);
                            if (num++ > 4096)
                            {
                                Assert.CannotBeReached();
                                break;
                            }
                        }
                        //Remove all shells that are part of the node
                        while (dysonNode.shells.Count > 0)
                        {
                            dsl.RemoveDysonShell(dysonNode.shells[0].id);
                            if (num++ > 4096)
                            {
                                Assert.CannotBeReached();
                                break;
                            }
                        }
                        dsl.RemoveDysonNode(packet.NodeId);
                    }
                }
            }
        }
        public void ProcessPacket(DysonSphereRemoveShellPacket packet, NebulaConnection conn)
        {
            Player player = playerManager.GetPlayer(conn);

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

                using (DysonSphere_Manager.IncomingDysonSpherePacket.On())
                {
                    DysonSphereLayer dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId);
                    if (DysonSphere_Manager.CanRemoveShell(packet.ShellId, dsl))
                    {
                        dsl.RemoveDysonShell(packet.ShellId);
                    }
                }
            }
        }
        public void ProcessPacket(DysonSphereRemoveShellPacket packet, NebulaConnection conn)
        {
            //Log.Info($"Processing DysonSphere remove shell 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);

                using (DysonSphere_Manager.IncomingDysonSpherePacket.On())
                {
                    DysonSphereLayer dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId);
                    if (DysonSphere_Manager.CanRemoveShell(packet.ShellId, dsl))
                    {
                        dsl.RemoveDysonShell(packet.ShellId);
                    }
                }
            }
        }
        private static bool Check(DysonSphereLayer layer, DysonSphereRemoveFramePacket packet)
        {
            if (packet.FrameId < 1 || packet.FrameId >= layer.frameCursor)
            {
                return(false);
            }
            DysonFrame frame = layer.framePool[packet.FrameId];

            if (frame == null)
            {
                //Sender and receiver are in the same state, so it's ok to pass
                return(true);
            }
            //Make sure that shells connected to the frame are removed first.
            //UIDysonBrush_Remove.DeleteSelectedNode() remove frames first, so we need to remove shells here.
            List <int> delShellList = new List <int>();

            foreach (DysonShell shell in frame.nodeA.shells)
            {
                if (shell.frames.Contains(frame) && !delShellList.Contains(shell.id))
                {
                    delShellList.Add(shell.id);
                }
            }
            foreach (DysonShell shell in frame.nodeB.shells)
            {
                if (shell.frames.Contains(frame) && !delShellList.Contains(shell.id))
                {
                    delShellList.Add(shell.id);
                }
            }
            foreach (int shellId in delShellList)
            {
                layer.RemoveDysonShell(shellId);
            }
            return(true);
        }