Beispiel #1
0
        private bool inventoryContainsScripts(SceneObjectPart part)
        {
            foreach (TaskInventoryItem item in part.ParentGroup.RootPart.Inventory.GetInventoryItems())
            {
                if (item.InvType == 10)
                {
                    AssetBase assetData = m_scene.AssetService.Get(item.AssetID.ToString());

                    if (assetData != null)
                    {
                        String script = new ASCIIEncoding().GetString(assetData.Data).ToUpper();

                        if (script.Contains("INVENTORY_TEXTURE"))
                        {
                            return(true);
                        }

                        if (script.Contains("INVENTORY_ALL"))
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #2
0
        public static string Decrypt(string Data, byte[] Key, byte[] IV)
        {
            try
            {
                MemoryStream msDecrypt = new MemoryStream(Convert.FromBase64String(Data));

                // Create a CryptoStream using the MemoryStream
                // and the passed key and initialization vector (IV).
                CryptoStream csDecrypt = new CryptoStream(msDecrypt,
                                                          new TripleDESCryptoServiceProvider().CreateDecryptor(Key, IV),
                                                          CryptoStreamMode.Read);

                // Create buffer to hold the decrypted data.
                byte[] fromEncrypt = new byte[Data.Length];

                // Read the decrypted data out of the crypto stream
                // and place it into the temporary buffer.
                csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);

                //Convert the buffer into a string and return it.
                string ReturnValue = new ASCIIEncoding().GetString(fromEncrypt);
                if (ReturnValue.Contains("\0\0\0"))
                {
                    ReturnValue = ReturnValue.Remove(ReturnValue.IndexOf("\0\0\0"));
                }
                return(ReturnValue);
            }
            catch (CryptographicException e)
            {
                Console.WriteLine("A Cryptographic error occurred: {0}", e.Message);
                return(null);
            }
        }
Beispiel #3
0
        public string myReceive(int size)
        {
            byte[] buffer = new byte[size];

            int totalBytesRecieved = 0;

            while (totalBytesRecieved < size)
            {
                try
                {
                    if (_secured)
                    {
                        totalBytesRecieved += _secureStream.Read(buffer, totalBytesRecieved, size - totalBytesRecieved);
                    }
                    else
                    {
                        totalBytesRecieved += _clientStream.Read(buffer, totalBytesRecieved, size - totalBytesRecieved);
                    }
                }
                catch (Exception)
                {
                    string errorMessage = "server closed unexpectedly";
                    MessageBox.Show(errorMessage);
                    throw new Exception(errorMessage);
                }
            }

            string decoded = new ASCIIEncoding().GetString(buffer); //seperated lines for debugging. TODO (make this a one-liner)

            if (decoded.Contains("\0"))
            {
                throw new Exception("bytes not recieved properly");
            }
            return(decoded);
        }
Beispiel #4
0
        void ExtractAuthToken(HttpContext context, out string username, out string password)
        {
            // The header is in the following format
            // "Basic 64BitEncodedUsernameAndPasswordString"
            // userAndPasswordDecoded is in the following
            // format "theusername:thepassword"
            var userAndPassDecoded = new ASCIIEncoding().GetString(
                Convert.FromBase64String(context.Request.Headers["Authorization"].Substring(6)));

            var userAndPasswordArray = userAndPassDecoded.Contains(":") ? userAndPassDecoded.Split(':') : new[] { userAndPassDecoded, "" };

            username = userAndPasswordArray[0];
            password = userAndPasswordArray[1];
        }
Beispiel #5
0
        private void WaitForTCPSocketServerMessages(TcpClient client, NetworkStream stream)
        {
            Thread.Sleep(2000);

            if (stream.DataAvailable &&
                client.Connected)
            {
                byte[] message = new byte[4096]; // Dies ist unser Buffer
                int    bytesRead;
                bytesRead = stream.Read(message, 0, 4096);

                if (bytesRead > 0)
                {
                    String receivedMessage = new ASCIIEncoding().GetString(message);
                    if (receivedMessage.Contains("Close"))
                    {
                        client.Close();
                        stream.Close();
                        CloseApplication = true;
                    }
                }
            }
        }