示例#1
0
        public static List<IRCServer> LoadServers()
        {
            string[] files = Directory.GetFiles("servers/");
            if (files.Length > 0)
            {
                List<IRCServer> servers = new List<IRCServer>(files.Length);
                foreach (string file in files)
                {
                    XDocument xd = XDocument.Load(file);
                    Console.Write("Loading " + file + "\n");

                    XElement el = xd.Element("connection");
                    string ip = el.Attribute("ip").Value;
                    int port = int.Parse(el.Attribute("port").Value);

                    string nick = el.Element("name").Value;
                    string pass = el.Element("pass").Value;
                    string altnick = el.Element("altnick").Value;
                    string realname = el.Element("realname").Value;
                    bool loggingRaw = bool.Parse(el.Element("lograw").Value);
                    bool ssl = bool.Parse(el.Element("ssl").Value);
                    List<IRCChannel> channels = new List<IRCChannel>();

                    XElement cc = el.Element("channels");
                    foreach (XElement dd in cc.Elements())
                    {
                        string channel = dd.Element("name").Value;
                        bool reconnect = bool.Parse(dd.Element("reconnect").Value);
                        IRCChannel chan = new IRCChannel(channel, reconnect);
                        channels.Add(chan);
                    }

                    XElement users = el.Element("users");
                    Dictionary<string, UserAccess> serverUsers = new Dictionary<string, UserAccess>();
                    foreach (XElement user in users.Elements())
                    {
                        string host = user.Element("host").Value;
                        string access = user.Element("access").Value;
                        UserAccess ua = UserAccessAttr.GetByAccess(int.Parse(access));
                        serverUsers.Add(host, ua);
                    }
                    IRCServer server = new IRCServer(file, ip, port, channels, ssl, nick, pass, altnick, realname, serverUsers, loggingRaw);
                    servers.Add(server);
                }
                Console.WriteLine("Loaded " + servers.Count + " servers");
                return servers;
            }
            else
            {
                return null;
            }
        }
示例#2
0
        public static List <IRCServer> LoadServers()
        {
            string[] files = Directory.GetFiles("servers/");
            if (files.Length > 0)
            {
                List <IRCServer> servers = new List <IRCServer>(files.Length);
                foreach (string file in files)
                {
                    XDocument xd = XDocument.Load(file);
                    Console.Write("Loading " + file + "\n");

                    XElement el   = xd.Element("connection");
                    string   ip   = el.Attribute("ip").Value;
                    int      port = int.Parse(el.Attribute("port").Value);

                    string            nick       = el.Element("name").Value;
                    string            pass       = el.Element("pass").Value;
                    string            altnick    = el.Element("altnick").Value;
                    string            realname   = el.Element("realname").Value;
                    bool              loggingRaw = bool.Parse(el.Element("lograw").Value);
                    bool              ssl        = bool.Parse(el.Element("ssl").Value);
                    List <IRCChannel> channels   = new List <IRCChannel>();

                    XElement cc = el.Element("channels");
                    foreach (XElement dd in cc.Elements())
                    {
                        string     channel   = dd.Element("name").Value;
                        bool       reconnect = bool.Parse(dd.Element("reconnect").Value);
                        IRCChannel chan      = new IRCChannel(channel, reconnect);
                        channels.Add(chan);
                    }

                    XElement users = el.Element("users");
                    Dictionary <string, UserAccess> serverUsers = new Dictionary <string, UserAccess>();
                    foreach (XElement user in users.Elements())
                    {
                        string     host   = user.Element("host").Value;
                        string     access = user.Element("access").Value;
                        UserAccess ua     = UserAccessAttr.GetByAccess(int.Parse(access));
                        serverUsers.Add(host, ua);
                    }
                    IRCServer server = new IRCServer(file, ip, port, channels, ssl, nick, pass, altnick, realname, serverUsers, loggingRaw);
                    servers.Add(server);
                }
                Console.WriteLine("Loaded " + servers.Count + " servers");
                return(servers);
            }
            else
            {
                return(null);
            }
        }