Example #1
0
 public InteractiveInputEvent(UserViewModel user, InteractiveGiveInputModel input, InteractiveConnectedControlCommand command)
     : this(user, input)
 {
     this.Command = command;
 }
Example #2
0
        private async void Client_OnGiveInput(object sender, InteractiveGiveInputModel e)
        {
            try
            {
                if (e != null && e.input != null)
                {
                    if (this.Controls.ContainsKey(e.input.controlID))
                    {
                        InteractiveConnectedControlCommand connectedControl = this.Controls[e.input.controlID];

                        if (!connectedControl.Command.IsEnabled)
                        {
                            return;
                        }

                        if (!connectedControl.DoesInputMatchCommand(e))
                        {
                            return;
                        }

                        UserViewModel user = null;
                        if (!string.IsNullOrEmpty(e.participantID))
                        {
                            user = await ChannelSession.ActiveUsers.GetUser(e.participantID);

                            if (user == null)
                            {
                                IEnumerable <InteractiveParticipantModel> recentParticipants = await this.GetRecentParticipants();

                                InteractiveParticipantModel participant = recentParticipants.FirstOrDefault(p => p.sessionID.Equals(e.participantID));
                                if (participant != null)
                                {
                                    user = await ChannelSession.ActiveUsers.AddOrUpdateUser(participant);
                                }
                            }
                        }

                        if (user == null)
                        {
                            user = InteractiveClientWrapper.defaultInteractiveUser;
                        }

                        if (!string.IsNullOrEmpty(e.transactionID) && !user.Data.IsSparkExempt)
                        {
                            await this.CaptureSparkTransaction(e.transactionID);
                        }

                        List <string> arguments = new List <string>();

                        if (connectedControl is InteractiveConnectedJoystickCommand)
                        {
                            arguments.Add(e.input.x.ToString());
                            arguments.Add(e.input.y.ToString());
                        }
                        else if (connectedControl is InteractiveConnectedTextBoxCommand)
                        {
                            arguments.Add(e.input.value);
                        }

                        await connectedControl.Perform(user, arguments);

                        if (this.OnInteractiveControlUsed != null)
                        {
                            this.OnInteractiveControlUsed(this, new Tuple <UserViewModel, InteractiveConnectedControlCommand>(user, connectedControl));
                        }
                    }
                }
                this.OnGiveInput(this, e);
            }
            catch (Exception ex) { MixItUp.Base.Util.Logger.Log(ex); }
        }
Example #3
0
        private async void Client_OnGiveInput(object sender, InteractiveGiveInputModel e)
        {
            try
            {
                if (e != null && e.input != null)
                {
                    InteractiveControlModel            control          = this.Controls[e.input.controlID];
                    InteractiveConnectedControlCommand connectedControl = null;
                    if (this.ControlCommands.ContainsKey(e.input.controlID))
                    {
                        connectedControl = this.ControlCommands[e.input.controlID];

                        if (!connectedControl.DoesInputMatchCommand(e))
                        {
                            return;
                        }

                        if (!connectedControl.Command.IsEnabled)
                        {
                            return;
                        }
                    }

                    UserViewModel user = null;
                    if (!string.IsNullOrEmpty(e.participantID))
                    {
                        user = await ChannelSession.ActiveUsers.GetUserByParticipantID(e.participantID);

                        if (user == null)
                        {
                            InteractiveParticipantModel participant = null;
                            if (this.Participants.TryGetValue(e.participantID, out participant))
                            {
                                user = new UserViewModel(participant);
                            }
                            else
                            {
                                IEnumerable <InteractiveParticipantModel> recentParticipants = await this.GetRecentParticipants();

                                participant = recentParticipants.FirstOrDefault(p => p.sessionID.Equals(e.participantID));
                                if (participant != null)
                                {
                                    user = await ChannelSession.ActiveUsers.AddOrUpdateUser(participant);
                                }
                            }
                        }
                    }

                    if (user == null)
                    {
                        user = new UserViewModel(0, "Unknown User");
                        user.InteractiveIDs[e.participantID] = new InteractiveParticipantModel()
                        {
                            sessionID = e.participantID, anonymous = true
                        };
                    }
                    else
                    {
                        await user.RefreshDetails();
                    }
                    user.UpdateLastActivity();

                    if (ChannelSession.Settings.PreventUnknownInteractiveUsers && user.IsAnonymous)
                    {
                        return;
                    }

                    if (user.IsInInteractiveTimeout)
                    {
                        return;
                    }

                    if (!ModerationHelper.MeetsChatInteractiveParticipationRequirement(user))
                    {
                        await ModerationHelper.SendChatInteractiveParticipationWhisper(user, isInteractive : true);

                        return;
                    }

                    if (!this.Controls.ContainsKey(e.input.controlID))
                    {
                        return;
                    }

                    if (connectedControl != null)
                    {
                        int sparkCost = 0;

                        await this.giveInputLock.WaitAndRelease(async() =>
                        {
                            if (await connectedControl.CheckAllRequirements(user))
                            {
                                if (!string.IsNullOrEmpty(e.transactionID) && !user.Data.IsSparkExempt)
                                {
                                    Util.Logger.LogDiagnostic("Sending Spark Transaction Capture - " + e.transactionID);

                                    await this.CaptureSparkTransaction(e.transactionID);

                                    if (control is InteractiveButtonControlModel)
                                    {
                                        sparkCost = ((InteractiveButtonControlModel)control).cost.GetValueOrDefault();
                                    }
                                    else if (control is InteractiveTextBoxControlModel)
                                    {
                                        sparkCost = ((InteractiveTextBoxControlModel)control).cost.GetValueOrDefault();
                                    }
                                }

                                List <string> arguments = new List <string>();

                                if (connectedControl is InteractiveConnectedJoystickCommand)
                                {
                                    arguments.Add(e.input.x.ToString());
                                    arguments.Add(e.input.y.ToString());
                                }
                                else if (connectedControl is InteractiveConnectedTextBoxCommand)
                                {
                                    arguments.Add(e.input.value);
                                }

                                await connectedControl.Perform(user, arguments);
                            }
                        });

                        if (sparkCost > 0)
                        {
                            GlobalEvents.SparkUseOccurred(new Tuple <UserViewModel, int>(user, sparkCost));
                        }
                    }

                    this.OnGiveInput(this, e);

                    this.OnInteractiveControlUsed(this, new InteractiveInputEvent(user, e, connectedControl));
                }
            }
            catch (Exception ex) { MixItUp.Base.Util.Logger.Log(ex); }
        }
        private async void Client_OnGiveInput(object sender, InteractiveGiveInputModel e)
        {
            if (e != null && e.input != null)
            {
                if (this.Controls.ContainsKey(e.input.controlID))
                {
                    InteractiveConnectedControlCommand connectedControl = this.Controls[e.input.controlID];

                    if (!connectedControl.Command.IsEnabled)
                    {
                        return;
                    }

                    if (connectedControl.Button != null && !connectedControl.TriggerTransactionString.Equals(e.input.eventType))
                    {
                        return;
                    }

                    if (connectedControl.Button != null)
                    {
                        connectedControl.Button.cooldown = connectedControl.Command.GetCooldownTimestamp();

                        List <InteractiveConnectedButtonControlModel> buttons = new List <InteractiveConnectedButtonControlModel>();
                        if (!string.IsNullOrEmpty(connectedControl.Command.CooldownGroup))
                        {
                            var otherItems = this.Controls.Values.Where(c => c.Button != null && connectedControl.Command.CooldownGroup.Equals(c.Command.CooldownGroup));
                            foreach (var otherItem in otherItems)
                            {
                                otherItem.Button.cooldown = connectedControl.Button.cooldown;
                            }
                            buttons.AddRange(otherItems.Select(i => i.Button));
                        }
                        else
                        {
                            buttons.Add(connectedControl.Button);
                        }

                        await this.UpdateControls(connectedControl.Scene, buttons);
                    }
                    else if (connectedControl.Joystick != null)
                    {
                    }

                    if (!string.IsNullOrEmpty(e.transactionID))
                    {
                        await this.CaptureSparkTransaction(e.transactionID);
                    }

                    UserViewModel user = ChannelSession.GetCurrentUser();
                    if (this.InteractiveUsers.ContainsKey(e.participantID))
                    {
                        InteractiveParticipantModel participant = this.InteractiveUsers[e.participantID];
                        if (ChannelSession.Chat.ChatUsers.ContainsKey(participant.userID))
                        {
                            user = ChannelSession.Chat.ChatUsers[participant.userID];
                        }
                        else
                        {
                            user = new UserViewModel(participant.userID, participant.username);
                        }
                    }

                    await connectedControl.Command.Perform(user);

                    return;
                }
            }

            this.OnGiveInput(this, e);
        }