Example #1
0
        public ServConfig(object caller, object mon)
        {
            InitializeComponent();
            this.caller = (Manager)caller;
            this.mon = (SrcdsMonitor)mon;

            autoStart.Checked = this.mon.isAutoStart;

            this.Text = this.mon.getName() + " - Configuration";

            addr.Text = this.mon.getAddr();
            parms.Text = this.mon.getCmd();
            executable.Text = this.mon.getExe();
            name.Text = this.mon.getName();
            port.Text = this.mon.getPort();
            maxplayers.Text = this.mon.getMaxplayers(true);

            //There has GOT to be a better way of doing this...
            cpuList.Add(cpu1);
            cpuList.Add(cpu2);
            cpuList.Add(cpu3);
            cpuList.Add(cpu4);
            cpuList.Add(cpu5);
            cpuList.Add(cpu6);
            cpuList.Add(cpu7);
            cpuList.Add(cpu8);
            cpuList.Add(cpu9);
            cpuList.Add(cpu10);
            cpuList.Add(cpu12);
            cpuList.Add(cpu13);
            cpuList.Add(cpu14);
            cpuList.Add(cpu15);
            cpuList.Add(cpu16);

            foreach (CheckBox box in cpuList)
            {
                box.CheckStateChanged += new EventHandler(cpu_CheckedChanged);
            }
            for (int c = 0; c < Environment.ProcessorCount; c++)
            {
                cpuList[c].Visible = true;
            }
            if (this.mon.AffinityMask != new String('1', Environment.ProcessorCount))
            {
                cpuAll.Checked = false;
                for (int c = 0; c < Environment.ProcessorCount; c++)
                {
                    if (this.mon.AffinityMask[c] == '1')
                    {
                        cpuList[c].Checked = true;
                    }
                    else
                    {
                        cpuList[c].Checked = false;
                    }
                }
            }
        }
Example #2
0
 internal void addMonitor(SrcdsMonitor mon)
 {
     monArray.Add(mon);
     ServerList.Rows.Add();
     ServerList.Rows[ServerList.Rows.Count - 1].Cells[0].Value = mon.getName();
     ServerList.Rows[ServerList.Rows.Count - 1].Cells[5].Value = mon.getMaxplayers(false);
     ServerList.Rows[ServerList.Rows.Count - 1].Cells[7].Value = mon.getAddr();
     ServerList.Rows[ServerList.Rows.Count - 1].Cells[8].Value = mon.getPort();
 }
Example #3
0
        internal void DeleteServer(SrcdsMonitor mon)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load("servers.xml");
            XmlNode root = xmlDoc.DocumentElement;
            XmlNode serv = root.SelectSingleNode(String.Format("descendant::server[@id='{0}']", monArray[ServerList.SelectedRows[0].Index].getId()));
            root.RemoveChild(serv);
            xmlDoc.Save("servers.xml");

            int i = monArray.IndexOf(mon);
            monArray.Remove(mon);
            ServerList.Rows.RemoveAt(i);
        }
Example #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load("servers.xml");
            XmlAttribute id = xmlDoc.CreateAttribute("id");
            XmlAttribute name = xmlDoc.CreateAttribute("name");
            XmlAttribute addr = xmlDoc.CreateAttribute("address");
            XmlAttribute port = xmlDoc.CreateAttribute("port");
            XmlAttribute maxplayers = xmlDoc.CreateAttribute("maxplayers");
            XmlAttribute auto = xmlDoc.CreateAttribute("autostart");
            XmlNode root = xmlDoc.DocumentElement;

            System.Net.IPAddress ip;
            if (!System.Net.IPAddress.TryParse(ipAddr.Text, out ip))
            {
                MessageBox.Show("The value enetered in the IP field is invalid", "Invalid IP");
                return;
            }
            uint _port;
            if (!uint.TryParse(iPort.Text, out _port))
            {
                MessageBox.Show("The value enetered in the port field is invalid", "Invalid port");
                return;
            }
            uint _maxplayers;
            if (!uint.TryParse(iMaxplayers.Text, out _maxplayers))
            {
                MessageBox.Show("The value enetered in the maxplayers field is invalid", "Invalid maxplayers");
                return;
            }

            name.Value = servName.Text;
            id.Value = servID.Text;
            addr.Value = ipAddr.Text;
            port.Value = iPort.Text;
            maxplayers.Value = iMaxplayers.Text;

            String exe = "srcds.exe";
            String app = "";
            String game = "";
            switch (comboBox1.SelectedIndex)
            {
                case 0:
                    app = "90";
                    exe = "hlds.exe";
                    game = "cstrike";
                    break;
                case 1:
                    app = "740";
                    game = "csgo";
                    break;
                case 2:
                    app = "90 +app_set_config \"90 mod czero\"";
                    exe = "hlds.exe";
                    game = "czero";
                    break;
                case 3:
                    app = "232330";
                    game = "cstrike";
                    break;
                case 4:
                    app = "232290";
                    game = "dods";
                    break;
                case 5:
                    app = "90 +app_set_config \"90 mod dmc\"";
                    exe = "hlds.exe";
                    break;
                case 6:
                    app = "4020";
                    game = "garrysmod";
                    break;
                case 7:
                    app = "90";
                    exe = "hlds.exe";
                    game = "cstrike";
                    break;
                case 8:
                    app = "222860";
                    game = "left4dead";
                    break;
                case 9:
                    app = "232250";
                    game = "tf";
                    break;
            }

            XmlAttribute xgame = xmlDoc.CreateAttribute("game");
            xgame.Value = game;

            XmlNode executable = xmlDoc.CreateElement("executable");
            executable.InnerText = servExe.Text + @"\" + exe;

            XmlNode param = xmlDoc.CreateElement("params");
            param.InnerText = servParams.Text;

            XmlNode autostart = xmlDoc.CreateElement("autostart");
            autostart.InnerText = checkBox1.Checked.ToString();

            XmlNode affn = xmlDoc.CreateElement("affinity");
            affn.InnerText = BuildAffinityString();

            XmlNode serv = xmlDoc.CreateElement("server");
            serv.Attributes.Append(id);
            serv.Attributes.Append(name);
            serv.Attributes.Append(xgame);
            serv.Attributes.Append(addr);
            serv.Attributes.Append(port);
            serv.Attributes.Append(maxplayers);

            serv.AppendChild(executable);
            serv.AppendChild(param);
            serv.AppendChild(autostart);
            serv.AppendChild(affn);

            root.AppendChild(serv);

            xmlDoc.Save("servers.xml");

            SrcdsMonitor mon = new SrcdsMonitor(servExe.Text + "\\" + exe, game, servParams.Text, servName.Text, servID.Text, ipAddr.Text, iPort.Text, iMaxplayers.Text, affn.InnerText, this.sender);
            this.sender.addMonitor(mon);
            if (download.Checked)
            {
                System.Diagnostics.ProcessStartInfo startinfo = new System.Diagnostics.ProcessStartInfo();
                startinfo.FileName = this.sender.getSteamCmd();
                startinfo.Arguments = String.Format("+login anonymous +force_install_dir {0} +app_update {1} validate +quit", servExe.Text, app);
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo = startinfo;
                try
                {
                    proc.Start();
                }
                catch (Exception ex)
                {
                    if (ex.GetType() == typeof(System.ComponentModel.Win32Exception))
                    {
                        MessageBox.Show("The path to the steamcmd executable was invalid", "SteamCMD not foud");
                        return;
                    }
                    else
                    {
                        throw;
                    }
                }
                mon.WaitForInstall(proc);
            }
            this.Dispose();
        }
Example #5
0
        private void ReadXml()
        {
            String sName, sExe, sCmd, sID, sAddr, sPort, sMaxplayers, sAffn, game;
            if (!System.IO.File.Exists("servers.xml"))
            {
                XmlDocument xmlDoc = new XmlDocument();
                XmlElement root = xmlDoc.CreateElement("servers");

                xmlDoc.AppendChild(root);

                xmlDoc.Save("servers.xml");
            }

            using(XmlReader reader = new XmlTextReader("servers.xml"))
            {
                while(reader.ReadToFollowing("server"))
                {
                    reader.MoveToFirstAttribute();
                    sID = reader.Value;

                    reader.MoveToNextAttribute();
                    sName = reader.Value;

                    reader.MoveToNextAttribute();
                    game = reader.Value;

                    reader.MoveToNextAttribute();
                    sAddr = reader.Value;

                    reader.MoveToNextAttribute();
                    sPort = reader.Value;

                    reader.MoveToNextAttribute();
                    sMaxplayers = reader.Value;

                    reader.ReadToFollowing("executable");
                    sExe = @reader.ReadElementContentAsString();

                    reader.ReadToFollowing("params");
                    sCmd = reader.ReadElementContentAsString();

                    reader.ReadToFollowing("autostart");
                    string autoStart = reader.ReadElementContentAsString();

                    reader.ReadToFollowing("affinity");
                    sAffn = reader.ReadElementContentAsString();

                    SrcdsMonitor mon = new SrcdsMonitor(sExe, game, sCmd, sName, sID, sAddr, sPort, sMaxplayers, sAffn, this);

                    monArray.Add(mon);
                    ServerList.Rows.Add();
                    ServerList.Rows[ServerList.Rows.Count - 1].Cells[0].Value = sName;
                    ServerList.Rows[ServerList.Rows.Count - 1].Cells[5].Value = sMaxplayers;
                    ServerList.Rows[ServerList.Rows.Count - 1].Cells[7].Value = sAddr;
                    ServerList.Rows[ServerList.Rows.Count - 1].Cells[8].Value = sPort;

                    if (bool.Parse(autoStart))
                    {
                        mon.Start();
                        mon.isAutoStart = true;
                    }
                }
            }

            System.Timers.Timer status = new System.Timers.Timer(1000);
            status.SynchronizingObject = this;
            status.Elapsed += new System.Timers.ElapsedEventHandler(sUpdateStatus);
            status.AutoReset = true;
            status.Enabled = true;
            status.Start();
        }
Example #6
0
 public WaitForExit(Process proc, object caller, int procType)
 {
     this.proc = proc;
     this.caller = (SrcdsMonitor)caller;
     this.procType = procType;
 }
Example #7
0
 public SrcdsPinger(object source, IPAddress addr, int port, Process proc)
 {
     this.caller = (SrcdsMonitor)source;
     this.proc = proc;
 }