Exemplo n.º 1
0
        /// <summary>
        /// Moves the away clients back.
        /// </summary>
        protected void MoveAwayClientsBack()
        {
            if (!Repository.Settings.Away.Enabled)
            {
                return;
            }

            foreach (var client in Repository.Client.GetClientList()
                     .Where(m => m.ChannelId.EqualsAny(Repository.Settings.Away.Channel.GetValueOrDefault(), Repository.Settings.Away.MuteMicrophoneChannel.GetValueOrDefault(), Repository.Settings.Away.MuteHeadphoneChannel.GetValueOrDefault()) && // Check for Channel
                            !m.IsAway(Repository.Settings.Away) &&                                                                                                                                                                                     // Check if not Away
                            !m.IsInputMuted(Repository.Settings.Away) &&                                                                                                                                                                               // Check if not muted Microphone
                            !m.IsOutputMuted(Repository.Settings.Away) &&                                                                                                                                                                              // Check if not muted Headphones
                            !m.IsIdle(Repository.Settings.Idle) &&                                                                                                                                                                                     // Check if not idle (to prevent endless loop)
                            Repository.Client.HasLastChannelByClientId(m.ClientDatabaseId)))                                                                                                                                                           // Check for an last-channel entry
            {
                if (!Repository.Channel.GetClientSticky(client.ClientDatabaseId).HasValue)
                {
                    var awayClient = Repository.Client.GetLastChannelByClientId(client.ClientDatabaseId);
                    if (awayClient != default(AwayClientEntity))
                    {
                        var channel = Repository.Channel.GetChannelListInfo((uint)awayClient.LastChannelId) ?? new ChannelListEntry();
                        QueryRunner.MoveClient(client.ClientId, (uint)awayClient.LastChannelId);

                        Log(Repository.Settings.Away,
                            string.Format("Client '{0}'(id:{1}) successfully moved back from Away Channel to '{2}'(id:{3}).",
                                          client.Nickname, client.ClientDatabaseId, channel.Name, awayClient.LastChannelId));

                        if (!string.IsNullOrEmpty(Repository.Settings.Away.TextMessage))
                        {
                            var awayTimespan   = Repository.Static.Now - awayClient.Creation;
                            var messageContext = new MessageContext
                            {
                                ClientDatabaseId = client.ClientDatabaseId,
                                ClientNickname   = client.Nickname,
                                ClientAwayTime   = BasicHelper.GetTimespanString(awayTimespan),
                                ChannelId        = (uint)awayClient.LastChannelId,
                                ChannelName      = channel.Name
                            };

                            if (Repository.Connection.CredentialEntity.Self != null)
                            {
                                QueryRunner.SendTextMessage(MessageTarget.Server, Repository.Connection.CredentialEntity.Self.VirtualServerId, Repository.Settings.Away.TextMessage.ToMessage(messageContext));
                            }
                        }
                    }
                }
                Repository.Client.RemoveLastChannelByClientId(client.ClientDatabaseId);
            }
        }