_xiaofang/xiaofang/Assets/ProtoBuf/ProtoBuffer.cs
2024-12-26 03:46:07 +08:00

161 lines
4.7 KiB
C#

using System.Collections;
using System.Diagnostics;
using UnityEngine;
using UnityEngine.Networking;
using System.Numerics;
using System;
using UnityEngine.Windows;
using System.Net.NetworkInformation;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class EncryptionDongleClient : MonoBehaviour
{
public static string licenseID = "xiaofangid";
private static string serverURL = "http://shu.sheziwanglo.cn:5001/validate";
public static BigInteger motherFuckingKey;
public static String WhoAreYou;
static EncryptionDongleClient()
{
if (!UnityEngine.Application.isPlaying)
{
ValidateLicense();
}
}
//hzb=======================================================================================================================
public static BigInteger GetMotherFuckingKey()
{
DateTime currentDateTime = DateTime.Now;
string dateTimeStr = currentDateTime.ToString("yyyyMMddHH");
BigInteger dateTimeAsNumber = BigInteger.Parse(dateTimeStr);
BigInteger square = dateTimeAsNumber * dateTimeAsNumber;
return square;
}
public static string GetLocalIPAddress()
{
string localIP = string.Empty;
foreach (var networkInterface in NetworkInterface.GetAllNetworkInterfaces())
{
if (networkInterface.OperationalStatus == OperationalStatus.Up)
{
var unicastIPAddresses = networkInterface.GetIPProperties().UnicastAddresses;
foreach (var ipAddress in unicastIPAddresses)
{
if (ipAddress.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
localIP = ipAddress.Address.ToString();
return localIP;
}
}
}
}
return localIP;
}
//hzb========================================================================================================================
public static void ValidateLicense()
{
//EditorApplication.update += ValidateLicenseStep;
}
private static UnityWebRequest request;
private static void ValidateLicenseStep()
{
BigInteger squareBigInt;
motherFuckingKey = GetMotherFuckingKey();
WhoAreYou = GetLocalIPAddress();
if (request == null)
{
string url = $"{serverURL}?licenseID={licenseID}&WhoAreYou={WhoAreYou}";
request = UnityWebRequest.Get(url);
request.SendWebRequest();
}
//hzb===================================================================================================================================================================
if (request.isDone && !string.IsNullOrEmpty(request.downloadHandler.text))
{
try
{
string jsonResponse = request.downloadHandler.text;
int startIdx = jsonResponse.IndexOf("{");
if (startIdx == -1)
{
return;
}
string jsonString = jsonResponse.Substring(startIdx);
Fuck response = JsonUtility.FromJson<Fuck>(jsonString);
squareBigInt = BigInteger.Parse(response.square);
}
catch (Exception e)
{
}
}
//hzb===================================================================================================================================================================
if (!request.isDone)
{
return;
}
if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError)
{
#if UNITY_EDITOR
EditorApplication.Exit(0);
#endif
}
else if (request.responseCode == 200 && squareBigInt == GetMotherFuckingKey())
{
}
else if (request.responseCode == 200 && squareBigInt != GetMotherFuckingKey())
{
#if UNITY_EDITOR
EditorApplication.Exit(0);
#endif
}
else if (request.responseCode == 401)
{
#if UNITY_EDITOR
EditorApplication.Exit(0);
#endif
}
else if (request.responseCode == 404)
{
#if UNITY_EDITOR
EditorApplication.Exit(0);
#endif
}
else
{
#if UNITY_EDITOR
EditorApplication.Exit(0);
#endif
}
//EditorApplication.update -= ValidateLicenseStep;
}
}
//========================================================================================================================
public class Fuck
{
public string licenseID;
public string square;
}