GetValue() public method

Retrieves the value of an entry inside a section.
/// is null or empty. /// Either section or entry is null.
public GetValue ( string section, string entry ) : object
section string /// The name of the section that holds the entry with the value.
entry string /// The name of the entry where the value is stored.
return object
コード例 #1
0
 public static int LoadServers(string serverFile, UInt16 defaultPort)
 {
     try
     {
         if (File.Exists(Environment.CurrentDirectory + @"\Settings\" + serverFile))
         {
             Systems.Ini ini = new Systems.Ini(Environment.CurrentDirectory + @"\Settings\" + serverFile);
             string[] sList = null;
             sList = ini.GetEntryNames("SERVERS");
             if (sList!=null && sList.Length > 0)
             {
                 foreach (string sectname in sList)
                 {
                     string sName = ini.GetValue("SERVERS", sectname, "");
                     Systems.SRX_Serverinfo SServerInfo = new Systems.SRX_Serverinfo();
                     SServerInfo.id = Convert.ToUInt16(ini.GetValue(sName, "id", 0));
                     SServerInfo.ip = ini.GetValue(sName, "ip", "192.168.1.5");
                     SServerInfo.wan = ini.GetValue(sName, "wan", "192.168.1.5");
                     SServerInfo.name = ini.GetValue(sName, "name", sName);
                     SServerInfo.port = Convert.ToUInt16(ini.GetValue(sName, "port", defaultPort));
                     SServerInfo.ipcport = Convert.ToUInt16(ini.GetValue(sName, "ipcport", "6001"));
                     SServerInfo.code = ini.GetValue(sName, "code", "");
                     SServerInfo.lan_wan = ini.GetValue(sName, "lan_wan", "0") == "1" ? true : false;
                     SServerInfo.Version = Convert.ToInt32(ini.GetValue(sName, "version", 0));
                     if (SServerInfo.ip == "" || SServerInfo.port == 0 || SServerInfo.id == 0 || SServerInfo.ipcport == 0 || GSList.ContainsKey(SServerInfo.id))
                     {
                         LogDebug.Show("IPC: Error on Server " + sName + " in " + serverFile + ": field missing or id already in use!");
                         SServerInfo = null;
                     }
                     else
                     {
                         GSList.Add(SServerInfo.id, SServerInfo);
                     }
                 }
             }
             if (GSList.Count() > 0)
             {
                 string servers = "Server";
                 if (GSList.Count > 1) servers = "Servers";
                 LogConsole.Show("Loaded " + GSList.Count() + " " + servers + " from server settings");
             }
             else
             {
                 Systems.SRX_Serverinfo GServer = new Systems.SRX_Serverinfo();
                 GServer.id = 1;
                 GServer.ip = "192.168.1.5";
                 if (Global.Network.multihomed)
                 {
                     //Multihomed
                 }
                 else
                 {
                     GServer.extip = Global.Network.LocalIP;
                 }
                 GServer.name = "[SERVER] Default";
                 GServer.port = defaultPort;
                 GServer.ipcport = 6001;
                 GServer.code = "xdxdxdxdxdxd";
                 GSList.Add(GServer.id, GServer);
             }
             sList = null;
             ini = null;
             return GSList.Count();
         }
         else
         {
             Systems.SRX_Serverinfo GServer = new Systems.SRX_Serverinfo();
             GServer.id = 1;
             GServer.ip = "192.168.1.5";
             if (Global.Network.multihomed)
             {
                 //Multihomed
             }
             else
             {
                 //No servers
                 GServer.extip = Global.Network.LocalIP;
             }
             GServer.name = "[SERVER "+ Global.Versions.appVersion +"]";
             GServer.port = defaultPort;
             GServer.ipcport = 6001;
             GServer.code = "";
             GSList.Add(GServer.id, GServer);
             return -1;
         }
     }
     catch (Exception ex)
     {
         LogConsole.Show("Error loading GameServer settings " + ex + "");
         return -2;
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: CarlosX/TestProjects
        static void Main(string[] args)
        {
            Program pro = new Program();
            //Definitions.Bootlogo._Load();
            Systems.Ini ini = null;
            LogConsole.Init();

            #region Default Settings
            int LSPort = 5999;
            int IPCPort = 5999;
            string LSIP = "127.0.0.1";
            string IPCIP = "127.0.0.1";
            #endregion

            #region Load Settings
            try
            {
                if (File.Exists(Environment.CurrentDirectory + @"\Settings\Settings.ini"))
                {
                    ini = new Systems.Ini(Environment.CurrentDirectory + @"\Settings\Settings.ini");
                    LSPort = Convert.ToInt32(ini.GetValue("SERVER", "port", 5999));
                    LSIP = ini.GetValue("SERVER", "ip", "127.0.0.1").ToString();
                    IPCPort = Convert.ToInt32(ini.GetValue("IPC", "port", 5999));
                    IPCIP = ini.GetValue("IPC", "ip", "127.0.0.1").ToString();
                    debug = ini.GetValue("CONSOLE", "debug", false);
                    MYSQL_USER = ini.GetValue("MYSQL", "user", "root");
                    MYSQL_PASS = ini.GetValue("MYSQL", "pass", "123456");
                    MYSQL_DATA = ini.GetValue("MYSQL", "data", "godswar");
                    MYSQL_IP = ini.GetValue("MYSQL", "ip", "127.0.0.1");
                    MYSQL_PORT = ini.GetValue("MYSQL", "port", 3306);
                    ini = null;
                    LogConsole.Show("Has loaded your ip settings successfully");
                }
                else
                {
                    LogConsole.Show("Settings.ini could not be found, using default setting");
                }
            }
            catch (Exception)
            {
                return;
            }
            #endregion

            _SQL.Init(MYSQL_IP, MYSQL_USER, MYSQL_PASS, MYSQL_DATA, MYSQL_PORT);

            Systems.Server net = new Systems.Server();

            net.OnConnect += new Systems.Server.dConnect(pro._OnClientConnect);
            net.OnError += new Systems.Server.dError(pro._ServerError);

            Systems.Client.OnReceiveData += new Systems.Client.dReceive(pro._OnReceiveData);
            Systems.Client.OnDisconnect += new Systems.Client.dDisconnect(pro._OnClientDisconnect);

            try
            {
                net.Start(LSIP, LSPort);
            }
            catch (Exception ex)
            {
                LogConsole.Show("Starting Server error: {0}", ex);
            }

            #region Load GameServers
            //Systems.LoadServers("GameServers.ini", 6001);
            #endregion

            #region IPC Listener
            /*IPCServer = new Network.Servers.IPCServer();
            IPCServer.OnReceive += new Network.Servers.IPCServer.dOnReceive(pro.OnIPC);
            try
            {
                IPCServer.Start(IPCIP, IPCPort);
                foreach (KeyValuePair<int, Systems.SRX_Serverinfo> GS in Systems.GSList)
                {
                    byte[] rqPacket = IPCServer.PacketRequestServerInfo(IPCPort);
                    Network.Servers.IPCenCode(ref rqPacket, GS.Value.code);
                    IPCServer.Send(GS.Value.ip, GS.Value.ipcport, rqPacket);
                    rqPacket = null;
                }
            }
            catch (Exception ex)
            {
                LogConsole.Show("Error start ICP: {0}", ex);
            }*/
            #endregion

            //LogConsole.Show("Ready for gameserver connection...");
            #region Loop Update GameServers
            while (true)
            {
                Thread.Sleep(100);
                /*foreach (KeyValuePair<int, Systems.SRX_Serverinfo> SSI in Systems.GSList)
                {
                    if (SSI.Value.status != 0 && SSI.Value.lastPing.AddMinutes(5) < DateTime.Now) // server unavailable
                    {
                        SSI.Value.status = 0;
                        LogConsole.Show("Server: {0}:({1}) has timed out, status changed to check", SSI.Value.id, SSI.Value.name);
                    }
                }*/
            }
            #endregion
        }