Ejemplo n.º 1
0
        public virtual bool SendMessage(ChatMessage message)
        {
            if (IsAnonymous)
            {
                return(false);
            }

            lock ( channelsLock)
            {
                this.With(x => ChatChannels.FirstOrDefault(channel => channel.ChannelName.Equals(message.Channel, StringComparison.InvariantCultureIgnoreCase)))
                .Do(x =>
                {
                    if (String.IsNullOrWhiteSpace(message.FromUserName))
                    {
                        message.FromUserName = NickName;
                    }
                    Task.Factory.StartNew(() => x.SendMessage(message));
                    if (ReceiveOwnMessages)
                    {
                        ReadMessage(message);
                    }
                });
            }

            return(true);
        }
 public override bool Stop()
 {
     Logger.Log(LogType.Debug, "Unloading ChatChannels...");
     ChatChannels.Clear();
     Logger.Log(LogType.Debug, "Unloaded ChatChannels.");
     return(true);
 }
Ejemplo n.º 3
0
        public void UpdateStats()
        {
            lock (toolTipLock)
            {
                UI.Dispatch(() =>
                {
                    lock ( channelsLock )
                    {
                        var channels = ChatChannels.ToList();

                        Status.ViewersCount  = channels.Sum(channel => channel.ChannelStats.ViewersCount);
                        Status.MessagesCount = channels.Sum(channel => channel.ChannelStats.MessagesCount);

                        channels.ForEach(channel =>
                        {
                            this.With(x => Status.ToolTips.ToList().FirstOrDefault(tooltip => tooltip.Header.Equals(channel.ChannelName)))
                            .Do(x =>
                            {
                                x.Number = channel.ChannelStats.ViewersCount;
                                x.Text   = channel.ChannelStats.ViewersCount.ToString();
                            });
                        });
                    }
                });
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// use this constructor when you want to create a
 /// chat bar in the chat background label.
 /// (Kingdom, Guild)
 /// </summary>
 /// <param name="myRes"></param>
 /// <param name="chatLabel"></param>
 public ChatBarLabel(IRes myRes, ChatBackgroundLabel chatLabel,
                     ChatChannels channel, bool isSelected = false) :
     base(myRes, LabelControlSpecies.ChatBarLabelControl)
 {
     Channel        = channel;
     ChatBackground = chatLabel;
     IsSelected     = isSelected;
     InitializeGeneralComponent();
 }
Ejemplo n.º 5
0
 private void OnDataChannelAdded(DataChannel channel)
 {
     Logger.Log($"Added data channel '{channel.Label}' (#{channel.ID}).");
     ThreadHelper.RunOnMainThread(() =>
     {
         var chat = new ChatChannelModel(channel);
         ChatChannels.Add(chat);
     });
 }
Ejemplo n.º 6
0
        /// <inheritdoc />
        protected BaseTextChatGroupBroadcastSignalRMessageHandler(ChatChannels targetChannel, [JetBrains.Annotations.NotNull] IFactoryCreatable <TSendMessageType, GenericChatMessageContext <TMessageType> > outgoingMessageFactory)
        {
            if (!Enum.IsDefined(typeof(ChatChannels), targetChannel))
            {
                throw new InvalidEnumArgumentException(nameof(targetChannel), (int)targetChannel, typeof(ChatChannels));
            }

            TargetChannel          = targetChannel;
            OutgoingMessageFactory = outgoingMessageFactory ?? throw new ArgumentNullException(nameof(outgoingMessageFactory));
        }
Ejemplo n.º 7
0
 private void OnDataChannelRemoved(DataChannel channel)
 {
     Logger.Log($"Removed data channel '{channel.Label}' (#{channel.ID}).");
     // FIXME - Delegating to another thread means possible race condition if user initiates
     // some action on the data channel before the delegated remove executes.
     ThreadHelper.RunOnMainThread(() =>
     {
         var chat = ChatChannels.Where(c => c.DataChannel == channel).First();
         ChatChannels.Remove(chat);
     });
 }
Ejemplo n.º 8
0
 public IServerProvider <QString, DataBaseClient> Get_Channel_Server(ChatChannels _channel_)
 {
     try
     {
         var _i = (int)_channel_;
         return(_channel_servers_[_i]);
     }
     catch
     {
         return(ServerInfo.GetInvalid());
     }
 }
Ejemplo n.º 9
0
        }                                                     //has to be protected so reflection CanWrite is true for child types

        /// <inheritdoc />
        public TargetlessChannelChatMessageRequestModel(string message, ChatChannels targetChannel)
        {
            if (string.IsNullOrEmpty(message))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(message));
            }
            if (!Enum.IsDefined(typeof(ChatChannels), targetChannel))
            {
                throw new InvalidEnumArgumentException(nameof(targetChannel), (int)targetChannel, typeof(ChatChannels));
            }

            Message       = message;
            TargetChannel = targetChannel;
        }
Ejemplo n.º 10
0
        protected override void Dispose(bool disposing)
        {
            if (!IsDisposed)
            {
                if (disposing)
                {
                    ChatChannels.Clear();
                }


                IsDisposed = true;
            }
            base.Dispose(disposing);
        }
Ejemplo n.º 11
0
        public static async Task <ChatConfiguration> GetChatConfiguration(ChatChannels channel)
        {
            var existingFile =
                await ThereIsServer.Actions.GetAllContentsByRef(
                    ThereIsServer.ServersInfo.MyServers[BasicDataBaseNum + (int)channel],
                    DataBaseLocation);

            if (existingFile.IsDeadCallBack || ThereIsServer.ServerSettings.HasConnectionClosed)
            {
                NoInternetConnectionSandBox.PrepareConnectionClosedSandBox();
                return(null); // don't set ServerSettings.IsWaitingForServerChecking = false;
            }
            return(Parse(existingFile.Decode(), channel));
        }
Ejemplo n.º 12
0
        public static async Task <ChatConfiguration> GetChatConfiguration(ChatChannels channel)
        {
            //---------------------------------------------
            var _s        = ThereIsServer.ServersInfo.ServerManager.Get_Channel_Server(channel);
            var _existing = await ThereIsServer.Actions.GetAllContentsByRef(_s, DataBaseLocation);

            //---------------------------------------------
            if (_existing.IsDeadCallBack || ThereIsServer.ServerSettings.HasConnectionClosed)
            {
                NoInternetConnectionSandBox.PrepareConnectionClosedSandBox();
                return(null); // don't set ServerSettings.IsWaitingForServerChecking = false;
            }
            return(Parse(_existing.Decode(), channel));
        }
Ejemplo n.º 13
0
        public static async Task <DataBaseDataChangedInfo> CreateNewConfiguration(ChatChannels channel)
        {
            ChatConfiguration configuration = new ChatConfiguration(channel)
            {
                Status     = ChatChannelStatus.FreeForAll,
                ItemPrice  = "notSet",
                MinimumLvl = 0,
                BanList    = ChatBlockList.GenerateBlankChatBlockList(),
            };

            configuration.SetLimitationTime();
            return(await ThereIsServer.Actions.CreateFile(ThereIsServer.ServersInfo.MyServers[BasicDataBaseNum + (int)channel],
                                                          DataBaseLocation, new DataBaseCreation("Created By SAO_Game",
                                                                                                 QString.Parse(configuration.GetForServer(), false))));
        }
Ejemplo n.º 14
0
        public virtual bool Stop()
        {
            if (!Enabled)
            {
                Status.ResetToDefault();
            }

            if (Status.IsStopping)
            {
                return(false);
            }

            Log.WriteInfo("Stopping {0} chat", ChatName);

            Status.IsStopping = true;
            Status.IsStarting = false;

            lock ( channelsLock )
            {
                ChatChannels.ToList().ForEach(chan =>
                {
                    chan.Leave();
                    if (chan.LeaveCallback != null)
                    {
                        chan.LeaveCallback(chan);
                    }

                    if (RemoveChannel != null)
                    {
                        RemoveChannel(chan.ChannelName, this);
                    }
                });
            }

            lock (toolTipLock)
            {
                UI.Dispatch(() => {
                    Status.ViewersCount  = 0;
                    Status.MessagesCount = 0;
                    lock (toolTipLock)
                        Status.ToolTips.Clear();
                });
            }


            Thread.Sleep(1000);
            return(true);
        }
Ejemplo n.º 15
0
        private ChatMessageType MessageTypeFromChannel(ChatChannels channel)
        {
            switch (channel)
            {
            case ChatChannels.Internal:
                return(ChatMessageType.System);

            case ChatChannels.ZoneChannel:
                return(ChatMessageType.Zone);

            case ChatChannels.GuildChannel:
                return(ChatMessageType.Guild);
            }

            throw new NotImplementedException($"Cannot handle Chat Channel: {channel}:{(int)channel}");
        }
Ejemplo n.º 16
0
        private void JoinChannel(IChatChannel chatChannel, string channel)
        {
            lock ( channelsLock )
            {
                if (!ChatChannels.Any(c => c.ChannelName == channel) &&
                    !channel.Replace("#", "").Equals(AnonymousNickName, StringComparison.InvariantCultureIgnoreCase))
                {
                    Log.WriteInfo("{0} joining {1}", Config.ChatName, channel);

                    if (RemoveChannel != null)
                    {
                        RemoveChannel(chatChannel.ChannelName, this);
                    }

                    ChatChannels.Add(chatChannel);

                    chatChannel.Join((joinChannel) =>
                    {
                        lock ( joinLock )
                        {
                            Log.WriteInfo("{0} joined {1}", Config.ChatName, channel);

                            UpdateStats();
                            if (AddChannel != null)
                            {
                                AddChannel(joinChannel.ChannelName, this);
                            }

                            if (Status.IsStopping)
                            {
                                return;
                            }

                            lock (toolTipLock)
                            {
                                if (!Status.ToolTips.ToList().Any(t => t.Header == channel))
                                {
                                    UI.Dispatch(() => Status.ToolTips.Add(new ToolTip(channel, joinChannel.ChannelStats.ViewersCount.ToString())));
                                }
                            }
                            Status.IsConnecting = false;
                            Status.IsConnected  = true;
                        }
                    }, channel);
                }
            }
        }
Ejemplo n.º 17
0
        //-------------------------------------------------
        #region static Methods Region
        private static ChatConfiguration Parse(StrongString serverValue, ChatChannels channels)
        {
            ChatConfiguration configuration;

            StrongString[] myTStrings = serverValue.Split(OutCharSeparator);
            StrongString[] myStrings  = myTStrings[ConfigurationPosition].Split(InCharSeparator);
            configuration = new ChatConfiguration(channels)
            {
                Status     = (ChatChannelStatus)myStrings[0].ToUInt16(),
                ItemPrice  = myStrings[1].GetValue(),
                MinimumLvl = myStrings[2].ToUInt16(),
                BanList    = ChatBlockList.Parse(myTStrings[BanListPosition]),
            };
            StrongString[] banTime = myTStrings[BanTimePosition].Split(InCharSeparator);
            configuration.SetLimitationTime(banTime);
            return(configuration);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// The read.
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="packet">
        /// </param>
        public static void Read(Client client, byte[] packet)
        {
            // TODO: Fix this mess.
            ushort data_length = BitConverter.ToUInt16(new[] { packet[3], packet[2] }, 0);

            byte[] sender_ID = BitConverter.GetBytes(client.Character.characterId);
            Array.Reverse(sender_ID);
            MemoryStream m_stream = new MemoryStream();

            m_stream.Write(packet, 0, 9);
            m_stream.Write(sender_ID, 0, 4);
            m_stream.Write(packet, 9, packet.Length - 9);
            m_stream.Capacity = (int)m_stream.Length;
            byte[] message    = m_stream.GetBuffer();
            byte[] new_length = BitConverter.GetBytes(message.Length - 4);
            message[2] = new_length[1];
            message[3] = new_length[0];
            m_stream.Close();
            m_stream.Dispose();

            foreach (Client m_client in client.Server.Clients)
            {
                if (!m_client.KnownClients.Contains(client.Character.characterId))
                {
                    byte[] pname = PlayerName.New(client, client.Character.characterId);
                    m_client.Send(pname);
                    m_client.KnownClients.Add(client.Character.characterId);
                }

                m_client.Send(message);
            }

            PacketReader reader = new PacketReader(ref packet);

            reader.ReadUInt16();
            reader.ReadUInt16();
            reader.ReadUInt16();
            reader.ReadUInt16();
            reader.ReadByte();
            string text        = reader.ReadString();
            string channelName = ChatChannels.GetChannel(packet).Name;

            ChatLogger.WriteString(channelName, text, client.Character.characterName);
        }
Ejemplo n.º 19
0
        public static async Task <DataBaseDataChangedInfo> CreateNewConfiguration(ChatChannels channel)
        {
            ChatConfiguration configuration = new ChatConfiguration(channel)
            {
                Status     = ChatChannelStatus.FreeForAll,
                ItemPrice  = "notSet",
                MinimumLvl = 0,
                BanList    = ChatBlockList.GenerateBlankChatBlockList(),
            };

            configuration.SetLimitationTime();
            //---------------------------------------------
            var _s   = ThereIsServer.ServersInfo.ServerManager.Get_Channel_Server(channel);
            var _req = new DataBaseCreation(MESSAGE, QString.Parse(configuration.GetForServer()));

            return(await ThereIsServer.Actions.CreateData(_s, DataBaseLocation, _req));

            //---------------------------------------------
        }
Ejemplo n.º 20
0
        private void LoadChatChannels()
        {
            var chatChannelTypes = typeof(ChatChannelManagerService).GetTypeInfo().Assembly.DefinedTypes
                                   .Where(typeInfo => typeof(ChatChannel).GetTypeInfo().IsAssignableFrom(typeInfo) &&
                                          !typeInfo.IsDefined(typeof(ChatChannelDisableAutoLoadAttribute), true) &&
                                          !typeInfo.IsAbstract);

            foreach (var chatChannel in chatChannelTypes.Where(type => type != typeof(ScriptChatChannel).GetTypeInfo()).Select(type => (ChatChannel)Activator.CreateInstance(type.AsType())))
            {
                ChatChannels.Add(chatChannel);
            }

            var scriptChatChannelLoaderTypes = typeof(ChatChannelManagerService).GetTypeInfo().Assembly.DefinedTypes
                                               .Where(typeInfo => typeof(ScriptChatChannelLoader).GetTypeInfo().IsAssignableFrom(typeInfo) &&
                                                      !typeInfo.IsDefined(typeof(ChatChannelDisableAutoLoadAttribute), true) &&
                                                      !typeInfo.IsAbstract);

            foreach (var scriptChatChannelLoader in scriptChatChannelLoaderTypes.Where(type => type != typeof(ScriptChatChannelLoader).GetTypeInfo()).Select(type => (ScriptChatChannelLoader)Activator.CreateInstance(type.AsType())))
            {
                ChatChannels.AddRange(scriptChatChannelLoader.LoadChatChannels());
            }
        }
Ejemplo n.º 21
0
 //-------------------------------------------------
 #region Constructors Region
 private ChatConfiguration(ChatChannels channel)
 {
     TheChannel = channel;
 }
Ejemplo n.º 22
0
 public ReasonCode Listen(ChatChannels channels)
 {
     SetInstance();
     return((ReasonCode)NativeMethods.aw_listen((int)channels));
 }
Ejemplo n.º 23
0
 public Result Listen(ChatChannels channels)
 {
     SetInstance();
     return((Result)NativeMethods.aw_listen((int)channels));
 }
Ejemplo n.º 24
0
 public Result SayChannel(ChatChannels channel, string message, params object[] args)
 {
     SetInstance();
     return (Result)NativeMethods.aw_say_channel(string.Format(message, args), (int)channel);
 }
Ejemplo n.º 25
0
 public Result SayChannel(ChatChannels channel, string message, object arg0, object arg1, object arg2)
 {
     SetInstance();
     return (Result)NativeMethods.aw_say_channel(string.Format(message, arg0, arg1, arg2), (int)channel);
 }
Ejemplo n.º 26
0
 public Result Listen(ChatChannels channels)
 {
     SetInstance();
     return (Result)NativeMethods.aw_listen((int) channels);
 }
Ejemplo n.º 27
0
 //-------------------------------------------------
 #region Constructors Region
 private ChatManager(ChatChannels channel, GameControls.ChatBackgroundLabel father)
 {
     Channel = channel;
     Father  = father;
 }
Ejemplo n.º 28
0
 public Result SayChannel(ChatChannels channel, string message, params object[] args)
 {
     SetInstance();
     return((Result)NativeMethods.aw_say_channel(string.Format(message, args), (int)channel));
 }
Ejemplo n.º 29
0
 //-------------------------------------------------
 #region Constructors Region
 private ChatManager(ChatChannels channel, object father)
 {
     Channel = channel;
     //Father = father;
 }
Ejemplo n.º 30
0
 private ChatManager(ChatChannels channel)
 {
     Channel = channel;
 }
Ejemplo n.º 31
0
        public void StartAllChats()
        {
            steamChat = (SteamChat)GetChat(SettingsRegistry.ChatTitleSteam);
            if (historyService.Config.Enabled)
            {
                historyService.Start();
            }

            //Accumulate messages and update ViewModel periodically
            receiveTimer.Interval = TimeSpan.FromMilliseconds(1500);
            receiveTimer.Tick    += receiveTimer_Tick;
            receiveTimer.Start();

            timerUpdateDatabase = new Timer((o) => { UpdateDatabase(); }, this, 0, 60000);

            int waitChatStatus = 5000;

            Chats.ForEach(chat =>
            {
                chat.MessageReceived += chat_MessageReceived;
                chat.AddChannel       = (channel, fromChat) =>
                {
                    lock ( channelsLock )
                    {
                        UI.Dispatch(() => {
                            lock (channelsLock)
                            {
                                if (!ChatChannels.Any(c => c.ChannelName == channel && c.ChatName == fromChat.ChatName))
                                {
                                    ChatChannels.Add(new ChatChannel()
                                    {
                                        ChatName = fromChat.ChatName, ChannelName = channel, ChatIconURL = fromChat.IconURL
                                    });
                                }
                            }
                        });
                    }
                };
                chat.RemoveChannel = (channel, fromChat) =>
                {
                    UI.Dispatch(() =>
                    {
                        lock (channelsLock)
                        {
                            var searchItem = ChatChannels.FirstOrDefault(item => item.ChatName == fromChat.ChatName && item.ChannelName == channel && item.ChatIconURL == fromChat.IconURL);
                            if (searchItem != null)
                            {
                                ChatChannels.Remove(searchItem);
                            }

                            if (ChatChannels.Count <= 0)
                            {
                                if (!chat.Status.IsStopping)
                                {
                                    chat.Status.IsConnected = false;
                                    chat.Status.IsLoggedIn  = false;
                                    chat.Restart();
                                }
                            }
                        }
                    });
                };
                if (chat.Enabled)
                {
                    Task.Factory.StartNew(() => {
                        var c = chat;
                        c.Start();

                        while (ChatStatusHandler == null && waitChatStatus > 0)
                        {
                            waitChatStatus -= 50;
                            Thread.Sleep(100);
                        }

                        if (ChatStatusHandler != null)
                        {
                            ChatStatusHandler(c);
                        }
                    });
                }
            });
        }
Ejemplo n.º 32
0
 public Result SayChannel(ChatChannels channel, string message, object arg0, object arg1, object arg2)
 {
     SetInstance();
     return((Result)NativeMethods.aw_say_channel(string.Format(message, arg0, arg1, arg2), (int)channel));
 }
Ejemplo n.º 33
0
 public ReasonCode SayChannel(ChatChannels channel, string message, object arg0)
 {
     SetInstance();
     return((ReasonCode)NativeMethods.aw_say_channel(string.Format(message, arg0), (int)channel));
 }