Ejemplo n.º 1
0
 void OnConvoComplete(Convo convo)
 {
     if (!string.IsNullOrEmpty(convo.id) && convo.id != "choice")
     {
         ProgressionManager.I.RegisterCompletedState(GetConvoIdPath(convo));
     }
 }
Ejemplo n.º 2
0
        public void AssignDialogue(string convoId)
        {
            if (!dialogueSO || convos == null)
            {
                Debug.LogWarning(gameObject.name + " has no dialogue");
                return;
            }
            if (dialogueId.ToLower().Contains("random"))
            {
                DialogueManager.I.AssignDialogue(this, GetRandomLines(dialogueSO.convos), 0);
                return;
            }
            // GetObjectivesInChildren();
            for (int i = objectives.Count - 1; i >= 0; --i)
            {
                if (objectives[i].state != Objective.ObjectiveState.Completed)
                {
                    if (objectives[i].state == Objective.ObjectiveState.NotStarted && !objectives[i].MetStartConds())
                    {
                        continue;
                    }
                    if (RegisterObjectiveChoice(objectives[i]))
                    {
                        objectives[i].onComplete += RemoveChoice;
                    }
                }
            }
            Convo c = string.IsNullOrEmpty(convoId) ? convos[0] : GetConvo(convoId);

            DialogueManager.I.AssignDialogue(this, c, 0);
            DialogueManager.I.onCompleteConvo = OnConvoComplete;
        }
Ejemplo n.º 3
0
 public string GetConvoIdPath(Convo convo)
 {
     if (!dialogueSO)
     {
         return(null);
     }
     return(string.Format("{0}/{1}", dialogueId, convo.id));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Submits a file to a <see cref="Convo"/>.
        /// </summary>
        /// <param name="convo">The <see cref="Convo"/> to post the message into (will use the <see cref="Convo.Id"/> and other credentials for establishing a connection to the Epistle server).</param>
        /// <param name="fileName">The file name.</param>
        /// <param name="fileBytes">File <c>byte[]</c> </param>
        /// <returns>Whether the message could be submitted successfully to the backend or not.</returns>
        public async Task <bool> PostFile(Convo convo, string fileName, byte[] fileBytes)
        {
            if (fileBytes.LongLength > MAX_FILE_SIZE_BYTES || fileName.NullOrEmpty() || fileBytes.NullOrEmpty() || fileName.Contains("///"))
            {
                return(false);
            }

            return(await PostMessageToConvo(convo, "FILE=" + fileName, fileBytes).ConfigureAwait(false));
        }
Ejemplo n.º 5
0
#pragma warning restore 1591

        /// <summary>
        /// Sends a text message to a <see cref="Convo"/>.
        /// </summary>
        /// <param name="convo">The <see cref="Convo"/> to post the message into (will use the <see cref="Convo.Id"/> and other credentials for establishing a connection to the Epistle server).</param>
        /// <param name="message">The text message to post.</param>
        /// <returns>Whether the message submission was successful or failed.</returns>
        public async Task <bool> PostText(Convo convo, string message)
        {
            if (convo is null || message.NullOrEmpty() || message.Length > MAX_FILE_SIZE_BYTES)
            {
                return(false);
            }

            byte[] utf8 = Encoding.UTF8.GetBytes(message.TrimEnd(MSG_TRIM_CHARS).TrimStart(MSG_TRIM_CHARS));
            return(await PostMessageToConvo(convo, "TEXT=UTF8", utf8).ConfigureAwait(false));
        }
        private async void OnJoinedConvo(Convo convo)
        {
            if (!activeConvos.TryGetValue(convo.Id, out var viewModel) || viewModel is null)
            {
                viewModel              = viewModelFactory.Create <ActiveConvoViewModel>();
                viewModel.ActiveConvo  = convo;
                activeConvos[convo.Id] = viewModel;
            }

            var view = new ActiveConvoPage {
                BindingContext = viewModel
            };
            await Application.Current.MainPage.Navigation.PushModalAsync(view);
        }
Ejemplo n.º 7
0
        public ConvoScene(string filename)
        {
            convo = JsonConvert.DeserializeObject <Convo>(File.ReadAllText(filename));

            this.keyboardSounds = new List <SoundEffectInstance>()
            {
                game.GetSoundManager().GetSoundEffectInstance("Sounds/Keyboard/keyboard_1"),
                game.GetSoundManager().GetSoundEffectInstance("Sounds/Keyboard/keyboard_2"),
                game.GetSoundManager().GetSoundEffectInstance("Sounds/Keyboard/keyboard_3"),
                game.GetSoundManager().GetSoundEffectInstance("Sounds/Keyboard/keyboard_4"),
                game.GetSoundManager().GetSoundEffectInstance("Sounds/Keyboard/keyboard_5")
            };

            int screenWidth  = game.GDM().GraphicsDevice.Viewport.Width;
            int screenHeight = game.GDM().GraphicsDevice.Viewport.Height;

            sb            = new SpriteBatch(game.GDM().GraphicsDevice);
            pixelTexture  = game.CM().Load <Texture2D>("pixel");
            this.bodyFont = game.CM().Load <SpriteFont>("Fonts/PressStart2P");

            speakerRectangle = new Rectangle(
                0,
                (int)(screenHeight * (1 - heightProp)),
                (int)(screenHeight * heightProp),
                (int)(screenHeight * heightProp));

            textBgRectangle = new Rectangle(
                speakerRectangle.Right,
                speakerRectangle.Top,
                screenWidth - speakerRectangle.Width,
                speakerRectangle.Height
                );

            textRectangle = new Rectangle(
                textBgRectangle.Left + 10,
                textBgRectangle.Top + 10,
                textBgRectangle.Width - 40,
                textBgRectangle.Height - 20);

            clickTextPos = new Vector2(
                screenWidth * 0.55f,
                screenHeight * 0.95f
                );
        }
Ejemplo n.º 8
0
    // Start is called before the first frame update
    void Start()
    {
        string filePath = Application.streamingAssetsPath + "/dialog.json";

        new HTTPRequest(new Uri(filePath), HTTPMethods.Get, (req, resp) =>
        {
            Debug.Log(string.Format("<color=blue>{0}</color>", resp.StatusCode));
            if (resp.StatusCode == 200)
            {
                convo = JsonConvert.DeserializeObject <Convo>(resp.DataAsText);
                Debug.Log(string.Format("<color=green>Convo loaded</color>"));
                Initialize();
            }
            else
            {
                Debug.Log(string.Format("<color=yellow>Convo not found</color>"));
            }
        }).Send();
    }
 private void OnJoinedConvo(Convo convo)
 {
     CollapseButton_OnClick(null, null);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Submits a message to a <see cref="Convo"/>.
        /// </summary>
        /// <param name="convo">The <see cref="Convo"/> to post the message into.</param>
        /// <param name="messageType">The type of message (e.g. "TEXT=UTF8", "FILE=example.png", etc...).</param>
        /// <param name="message">The message body to encrypt and post.</param>
        /// <returns>Whether the message could be submitted successfully or not.</returns>
        private async Task <bool> PostMessageToConvo(Convo convo, string messageType, byte[] message)
        {
            if (message.NullOrEmpty())
            {
                return(false);
            }

            Task <IDictionary <string, string> > publicKeys = userService.GetUserPublicKeys(user.Id, convo.GetParticipantIdsCommaSeparated(), user.Token.Item2);

            byte[] compressedMessage = await compressionUtility.Compress(message, CompressionSettings.Default).ConfigureAwait(false);

            using var encryptionResult = await aes.EncryptAsync(compressedMessage).ConfigureAwait(false);

            byte[] key = new byte[48];

            for (int i = 0; i < 32; i++)
            {
                key[i] = encryptionResult.Key[i];
            }

            for (int i = 0; i < 16; i++)
            {
                key[i + 32] = encryptionResult.IV[i];
            }

            // Encrypt the message decryption key for every convo participant individually.
            var encryptedKeys = new ConcurrentBag <string>();

            Parallel.ForEach(await publicKeys.ConfigureAwait(false), kvp =>
            {
                (string userId, string userPublicKey) = kvp;

                if (userId.NotNullNotEmpty() && userPublicKey.NotNullNotEmpty())
                {
                    string decompressedPublicKey = keyExchange.DecompressPublicKey(userPublicKey);
                    encryptedKeys.Add(userId + ':' + Convert.ToBase64String(rsa.Encrypt(key, decompressedPublicKey)));
                }
            });

            try
            {
                var postParamsDto = new PostMessageParamsDto
                {
                    Type                = messageType,
                    SenderName          = userSettings.Username,
                    ConvoId             = convo.Id,
                    ConvoPasswordSHA512 = convoPasswordProvider.GetPasswordSHA512(convo.Id),
                    EncryptedKeys       = encryptedKeys.ToCommaSeparatedString(),
                    EncryptedBody       = Convert.ToBase64String(encryptionResult.EncryptedData)
                };

                var body = new EpistleRequestBody
                {
                    UserId = user.Id,
                    Auth   = user.Token.Item2,
                    Body   = JsonSerializer.Serialize(postParamsDto)
                };

                return(await convoService.PostMessage(body.Sign(rsa, user.PrivateKeyPem)).ConfigureAwait(false));
            }
            catch
            {
                return(false);
            }
        }