示例#1
0
 public List <Computer> generateDemoNodes()
 {
     return(new List <Computer>
     {
         new Computer("AvCon Hatland Demo PC", "192.168.1.3", getRandomPosition(), 1, 2, os)
         {
             idName = "avcon1",
             externalCounterpart =
                 new ExternalCounterpart("avcon1", ExternalCounterpart.getIPForServerName("avconServer"))
         }
     });
 }
示例#2
0
 public static string getIPForServerName(string serverName)
 {
     if (ExternalCounterpart.networkIPList == null)
     {
         ExternalCounterpart.loadNetIPList();
     }
     if (ExternalCounterpart.networkIPList.ContainsKey(serverName))
     {
         return(ExternalCounterpart.networkIPList[serverName]);
     }
     throw new InvalidOperationException("Server Name Not Found");
 }
示例#3
0
 public static object loadComputer(string filename)
 {
     var rdr = XmlReader.Create(TitleContainer.OpenStream(filename));
     var str1 = "UNKNOWN";
     var compName = "UNKNOWN";
     string str2 = null;
     var seclevel = 0;
     byte compType = 1;
     var flag1 = true;
     var compIP = NetworkMap.generateRandomIP();
     while (rdr.Name != "Computer")
         rdr.Read();
     if (rdr.MoveToAttribute("id"))
         str1 = rdr.ReadContentAsString();
     if (rdr.MoveToAttribute("name"))
         compName = rdr.ReadContentAsString();
     if (rdr.MoveToAttribute("security"))
         seclevel = rdr.ReadContentAsInt();
     if (rdr.MoveToAttribute("type"))
         compType = (byte) rdr.ReadContentAsInt();
     if (rdr.MoveToAttribute("ip"))
         compIP = rdr.ReadContentAsString();
     if (rdr.MoveToAttribute("icon"))
         str2 = rdr.ReadContentAsString();
     if (rdr.MoveToAttribute("allowsDefaultBootModule"))
         flag1 = rdr.ReadContentAsBoolean();
     var computer1 = new Computer(compName, compIP, os.netMap.getRandomPosition(), seclevel, compType, os);
     computer1.idName = str1;
     computer1.AllowsDefaultBootModule = flag1;
     computer1.icon = str2;
     if (computer1.type == 4)
     {
         var folder = computer1.files.root.searchForFolder("home");
         if (folder != null)
         {
             folder.files.Clear();
             folder.folders.Clear();
         }
     }
     while (rdr.Name != "Computer")
     {
         if (rdr.Name.Equals("file"))
         {
             var path = !rdr.MoveToAttribute("path") ? "home" : rdr.ReadContentAsString();
             var str3 = filter(!rdr.MoveToAttribute("name") ? "Data" : rdr.ReadContentAsString());
             var num = (int) rdr.MoveToContent();
             var s = rdr.ReadElementContentAsString();
             if (s.Equals(""))
                 s = Computer.generateBinaryString(500);
             var dataEntry = filter(s);
             var folderFromPath = computer1.getFolderFromPath(path, true);
             if (folderFromPath.searchForFile(str3) != null)
                 folderFromPath.searchForFile(str3).data = dataEntry;
             else
                 folderFromPath.files.Add(new FileEntry(dataEntry, str3));
         }
         if (rdr.Name.Equals("encryptedFile"))
         {
             var flag2 = false;
             var path = !rdr.MoveToAttribute("path") ? "home" : rdr.ReadContentAsString();
             var s1 = !rdr.MoveToAttribute("name") ? "Data" : rdr.ReadContentAsString();
             var header = !rdr.MoveToAttribute("header") ? "ERROR" : rdr.ReadContentAsString();
             var ipLink = !rdr.MoveToAttribute("ip") ? "ERROR" : rdr.ReadContentAsString();
             var pass = !rdr.MoveToAttribute("pass") ? "" : rdr.ReadContentAsString();
             var fileExtension = !rdr.MoveToAttribute("extension") ? null : rdr.ReadContentAsString();
             if (rdr.MoveToAttribute("double"))
                 flag2 = rdr.ReadContentAsBoolean();
             var str3 = filter(s1);
             var num = (int) rdr.MoveToContent();
             var s2 = rdr.ReadElementContentAsString();
             if (s2.Equals(""))
                 s2 = Computer.generateBinaryString(500);
             var data = filter(s2);
             if (flag2)
                 data = FileEncrypter.EncryptString(data, header, ipLink, pass, fileExtension);
             var dataEntry = FileEncrypter.EncryptString(data, header, ipLink, pass,
                 flag2 ? "_LAYER2.dec" : fileExtension);
             var folderFromPath = computer1.getFolderFromPath(path, true);
             if (folderFromPath.searchForFile(str3) != null)
                 folderFromPath.searchForFile(str3).data = dataEntry;
             else
                 folderFromPath.files.Add(new FileEntry(dataEntry, str3));
         }
         else if (rdr.Name.Equals("ports"))
         {
             var num = (int) rdr.MoveToContent();
             loadPortsIntoComputer(rdr.ReadElementContentAsString(), computer1);
         }
         else if (rdr.Name.Equals("positionNear"))
         {
             var ip_Or_ID_or_Name = "";
             if (rdr.MoveToAttribute("target"))
                 ip_Or_ID_or_Name = rdr.ReadContentAsString();
             var num = 0;
             var total = 3;
             if (rdr.MoveToAttribute("position"))
                 num = rdr.ReadContentAsInt();
             var positionNumber = num + 1;
             if (rdr.MoveToAttribute("total"))
                 total = rdr.ReadContentAsInt();
             var computer2 = Programs.getComputer(os, ip_Or_ID_or_Name);
             if (computer2 != null)
                 computer1.location = computer2.location +
                                      Corporation.getNearbyNodeOffset(computer2.location, positionNumber, total,
                                          os.netMap);
         }
         else if (rdr.Name.Equals("proxy"))
         {
             var num = 1f;
             if (rdr.MoveToAttribute("time"))
                 num = rdr.ReadContentAsFloat();
             if (num > 0.0)
             {
                 computer1.addProxy(Computer.BASE_PROXY_TICKS*num);
             }
             else
             {
                 computer1.hasProxy = false;
                 computer1.proxyActive = false;
             }
         }
         else if (rdr.Name.Equals("portsForCrack"))
         {
             var num = -1;
             if (rdr.MoveToAttribute("val"))
                 num = rdr.ReadContentAsInt();
             if (num != -1)
                 computer1.portsNeededForCrack = num - 1;
         }
         else if (rdr.Name.Equals("firewall"))
         {
             var level = 1;
             if (rdr.MoveToAttribute("level"))
                 level = rdr.ReadContentAsInt();
             if (level > 0)
             {
                 string solution = null;
                 var additionalTime = 0.0f;
                 if (rdr.MoveToAttribute("solution"))
                     solution = rdr.ReadContentAsString();
                 if (rdr.MoveToAttribute("additionalTime"))
                     additionalTime = rdr.ReadContentAsFloat();
                 if (solution != null)
                     computer1.addFirewall(level, solution, additionalTime);
                 else
                     computer1.addFirewall(level);
             }
             else
                 computer1.firewall = null;
         }
         else if (rdr.Name.Equals("link"))
         {
             var ip_Or_ID_or_Name = "";
             if (rdr.MoveToAttribute("target"))
                 ip_Or_ID_or_Name = rdr.ReadContentAsString();
             var computer2 = Programs.getComputer(os, ip_Or_ID_or_Name);
             if (computer2 != null)
                 computer1.links.Add(os.netMap.nodes.IndexOf(computer2));
         }
         else if (rdr.Name.Equals("dlink"))
         {
             var comp = "";
             if (rdr.MoveToAttribute("target"))
                 comp = rdr.ReadContentAsString();
             var local = computer1;
             postAllLoadedActions += () =>
             {
                 var computer2 = Programs.getComputer(os, comp);
                 if (computer2 == null)
                     return;
                 local.links.Add(os.netMap.nodes.IndexOf(computer2));
             };
         }
         else if (rdr.Name.Equals("trace"))
         {
             var num = 1f;
             if (rdr.MoveToAttribute("time"))
                 num = rdr.ReadContentAsFloat();
             computer1.traceTime = num;
         }
         else if (rdr.Name.Equals("adminPass"))
         {
             string newPass = null;
             if (rdr.MoveToAttribute("pass"))
                 newPass = rdr.ReadContentAsString();
             if (newPass == null)
                 newPass = PortExploits.getRandomPassword();
             computer1.setAdminPassword(newPass);
         }
         else if (rdr.Name.Equals("admin"))
         {
             var str3 = "basic";
             var flag2 = true;
             var flag3 = false;
             if (rdr.MoveToAttribute("type"))
                 str3 = rdr.ReadContentAsString();
             if (rdr.MoveToAttribute("resetPassword"))
                 flag2 = rdr.ReadContentAsBoolean();
             if (rdr.MoveToAttribute("isSuper"))
                 flag3 = rdr.ReadContentAsBoolean();
             switch (str3)
             {
                 case "fast":
                     computer1.admin = new FastBasicAdministrator();
                     break;
                 default:
                     computer1.admin = new BasicAdministrator();
                     break;
             }
             computer1.admin.ResetsPassword = flag2;
             computer1.admin.IsSuper = flag3;
         }
         else if (rdr.Name.Equals("ExternalCounterpart"))
         {
             var serverName = "";
             var idName = "";
             if (rdr.MoveToAttribute("id"))
                 serverName = rdr.ReadContentAsString();
             if (rdr.MoveToAttribute("name"))
                 idName = rdr.ReadContentAsString();
             var externalCounterpart = new ExternalCounterpart(idName,
                 ExternalCounterpart.getIPForServerName(serverName));
             computer1.externalCounterpart = externalCounterpart;
         }
         else if (rdr.Name.Equals("account"))
         {
             byte accountType = 0;
             string s1;
             var s2 = s1 = "ERROR";
             if (rdr.MoveToAttribute("username"))
                 s2 = rdr.ReadContentAsString();
             if (rdr.MoveToAttribute("password"))
                 s1 = rdr.ReadContentAsString();
             if (rdr.MoveToAttribute("type"))
                 accountType = (byte) rdr.ReadContentAsInt();
             var user = filter(s2);
             var password = filter(s1);
             var flag2 = false;
             for (var index = 0; index < computer1.users.Count; ++index)
             {
                 var userDetail = computer1.users[index];
                 if (userDetail.name.Equals(user))
                 {
                     userDetail.pass = password;
                     userDetail.type = accountType;
                     computer1.users[index] = userDetail;
                     if (user.Equals("admin"))
                         computer1.adminPass = password;
                     flag2 = true;
                 }
             }
             if (!flag2)
             {
                 var userDetail = new UserDetail(user, password, accountType);
                 computer1.users.Add(userDetail);
             }
         }
         else if (rdr.Name.Equals("missionListingServer"))
         {
             var flag2 = false;
             var _isPublic = false;
             string serviceName;
             var group = serviceName = "ERROR";
             if (rdr.MoveToAttribute("name"))
                 serviceName = rdr.ReadContentAsString();
             if (rdr.MoveToAttribute("group"))
                 group = rdr.ReadContentAsString();
             if (rdr.MoveToAttribute("assigner"))
                 flag2 = rdr.ReadContentAsBoolean();
             if (rdr.MoveToAttribute("public"))
                 _isPublic = rdr.ReadContentAsBoolean();
             computer1.daemons.Add(new MissionListingServer(computer1, serviceName, group, os, _isPublic, false)
             {
                 missionAssigner = flag2
             });
         }
         else if (rdr.Name.Equals("mailServer"))
         {
             var name = "Mail Server";
             if (rdr.MoveToAttribute("name"))
                 name = rdr.ReadContentAsString();
             var ms = new MailServer(computer1, name, os);
             if (rdr.MoveToAttribute("color"))
                 ms.setThemeColor(Utils.convertStringToColor(rdr.ReadContentAsString()));
             while (!(rdr.Name == "mailServer") || rdr.IsStartElement())
             {
                 if (rdr.Name == "email")
                 {
                     var sender = "UNKNOWN";
                     string str3 = null;
                     var subject = "UNKNOWN";
                     if (rdr.MoveToAttribute("sender"))
                         sender = rdr.ReadContentAsString();
                     if (rdr.MoveToAttribute("recipient"))
                         str3 = rdr.ReadContentAsString();
                     if (rdr.MoveToAttribute("subject"))
                         subject = rdr.ReadContentAsString();
                     var num = (int) rdr.MoveToContent();
                     var body = rdr.ReadElementContentAsString();
                     if (str3 != null)
                     {
                         var email = MailServer.generateEmail(subject, body, sender);
                         var recp = str3;
                         ms.setupComplete += () => ms.addMail(email, recp);
                     }
                 }
                 rdr.Read();
             }
             computer1.daemons.Add(ms);
         }
         else if (rdr.Name.Equals("addEmailDaemon"))
         {
             var addEmailDaemon = new AddEmailDaemon(computer1, "Final Task", os);
             computer1.daemons.Add(addEmailDaemon);
         }
         else if (rdr.Name.Equals("deathRowDatabase"))
         {
             var rowDatabaseDaemon = new DeathRowDatabaseDaemon(computer1, "Death Row Database", os);
             computer1.daemons.Add(rowDatabaseDaemon);
         }
         else if (rdr.Name.Equals("ispSystem"))
         {
             var ispDaemon = new ISPDaemon(computer1, os);
             computer1.daemons.Add(ispDaemon);
         }
         else if (rdr.Name.Equals("messageBoard"))
         {
             var messageBoardDaemon = new MessageBoardDaemon(computer1, os);
             var str3 = "Anonymous";
             if (rdr.MoveToAttribute("name"))
                 str3 = rdr.ReadContentAsString();
             messageBoardDaemon.name = str3;
             while (!(rdr.Name == "messageBoard") || rdr.IsStartElement())
             {
                 if (rdr.Name == "thread")
                 {
                     var num = (int) rdr.MoveToContent();
                     var filename1 = rdr.ReadElementContentAsString();
                     if (filename1 != null)
                         messageBoardDaemon.AddThread(Utils.readEntireFile(filename1));
                 }
                 rdr.Read();
             }
             computer1.daemons.Add(messageBoardDaemon);
         }
         else if (rdr.Name.Equals("addAvconDemoEndDaemon"))
         {
             var avconDemoEndDaemon = new AvconDemoEndDaemon(computer1, "Demo End", os);
             computer1.daemons.Add(avconDemoEndDaemon);
         }
         else if (rdr.Name.Equals("addWebServer"))
         {
             var serviceName = "Web Server";
             string pageFileLocation = null;
             if (rdr.MoveToAttribute("name"))
                 serviceName = rdr.ReadContentAsString();
             if (rdr.MoveToAttribute("url"))
                 pageFileLocation = rdr.ReadContentAsString();
             var webServerDaemon = new WebServerDaemon(computer1, serviceName, os, pageFileLocation);
             webServerDaemon.registerAsDefaultBootDaemon();
             computer1.daemons.Add(webServerDaemon);
         }
         else if (rdr.Name.Equals("addOnlineWebServer"))
         {
             var serviceName = "Web Server";
             string url = null;
             if (rdr.MoveToAttribute("name"))
                 serviceName = rdr.ReadContentAsString();
             if (rdr.MoveToAttribute("url"))
                 url = rdr.ReadContentAsString();
             var onlineWebServerDaemon = new OnlineWebServerDaemon(computer1, serviceName, os);
             if (url != null)
                 onlineWebServerDaemon.setURL(url);
             onlineWebServerDaemon.registerAsDefaultBootDaemon();
             computer1.daemons.Add(onlineWebServerDaemon);
         }
         else if (rdr.Name.Equals("uploadServerDaemon"))
         {
             var serviceName = "File Upload Server";
             string foldername = null;
             var input = "0,94,38";
             var needsAuthentication = false;
             if (rdr.MoveToAttribute("name"))
                 serviceName = rdr.ReadContentAsString();
             if (rdr.MoveToAttribute("folder"))
                 foldername = rdr.ReadContentAsString();
             if (rdr.MoveToAttribute("color"))
                 input = rdr.ReadContentAsString();
             if (rdr.MoveToAttribute("needsAuth"))
                 needsAuthentication = rdr.ReadContentAsString().ToLower() == "true";
             var themeColor = Utils.convertStringToColor(input);
             var uploadServerDaemon = new UploadServerDaemon(computer1, serviceName, themeColor, os, foldername,
                 needsAuthentication);
             uploadServerDaemon.registerAsDefaultBootDaemon();
             computer1.daemons.Add(uploadServerDaemon);
         }
         else if (rdr.Name.Equals("MedicalDatabase"))
         {
             var medicalDatabaseDaemon = new MedicalDatabaseDaemon(computer1, os);
             computer1.daemons.Add(medicalDatabaseDaemon);
         }
         else if (rdr.Name.Equals("HeartMonitor"))
         {
             var str3 = "UNKNOWN";
             if (rdr.MoveToAttribute("patient"))
                 str3 = rdr.ReadContentAsString();
             computer1.daemons.Add(new HeartMonitorDaemon(computer1, os)
             {
                 PatientID = str3
             });
         }
         else if (rdr.Name.Equals("PointClicker"))
         {
             var pointClickerDaemon = new PointClickerDaemon(computer1, "Point Clicker!", os);
             computer1.daemons.Add(pointClickerDaemon);
         }
         else if (rdr.Name.Equals("PorthackHeart"))
         {
             var porthackHeartDaemon = new PorthackHeartDaemon(computer1, os);
             computer1.daemons.Add(porthackHeartDaemon);
         }
         else if (rdr.Name.Equals("SongChangerDaemon"))
         {
             var songChangerDaemon = new SongChangerDaemon(computer1, os);
             computer1.daemons.Add(songChangerDaemon);
         }
         else if (rdr.Name.Equals("eosDevice"))
             EOSComp.AddEOSComp(rdr, computer1, os);
         rdr.Read();
     }
     computer1.initDaemons();
     os.netMap.nodes.Add(computer1);
     return computer1;
 }