Exemplo n.º 1
0
        //mxd
        private void CheckHash()
        {
            // Open the file stream
            FileStream fs = File.Open(filename, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite);

            // Empty file can't be official iwad
            if (fs.Length > 4)
            {
                BinaryReader r = new BinaryReader(fs, ENCODING);

                // Read WAD type
                if (ENCODING.GetString(r.ReadBytes(4)) == TYPE_IWAD)
                {
                    // Rewind
                    r.BaseStream.Position = 0;
                    isofficialiwad        = IWAD_HASHES.Contains(MD5Hash.Get(r.BaseStream));
                    if (!isreadonly && isofficialiwad)
                    {
                        isreadonly = true;
                    }
                }

                // Close the reader
                r.Close();
            }
            else
            {
                // Close the file
                fs.Dispose();
            }
        }
Exemplo n.º 2
0
        internal ScriptResourceDocumentTab(ScriptEditorPanel panel, ScriptResource resource, ScriptConfiguration config) : base(panel, config)
        {
            // Store resource
            source = resource;

            // Load the data
            MemoryStream stream = source.Resource.LoadFile(source.Filename, source.LumpIndex);

            if (stream != null)
            {
                hash = MD5Hash.Get(stream);
                editor.SetText(stream.ToArray());
                editor.Scintilla.ReadOnly = source.IsReadOnly;
                editor.ClearUndoRedo();
            }
            else
            {
                General.ErrorLogger.Add(ErrorType.Warning, "Failed to load " + source.ScriptType + " resource \"" + source.Filename + "\" from \"" + source.Resource.Location.GetDisplayName() + "\".");
            }

            // Set title and tooltip
            tabtype      = ScriptDocumentTabType.RESOURCE;
            filepathname = source.FilePathName;
            SetTitle(source.ToString());
            this.ToolTipText = filepathname;

            // Update navigator
            panel.ShowErrors(UpdateNavigator(), true);
        }
Exemplo n.º 3
0
        private static IEnumerator LoadMetaOfResourceAsync(string relativePath)
        {
            if (metaOfResource.ContainsKey(relativePath))
            {
                yield break;
            }

            var metaPath = GetMetaFileName(relativePath);
            var file     = new FileStream(LocalDataPath + "/" + metaPath,
                                          FileMode.OpenOrCreate, FileAccess.ReadWrite);

            var md5 = MD5Hash.Get(file);

            file.Position = 0;

            var document = new XmlDocument();

            if (md5 == metaOfMeta[metaPath])
            {
                document.Load(file);
            }
            else
            {
                var www = new WWW(RemoteDataPath + "/" + metaPath);
                yield return(www);

                document.LoadXml(www.text);
                file.SetLength(0);
                file.Write(www.bytes, 0, www.bytes.Length);
            }

            file.Close();

            LoadMetaOfResource(document);
        }
Exemplo n.º 4
0
        private void Login()
        {
            var login = textBoxLogin.Text.Trim();
            var pass  = MD5Hash.Get(textBoxPassword.Text.Trim(), Encoding.Default);
            var users = Model.Users.GetAll();

            _currentUser = users.FirstOrDefault(q => q.Login == login && q.PasswordHash == pass);
            if (_currentUser == null)
            {
                _currentUser = users.FirstOrDefault(q => q.Login == login);
                if (_currentUser != null)
                {
                    MessageBox.Show(Resources.LoginForm_Login_Не_правильно_введен_пароль_, Resources.LoginForm_Login_Внимание);
                    return;
                }

                if (MessageBox.Show(Resources.LoginForm_Login_Такого_пользователя_нет__Хотите_создать_нового_,
                                    Resources.LoginForm_Login_Внимание, MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
                var uf = new UserForm();
                uf.ShowDialog();
                return;
            }
            _currentUser.Password = textBoxPassword.Text.Trim();
            var mf = new MainForm(_currentUser, this);

            Hide();
            mf.Show();
        }
Exemplo n.º 5
0
        private static IEnumerator LoadWWWAsync(Resource resource)
        {
            var exportFileName = GetExportFileName(resource.RelativePath);
            var www            = new WWW("file://" + LocalDataPath + "/" + exportFileName);

            yield return(www);

            if (www.error == null)
            {
                var md5  = MD5Hash.Get(www.bytes);
                var meta = metaOfResource[resource.RelativePath];
                if (md5 == meta.MD5)
                {
                    resource.www = www;
                    yield break;
                }
            }

            www = new WWW(RemoteDataPath + "/" + exportFileName);
            yield return(www);

            resource.www = www;

            var file = new FileStream(LocalDataPath + "/" + exportFileName,
                                      FileMode.Create,
                                      FileAccess.Write);

            file.Write(www.bytes, 0, www.bytes.Length);
            file.Close();
        }
        // This saves the document (used for both explicit and implicit)
        // Return true when successfully saved
        public override bool Save()
        {
            if (source.IsReadOnly)
            {
                return(false);
            }

            // [ZZ] remove trailing whitespace
            RemoveTrailingWhitespace();

            // Find lump, check it's hash
            bool       dosave = true;
            DataReader reader = source.Resource;
            // reload the reader
            bool wasReadOnly = reader.IsReadOnly;

            reader.Reload(false);
            try
            {
                if (reader.FileExists(source.Filename, source.LumpIndex))
                {
                    using (MemoryStream ms = reader.LoadFile(source.Filename, source.LumpIndex))
                    {
                        if (MD5Hash.Get(ms) != hash &&
                            MessageBox.Show("Target lump was modified by another application. Do you still want to replace it?", "Warning", MessageBoxButtons.OKCancel)
                            == DialogResult.Cancel)
                        {
                            dosave = false;
                        }
                    }
                }

                if (dosave)
                {
                    // Store the lump data
                    using (MemoryStream stream = new MemoryStream(editor.GetText()))
                    {
                        if (reader.SaveFile(stream, source.Filename, source.LumpIndex))
                        {
                            // Update what must be updated
                            hash = MD5Hash.Get(stream);
                            editor.SetSavePoint();
                            UpdateTitle();
                        }
                    }
                }
            }
            finally
            {
                reader.Reload(wasReadOnly);
            }

            return(dosave);
        }
Exemplo n.º 7
0
 private static void InitTables()
 {
     if (!Users.HasAny())
     {
         var user = new User()
         {
             PasswordHash = MD5Hash.Get("123456", Encoding.Default),
             Login        = "******",
         };
         Users.AddNew(user);
     }
 }
Exemplo n.º 8
0
        private void simpleButtonChangePassword_Click(object sender, EventArgs e)
        {
            try
            {
                var pass1   = textEditPassword1.Text.Trim();
                var pass2   = textEditPassword2.Text.Trim();
                var oldpass = textEditOldPassword.Text.Trim();
                if (string.IsNullOrEmpty(pass1) || string.IsNullOrEmpty(oldpass) || string.IsNullOrEmpty(pass2))
                {
                    MessageBox.Show("Пароль не может быть пустым");
                    return;
                }
                var oldpassHash = MD5Hash.Get(oldpass, Encoding.Default);
                if (_user.PasswordHash != oldpassHash)
                {
                    MessageBox.Show("Старый пароль не совпадает с введенным");
                    return;
                }
                if (!pass1.Equals(pass2))
                {
                    MessageBox.Show("Новые пароли не совпадают");
                    return;
                }

                string url = string.Format("https://" + _mf._serverUrl + "/api/company/update_password?password={0}", pass1);
                VLog.Log("Постим пароль.");
                var result = _mf.PostString(url);
                VLog.Log("Запостили пароль: " + result);
                if (result.ToLower() != "true")
                {
                    throw new Exception("Ошибка во время создания пароля.");
                }
                _user.PasswordHash = MD5Hash.Get(pass1, Encoding.Default);
                _user.Password     = pass1;

                Model.Users.Put(_user, true);
                textEditPassword1.Text   = "";
                textEditPassword2.Text   = "";
                textEditOldPassword.Text = "";
                MessageBox.Show("Пароль изменен.");
            }
            catch (Exception ex)
            {
                VLog.Log(ex);
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 9
0
 private void simpleButton2_Click(object sender, EventArgs e)
 {
     try
     {
         var login = textBox1.Text.Trim();
         var pass  = textBox2.Text.Trim();
         var user  = new User()
         {
             PasswordHash = MD5Hash.Get(pass, Encoding.Default),
             Login        = login,
         };
         Model.Users.Post(user);
         DialogResult = DialogResult.OK;
     }
     catch (Exception ex)
     {
         VLog.Log(ex);
         MessageBox.Show(Resources.UserForm_simpleButton2_Click_Ошибка_во_время_создания_пользователя_);
     }
 }
Exemplo n.º 10
0
        private void HandleRegistration(Packet packet)
        {
            string username = packet.ReadUTF8String();
            string password = packet.ReadUTF8String();

            RegistrationResponse responseCode = RegistrationResponse.REG_RESPONSE_SUCCESS;

            int accountId = 0;
            var mysql     = MySQL.Instance();

            using (var reader = mysql.Execute($"SELECT `Id` FROM `users` WHERE `username` = '{username}'"))
            {
                if (reader == null)
                {
                    responseCode = RegistrationResponse.REG_RESPONSE_UNKNOWN_ERROR;
                }
                else if (reader.Read())
                {
                    responseCode = RegistrationResponse.REG_RESPONSE_HERE_USER;
                }
            }

            if (responseCode == RegistrationResponse.REG_RESPONSE_SUCCESS)
            {
                accountId = (int)mysql.PExecute($"INSERT INTO `users` ( `type`, `username`, `password`) VALUES ('{(int)UserType.USER_TYPE_CLIENT}', '{username}', '{MD5Hash.Get(username + ":" + password)}')");
                if (accountId != -1)
                {
                    UserMgr.Instance.AddNewUser(username, (uint)accountId, UserType.USER_TYPE_CLIENT);
                    _session = new Server.Session(username, (uint)accountId, this);
                    Server.Server.Instance.AddSessionQueue(_session);
                }
                else
                {
                    responseCode = RegistrationResponse.REG_RESPONSE_UNKNOWN_ERROR;
                }
            }

            var response = new Packet(Opcode.SMSG_REGISTRATION_RESPONSE);

            response.WriteUInt8((byte)responseCode);
            response.WriteUInt32((uint)accountId);
            response.WriteUTF8String(username);
            response.WriteUInt8((byte)UserType.USER_TYPE_CLIENT);
            SendPacket(response);
        }
Exemplo n.º 11
0
        private void HandleAuth(Packet packet)
        {
            var username = packet.ReadUTF8String();
            var password = packet.ReadUTF8String();

            AuthResponse responseCode = AuthResponse.AUTH_RESPONSE_SUCCESS;

            var      mysql     = MySQL.Instance();
            var      uName     = string.Empty;
            uint     accountId = 0;
            UserType type      = UserType.USER_TYPE_UNKNOWN;

            using (var reader = mysql.Execute($"SELECT `Id`, `type`, `username` FROM `users` WHERE `username` = '{username}' AND `password` = '{MD5Hash.Get(username + ":" + password)}'"))
            {
                if (reader == null || _session != null)
                {
                    responseCode = AuthResponse.AUTH_RESPONSE_UNKNOWN_ERROR;
                }
                else if (!reader.Read())
                {
                    responseCode = AuthResponse.AUTH_RESPONSE_UNKNOWN_USER;
                }

                if (responseCode == AuthResponse.AUTH_RESPONSE_SUCCESS)
                {
                    accountId = reader.GetUInt32(0);
                    type      = (UserType)reader.GetByte(1);
                    uName     = reader.GetString(2);
                }
            }

            if (!string.IsNullOrEmpty(uName) && accountId != 0)
            {
                _session = new Server.Session(uName, accountId, this);
                Server.Server.Instance.AddSessionQueue(_session);
            }

            var response = new Packet(Opcode.SMSG_AUTH_RESPONSE);

            response.WriteUInt8((byte)responseCode);
            response.WriteUInt32(accountId);
            response.WriteUTF8String(uName);
            response.WriteUInt8((byte)type);
            SendPacket(response);
        }
Exemplo n.º 12
0
    static void SaveBuildList(string outputPath)
    {
        AssetList        buildList = new AssetList();
        HashSet <string> bundeList = new HashSet <string>();

        buildList.manifest = EditorUserBuildSettings.activeBuildTarget.ToString();
        bundeList.Add(buildList.manifest);

        foreach (var file in list.assets.Values)
        {
            if (file.asset.Contains("resources/") == false || string.IsNullOrEmpty(file.bundle) == false)
            {
                if (buildList.Contains(file.name) == false && buildList.assets.ContainsValue(file) == false)
                {
                    if (string.IsNullOrEmpty(file.bundle))
                    {
                        string fullPath = string.Format("{0}{1}", outputPath, file.asset);
                        byte[] bytes    = File.ReadAllBytes(fullPath);
                        file.size = bytes.Length;
                        file.md5  = MD5Hash.Get(bytes);
                    }
                    else
                    {
                        file.size = 0;
                        file.md5  = null;
                        bundeList.Add(file.bundle);
                    }
                    buildList.assets.Add(file.name, file);
                }
            }
            else
            {
                if (buildList.Contains(file.name) == false && buildList.assets.ContainsValue(file) == false)
                {
                    string fullPath = string.Format("{0}{1}", Application.dataPath.Replace("Assets", ""), file.asset);
                    byte[] bytes    = File.ReadAllBytes(fullPath);
                    file.size = bytes.Length;
                    file.md5  = MD5Hash.Get(bytes);
                    buildList.assets.Add(file.name, file);
                }
            }
        }
        foreach (var name in bundeList)
        {
            string    fullPath = string.Format("{0}{1}", outputPath, name);
            byte[]    bytes    = File.ReadAllBytes(fullPath);
            AssetFile file     = new AssetFile();
            file.name   = name;
            file.bundle = name;
            file.size   = bytes.Length;
            file.md5    = MD5Hash.Get(bytes);
            buildList.assets.Add(file.name, file);
        }

        string assetXmlFile = outputPath + "/" + AssetPath.ASSETSFILE;

        StreamWriter writerXml = new StreamWriter(assetXmlFile);

        writerXml.Write(buildList.ToXml());
        writerXml.Close();
        writerXml.Dispose();
    }