Пример #1
0
        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}.");
            }
        }
Пример #2
0
        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);
            });
        }
Пример #3
0
        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);
            });
        }
Пример #4
0
 public bool Exists(Channel chan)
 {
     return Channels.ContainsValue(chan);
 }
Пример #5
0
 public void Update(Channel old, Channel chan)
 {
     Update(old.Id, chan);
 }
Пример #6
0
        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);
                });
            }
        }
Пример #7
0
 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
     ));
 }
Пример #8
0
 private void HandleChannelRemove(ChannelManager manager, Channel chan)
 {
     Socket.WebSocketServices[Endpoint].Sessions.Broadcast(Shared.Pack(
         ServerMethod.Channel,
         2, // channel deleted
         chan.Name
     ));
 }
Пример #9
0
 private void HandleChannelUpdate(ChannelManager manager, Channel old, Channel chan)
 {
 }
Пример #10
0
 private void HandleChannelRemove(ChannelManager manager, Channel chan)
 {
 }
Пример #11
0
 private void HandleChannelAdd(ChannelManager manager, Channel chan)
 {
 }