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); }
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(); }); }); } }); } }
/// <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(); }
private void OnDataChannelAdded(DataChannel channel) { Logger.Log($"Added data channel '{channel.Label}' (#{channel.ID})."); ThreadHelper.RunOnMainThread(() => { var chat = new ChatChannelModel(channel); ChatChannels.Add(chat); }); }
/// <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)); }
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); }); }
public IServerProvider <QString, DataBaseClient> Get_Channel_Server(ChatChannels _channel_) { try { var _i = (int)_channel_; return(_channel_servers_[_i]); } catch { return(ServerInfo.GetInvalid()); } }
} //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; }
protected override void Dispose(bool disposing) { if (!IsDisposed) { if (disposing) { ChatChannels.Clear(); } IsDisposed = true; } base.Dispose(disposing); }
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)); }
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)); }
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)))); }
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); }
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}"); }
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); } } }
//------------------------------------------------- #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); }
/// <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); }
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)); //--------------------------------------------- }
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()); } }
//------------------------------------------------- #region Constructors Region private ChatConfiguration(ChatChannels channel) { TheChannel = channel; }
public ReasonCode Listen(ChatChannels channels) { SetInstance(); return((ReasonCode)NativeMethods.aw_listen((int)channels)); }
public Result Listen(ChatChannels channels) { SetInstance(); return((Result)NativeMethods.aw_listen((int)channels)); }
public Result SayChannel(ChatChannels channel, string message, params object[] args) { SetInstance(); return (Result)NativeMethods.aw_say_channel(string.Format(message, args), (int)channel); }
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); }
public Result Listen(ChatChannels channels) { SetInstance(); return (Result)NativeMethods.aw_listen((int) channels); }
//------------------------------------------------- #region Constructors Region private ChatManager(ChatChannels channel, GameControls.ChatBackgroundLabel father) { Channel = channel; Father = father; }
public Result SayChannel(ChatChannels channel, string message, params object[] args) { SetInstance(); return((Result)NativeMethods.aw_say_channel(string.Format(message, args), (int)channel)); }
//------------------------------------------------- #region Constructors Region private ChatManager(ChatChannels channel, object father) { Channel = channel; //Father = father; }
private ChatManager(ChatChannels channel) { Channel = channel; }
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); } }); } }); }
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)); }
public ReasonCode SayChannel(ChatChannels channel, string message, object arg0) { SetInstance(); return((ReasonCode)NativeMethods.aw_say_channel(string.Format(message, arg0), (int)channel)); }