// // openmapi.org - IRC <--> Jabber bridge - Config.cs // // (C) 2009 by Johannes Roith // // Author: Johannes Roith // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // namespace Jonfo.Jabber.IRC { using System; using System.IO; using System.Text; using System.ComponentModel; using System.Runtime.Serialization; using System.Xml.Serialization; /// /// Stores configuration information. /// [Serializable] public sealed class Config { /// /// The user part of a JID to be used. /// [XmlElement ("jabberuser")] public string JabberUser { get; set; } /// /// the server part of a JID to be used. /// [XmlElement ("jabberserver")] public string JabberServer { get; set; } /// /// The host where the jabber server is running. /// [XmlElement ("jabbernetworkhost")] public string JabberNetworkHost { get; set; } /// /// The Port where the jabber server is running. /// [XmlElement ("jabberport")] public int JabberPort { get; set; } /// /// The Jabber Resource name to be used for the bot. /// [XmlElement ("jabberresource")] public string JabberResource { get; set; } /// /// The password used for authentication at the jabber server. /// [XmlElement ("jabberpassword")] public string JabberPassword { get; set; } /// /// If true, the bot will subscribe to users that have requested /// authorization; They are added to the roster and will receive /// messages from XMPP and IRC. /// This should almost always be set to 'true'! /// [XmlElement ("jabberautosubscribe")] public bool JabberAutoSubscribe { get; set; } /// /// The name of the IRC host. /// [XmlElement ("irchost")] public string IRCHost { get; set; } /// /// The name of the IRC port. /// [XmlElement ("ircport")] public int IRCPort { get; set; } /// /// The IRC nickname of the bot. /// [XmlElement ("ircnick")] public string IRCNick { get; set; } /// /// The IRC name of the bot. /// [XmlElement ("ircname")] public string IRCName { get; set; } /// /// The name of the channel to join. /// [XmlElement ("ircchannel")] public string IRCChannel { get; set; } public Config () { } public static Config Load (string fileName) { var serializer = new XmlSerializer (typeof (Config)); var fileStream = new FileStream (fileName, FileMode.Open); return (Config) serializer.Deserialize (fileStream); } public void Save (string fileName) { var serializer = new XmlSerializer (typeof (Config)); using (TextWriter writer = new StreamWriter (fileName)) { serializer.Serialize (writer, this); writer.Close (); } } } }