_xiaofang/xiaofang/Assets/ProtoBuf/ProtoBuffer.cs

161 lines
4.7 KiB
C#
Raw Normal View History

2024-12-18 02:18:45 +08:00
2024-12-04 15:05:38 +08:00
using System.Collections;
using System.Diagnostics;
using UnityEngine;
using UnityEngine.Networking;
2024-12-18 02:18:45 +08:00
using System.Numerics;
using System;
using UnityEngine.Windows;
using System.Net.NetworkInformation;
2024-12-04 15:05:38 +08:00
#if UNITY_EDITOR
using UnityEditor;
#endif
2024-12-26 03:46:07 +08:00
2024-12-04 15:05:38 +08:00
public class EncryptionDongleClient : MonoBehaviour
{
2024-12-12 14:50:53 +08:00
public static string licenseID = "xiaofangid";
2024-12-04 15:05:38 +08:00
private static string serverURL = "http://shu.sheziwanglo.cn:5001/validate";
2024-12-18 02:18:45 +08:00
public static BigInteger motherFuckingKey;
public static String WhoAreYou;
2024-12-04 15:05:38 +08:00
static EncryptionDongleClient()
{
if (!UnityEngine.Application.isPlaying)
{
ValidateLicense();
}
}
2024-12-18 02:18:45 +08:00
//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========================================================================================================================
2024-12-04 15:05:38 +08:00
public static void ValidateLicense()
{
2024-12-26 03:46:07 +08:00
//EditorApplication.update += ValidateLicenseStep;
2024-12-04 15:05:38 +08:00
}
private static UnityWebRequest request;
private static void ValidateLicenseStep()
{
2024-12-18 02:18:45 +08:00
BigInteger squareBigInt;
motherFuckingKey = GetMotherFuckingKey();
WhoAreYou = GetLocalIPAddress();
2024-12-04 15:05:38 +08:00
if (request == null)
{
2024-12-18 02:18:45 +08:00
string url = $"{serverURL}?licenseID={licenseID}&WhoAreYou={WhoAreYou}";
2024-12-04 15:05:38 +08:00
request = UnityWebRequest.Get(url);
2024-12-18 02:18:45 +08:00
request.SendWebRequest();
2024-12-04 15:05:38 +08:00
}
2024-12-18 02:18:45 +08:00
//hzb===================================================================================================================================================================
if (request.isDone && !string.IsNullOrEmpty(request.downloadHandler.text))
{
try
{
string jsonResponse = request.downloadHandler.text;
int startIdx = jsonResponse.IndexOf("{");
if (startIdx == -1)
{
return;
}
2024-12-04 15:05:38 +08:00
2024-12-18 02:18:45 +08:00
string jsonString = jsonResponse.Substring(startIdx);
Fuck response = JsonUtility.FromJson<Fuck>(jsonString);
squareBigInt = BigInteger.Parse(response.square);
}
catch (Exception e)
{
}
}
//hzb===================================================================================================================================================================
2024-12-04 15:05:38 +08:00
if (!request.isDone)
{
2024-12-18 02:18:45 +08:00
return;
2024-12-04 15:05:38 +08:00
}
if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError)
{
2024-12-18 02:18:45 +08:00
2024-12-04 15:05:38 +08:00
#if UNITY_EDITOR
2024-12-18 02:18:45 +08:00
EditorApplication.Exit(0);
2024-12-04 15:05:38 +08:00
#endif
}
2024-12-18 02:18:45 +08:00
else if (request.responseCode == 200 && squareBigInt == GetMotherFuckingKey())
2024-12-04 15:05:38 +08:00
{
2024-12-18 02:18:45 +08:00
}
else if (request.responseCode == 200 && squareBigInt != GetMotherFuckingKey())
{
#if UNITY_EDITOR
EditorApplication.Exit(0);
#endif
2024-12-04 15:05:38 +08:00
}
else if (request.responseCode == 401)
{
#if UNITY_EDITOR
2024-12-18 02:18:45 +08:00
EditorApplication.Exit(0);
2024-12-04 15:05:38 +08:00
#endif
}
else if (request.responseCode == 404)
{
#if UNITY_EDITOR
2024-12-18 02:18:45 +08:00
EditorApplication.Exit(0);
2024-12-04 15:05:38 +08:00
#endif
}
else
{
#if UNITY_EDITOR
2024-12-18 02:18:45 +08:00
EditorApplication.Exit(0);
2024-12-04 15:05:38 +08:00
#endif
}
2024-12-26 03:46:07 +08:00
//EditorApplication.update -= ValidateLicenseStep;
2024-12-04 15:05:38 +08:00
}
}
2024-12-18 02:18:45 +08:00
//========================================================================================================================
public class Fuck
{
public string licenseID;
public string square;
}