Exemplo n.º 1
0
        public static Computer load(XmlReader reader, OS os)
        {
            while (reader.Name != "computer")
            {
                reader.Read();
            }
            reader.MoveToAttribute("name");
            var compName = reader.ReadContentAsString();

            reader.MoveToAttribute("ip");
            var compIP = reader.ReadContentAsString();

            reader.MoveToAttribute("type");
            var compType = (byte)reader.ReadContentAsInt();

            reader.MoveToAttribute("spec");
            var str1 = reader.ReadContentAsString();

            reader.MoveToAttribute("id");
            var    str2 = reader.ReadContentAsString();
            string str3 = null;

            if (reader.MoveToAttribute("devices"))
            {
                str3 = reader.ReadContentAsString();
            }
            string str4 = null;

            if (reader.MoveToAttribute("icon"))
            {
                str4 = reader.ReadContentAsString();
            }
            while (reader.Name != "location")
            {
                reader.Read();
            }
            reader.MoveToAttribute("x");
            var x = reader.ReadContentAsFloat();

            reader.MoveToAttribute("y");
            var y = reader.ReadContentAsFloat();

            while (reader.Name != "security")
            {
                reader.Read();
            }
            reader.MoveToAttribute("level");
            var seclevel = reader.ReadContentAsInt();

            reader.MoveToAttribute("traceTime");
            var num1 = reader.ReadContentAsFloat();

            reader.MoveToAttribute("portsToCrack");
            var num2 = reader.ReadContentAsInt();

            reader.MoveToAttribute("adminIP");
            var str5 = reader.ReadContentAsString();
            var time = -1f;

            if (reader.MoveToAttribute("proxyTime"))
            {
                time = reader.ReadContentAsFloat();
            }
            while (reader.Name != "admin")
            {
                reader.Read();
            }
            reader.MoveToAttribute("type");
            var str6 = reader.ReadContentAsString();

            reader.MoveToAttribute("resetPass");
            var flag1 = reader.ReadContentAsBoolean();

            reader.MoveToAttribute("isSuper");
            var           flag2         = reader.ReadContentAsBoolean();
            Administrator administrator = null;

            switch (str6)
            {
            case "fast":
                administrator = new FastBasicAdministrator();
                break;

            case "basic":
                administrator = new BasicAdministrator();
                break;
            }
            if (administrator != null)
            {
                administrator.ResetsPassword = flag1;
            }
            if (administrator != null)
            {
                administrator.IsSuper = flag2;
            }
            while (reader.Name != "links")
            {
                reader.Read();
            }
            var      strArray = reader.ReadElementContentAsString().Split();
            Firewall firewall = null;

            while (reader.Name != "portsOpen" && reader.Name != "firewall")
            {
                reader.Read();
            }
            if (reader.Name == "firewall")
            {
                firewall = Firewall.load(reader);
            }
            while (reader.Name != "portsOpen")
            {
                reader.Read();
            }
            var portsList = reader.ReadElementContentAsString();
            var computer  = new Computer(compName, compIP, new Vector2(x, y), seclevel, compType, os);

            computer.firewall = firewall;
            computer.admin    = administrator;
            if (time > 0.0)
            {
                computer.addProxy(time);
            }
            else
            {
                computer.hasProxy    = false;
                computer.proxyActive = false;
            }
            while (reader.Name != "users")
            {
                reader.Read();
            }
            computer.users.Clear();
            while (!(reader.Name == "users") || reader.NodeType != XmlNodeType.EndElement)
            {
                if (reader.Name == "user")
                {
                    var userDetail = UserDetail.loadUserDetail(reader);
                    if (userDetail.name.ToLower() == "admin")
                    {
                        computer.adminPass = userDetail.pass;
                    }
                    computer.users.Add(userDetail);
                }
                reader.Read();
            }
            while (reader.Name != "daemons")
            {
                reader.Read();
            }
            reader.Read();
            while (!(reader.Name == "daemons") || reader.NodeType != XmlNodeType.EndElement)
            {
                if (reader.Name == "MailServer")
                {
                    reader.MoveToAttribute("name");
                    var name       = reader.ReadContentAsString();
                    var mailServer = new MailServer(computer, name, os);
                    computer.daemons.Add(mailServer);
                    if (reader.MoveToAttribute("color"))
                    {
                        var newThemeColor = Utils.convertStringToColor(reader.ReadContentAsString());
                        mailServer.setThemeColor(newThemeColor);
                    }
                }
                else if (reader.Name == "MissionListingServer")
                {
                    reader.MoveToAttribute("name");
                    var serviceName = reader.ReadContentAsString();
                    reader.MoveToAttribute("group");
                    var group = reader.ReadContentAsString();
                    reader.MoveToAttribute("public");
                    var _isPublic = reader.ReadContentAsString().ToLower().Equals("true");
                    reader.MoveToAttribute("assign");
                    var _isAssigner          = reader.ReadContentAsString().ToLower().Equals("true");
                    var missionListingServer = new MissionListingServer(computer, serviceName, group, os, _isPublic,
                                                                        _isAssigner);
                    computer.daemons.Add(missionListingServer);
                }
                else if (reader.Name == "AddEmailServer")
                {
                    reader.MoveToAttribute("name");
                    var serviceName    = reader.ReadContentAsString();
                    var addEmailDaemon = new AddEmailDaemon(computer, serviceName, os);
                    computer.daemons.Add(addEmailDaemon);
                }
                else if (reader.Name == "MessageBoard")
                {
                    reader.MoveToAttribute("name");
                    var str7 = reader.ReadContentAsString();
                    var messageBoardDaemon = new MessageBoardDaemon(computer, os);
                    messageBoardDaemon.name = str7;
                    computer.daemons.Add(messageBoardDaemon);
                }
                else if (reader.Name == "WebServer")
                {
                    reader.MoveToAttribute("name");
                    var serviceName = reader.ReadContentAsString();
                    reader.MoveToAttribute("url");
                    var pageFileLocation = reader.ReadContentAsString();
                    var webServerDaemon  = new WebServerDaemon(computer, serviceName, os, pageFileLocation);
                    computer.daemons.Add(webServerDaemon);
                }
                else if (reader.Name == "OnlineWebServer")
                {
                    reader.MoveToAttribute("name");
                    var serviceName = reader.ReadContentAsString();
                    reader.MoveToAttribute("url");
                    var url = reader.ReadContentAsString();
                    var onlineWebServerDaemon = new OnlineWebServerDaemon(computer, serviceName, os);
                    onlineWebServerDaemon.setURL(url);
                    computer.daemons.Add(onlineWebServerDaemon);
                }
                else if (reader.Name == "AcademicDatabse")
                {
                    reader.MoveToAttribute("name");
                    var serviceName            = reader.ReadContentAsString();
                    var academicDatabaseDaemon = new AcademicDatabaseDaemon(computer, serviceName, os);
                    computer.daemons.Add(academicDatabaseDaemon);
                }
                else if (reader.Name == "MissionHubServer")
                {
                    var missionHubServer = new MissionHubServer(computer, "unknown", "unknown", os);
                    computer.daemons.Add(missionHubServer);
                }
                else if (reader.Name == "DeathRowDatabase")
                {
                    var rowDatabaseDaemon = new DeathRowDatabaseDaemon(computer, "Death Row Database", os);
                    computer.daemons.Add(rowDatabaseDaemon);
                }
                else if (reader.Name == "MedicalDatabase")
                {
                    var medicalDatabaseDaemon = new MedicalDatabaseDaemon(computer, os);
                    computer.daemons.Add(medicalDatabaseDaemon);
                }
                else if (reader.Name == "HeartMonitor")
                {
                    var str7 = "UNKNOWN";
                    if (reader.MoveToAttribute("patient"))
                    {
                        str7 = reader.ReadContentAsString();
                    }
                    computer.daemons.Add(new HeartMonitorDaemon(computer, os)
                    {
                        PatientID = str7
                    });
                }
                else if (reader.Name.Equals("PointClicker"))
                {
                    var pointClickerDaemon = new PointClickerDaemon(computer, "Point Clicker!", os);
                    computer.daemons.Add(pointClickerDaemon);
                }
                else if (reader.Name.Equals("ispSystem"))
                {
                    var ispDaemon = new ISPDaemon(computer, os);
                    computer.daemons.Add(ispDaemon);
                }
                else if (reader.Name.Equals("porthackheart"))
                {
                    var porthackHeartDaemon = new PorthackHeartDaemon(computer, os);
                    computer.daemons.Add(porthackHeartDaemon);
                }
                else if (reader.Name.Equals("SongChangerDaemon"))
                {
                    var songChangerDaemon = new SongChangerDaemon(computer, os);
                    computer.daemons.Add(songChangerDaemon);
                }
                else if (reader.Name == "UploadServerDaemon")
                {
                    string str7;
                    var    input       = str7 = "";
                    var    foldername  = str7;
                    var    serviceName = str7;
                    if (reader.MoveToAttribute("name"))
                    {
                        serviceName = reader.ReadContentAsString();
                    }
                    if (reader.MoveToAttribute("foldername"))
                    {
                        foldername = reader.ReadContentAsString();
                    }
                    if (reader.MoveToAttribute("color"))
                    {
                        input = reader.ReadContentAsString();
                    }
                    var needsAuthentication = false;
                    if (reader.MoveToAttribute("needsAuh"))
                    {
                        needsAuthentication = reader.ReadContentAsBoolean();
                    }
                    var themeColor = Color.White;
                    if (input != "")
                    {
                        themeColor = Utils.convertStringToColor(input);
                    }
                    var uploadServerDaemon = new UploadServerDaemon(computer, serviceName, themeColor, os, foldername,
                                                                    needsAuthentication);
                    computer.daemons.Add(uploadServerDaemon);
                }
                reader.Read();
            }
            computer.files               = FileSystem.load(reader);
            computer.traceTime           = num1;
            computer.portsNeededForCrack = num2;
            computer.adminIP             = str5;
            computer.idName              = str2;
            computer.icon = str4;
            computer.attatchedDeviceIDs = str3;
            for (var index = 0; index < strArray.Length; ++index)
            {
                if (strArray[index] != "")
                {
                    computer.links.Add(Convert.ToInt32(strArray[index]));
                }
            }
            if (portsList.Length > 0)
            {
                ComputerLoader.loadPortsIntoComputer(portsList, computer);
            }
            if (str1 == "mail")
            {
                os.netMap.mailServer = computer;
            }
            else if (str1 == "player")
            {
                os.thisComputer = computer;
            }
            return(computer);
        }
Exemplo n.º 2
0
 public static Computer load(XmlReader reader, OS os)
 {
     while (reader.Name != "computer")
         reader.Read();
     reader.MoveToAttribute("name");
     var compName = reader.ReadContentAsString();
     reader.MoveToAttribute("ip");
     var compIP = reader.ReadContentAsString();
     reader.MoveToAttribute("type");
     var compType = (byte) reader.ReadContentAsInt();
     reader.MoveToAttribute("spec");
     var str1 = reader.ReadContentAsString();
     reader.MoveToAttribute("id");
     var str2 = reader.ReadContentAsString();
     string str3 = null;
     if (reader.MoveToAttribute("devices"))
         str3 = reader.ReadContentAsString();
     string str4 = null;
     if (reader.MoveToAttribute("icon"))
         str4 = reader.ReadContentAsString();
     while (reader.Name != "location")
         reader.Read();
     reader.MoveToAttribute("x");
     var x = reader.ReadContentAsFloat();
     reader.MoveToAttribute("y");
     var y = reader.ReadContentAsFloat();
     while (reader.Name != "security")
         reader.Read();
     reader.MoveToAttribute("level");
     var seclevel = reader.ReadContentAsInt();
     reader.MoveToAttribute("traceTime");
     var num1 = reader.ReadContentAsFloat();
     reader.MoveToAttribute("portsToCrack");
     var num2 = reader.ReadContentAsInt();
     reader.MoveToAttribute("adminIP");
     var str5 = reader.ReadContentAsString();
     var time = -1f;
     if (reader.MoveToAttribute("proxyTime"))
         time = reader.ReadContentAsFloat();
     while (reader.Name != "admin")
         reader.Read();
     reader.MoveToAttribute("type");
     var str6 = reader.ReadContentAsString();
     reader.MoveToAttribute("resetPass");
     var flag1 = reader.ReadContentAsBoolean();
     reader.MoveToAttribute("isSuper");
     var flag2 = reader.ReadContentAsBoolean();
     Administrator administrator = null;
     switch (str6)
     {
         case "fast":
             administrator = new FastBasicAdministrator();
             break;
         case "basic":
             administrator = new BasicAdministrator();
             break;
     }
     if (administrator != null)
         administrator.ResetsPassword = flag1;
     if (administrator != null)
         administrator.IsSuper = flag2;
     while (reader.Name != "links")
         reader.Read();
     var strArray = reader.ReadElementContentAsString().Split();
     Firewall firewall = null;
     while (reader.Name != "portsOpen" && reader.Name != "firewall")
         reader.Read();
     if (reader.Name == "firewall")
         firewall = Firewall.load(reader);
     while (reader.Name != "portsOpen")
         reader.Read();
     var portsList = reader.ReadElementContentAsString();
     var computer = new Computer(compName, compIP, new Vector2(x, y), seclevel, compType, os);
     computer.firewall = firewall;
     computer.admin = administrator;
     if (time > 0.0)
     {
         computer.addProxy(time);
     }
     else
     {
         computer.hasProxy = false;
         computer.proxyActive = false;
     }
     while (reader.Name != "users")
         reader.Read();
     computer.users.Clear();
     while (!(reader.Name == "users") || reader.NodeType != XmlNodeType.EndElement)
     {
         if (reader.Name == "user")
         {
             var userDetail = UserDetail.loadUserDetail(reader);
             if (userDetail.name.ToLower() == "admin")
                 computer.adminPass = userDetail.pass;
             computer.users.Add(userDetail);
         }
         reader.Read();
     }
     while (reader.Name != "daemons")
         reader.Read();
     reader.Read();
     while (!(reader.Name == "daemons") || reader.NodeType != XmlNodeType.EndElement)
     {
         if (reader.Name == "MailServer")
         {
             reader.MoveToAttribute("name");
             var name = reader.ReadContentAsString();
             var mailServer = new MailServer(computer, name, os);
             computer.daemons.Add(mailServer);
             if (reader.MoveToAttribute("color"))
             {
                 var newThemeColor = Utils.convertStringToColor(reader.ReadContentAsString());
                 mailServer.setThemeColor(newThemeColor);
             }
         }
         else if (reader.Name == "MissionListingServer")
         {
             reader.MoveToAttribute("name");
             var serviceName = reader.ReadContentAsString();
             reader.MoveToAttribute("group");
             var group = reader.ReadContentAsString();
             reader.MoveToAttribute("public");
             var _isPublic = reader.ReadContentAsString().ToLower().Equals("true");
             reader.MoveToAttribute("assign");
             var _isAssigner = reader.ReadContentAsString().ToLower().Equals("true");
             var missionListingServer = new MissionListingServer(computer, serviceName, group, os, _isPublic,
                 _isAssigner);
             computer.daemons.Add(missionListingServer);
         }
         else if (reader.Name == "AddEmailServer")
         {
             reader.MoveToAttribute("name");
             var serviceName = reader.ReadContentAsString();
             var addEmailDaemon = new AddEmailDaemon(computer, serviceName, os);
             computer.daemons.Add(addEmailDaemon);
         }
         else if (reader.Name == "MessageBoard")
         {
             reader.MoveToAttribute("name");
             var str7 = reader.ReadContentAsString();
             var messageBoardDaemon = new MessageBoardDaemon(computer, os);
             messageBoardDaemon.name = str7;
             computer.daemons.Add(messageBoardDaemon);
         }
         else if (reader.Name == "WebServer")
         {
             reader.MoveToAttribute("name");
             var serviceName = reader.ReadContentAsString();
             reader.MoveToAttribute("url");
             var pageFileLocation = reader.ReadContentAsString();
             var webServerDaemon = new WebServerDaemon(computer, serviceName, os, pageFileLocation);
             computer.daemons.Add(webServerDaemon);
         }
         else if (reader.Name == "OnlineWebServer")
         {
             reader.MoveToAttribute("name");
             var serviceName = reader.ReadContentAsString();
             reader.MoveToAttribute("url");
             var url = reader.ReadContentAsString();
             var onlineWebServerDaemon = new OnlineWebServerDaemon(computer, serviceName, os);
             onlineWebServerDaemon.setURL(url);
             computer.daemons.Add(onlineWebServerDaemon);
         }
         else if (reader.Name == "AcademicDatabse")
         {
             reader.MoveToAttribute("name");
             var serviceName = reader.ReadContentAsString();
             var academicDatabaseDaemon = new AcademicDatabaseDaemon(computer, serviceName, os);
             computer.daemons.Add(academicDatabaseDaemon);
         }
         else if (reader.Name == "MissionHubServer")
         {
             var missionHubServer = new MissionHubServer(computer, "unknown", "unknown", os);
             computer.daemons.Add(missionHubServer);
         }
         else if (reader.Name == "DeathRowDatabase")
         {
             var rowDatabaseDaemon = new DeathRowDatabaseDaemon(computer, "Death Row Database", os);
             computer.daemons.Add(rowDatabaseDaemon);
         }
         else if (reader.Name == "MedicalDatabase")
         {
             var medicalDatabaseDaemon = new MedicalDatabaseDaemon(computer, os);
             computer.daemons.Add(medicalDatabaseDaemon);
         }
         else if (reader.Name == "HeartMonitor")
         {
             var str7 = "UNKNOWN";
             if (reader.MoveToAttribute("patient"))
                 str7 = reader.ReadContentAsString();
             computer.daemons.Add(new HeartMonitorDaemon(computer, os)
             {
                 PatientID = str7
             });
         }
         else if (reader.Name.Equals("PointClicker"))
         {
             var pointClickerDaemon = new PointClickerDaemon(computer, "Point Clicker!", os);
             computer.daemons.Add(pointClickerDaemon);
         }
         else if (reader.Name.Equals("ispSystem"))
         {
             var ispDaemon = new ISPDaemon(computer, os);
             computer.daemons.Add(ispDaemon);
         }
         else if (reader.Name.Equals("porthackheart"))
         {
             var porthackHeartDaemon = new PorthackHeartDaemon(computer, os);
             computer.daemons.Add(porthackHeartDaemon);
         }
         else if (reader.Name.Equals("SongChangerDaemon"))
         {
             var songChangerDaemon = new SongChangerDaemon(computer, os);
             computer.daemons.Add(songChangerDaemon);
         }
         else if (reader.Name == "UploadServerDaemon")
         {
             string str7;
             var input = str7 = "";
             var foldername = str7;
             var serviceName = str7;
             if (reader.MoveToAttribute("name"))
                 serviceName = reader.ReadContentAsString();
             if (reader.MoveToAttribute("foldername"))
                 foldername = reader.ReadContentAsString();
             if (reader.MoveToAttribute("color"))
                 input = reader.ReadContentAsString();
             var needsAuthentication = false;
             if (reader.MoveToAttribute("needsAuh"))
                 needsAuthentication = reader.ReadContentAsBoolean();
             var themeColor = Color.White;
             if (input != "")
                 themeColor = Utils.convertStringToColor(input);
             var uploadServerDaemon = new UploadServerDaemon(computer, serviceName, themeColor, os, foldername,
                 needsAuthentication);
             computer.daemons.Add(uploadServerDaemon);
         }
         reader.Read();
     }
     computer.files = FileSystem.load(reader);
     computer.traceTime = num1;
     computer.portsNeededForCrack = num2;
     computer.adminIP = str5;
     computer.idName = str2;
     computer.icon = str4;
     computer.attatchedDeviceIDs = str3;
     for (var index = 0; index < strArray.Length; ++index)
     {
         if (strArray[index] != "")
             computer.links.Add(Convert.ToInt32(strArray[index]));
     }
     if (portsList.Length > 0)
         ComputerLoader.loadPortsIntoComputer(portsList, computer);
     if (str1 == "mail")
         os.netMap.mailServer = computer;
     else if (str1 == "player")
         os.thisComputer = computer;
     return computer;
 }