public virtual void Handle(ChatMessage message) { foreach (var token in Tokens) { if (token.Check(message.Message)) { if (Channels.ContainsKey(message.Channel)) { Channels[message.Channel].MessageCount = Channels[message.Channel].MessageCount + 1; } else { Channels.TryAdd(message.Channel, new AverageTokensChannelInfo() { Channel = message.Channel, HandlerName = MessageHandlerType, MessageCount = 1, StartDate = DateTime.UtcNow }); } } } }
/// <summary> /// Unjoins the specified channel. If it wasn't joined, the events trigger anyway. /// </summary> /// <param name="channelId">Its ID.</param> public void UnjoinChannel(int channelId) { if (!Channels.ContainsKey(channelId)) { return; } KgsChannel channel = Channels[channelId]; channel.Joined = false; _kgsConnection.Events.RaiseUnjoin(channel); if (channel is KgsGameContainer) { KgsGameContainer container = channel as KgsGameContainer; GameContainers.Remove(container); } if (channel is KgsTrueGameChannel) { if (_joinedGames.ContainsKey(channel.ChannelId)) { _joinedGames.Remove(channel.ChannelId); } } SomethingChanged(); // Old: _kgsConnection.Events.RaiseChannelUnjoined(channel); }
private static void ProcessChannelUpdateFrame(ChannelUpdateFrame channelUpdateFrame) { if (Channels.ContainsKey(channelUpdateFrame.data.id)) { Channels[channelUpdateFrame.data.id] = channelUpdateFrame.data; } }
public void OnClientChatReceive(NetworkMessage netMsg) { MsgChatReceiveFromServer msg = netMsg.ReadMessage <MsgChatReceiveFromServer>(); ChatChannelData channel = defaultChannel; if (Channels.ContainsKey(msg.channelId)) { channel = Channels[msg.channelId]; } else { Debug.LogWarning("[Warning] Chat channel (" + msg.channelId + ") not found"); } if (channel != null) { ChatMessage.ChatState chatState = ChatMessage.ChatState.Receive; if (msg.senderId.Equals(clientChatUser.userId)) { chatState = ChatMessage.ChatState.Send; } ChatMessage chatMessage = new ChatMessage(channel, msg.senderId, msg.senderName, msg.message, chatState); Messages.Add(chatMessage); if (onReceiveMessage != null) { onReceiveMessage(this, chatMessage); } } }
private static void ProcessMessageDeleteFrame(MessageDeleteFrame messageDeleteFrame) { var frameMessage = messageDeleteFrame.data; if (Channels.ContainsKey(frameMessage.channelId) && Channels[frameMessage.channelId].lastMessage.id == frameMessage.id) { Channels[frameMessage.channelId].lastMessage = frameMessage; } if (Messages.ContainsKey(frameMessage.channelId)) { for (var i = 0; i < Messages[frameMessage.channelId].Count; ++i) { if (Messages[frameMessage.channelId][i].id == frameMessage.id) { Messages[frameMessage.channelId][i] = frameMessage; } } } for (var i = 0; i < NewMessages.Count; ++i) { if (NewMessages[i].id == frameMessage.id) { NewMessages[i] = frameMessage; } } }
public void OnServerChatReceive(NetworkMessage netMsg) { MsgChatSendFromClient msg = netMsg.ReadMessage <MsgChatSendFromClient>(); ChatChannelData channel = defaultChannel; if (ChatUsers.ContainsKey(netMsg.conn)) { ChatUser user = ChatUsers[netMsg.conn]; if (Channels.ContainsKey(msg.channelId)) { channel = Channels[msg.channelId]; } else { Debug.LogWarning("[Warning] Chat channel (" + msg.channelId + ") not found"); } if (channel != null) { ClientChatReceive(channel.DoChatLogic(user, msg.chatData)); } } else { Debug.LogError("[Error] Invalid chat user " + netMsg.conn.connectionId); } }
public IClientSessionChannel GetChannel(string channelId, long replayId) { Channels.TryGetValue(channelId, out var channel); if (channel == null) { var id = NewChannelId(channelId); var new_channel = NewChannel(id, replayId); if (Channels.ContainsKey(channelId)) { channel = Channels[channelId]; } else { Channels[channelId] = new_channel; } if (channel == null) { channel = new_channel; } } return(channel); }
private Channel SubscribeToChannel(string channelName) { var channelType = GetChannelType(channelName); if (!Channels.ContainsKey(channelName)) { CreateChannel(channelType, channelName); } if (State == ConnectionState.Connected) { if (channelType == ChannelTypes.Presence || channelType == ChannelTypes.Private) { var jsonAuth = _options.Authorizer.Authorize(channelName, _connection.SocketId); var template = new { auth = string.Empty, channel_data = string.Empty }; var message = JsonConvert.DeserializeAnonymousType(jsonAuth, template); _connection.Send(JsonConvert.SerializeObject(new { @event = Constants.CHANNEL_SUBSCRIBE, data = new { channel = channelName, auth = message.auth, channel_data = message.channel_data } })); } else { // No need for auth details. Just send subscribe event _connection.Send(JsonConvert.SerializeObject(new { @event = Constants.CHANNEL_SUBSCRIBE, data = new { channel = channelName } })); } } return(Channels[channelName]); }
/// <summary> /// Stops the streaming channels. /// </summary> /// <param name="messageId">The message identifier.</param> /// <param name="channels">The channels.</param> protected virtual void StopStreamingChannels(long messageId, IList <long> channels) { foreach (var channel in channels) { // Find the ChannelStreamingInfo list that contains the channelId var streamingContextList = _channelStreamingContextLists.FirstOrDefault(list => list.Any(l => l.ChannelId == channel)); if (streamingContextList != null) { // Find the context for the channelId to remove var contextToRemove = streamingContextList.First(l => l.ChannelId == channel); // Remove context from its list. streamingContextList.Remove(contextToRemove); // If the context list is empty remove it from its list of lists. if (streamingContextList.Count == 0) { _channelStreamingContextLists.Remove(streamingContextList); } } else { // Try to get the mnemonic from the Described channels var mnemonic = Channels.ContainsKey(channel) ? $" ({Channels[channel].Item2.ChannelName})" : string.Empty; this.InvalidState($"Channel {channel}{mnemonic} is not currently streaming.", messageId); } } }
/// <summary> /// A channel has transitioned to the faulted state /// </summary> /// <param name="sender"></param> /// <param name="e"></param> static void channel_Faulted(object sender, EventArgs e) { try { IContextChannel channel = sender as IContextChannel; if (channel != null) { string typeName = channel.GetType().FullName; if (Channels.ContainsKey(typeName)) { Channels.Remove(typeName); } System.Diagnostics.Debug.WriteLine(string.Format("{0} is in the faulted state.", typeName), string.Format("{0}.{1}.{2}", MethodBase.GetCurrentMethod().DeclaringType.Namespace, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name)); try { channel.Abort(); } catch { // No op... } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message, string.Format("{0}.{1}.{2}", MethodBase.GetCurrentMethod().DeclaringType.Namespace, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name)); } }
void IPusher.EmitChannelEvent(string channelName, string eventName, string data) { if (Channels.ContainsKey(channelName)) { Channels[channelName].EmitEvent(eventName, data); } }
public void EnsureChannelExists(KgsChannel channel) { if (!Channels.ContainsKey(channel.ChannelId)) { Channels.Add(channel.ChannelId, channel); } }
public Messages Get(string queue, string channelName) { if (!Channels.ContainsKey(channelName)) { return(new Messages()); } return(Get(queue, Channels[channelName])); }
/// <summary> /// remove channel /// </summary> /// <param name="channelName">name of the channel to remove</param> public void RemoveChannel(string channelName) { //check if the speaker is in the channel if (!Channels.ContainsKey(channelName)) { Channels.Remove(channelName); new Thread(() => RemoveChannelThreaded(channelName)).Start(); } }
/// <summary> /// Joins the channel. /// </summary> /// <param name="channelName"></param> /// <returns></returns> public async Task JoinChannelAsync(string channelName) { if (Channels.ContainsKey(channelName)) { throw new ArgumentException("The client has already present in this channel."); } await SendRawMessageAsync(string.Format("JOIN #{0}", channelName.ToLower().ToLower())); }
/// <summary> /// add channel /// </summary> /// <param name="channel">channel to add to speaker</param> public void AddChannel(Channel channel) { //check if the speaker doesn't have the channel yet if (!Channels.ContainsKey(channel.Name)) { Channels.Add(channel.Name, channel); new Thread(() => AddChannelThreaded(channel)).Start(); } }
/// <summary> /// Joins the specified channel. If it was already joined, events trigger anyway. /// This only affects <see cref="Channels"/>. /// </summary> /// <param name="channel">The channel.</param> private void JoinChannel(KgsChannel channel) { if (!Channels.ContainsKey(channel.ChannelId)) { Channels.Add(channel.ChannelId, channel); } channel.Joined = true; _kgsConnection.Events.RaiseChannelJoined(channel); SomethingChanged(); }
/// <summary> /// Close the specified channel. /// </summary> /// <param name="channel">The channel to close.</param> public static void Close <T>(T channel) { Type type = typeof(T); string typeName = type.FullName; if (Channels.ContainsKey(typeName)) { Channels.Remove(typeName); } CloseChannel(channel as IContextChannel, false); }
/// <summary> /// Gets the channel with the specified ID, if it exists. Otherwise, it returns null, but that means there is an error /// somewhere in our code or the protocol. /// </summary> /// <param name="channelId">The channel identifier of the channel to get.</param> /// <returns></returns> public KgsChannel GetChannel(int channelId) { if (Channels.ContainsKey(channelId)) { return(Channels[channelId]); } else { return(null); } }
// PRIVATE METHODS void RegisterImpl(string channel, IListener listener) { if (string.IsNullOrEmpty(channel) == true) { return; } if (m_Channels.ContainsKey(channel) == false) { m_Channels[channel] = new Listeners(); } Listeners listeners = m_Channels[channel]; if (listeners.Contains(listener) == true) { return; } listeners.Add(listener); }
/// <summary> /// Receive a message from another source. /// </summary> /// <param name="message">The message to receive</param> /// <returns>A task for continuation purposes</returns> public Task Receive(Message message) { if (Channels.ContainsKey(message.ChannelName)) { if (Channels[message.ChannelName].Id != message.ChannelId) { return(Channels[message.ChannelName].Receive(message)); } } return(Task.CompletedTask); }
/// <summary> /// Adds and Creates RemoteChannel. /// </summary> /// <param name="channel">The channel to add.</param> public RemoteChannel CreateChannel(ushort id) { if (Channels.ContainsKey(id)) { throw new NetException("Failed to create RemoteChannel, the channel with the id {0} already exists!", id); } RemoteChannel channel = new RemoteChannel(this, id); Channels.TryAdd(channel.Id, channel); return(channel); }
/// <summary> /// Gets or creates the channel indicated by name /// </summary> /// <param name="name">The name of the channel to retrieve</param> /// <returns>An instance of the <see cref="Channel"/> class</returns> public Channel Channel(string name) { if (!Channels.ContainsKey(name)) { var channel = MessageHub.Channel.Create().WithName(name).WithSerializationType(_serializationType); channel.MessageSending += Channel_MessageSending; Channels[name] = channel; } return(Channels[name]); }
/// <summary> /// Gets the room with the specified ID. If it doesn't exist, it is created. /// </summary> /// <param name="channelId">The channel identifier.</param> private KgsRoom EnsureRoomExists(int channelId) { if (Channels.ContainsKey(channelId)) { } else { var room = new KgsRoom(channelId); Channels[channelId] = room; AllRooms.Add(room); } return(Channels[channelId] as KgsRoom); }
public void LeaveChat(string name) { if (!Channels.ContainsKey(name)) { return; } var msg = new ClientGCMsgProtobuf <CMsgDOTALeaveChatChannel>( (uint)EDOTAGCMsg.k_EMsgGCLeaveChatChannel); msg.Body.channel_id = Channels[name]; Bot.Coordinator.Send(msg, Games.DotaGameId); Channels.Remove(name); }
public override ChannelSurrogate GetRegisteredChannel(string channel) { if (Channels.ContainsKey(channel)) { return(Channels[channel]); } else if (Cache.Channels.ContainsKey(channel)) { return(Cache.Channels[channel]); } else { return(null); } }
/// <summary> /// Gets the channel with the specified channel ID, if it exists and if it has the appropriate type. /// Otherwise, it returns null, but that means there is an error /// somewhere in our code or the protocol. /// </summary> /// <param name="channelId">The channel identifier of a channel of a particular kind.</param> /// <returns></returns> public T GetChannel <T>(int channelId) where T : KgsChannel { if (Channels.ContainsKey(channelId)) { T t = Channels[channelId] as T; if (t == null) { Debug.WriteLine("This isn't supposed to happen - bad cast."); } return(t); } else { return(null); } }
/// <summary> ///根据栏目ID取得栏目信息 /// </summary> /// <param name="ownerID"></param> /// <returns></returns> public static Channel GetChannel(string ownerID) { Channel ch = null; if (!String.IsNullOrEmpty(ownerID)) { if (Channels.ContainsKey(ownerID)) { ch = Channels[ownerID]; } else { ch = HelperFactory.Instance.GetHelper <ChannelHelper>().GetChannel(ownerID, null); Channels.Add(ownerID, ch); } } return(ch); }
private async Task <Channel> SubscribeAsync(string channelName, Channel channel, SubscriptionEventHandler subscribedEventHandler = null) { if (channel == null) { channel = CreateChannel(channelName); } if (subscribedEventHandler != null) { channel.Subscribed -= subscribedEventHandler; channel.Subscribed += subscribedEventHandler; } if (State == ConnectionState.Connected) { try { TimeSpan timeoutPeriod = Options.ClientTimeout; if (!await channel._subscribeLock.WaitAsync(timeoutPeriod).ConfigureAwait(false)) { throw new OperationTimeoutException(timeoutPeriod, $"{Constants.CHANNEL_SUBSCRIPTION_SUCCEEDED} on {channelName}"); } if (!channel.IsSubscribed) { if (Channels.ContainsKey(channelName)) { await SubscribeChannelAsync(channel).ConfigureAwait(false); } } } catch (Exception error) { HandleSubscribeChannelError(channel, error); throw; } finally { channel._subscribeLock.Release(); } } return(channel); }
public override bool AddToChannel(ChannelBase channel) { string id = channel.Name.ToLower(); if (Channels.ContainsKey(id)) { return(false); } try { channel.Users[Id] = this; Channels[id] = channel; return(true); } catch { return(false); } }