aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn/Hacking.cs
blob: db47f668e533392069fa657a7ccd1821de172b9f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ShiftOS.Engine
{
    public static class Hacking
    {
        private static List<HackableSystem> _activeConnections = new List<HackableSystem>();
        private static List<Objects.Hackable> Hackables = new List<Objects.Hackable>();

        public static Objects.Hackable[] AvailableToHack
        {
            get
            {
                return Hackables.Where(x => Shiftorium.UpgradeInstalled(x.Dependencies) && !Shiftorium.UpgradeInstalled(x.ID)).ToArray();
            }
        }


        public static HackableSystem[] ActiveConnections
        {
            get
            {
                return _activeConnections.ToArray();
            }
        }

        public static HackableSystem[] PwnedConnections
        {
            get
            {
                return _activeConnections.Where(x => x.IsPwn3d).ToArray();
            }
        }

        public static HackableSystem[] TimedConnections
        {
            get
            {
                return _activeConnections.Where(x => x.Data.ConnectionTimeoutLevel > 0&&!x.IsPwn3d).ToArray();
            }
        }

        public static void Initiate()
        {
            foreach(var type in ReflectMan.Types.Where(x => x.GetInterfaces().Contains(typeof(IHackableProvider))))
            {
                var @interface = (IHackableProvider)Activator.CreateInstance(type, null);
                Hackables.AddRange(@interface.GetHackables());

            }

            var hackable = Hackables.FirstOrDefault(x => Hackables.Where(y => x.SystemName == y.SystemName).Count() > 1);
            if(hackable != null)
            {
                throw new DataConflictException("Data conflict encountered while initiating the hacking engine. Two or more hackables were found with the same hostname \"" + hackable.SystemName + "\". This is a direct violation of the ShiftOS save system and Shiftorium backend.");
            }
        }
    }

    public class DataConflictException : Exception
    {
        public DataConflictException(string message) : base(message)
        {

        }
    }

    public interface IHackableProvider
    {
        Objects.Hackable[] GetHackables();
    }

    public class HackableSystem
    {
        public Objects.Hackable Data { get; set; }
        public List<Port> PortsToUnlock { get; set; }
        public bool FirewallCracked { get; set; }
        public Objects.ShiftFS.Directory Filesystem { get; set; }
        public int MillisecondsCountdown { get; set; }
        public bool IsPwn3d { get; set; }
    }

    public class Port
    {
        public string Name { get; set; }
        public int Value { get; set; }
        public int Difficulty { get; set; }
        public bool Cracked { get; set; }
    }
}