public ServerDB(Setup setup) { dbDir = (string)setup.serverDBDir.Clone(); // read that sucker in FileInfo dbFile = new FileInfo(dbDir+"serverdb.xml"); if (dbFile.Exists) { XmlSerializer xml = new XmlSerializer(typeof(List<GameServer>)); FileStream fs = dbFile.OpenRead(); StreamReader file = new StreamReader(fs); try { servers = (List<GameServer>)xml.Deserialize(file); } catch (System.Exception e) { Console.WriteLine("Error reading server db " + e.ToString()); } file.Close(); fs.Close(); } if (servers == null) servers = new List<GameServer>(); }
public Server(string[] args) { string configFile; string argConf = string.Empty; // load the setup from the args if (args.Length > 0) configFile = argConf = args[0]; else configFile = "./config.xml"; bool saveConfig = false; FileInfo conf = new FileInfo(configFile); bool confRead = false; if (conf.Exists) { XmlSerializer xml = new XmlSerializer(typeof(Setup)); FileStream fs = conf.OpenRead(); StreamReader file = new StreamReader(fs); try { setup = (Setup)xml.Deserialize(file); confRead = true; } catch (System.Exception e) { Console.WriteLine("Error reading config " + e.ToString()); } file.Close(); fs.Close(); } if (!confRead) { // default setups? setup.hosts.Add("http://localhost:88/"); if (argConf.Length > 0)// try to save out the conf if they wanted one saveConfig = true; setup.serverDBDir = "./"; setup.playerDBDir = "./"; } if (setup.mimeTypes.Count == 0) { setup.mimeTypes.Add(new MimeTypePair("html", "text/html")); setup.mimeTypes.Add(new MimeTypePair("htm", "text/html")); setup.mimeTypes.Add(new MimeTypePair("txt", "text/plain")); setup.mimeTypes.Add(new MimeTypePair("css", "text/css")); setup.mimeTypes.Add(new MimeTypePair("png", "image/png")); setup.mimeTypes.Add(new MimeTypePair("ico", "image/vnd.microsoft.icon")); setup.mimeTypes.Add(new MimeTypePair("*", "application/octet-stream")); } if (saveConfig) { XmlSerializer xml = new XmlSerializer(typeof(Setup)); FileStream fs = conf.OpenWrite(); StreamWriter file = new StreamWriter(fs); xml.Serialize(file, setup); file.Close(); fs.Close(); } serverDB = new ServerDB(setup); playerDB = new PlayerDB(setup); testXMLDump(); }
public PlayerDB(Setup setup) { }