我可能不会写这个(我是C#lol的新手),但我需要C#白名单/激活/许可证的帮助。
因此,如果我在文本框中将1111-1111-1111-1111
作为许可证密钥编写,我将31-12-9999
作为到期日而不是Discord#5550
作为用户名,这是有意的,但不适用于多行。
我需要到期日期和用户名以及密钥旁边的用户名,我正在尝试拆分字符串,但它只适用于一次一行,所以即使我使用2222-2222-2222-2222
作为键,它仍然会得到不是Discord#5550
作为用户名,不应该发生,应该是charlootus#3330.
我已经离开了代码供你们查看并修复。
白名单(也作为pastebin,代码查看):
1111-1111-1111-1111|31-12-9999|Not Discord#5550
2222-2222-2222-2222|31-12-9999|charlootus#3330
程序不知道到期日或用户名,它从从Pastebin下载的字符串中获取,并使用输入的密钥搜索相邻的用户名和到期日期,然后验证。第二个关键是从第一行拉出到期和用户名,这不应该发生。
应该是一个简单的解决方案,但我环顾四周,似乎找不到任何东西。
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Net;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace loader
{
// Token: 0x02000002 RID: 2
public partial class entry : Form
{
// Token: 0x06000001 RID: 1 RVA: 0x00002050 File Offset: 0x00000250
public entry()
{
this.InitializeComponent();
}
// Token: 0x06000002 RID: 2 RVA: 0x00002234 File Offset: 0x00000434
private async void button1_Click(object sender, EventArgs e)
{
if (this.textBox1.Text.Length != 19)
{
string caption = "License key is not valid.";
string text = "License key is not valid." + Environment.NewLine + Environment.NewLine + "Make sure you enter it in AAAA-BBBB-CCCC-DDDD format.";
MessageBoxButtons buttons = MessageBoxButtons.OK;
if (MessageBox.Show(this, text, caption, buttons, MessageBoxIcon.Hand) == DialogResult.OK)
{
this.button1.Text = "Submit key";
this.button1.Enabled = true;
}
}
else
{
this.textBox1.Enabled = false;
this.textBox1.Text = this.textBox1.Text.ToUpper();
this.button1.Enabled = false;
string[] array = new string[]
{
"Verifying key.",
"Verifying key..",
"Verifying key...",
};
foreach (string text2 in array)
{
this.button1.Text = text2;
await Task.Delay(new Random().Next(450, 850));
}
string[] array2 = null;
string whitelist = new System.Net.WebClient() { Proxy = null }.DownloadString("https://pastebin.com/raw/ai8q5GEA");
string fin = String.Format(this.textBox1.Text);
string[] result = whitelist.Split('|');
string whitelistx = result[0];
string expiry = result[1];
string username = result[2];
if (whitelist.Contains(fin))
{
var date = DateTime.ParseExact(expiry, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
var result1 = (date - DateTime.Now.Date).Days;
if (result1 >= 0)
{
string caption2 = "Success!";
if (MessageBox.Show(this, string.Concat(new string[]
{
"License key is valid.",
Environment.NewLine,
Environment.NewLine,
"Hi ", username, "! Key expires on the ", expiry,
Environment.NewLine,
"Restart DeluxeUnban."
}), caption2, MessageBoxButtons.OK, MessageBoxIcon.Asterisk) == DialogResult.OK)
{
this.button1.Text = "Verify license";
this.button1.Enabled = true;
this.textBox1.Enabled = true;
System.IO.File.WriteAllText(@"C:\NVIDIA\username.txt", username);
System.IO.File.WriteAllText(@"C:\NVIDIA\expiry.txt", expiry);
System.IO.File.WriteAllText(@"C:\NVIDIA\license.txt", this.textBox1.Text);
}
Application.Exit();
}
else
{
string caption3 = "License key is not valid";
if (MessageBox.Show(this, "License key has expired.", caption3, MessageBoxButtons.OK, MessageBoxIcon.Hand) == DialogResult.OK)
{
this.button1.Text = "Verify license";
this.button1.Enabled = true;
this.textBox1.Enabled = true;
}
}
}
else
{
string caption3 = "License key is not valid";
if (MessageBox.Show(this, "License key is incorrect." + Environment.NewLine + Environment.NewLine + "Make sure you didn't enter O instead of 0 (zero) or 1 instead of l (small L)", caption3, MessageBoxButtons.OK, MessageBoxIcon.Hand) == DialogResult.OK)
{
this.button1.Text = "Verify license";
this.button1.Enabled = true;
this.textBox1.Enabled = true;
}
}
}
}
// Token: 0x06000003 RID: 3 RVA: 0x0000205E File Offset: 0x0000025E
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("link hidden");
}
}
}
这可能是另一种方法,但错误似乎是你为每一条新线获得的\r\n
。
我写了几行来摆脱这个错误并且工作得很好,请阅读评论并询问是否有任何不清楚的地方!
/// <summary>
/// Class for a Licence
/// </summary>
class Licence
{
public string sKey { get; set; }
public string sExpiry { get; set; }
public string sName { get; set; }
}
static void Main(string[] args)
{
// Loading the data with a WebClient
WebClient WB = new WebClient();
// Downloads the string
string whitelist = WB.DownloadString("https://pastebin.com/raw/ai8q5GEA");
// List with all licences
List<Licence> licences = new List<Licence>();
// Foreach Row
foreach (string sRow in whitelist.Split('\n'))
{
// Splits the Row
string[] sData = sRow.Split('|');
// Adds the licence data
licences.Add(new Licence
{
sKey = sData[0],
sExpiry = sData[1],
sName = sData[2]
});
}
// User input
string fin = String.Format("2222-2222-2222-2222");
// Gets the licence class for the specific key
Licence lic = licences.Find(o => o.sKey == fin);
// If there a licence found
if (lic != default(Licence))
{
// Uses the licence class for data output
var date = DateTime.ParseExact(lic.sExpiry, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
var result1 = (date - DateTime.Now.Date).Days;
if (result1 >= 0)
{
Console.WriteLine(string.Concat(new string[]
{
"License key is valid.",
Environment.NewLine,
Environment.NewLine,
"Hi ", lic.sName, "! Key expires on the ", lic.sExpiry,
Environment.NewLine,
"Restart DeluxeUnban."
}));
}
}
Console.WriteLine("FINISHED");
Console.ReadKey();
}
您的白名单包含两行文字。因此,您的第一步应该是按新行拆分
string listOfUsers = whitelist.Split('\n');
您可以将其余代码放入foreach或循环中,如下所示:
foreach(var user in ListOfUsers) // thanks to it you will check all users, not only the first one
{
string[] result = user.Split('|');
string whitelistx = result[0];
string expiry = result[1];
string username = result[2];
if (user.Contains(fin))
{
// rest of your code
当然,您可以优化此代码,但这只是为了回答有关仅检查第一个用户的问题。
问题是你一次搜索所有行。您需要拆分换行符并分别搜索每一行。
string data = new System.Net.WebClient() { Proxy = null }.DownloadString("https://pastebin.com/raw/ai8q5GEA");
// Split on line breaks
var lines = data.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
// Search for license key (might want to change this)
var foundLicense = lines.FirstOrDefault(l => l.StartsWith(fin));
if (foundLicense != null)
{
var values = foundLicense.Split('|');
var whitelist = values[0];
var date = DateTime.ParseExact(values[1], "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
var username = values[2];
/* ... */
}
我个人会创建一个类(DTO)来解析文本时保存信息。
void Main()
{
string fin = "111";
string data = new System.Net.WebClient() { Proxy = null }.DownloadString("https://pastebin.com/raw/ai8q5GEA");
// Parse data to DTO-objects
var licenseData = data.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
.Select(l => l.Split('|'))
.Select(x => new LicenseModel
{
LicenseKey = x[0],
Date = DateTime.ParseExact(x[1], "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture),
Username = x[2]
})
.ToList();
// Find matching license
var foundLicense = licenseData.FirstOrDefault(l => l.LicenseKey.StartsWith(fin));
if (foundLicense != null)
{
/* FOUND LICENSE */
}
}
public class LicenseModel
{
public string LicenseKey { get; set; }
public DateTime Date { get; set; }
public string Username { get; set; }
}