Beispiel #1
0
    /// <summary>
    /// 网络解密,因为使用了Unity的WWW类,暂时无法模块化,要模块化可使用C#的相关API;
    /// </summary>
    /// <param name="user_name">用户名;</param>
    /// <param name="pass_word">密码;</param>
    /// <returns></returns>
    IEnumerator NetworkDecoding(string user_name, string pass_word)
    {
        string url = "http://www.51cax.com/vt/authen.jsp?username="******"&password="******"&id=mold";

        WWW networkCheck = new WWW(url);

        yield return(networkCheck);

        if (networkCheck.error != null)
        {
            Debug.Log(networkCheck.error);
        }
        else
        {
            if (networkCheck.text.Length < 16)
            {
                string x  = networkCheck.text;
                int    xx = int.Parse(x);
                if (xx == 1)
                {
                    _isDecoding = DecodingFlag.NetworkDecoding;
                }
            }
        }
        _decodingResult = true;
    }
Beispiel #2
0
    /// <summary>
    /// 解密入口,如果加入局域网解密,此处也要修改;
    /// </summary>
    /// <param name="check_network_encryption">是否最后查询网络解密;</param>
    public void CheckEncryption(bool check_network_encryption)
    {
        //加密狗解密尝试
        Softdog _softDog = new Softdog();

        _isDecoding = _softDog.DogReturn();

        if (_isDecoding == DecodingFlag.Fail)
        {
            //文件解密尝试
            FileDecode filedecode = new FileDecode();
            _isDecoding = filedecode.IsFileIdentitySuccess();

            //如果解密成功,关闭学生机局域网
            if (_isDecoding != DecodingFlag.Fail)
            {
                if (_clientEncryption != null)
                {
                    _clientEncryption.BeforeQuit();
                }
            }

            if (_isDecoding == DecodingFlag.Fail)
            {
                //局域网解密会消耗一些时间,采用协程处理后续试用期和网络解密
                StartCoroutine(StartLANEncryption(check_network_encryption));
            }
        }
        else
        {
            //如果解密成功,关闭学生机局域网
            if (_clientEncryption != null)
            {
                _clientEncryption.BeforeQuit();
            }
        }
    }
Beispiel #3
0
        /// <summary>
        /// 加密狗解密,根据写入字符串第一个字符是否为数字,判断是否为教师机;
        /// </summary>
        /// <returns>加密狗解密是否成功;</returns>
        public DecodingFlag DogReturn()
        {
            //UnityEngine.Debug.Log("Softdog: DogReturn");

            DecodingFlag  _dogInfo   = DecodingFlag.Fail;
            StringBuilder DevicePath = new StringBuilder(500);
            //加密狗第一阶段解密是否成功
            bool firstStateSuccess = false;

            if (FindPort(0, DevicePath) == 0)
            {
                if (FindPort_2(0, 1, 74532473, DevicePath) == 0)
                {
                    firstStateSuccess = true;
                }
                else if (FindPort_2(0, 1, -379880570, DevicePath) == 0)
                {
                    firstStateSuccess = true;
                }

                //第一阶段验证成功
                if (firstStateSuccess)
                {
                    //读取存储器里面的字符串
                    StringBuilder outString = new StringBuilder(500);
                    StringBuilder hKey      = new StringBuilder("20D30D25");
                    StringBuilder lKey      = new StringBuilder("FFB706AF");

                    bool tmpIsTeachermachine = false;

                    if (YReadString(outString, 0, 494, hKey, lKey, DevicePath) == 0)
                    {
                        //UnityEngine.Debug.LogWarning(outString);
                        string[] softNameArray = outString.ToString().Split('~');
                        //Dictionary<string, bool> nameDic = new Dictionary<string, bool>();
                        Dictionary <string, int> nameDic = new Dictionary <string, int>();
                        for (int i = 0; i < softNameArray.Length; i++)
                        {
                            string[] tmpStrsss = softNameArray[i].Split('|');
                            if (tmpStrsss.Length == 2)
                            {
                                string tmpSoftwareName = tmpStrsss[0];

                                try
                                {
                                    int num = int.Parse(tmpStrsss[1]);
                                    if (!nameDic.ContainsKey(tmpSoftwareName))
                                    {
                                        nameDic.Add(tmpSoftwareName, num);
                                    }
                                    if (num > 0)
                                    {
                                        tmpIsTeachermachine = true;
                                    }
                                }
                                catch
                                {
                                    UnityEngine.Debug.LogError(outString + "加密狗节点数填写错误:" + softNameArray[i]);
                                }
                            }
                            else if (tmpStrsss.Length == 1)
                            {
                                if (!nameDic.ContainsKey(softNameArray[i]))
                                {
                                    nameDic.Add(softNameArray[i], 0);
                                }
                            }
                        }
                        //根据当前软件ID和加密狗读取出来的字符串中是否含有该ID来判断该软件是否解密;
                        if (nameDic.ContainsKey(JiamiString.SoftwareName))
                        {
                            _dogInfo = DecodingFlag.SoftdogDecoding;

                            //UnityEngine.Debug.Log("Softdog: 加密狗解密");
                            if (tmpIsTeachermachine && nameDic[JiamiString.SoftwareName] > 0)
                            {
                                //UnityEngine.Debug.Log("节点数:" + nameDic[JiamiString.SoftwareName]);
                                //当前为教师机
                                EncryptionManager._isTeacherMachine = true;
                                if (EncryptionManager.ServerEncryption == null)
                                {
                                    //局域网教师机服务器开启
                                    EncryptionManager.ServerEncryption = new UDPLANEncryption();
                                    EncryptionManager.ServerEncryption.Start(true, nameDic[JiamiString.SoftwareName]);
                                }
                            }
                        }
                    }
                }
            }
            return(_dogInfo);
        }
Beispiel #4
0
        /// <summary>
        /// 检查加密狗
        /// </summary>
        void CheckSoftdog()
        {
            if (UDPLANEncryption.IsDebug)
            {
                Debug.Log("开始检查教师机加密狗:————————");
            }
            while (_checkSoftdog)
            {
                //检查间隔60s
                Thread.Sleep(1000 * _checkSoftdogSpaceTime);

                //加密狗解密尝试
                Softdog      _softDog        = new Softdog();
                DecodingFlag tmpDecodingFlag = _softDog.DogReturn();

                //如果重新插入加密狗
                if (_isSoftdogOut && tmpDecodingFlag == DecodingFlag.SoftdogDecoding)
                {
                    if (UDPLANEncryption.IsDebug)
                    {
                        Debug.Log("重新插入加密狗,:" + tmpDecodingFlag);
                    }

                    _checkSoftdog = false;
                    checkSoftDogThread.Abort();
                }
                //统一向学生机发送确认在线的消息
                else if (!_isSoftdogOut && tmpDecodingFlag == DecodingFlag.SoftdogDecoding)
                {
                    if (dicConnectMachines.Keys.Count > 0)
                    {
                        string   tmpMachineInfo = JiamiString.SoftwareName + "~";
                        string[] tmpStringArray = UDPLANEncryption.LANIP.ToString().Split('.');
                        tmpMachineInfo += (tmpStringArray[0] + "." + tmpStringArray[1] + "~");
                        List <string> tmpList = new List <string>(dicConnectMachines.Keys);
                        for (int i = 0; i < tmpList.Count; i++)
                        {
                            string[] tmpStringArray2 = tmpList[i].Split('~');
                            string[] tmpStringArray3 = tmpStringArray2[0].Split('.');
                            if (i == 0)
                            {
                                tmpMachineInfo += (tmpStringArray3[2] + "." + tmpStringArray3[3]);
                            }
                            else
                            {
                                tmpMachineInfo += ("|" + tmpStringArray3[2] + "." + tmpStringArray3[3]);
                            }
                        }

                        //TODO:不再单独开启线程
                        SendMsg(tmpMachineInfo);
                    }
                }

                if (tmpDecodingFlag == DecodingFlag.Fail && !_isSoftdogOut)
                {
                    if (UDPLANEncryption.IsDebug)
                    {
                        Debug.LogWarning("教师机加密狗被拔出");
                    }

                    //服务器解密实例为null
                    EncryptionManager.ServerEncryption = null;
                    //加密狗被拔出
                    _isSoftdogOut = true;

                    //TODO:向局域网发送教师机加密狗失效的消息
                    SendMsg("SoftDogOut");
                }
            }
        }