unity3d mac地址校验 有效期验证
来源:互联网 发布:淘宝ebay代购 编辑:程序博客网 时间:2024/05/20 22:00
FileUtil.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Text;
public class FileUtil{
public static string GetValue(string fileName)
{
string absPath = Application.streamingAssetsPath + "/" + fileName + ".unity3d";
Debug.Log("absPath=" + absPath);
if (!File.Exists(absPath)) return "";
FileStream fs = new FileStream(absPath, FileMode.OpenOrCreate, FileAccess.Read);
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, (int)fs.Length);
fs.Close();
string value = Encoding.UTF8.GetString(bytes);
return value;
}
public static void SetValue(string fileName,string valule)
{
string path = Application.streamingAssetsPath + "/" + fileName + ".unity3d";
Debug.Log("path="+ path);
FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.Flush();
sw.BaseStream.Seek(0, SeekOrigin.Begin);
sw.Write(valule);
sw.Close();
}
}
VerifyMacAddress.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HutongGames.PlayMaker;
using System.Net.NetworkInformation;
using Tooltip = UnityEngine.TooltipAttribute;
public class VerifyMacAddress : FsmStateAction {
[UIHint(UIHint.Variable)]
[Tooltip("电脑物理地址串/mac地址")]
public FsmString mac;
[UIHint(UIHint.Variable)]
[Tooltip("有效标记")]
public FsmBool valid;
[UIHint(UIHint.FsmEvent)]
[Tooltip("验证通过事件")]
public FsmEvent valided;
[UIHint(UIHint.FsmEvent)]
[Tooltip("验证失败事件")]
public FsmEvent notValided;
public override void OnEnter()
{
NetworkInterface[] nis = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface ni in nis)
{
string macTemp = ni.GetPhysicalAddress().ToString();
Debug.Log(macTemp);
mac.Value += macTemp + "|";
}
#region use PlayerPrefs keep the mac address .but it is not ok on a new pc which also can run right.we want it can't run on new pc.
//if (PlayerPrefs.HasKey("mac"))
//{
// Debug.Log("有mac持久化值");
// if (mac.Value.Equals(PlayerPrefs.GetString("mac")))
// {
// valid.Value = true;
// }
// else
// {
// valid.Value = false;
// }
//}
//else
//{
// Debug.Log("无mac持久化值");
// valid.Value = true;
// PlayerPrefs.SetString("mac", mac.Value);
// PlayerPrefs.Save();
//}
#endregion
string storedMac = FileUtil.GetValue("q");
if (storedMac.Length > 0)
{
Debug.Log("有mac持久化值");
if (storedMac.Equals(mac.Value))
{
valid.Value = true;
}
else
{
valid.Value = false;
}
}
else
{
Debug.Log("无mac持久化值");
//初始化数据
valid.Value = true;
FileUtil.SetValue("q",mac.Value);
}
if (valid.Value)
{
Fsm.Event(valided);
}
else
{
Fsm.Event(notValided);
}
}
}
VerifyTime.cs
using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
using HutongGames.PlayMaker;
using Tooltip = UnityEngine.TooltipAttribute;
using System.Globalization;
public class VerifyTime : FsmStateAction {
[Tooltip("Store System DateTime as a string.")]
public FsmString endDate;
[Tooltip("Optional format string. E.g., MM/dd/yyyy HH:mm")]
public FsmString format;
[UIHint(UIHint.FsmEvent)]
public FsmEvent beforeEndTime;
[UIHint(UIHint.FsmEvent)]
public FsmEvent afterEdnTime;
public override void OnEnter()
{
DateTimeFormatInfo dtFormat = new System.Globalization.DateTimeFormatInfo();
dtFormat.LongTimePattern = format.Value;
DateTime end = Convert.ToDateTime(endDate.Value, dtFormat);
//DateTime end = Convert.ToDateTime("2017-06-20 23:59:59");
Debug.Log(string.Format("now = {0} end= {1}",DateTime.Now,end));
if (DateTime.Now > end)
{
Fsm.Event(afterEdnTime);
}
else
{
Fsm.Event(beforeEndTime);
}
}
}
- unity3d mac地址校验 有效期验证
- 【JavaScript】JS校验MAC地址
- 校验mac地址的正则
- Mac地址验证------javascript
- crc32校验48位mac 地址
- ip和mac地址格式填报校验
- 用正则校验IP地址与MAC地址
- 用正则校验IP地址与MAC地址
- JS判断、校验MAC地址的2个实例
- MAC地址进行验证的方法
- 微信token校验以及服务器地址验证
- python 正则验证 IP地址与MAC地址
- js_验证时间、ip地址、数字、mac地址函数
- 安卓登陆的验证与有效期
- 字符串自带有效期的验证
- iptable+SQUID 透明代理验证mac地址上网.
- 利用mac地址来验证用户权限实现问题
- 获取本地Mac地址,服务器IP,及验证
- 实现ScrollView中包含ListView,动态设置ListView的高度(listview不能显示全,不能正确计算item的高度)
- 云计算是什么?【科普】
- php第三方登录 Oauth2.0协议
- 部署两个tomcat
- 积累的编程知识在十年后将有一半没用?一位 40 岁程序员的反思
- unity3d mac地址校验 有效期验证
- Mac环境配置本地PHP项目路径
- PHP 第三方调用 UC_Center用户登录认证
- 刷清橙OJ--A1063.求导函数
- 外网访问内网的FTP服务器
- Android 网络发送xml数据和调用webservice(传智播客)
- 设计模式---桥接模式
- 比特币开发专题(区块链密匙生成详细介绍)
- PHP文件包含漏洞原理分析和利用方法