Example #1
0
        private static Dictionary <int, GameFile> FetchGameServers()
        {
            Dictionary <int, GameFile> gs = new Dictionary <int, GameFile>();
            int count = 1;

            try
            {
                string          sql = "SELECT Id, exepath, parameters, type, enabled  FROM data";
                MySqlCommand    cmd = new MySqlCommand(sql, conn);
                MySqlDataReader rdr = cmd.ExecuteReader();
                GameFile        gf  = new GameFile();
                while (rdr.Read())
                {
                    gf.UniqueID       = Convert.ToInt32(rdr["Id"]);
                    gf.ExecutablePath = rdr["exepath"].ToString();
                    gf.Parameters     = rdr["parameters"].ToString();
                    gf.GameType       = rdr["type"].ToString();
                    int enabled = Convert.ToInt32(rdr["enabled"]);
                    if (enabled == 1)
                    {
                        gf.AutoRestart = true;
                    }
                    else
                    {
                        gf.AutoRestart = false;
                    }
                    gf.PID = -1;
                    gs.Add(count, gf);
                    count++;
                }
                rdr.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            return(gs);
        }
Example #2
0
        public static void StartGame(int uniqueid)
        {
            UpdatePathParams(uniqueid);
            int      index = -1;
            GameFile g     = null;

            foreach (KeyValuePair <int, GameFile> pairs in ActiveGameServers)
            {
                if (pairs.Value.UniqueID == uniqueid)
                {
                    index = pairs.Key;
                    g     = pairs.Value;
                }
            }
            if (index != -1 && g != null && g.PID == -1)
            {
                try
                {
                    Process p = new Process();
                    p.StartInfo.RedirectStandardOutput = false;
                    p.StartInfo.UseShellExecute        = true;
                    p.StartInfo.FileName  = g.ExecutablePath;
                    p.StartInfo.Arguments = g.Parameters;
                    p.EnableRaisingEvents = true;
                    p.Exited += GameExited;
                    p.Start();
                    ActiveGameServers[index].AutoRestart = true;
                    ActiveGameServers[index].PID         = p.Id;
                    ChangeActEna(1, g.UniqueID);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
        }