public ChatServer(string identifier, Config config) { Identifier = identifier; Context = new ChatServerContext(config); Endpoints = new Dictionary<string, ServerProtocol>(); Log = new Logger($"Chat Server ({Identifier})"); Log.Write(LogSeverity.Info, "Created chat server container."); string[] channels = Context.Config.Get("Chat.Context", "Channels", "Lounge").Split(' '); for (int i = 0; i < channels.Length; i++) { string configSection = $"Chat.Channel.{channels[i]}"; Channel channel = new Channel { Id = i + 1, Name = "#" + (Context.Config.ContainsKey(configSection, "Name") ? Context.Config.Get<string>(configSection, "Name") : channels[i]).ToLower(), Topic = Context.Config.ContainsKey(configSection, "Topic") ? Context.Config.Get<string>(configSection, "Topic") : "This channel has no topic.", Created = DateTime.UtcNow }; if (Context.Config.ContainsKey(configSection, "Password")) { channel.SetPassword(Context.Config.Get<string>(configSection, "Password")); } if (Context.Config.ContainsKey(configSection, "MinimumHierarchy")) { channel.MinimumHierarchy = Context.Config.Get<int>(configSection, "MinimumHierarchy"); } Context.Channels.Add(channel); Log.Write(LogSeverity.Info, $"Created {channel.Name}."); } }
public void Add(Channel chan) { Actions.BeforeChannelAdd.ForEach((Action<ChannelManager, Channel> action) => { action.Invoke(this, chan); }); Channels.Add(chan.Id, chan); Actions.AfterChannelAdd.ForEach((Action<ChannelManager, Channel> action) => { action.Invoke(this, chan); }); }
public void Remove(Channel chan) { Actions.BeforeChannelRemove.ForEach((Action<ChannelManager, Channel> action) => { action.Invoke(this, chan); }); Channels.Remove(chan.Id); Actions.AfterChannelRemove.ForEach((Action<ChannelManager, Channel> action) => { action.Invoke(this, chan); }); }
public bool Exists(Channel chan) { return Channels.ContainsValue(chan); }
public void Update(Channel old, Channel chan) { Update(old.Id, chan); }
public void Update(int id, Channel chan) { if (Channels.ContainsKey(id)) { Channel prev = Channels[id]; Actions.BeforeChannelUpdate.ForEach((Action<ChannelManager, Channel, Channel> action) => { action.Invoke(this, prev, chan); }); Channels[id] = chan; Actions.AfterChannelUpdate.ForEach((Action<ChannelManager, Channel, Channel> action) => { action.Invoke(this, prev, chan); }); } }
private void HandleChannelUpdate(ChannelManager manager, Channel old, Channel chan) { Socket.WebSocketServices[Endpoint].Sessions.Broadcast(Shared.Pack( ServerMethod.Channel, 1, // channel updated old.Name, chan.Name, chan.HasPassword, chan.IsTemporary )); }
private void HandleChannelRemove(ChannelManager manager, Channel chan) { Socket.WebSocketServices[Endpoint].Sessions.Broadcast(Shared.Pack( ServerMethod.Channel, 2, // channel deleted chan.Name )); }
private void HandleChannelUpdate(ChannelManager manager, Channel old, Channel chan) { }
private void HandleChannelRemove(ChannelManager manager, Channel chan) { }
private void HandleChannelAdd(ChannelManager manager, Channel chan) { }