예제 #1
0
        /// <summary>
        /// Either reads in or creates a config file.
        /// </summary>
        /// <param name="configFile">Info about the file to be opened/created.</param>
        /// <returns>Returns true if it succesfully reads or creates the config file.</returns>
        private bool parseCreateConf(System.IO.FileInfo configFile)
        {
            string path = configFile.FullName;


            if (!configFile.Exists)
            {
                System.IO.Stream newConfigFile = new System.IO.FileStream(configFile.FullName, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write);


                serialize.Serialize(newConfigFile, this);
                newConfigFile.Close();
                return(true);
            }
            else
            {
                System.IO.StreamReader oldConfigFile = new System.IO.StreamReader(configFile.FullName);
                Instance = (ServerParam)serialize.Deserialize(oldConfigFile);
                oldConfigFile.Close();
                return(true);
            }
        }
예제 #2
0
        /// <summary>
        /// Initalizes the server paramters (including Player Parameters, CVSSaver Parameters, and command lines).
        /// </summary>
        /// <param name="args">Arguments from the command line.</param>
        /// <returns>Returns true after successful intialization.</returns>
        public static bool Initialize(string[] args)
        {
            Instance = new ServerParam();


            string configDirectory = CONF_DIR;

            string environmentalVariableConfDirectory = System.Environment.GetEnvironmentVariable("RCSS_CONF_DIR");

            if (environmentalVariableConfDirectory != null)
            {
                configDirectory = environmentalVariableConfDirectory;
            }

            System.IO.DirectoryInfo configPath;

            try
            {
                configPath = new System.IO.DirectoryInfo(Utilities.tildeExpand(configDirectory));

                if (!configPath.Exists)
                {
                    configPath.Create();
                    if (!configPath.Exists)
                    {
                        Console.Error.WriteLine("Could not read or create the config directory '"
                                                + configPath.FullName + "'");

                        return(false);
                    }
                }
            }
            catch (System.Exception exception)
            {
                Console.Error.WriteLine("Exception caught! " + exception.Message
                                        + System.Environment.NewLine + "Could not read or create config directory '"
                                        + Utilities.tildeExpand(configDirectory) + "' in " + exception.TargetSite);
                return(false);
            }

            System.IO.FileInfo filePath = new System.IO.FileInfo(configPath.FullName + System.IO.Path.DirectorySeparatorChar + SERVER_CONF);


            if (!Instance.parseCreateConf(filePath))
            {
                Console.Error.WriteLine("could not create or parse configuration file '"
                                        + filePath.ToString() + "'");
                return(false);
            }



            if (!PlayerParam.Initialize())
            {
                return(false);
            }



            return(true);
        }