コード例 #1
0
ファイル: ChatServer.cs プロジェクト: flashwave/railgun
        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}.");
            }
        }