Exemple #1
0
        /// <summary>
        /// Determines whether the vanilla port is open.
        /// </summary>
        /// <returns><c>true</c>, if the port exists and is open, <c>false</c> otherwise.</returns>
        /// <param name="comp">The Computer</param>
        /// <param name="info">The ExecutableInfo to search by</param>
        public static bool IsVanillaPortOpen(this Hacknet.Computer comp, ExeInfoManager.ExecutableInfo info)
        {
            var i = comp.ports.IndexOf(info.PortNumber);

            if (i < 0)
            {
                return(false);
            }
            return(comp.portsOpen[i] >= 1);
        }
Exemple #2
0
 /// <summary>
 /// Adds a vanilla port by ExecutableInfo.
 /// </summary>
 /// <returns><c>true</c>, if vanilla port was added, <c>false</c> otherwise.</returns>
 /// <param name="comp">The Computer</param>
 /// <param name="info">The ExecutableInfo for the port</param>
 /// <param name="unlocked">If set to <c>true</c> then sets the port to be unlocked.</param>
 public static bool AddVanillaPort(this Hacknet.Computer comp, ExeInfoManager.ExecutableInfo info, bool unlocked = false)
 {
     if (info.IsEmpty)
     {
         return(false);
     }
     comp.ports.Add(info.PortNumber);
     comp.portsOpen.Add(unlocked ? (byte)1 : (byte)0);
     return(true);
 }
Exemple #3
0
        /// <summary>
        /// Removes a vanilla port by ExecutableInfo.
        /// </summary>
        /// <returns><c>true</c>, if vanilla port was found and removed, <c>false</c> otherwise.</returns>
        /// <param name="comp">The Computer</param>
        /// <param name="info">The ExecutableInfo for the port</param>
        public static bool RemoveVanillaPort(this Hacknet.Computer comp, ExeInfoManager.ExecutableInfo info)
        {
            if (info.IsEmpty)
            {
                return(false);
            }
            var index = comp.ports.IndexOf(info.PortNumber);

            if (index < 0)
            {
                return(false);
            }
            comp.ports.RemoveAt(index);
            comp.portsOpen.RemoveAt(index);
            return(true);
        }
Exemple #4
0
        /// <summary>
        /// Opens a vanilla port. Doesn't add a port
        /// </summary>
        /// <param name="comp">The Computer.</param>
        /// <param name="info">The ExecutableInfo to search for.</param>
        /// <param name="ipFrom">The ip responsible for the change.</param>
        public static void OpenVanillaPort(this Hacknet.Computer comp, ExeInfoManager.ExecutableInfo info, string ipFrom = null)
        {
            var i = comp.ports.IndexOf(info.PortNumber);

            if (i < 0)
            {
                return;
            }
            if (!comp.silent)
            {
                comp.portsOpen[i] = 1;
            }
            if (!string.IsNullOrEmpty(ipFrom))
            {
                comp.log(ipFrom + " Opened Port#" + info.PortNumber);
            }
            comp.sendNetworkMessage("cPortOpen " + comp.ip + " " + ipFrom + " " + info.PortNumber);
        }
Exemple #5
0
 /// <summary>
 /// Determines whether Computer has a certain vanilla port.
 /// </summary>
 /// <returns><c>true</c>, if Computer has the port, <c>false</c> otherwise.</returns>
 /// <param name="info">The ExecutableInfo to search by.</param>
 public static bool HasVanilaPort(this Hacknet.Computer comp, ExeInfoManager.ExecutableInfo info) =>
 comp.ports.Contains(info.PortNumber);