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) { 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); } }