Exemple #1
0
        public static bool AssignTo(Instance ins, Hacknet.Computer c, bool replace = false)
        {
            if (!compToInst.ContainsKey(c))
            {
                compToInst.Add(c, new List <Instance>());
            }
            var sameDisplay = compToInst[c].FirstOrDefault((i) => i.Port.PortDisplay == ins.Port.PortDisplay);

            if (c.PortRemapping.ContainsKey(ins.Port.PortDisplay) && !compToInst[c].Contains(ins) && replace || sameDisplay == null)
            {
                if (replace)
                {
                    c.ports.Remove(ExeInfoManager.GetExecutableInfo(ins.Port.PortDisplay).PortNumber);
                    c.PortRemapping.Remove(ins.Port.PortDisplay);
                }
                else
                {
                    return(false);
                }
            }
            if (!compToInst[c].Contains(ins) && sameDisplay == null)
            {
                compToInst[c].Add(ins);
                return(true);
            }
            if (sameDisplay != null && replace)
            {
                compToInst[c].Remove(sameDisplay);
                compToInst[c].Add(ins);
                ins.activeComputer = c;
                return(true);
            }
            return(false);
        }
Exemple #2
0
 /// <summary>
 /// Closes a vanilla port. Doesn't add a port
 /// </summary>
 /// <param name="comp">The Computer.</param>
 /// <param name="portNum">The port number to search for.</param>
 /// <param name="ipFrom">The ip responsible for the change.</param>
 public static void CloseVanillaPort(this Hacknet.Computer comp, int portNum, string ipFrom = null) =>
 comp.CloseVanillaPort(ExeInfoManager.GetExecutableInfo(portNum), ipFrom);
Exemple #3
0
 /// <summary>
 /// Opens a vanilla port. Doesn't add a port
 /// </summary>
 /// <param name="comp">The Computer.</param>
 /// <param name="portName">The port name to search for.</param>
 /// <param name="ipFrom">The ip responsible for the change.</param>
 public static void OpenVanillaPort(this Hacknet.Computer comp, string portName, string ipFrom = null) =>
 comp.OpenVanillaPort(ExeInfoManager.GetExecutableInfo(portName), ipFrom);
Exemple #4
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="portNum">The port number to search by</param>
 public static bool IsVanillaPortOpen(this Hacknet.Computer comp, int portNum) =>
 comp.IsVanillaPortOpen(ExeInfoManager.GetExecutableInfo(portNum));
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="portName">The port name to search by.</param>
 public static bool HasVanillaPort(this Hacknet.Computer comp, string portName) =>
 comp.HasVanilaPort(ExeInfoManager.GetExecutableInfo(portName));
Exemple #6
0
 /// <summary>
 /// Removes a vanilla port by port number.
 /// </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="portNum">The number for the port</param>
 public static bool RemoveVanillaPort(this Hacknet.Computer comp, int portNum) =>
 comp.RemoveVanillaPort(ExeInfoManager.GetExecutableInfo(portNum));
Exemple #7
0
 /// <summary>
 /// Adds a vanilla port by port number.
 /// </summary>
 /// <returns><c>true</c>, if vanilla port was added, <c>false</c> otherwise.</returns>
 /// <param name="comp">The Computer</param>
 /// <param name="portNum">The number 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, int portNum, bool unlocked = false) =>
 comp.AddVanillaPort(ExeInfoManager.GetExecutableInfo(portNum), unlocked);
Exemple #8
0
 /// <summary>
 /// Creates a vanilla executable File based on the name and the vanilla data index.
 /// </summary>
 /// <returns>The executable File that was created.</returns>
 /// <param name="name">The name to assign to the File.</param>
 /// <param name="vanillaIndex">The vanilla data index.</param>
 public File CreateExecutableFile(string name, int vanillaIndex) =>
 CreateFile(name, ExeInfoManager.GetExecutableInfo(vanillaIndex).Data);
Exemple #9
0
 /// <summary>
 /// Creates an executable File based on the name and the file data string id.
 /// </summary>
 /// <returns>The executable File that was created.</returns>
 /// <param name="name">The name to assign to the File.</param>
 /// <param name="exeId">The file data string id.</param>
 public File CreateExecutableFile(string name, string exeId) =>
 CreateFile(name, ExeInfoManager.GetExecutableInfo(exeId).Data ?? Executable.Handler.GetStandardFileDataBy(exeId, true));
Exemple #10
0
 public static Hacknet.Folder AddExecutableFile(this Hacknet.Folder self, string name, int id) =>
 self.AddFile(name, ExeInfoManager.GetExecutableInfo(id).Data);
Exemple #11
0
 public static Hacknet.Folder AddExecutableFile(this Hacknet.Folder self, string name, string id) =>
 self.AddFile(name,
              ExeInfoManager.GetExecutableInfo(id).Data ??
              Executable.Handler.GetStandardFileDataBy(id, true));