示例#1
0
        public void SetArrayParameter(string[] lines, SrvParam param)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("{");
            foreach (var item in lines)
            {
                sb.Append("\"").Append(item).Append("\"").Append(",");
            }
            sb.Remove(sb.Length - 1, 1);
            sb.Append("}");
            param.paramValue = sb.ToString();
        }
示例#2
0
        //Update Arma3Server member / property.
        public static string UpdateConfigParam(int serverId, string paramName, object value)
        {
            Arma3Server server = Arma3ServerUtility.FindArma3ServerByID(serverId);

            if (server == null)
            {
                return("Failed to update config parameter. Given ID didn't match any server.");
            }
            SrvParam param = FindSrvParam(server, paramName);

            if (param == null)
            {
                return("Failed to update config parameter. Given parameter not found");
            }

            param.paramValue = value;
            //Serverlist saving

            return(paramName + " updated");
        }
示例#3
0
        //Update Arma3Server member/property -state.
        public static string UpdateConfigParamState(int serverId, string paramName, bool state)
        {
            Arma3Server server = Arma3ServerUtility.FindArma3ServerByID(serverId);

            if (server == null)
            {
                return("Failed to update config parameter. Given ID didn't match any server.");
            }
            SrvParam param = FindSrvParam(server, paramName);

            if (param == null)
            {
                return("Failed to update config parameter. Given parameter not found");
            }


            param.include = state;
            //Serverlist saving

            return(paramName + " state updated to " + state.ToString());
        }
示例#4
0
        public static void WriteConfigFile(Arma3Server server, Settings settings)
        {
            CultureInfo oldCulture = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");

            List <string> lines = new List <string>();

            #region PopulateList
            foreach (var field in typeof(Arma3Server).GetFields())
            {
                var p = field.GetValue(server);

                if (p is SrvParam)
                {
                    SrvParam param = (SrvParam)p;

                    if (param.include)
                    {
                        if (param.surroundWithQuotation)
                        {
                            lines.Add(param.paramName + " = \"" + param.paramValue + "\";");
                        }
                        else
                        {
                            lines.Add(param.paramName + " = " + param.paramValue.ToString() + ";");
                        }
                    }
                }

                else if (p is Arma3ClassObject)
                {
                    StringBuilder sb = new StringBuilder();
                    AppendSubClasses((Arma3ClassObject)p, sb, 0);
                    lines.Add(sb.ToString());
                }
            }
            //Same for property fields
            foreach (var field in typeof(Arma3Server).GetProperties())
            {
                var p = field.GetValue(server);
                if (!(p is SrvParam))
                {
                    continue;
                }

                SrvParam param = (SrvParam)p;

                if (param.include)
                {
                    if (param.surroundWithQuotation)
                    {
                        lines.Add(param.paramName + " = \"" + param.paramValue + "\";");
                    }
                    else
                    {
                        lines.Add(param.paramName + " = " + param.paramValue.ToString() + ";");
                    }
                }
            }



            #endregion


            StringBuilder configData = new StringBuilder();
            configData.Append("// Automatically generated config file - ").AppendLine(DateTime.Now.ToString()).AppendLine("// With ArmaServerManager\r\n");

            foreach (var item in lines)
            {
                configData.AppendLine(item);
            }


            string path = settings.ArmaServersDataPath + "/" + server.ServerID.ToString();
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            File.WriteAllText(path + "/serverconfig.cfg", configData.ToString());


            Thread.CurrentThread.CurrentCulture = oldCulture;
        }