public void RemoveInteractiveDetails(InteractiveParticipantModel participant) { this.InteractiveIDs.Remove(participant.sessionID); if (this.InteractiveIDs.Count == 0) { this.InteractiveGroupID = InteractiveUserGroupViewModel.DefaultName; } }
private async void Chat_OnUserJoinOccurred(object sender, UserViewModel user) { InteractiveParticipantModel participant = this.InteractiveUsers.Values.ToList().FirstOrDefault(u => u.userID.Equals(user.ID)); if (participant != null) { await this.AddParticipants(new List <InteractiveParticipantModel>() { participant }); } }
public async Task RemoveInteractiveUser(InteractiveParticipantModel interactiveUser) { await this.semaphore.WaitAndRelease(() => { if (this.users.ContainsKey(interactiveUser.userID)) { UserViewModel user = this.users[interactiveUser.userID]; user.RemoveInteractiveDetails(interactiveUser); } return(Task.FromResult(0)); }); }
public async Task RemoveInteractiveUser(InteractiveParticipantModel interactiveUser) { await this.LockWrapper(() => { if (this.users.ContainsKey(interactiveUser.userID)) { UserViewModel user = this.users[interactiveUser.userID]; user.RemoveInteractiveDetails(); } return(Task.FromResult(0)); }); }
protected override async Task PerformInternal(UserViewModel user, IEnumerable <string> arguments) { if (ChannelSession.Interactive != null && ChannelSession.Interactive.Client.Authenticated) { if (!user.Roles.Any(r => r >= this.RoleRequirement)) { if (ChannelSession.Chat != null) { await ChannelSession.Chat.Whisper(user.UserName, "You do not permission to perform this action."); } return; } if (this.group == null) { InteractiveGroupCollectionModel groups = await ChannelSession.Interactive.GetGroups(); if (groups != null && groups.groups != null) { this.group = groups.groups.FirstOrDefault(g => g.groupID.Equals(this.GroupName)); if (this.group == null) { this.group = new InteractiveGroupModel() { groupID = this.GroupName, sceneID = this.SceneID }; await ChannelSession.Interactive.CreateGroups(new List <InteractiveGroupModel>() { this.group }); } } } if (this.InteractiveType == InteractiveActionTypeEnum.MoveGroupToScene || this.InteractiveType == InteractiveActionTypeEnum.MoveUserToScene) { this.group.sceneID = this.SceneID; await ChannelSession.Interactive.UpdateGroups(new List <InteractiveGroupModel>() { this.group }); } if (this.InteractiveType == InteractiveActionTypeEnum.MoveUserToGroup || this.InteractiveType == InteractiveActionTypeEnum.MoveUserToScene) { InteractiveParticipantModel participant = ChannelSession.Interactive.InteractiveUsers.Values.FirstOrDefault(p => p.userID.Equals(user.ID)); if (participant != null) { participant.groupID = this.GroupName; await ChannelSession.Interactive.UpdateParticipants(new List <InteractiveParticipantModel>() { participant }); } } } }
public async Task <UserViewModel> AddOrUpdateUser(InteractiveParticipantModel interactiveUser) { await this.LockWrapper(async() => { bool performFirstUserJoin = !ChannelSession.Settings.UserData.ContainsKey(interactiveUser.userID); if (!this.users.ContainsKey(interactiveUser.userID)) { this.users[interactiveUser.userID] = new UserViewModel(interactiveUser); await this.users[interactiveUser.userID].RefreshDetails(); } this.users[interactiveUser.userID].SetInteractiveDetails(interactiveUser); if (performFirstUserJoin) { await this.PerformUserFirstJoin(this.users[interactiveUser.userID]); } }); return(await this.GetUser(interactiveUser.userID)); }
public async Task <UserViewModel> AddOrUpdateUser(InteractiveParticipantModel interactiveUser) { await this.AddOrUpdateUsers(new List <InteractiveParticipantModel>() { interactiveUser }); return(await this.GetUserByID(interactiveUser.userID)); }
public void SetInteractiveDetails(InteractiveParticipantModel participant) { this.InteractiveIDs[participant.sessionID] = participant; this.InteractiveGroupID = participant.groupID; }
public UserViewModel(InteractiveParticipantModel participant) : this(participant.userID, participant.username) { this.SetInteractiveDetails(participant); }
public async Task UpdateParticipant(InteractiveParticipantModel participant) { await this.UpdateParticipants(new List <InteractiveParticipantModel>() { participant }); }
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); } }
public UserViewModel(InteractiveParticipantModel participant) : this(participant.userID, participant.username) { }
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); }
public static void Main(string[] args) { Task.Run(async() => { List <OAuthClientScopeEnum> scopes = new List <OAuthClientScopeEnum>() { OAuthClientScopeEnum.channel__details__self, OAuthClientScopeEnum.channel__update__self, OAuthClientScopeEnum.interactive__manage__self, OAuthClientScopeEnum.interactive__robot__self, OAuthClientScopeEnum.user__details__self, OAuthClientScopeEnum.user__log__self, OAuthClientScopeEnum.user__notification__self, OAuthClientScopeEnum.user__update__self, }; MixerConnection connection = await MixerConnection.ConnectViaLocalhostOAuthBrowser("ba911f5e09c2d3a87b715e0371f1e9ba96d476b5a7b26ba0", scopes); if (connection != null) { System.Console.WriteLine("Mixer connection successful!"); UserModel user = await connection.Users.GetCurrentUser(); ExpandedChannelModel channel = await connection.Channels.GetChannel(user.username); System.Console.WriteLine(string.Format("Logged in as: {0}", user.username)); InteractiveGameVersionModel version = await connection.Interactive.GetInteractiveGameVersion(Program.GameVersionID); if (version != null) { InteractiveGameModel game = await connection.Interactive.GetInteractiveGame(version.gameId); if (game != null) { System.Console.WriteLine(); System.Console.WriteLine(string.Format("Connecting to channel interactive using game {0}...", game.name)); Program.interactiveClient = await InteractiveClient.CreateFromChannel(connection, channel, game, version, Program.GameShareCode); Program.interactiveClient.OnDisconnectOccurred += InteractiveClient_OnDisconnectOccurred; Program.interactiveClient.OnParticipantJoin += InteractiveClient_OnParticipantJoin; Program.interactiveClient.OnParticipantLeave += InteractiveClient_OnParticipantLeave; Program.interactiveClient.OnGiveInput += InteractiveClient_OnGiveInput; if (await Program.interactiveClient.Connect() && await Program.interactiveClient.Ready()) { InteractiveConnectedSceneGroupCollectionModel scenes = await Program.interactiveClient.GetScenes(); if (scenes != null) { InteractiveConnectedSceneModel scene = scenes.scenes.First(); InteractiveConnectedButtonControlModel gameStartButton = scene.buttons.First(b => b.controlID.Equals("gameStart")); InteractiveConnectedButtonControlModel timeLeftButton = scene.buttons.First(b => b.controlID.Equals("timeLeft")); InteractiveConnectedButtonControlModel flyHitButton = scene.buttons.First(b => b.controlID.Equals("flyHit")); InteractiveConnectedButtonControlModel gameEndButton = scene.buttons.First(b => b.controlID.Equals("gameEnd")); InteractiveConnectedButtonControlModel resultsButton = scene.buttons.First(b => b.controlID.Equals("results")); InteractiveParticipantCollectionModel participantCollection = await Program.interactiveClient.GetAllParticipants(DateTimeOffset.Now.Subtract(TimeSpan.FromMinutes(5))); if (participantCollection != null && participantCollection.participants != null) { foreach (InteractiveParticipantModel participant in participantCollection.participants) { Program.participants[participant.sessionID] = participant; } } while (true) { try { System.Console.WriteLine("Starting new game..."); userTotals.Clear(); gameStartButton.meta["timeLeft"] = 30; await Program.interactiveClient.UpdateControls(scene, new List <InteractiveControlModel>() { gameStartButton }); for (int i = 30; i >= 0; i--) { timeLeftButton.meta["timeLeft"] = i; await Program.interactiveClient.UpdateControls(scene, new List <InteractiveControlModel>() { timeLeftButton }); await Task.Delay(1000); } await Task.Delay(2000); System.Console.WriteLine("Game completed, selecting winner..."); InteractiveParticipantModel winner = null; foreach (var kvp in userTotals.OrderByDescending(kvp => kvp.Value)) { if (Program.participants.TryGetValue(kvp.Key, out winner)) { resultsButton.meta["winner"] = JObject.FromObject(winner); await Program.interactiveClient.UpdateControls(scene, new List <InteractiveControlModel>() { resultsButton }); break; } } if (winner != null) { System.Console.WriteLine("Winner: " + winner.username); } await Task.Delay(5000); } catch (Exception ex) { System.Console.WriteLine(ex.ToString()); } } } } } } } }).Wait(); }