public DpsServerData(DpsServerData data) { UploadUrl = data.UploadUrl; AllowedAreaUrl = data.AllowedAreaUrl; GlyphUrl = data.GlyphUrl; Username = data.Username; Token = data.Token; Enabled = data.Enabled; }
private void ParseDpsServers() { var root = _xml.Root; var teradps = root.Element("dps_servers"); if (teradps == null) { return; } DpsServers = new List <DpsServerData>(); if (teradps.Elements("server") == null) { return; } foreach (var server in teradps.Elements("server")) { var username = server.Element("username"); var token = server.Element("token"); var enabled = server.Element("enabled"); var uploadUrl = server.Element("dps_url"); var allowedAreaUrl = server.Element("allowed_area_url"); var glyphUrl = server.Element("glyph_url"); var parseSuccess = bool.TryParse(enabled?.Value ?? "false", out bool enabledBool); if (String.IsNullOrWhiteSpace(uploadUrl?.Value)) { continue; } DpsServerData serverData = new DpsServerData( new Uri(uploadUrl.Value), String.IsNullOrWhiteSpace(allowedAreaUrl?.Value) ? null: new Uri(allowedAreaUrl.Value), String.IsNullOrWhiteSpace(glyphUrl?.Value) ? null : new Uri(glyphUrl.Value), username?.Value ?? null, token?.Value ?? null, enabledBool ); DpsServers.Add(serverData); } if (teradps.Element("blacklist") == null) { return; } if (teradps.Element("blacklist").Elements("id") == null) { return; } foreach (var blacklistedAreaId in teradps.Element("blacklist").Elements("id")) { var parseSuccess = int.TryParse(blacklistedAreaId.Value, out int areaId); if (parseSuccess) { blacklistedAreaId.Add(areaId); } } }
private void ParseOldDpsServers() { var root = _xml.Root; var teradps = root.Element("teradps.io"); if (teradps == null) { return; } var token = teradps.Element("token"); if (token != null) { DpsServerData.Moongourd.Token = token.Value; } var exp = teradps.Element("enabled"); if (exp != null) { var parseSuccess = bool.TryParse(exp.Value, out bool val); DpsServerData.Moongourd.Enabled = val; DpsServerData.TeraLogs.Enabled = val; } var privateS = teradps.Element("private_servers"); if (privateS == null) { return; } var exp1 = privateS.Attribute("enabled"); var parseS = bool.TryParse(exp1?.Value ?? "false", out bool enabled); if (!parseS || !privateS.HasElements) { return; } foreach (var server in privateS.Elements()) { if (String.IsNullOrWhiteSpace(server?.Value)) { continue; } DpsServerData serverData = new DpsServerData(new Uri(server.Value), null, null, null, null, enabled); DpsServers.Add(serverData); } }