Example #1
0
        /// <summary>
        /// Gets the EOS Devices sorted by retType.
        /// </summary>
        /// <returns>The EOS Devices.</returns>
        /// <param name="comp">The Computer.</param>
        /// <param name="retType">Determines how to sort the devices.</param>
        public static Dictionary <string, Hacknet.Computer> GetEOSDevicesBy(this Hacknet.Computer comp, RetrieveType retType)
        {
            var res = new Dictionary <string, Hacknet.Computer>();

            if (comp.attatchedDeviceIDs != null)
            {
                foreach (var id in comp.attatchedDeviceIDs.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var c = comp.GetNetworkMap().GetComputerById(id);
                    if (c != null)
                    {
                        switch (retType)
                        {
                        case RetrieveType.ID:
                            res[id] = c;
                            break;

                        case RetrieveType.ADDRESS:
                            res[c.ip] = c;
                            break;

                        case RetrieveType.NAME:
                            res[c.name] = c;
                            break;

                        case RetrieveType.INDEX:
                            res[c.GetNetworkMap().nodes.IndexOf(c).ToString()] = c;
                            break;
                        }
                    }
                }
            }
            return(res);
        }
Example #2
0
        /// <summary>
        /// Adds a EOS Device connection represented by device
        /// </summary>
        /// <param name="comp">The Computer.</param>
        /// <param name="device">The Computer device to link to.</param>
        public static void AddEOSDevice(this Hacknet.Computer comp, Hacknet.Computer device)
        {
            if (comp.attatchedDeviceIDs == null)
            {
                comp.attatchedDeviceIDs = device.idName;
            }
            else
            {
                comp.attatchedDeviceIDs += ',' + device.idName;
            }

            if (!comp.GetNetworkMap().nodes.Contains(device))
            {
                comp.GetNetworkMap().nodes.Add(device);
            }

            device.AddLink(comp);
        }
Example #3
0
        /// <summary>
        /// Creates the EOS Device connected to Computer.
        /// </summary>
        /// <returns>The created EOS Device.</returns>
        /// <param name="comp">The Computer.</param>
        /// <param name="name">The device's name.</param>
        /// <param name="ip">The device's ip.</param>
        /// <param name="icon">The device's icon.</param>
        /// <param name="location">The device's NetworkMap position.</param>
        /// <param name="password">The device's password, by game default should be alpine.</param>
        /// <param name="vanillaPorts">The device's closed vanilla port numbers.</param>
        /// <param name="portCracksRequired">The device's cracked ports required to unlock.</param>
        /// <param name="eosFolder">The device's eos folder.</param>
        /// <param name="modPorts">The device's closed modded Port.Type List.</param>
        public static Hacknet.Computer CreateEOSDeviceOn(this Hacknet.Computer comp,
                                                         string name               = "Unregistered eOS Device",
                                                         string ip                 = null,
                                                         string icon               = "ePhone",
                                                         Vector2?location          = null,
                                                         string password           = "******",
                                                         List <int> vanillaPorts   = null,
                                                         int portCracksRequired    = 2,
                                                         Hacknet.Folder eosFolder  = null,
                                                         List <Port.Type> modPorts = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (icon == null)
            {
                throw new ArgumentNullException(nameof(icon));
            }
            if (password == null)
            {
                throw new ArgumentNullException(nameof(password));
            }

            var c = new Hacknet.Computer(name, comp.idName + "_eos", location ??
                                         comp.location + Corporation.getNearbyNodeOffset(comp.location,
                                                                                         Utils.random.Next(12),
                                                                                         12,
                                                                                         comp.GetNetworkMap(),
                                                                                         0f), 0, 5, comp.os);

            c.icon = icon;
            c.setAdminPassword(password);
            vanillaPorts = vanillaPorts ?? new List <int>(new int[] { 22, 3659 });
            foreach (var p in vanillaPorts)
            {
                c.AddVanillaPort(p);
            }
            if (modPorts != null)
            {
                foreach (var p in modPorts)
                {
                    c.AddModPort(p);
                }
            }
            c.portsNeededForCrack = portCracksRequired;
            if (eosFolder != null)
            {
                c.files.root.folders.Add(eosFolder);
            }
            else
            {
                EOSComp.GenerateEOSFilesystem(c);
            }
            comp.AddEOSDevice(c);
            return(c);
        }
Example #4
0
 /// <summary>
 /// Adds a link on the NetworkMap from Computer connecting to newLink.
 /// </summary>
 /// <returns><c>true</c>, if the link was added, <c>false</c> otherwise.</returns>
 /// <param name="comp">The Computer</param>
 /// <param name="newLink">The New link.</param>
 public static bool AddLink(this Hacknet.Computer comp, Hacknet.Computer newLink) =>
 comp.GetNetworkMap().AddLink(comp, newLink);