public static void Parse(String text, Player p)
        {
            string cmd = GetCommand(text).Substring(1);

            if (!IsCommand(text) || !cmds.ContainsKey(cmd) || p.level < cmdsLevel[cmd])
            {
                return;
            }

            string[] parameters = null;

            if (text.IndexOf(' ') != -1)
                parameters = text.Substring(cmd.Length + 2).Split(' ');

            File.AppendAllText("admin.log", "[ADMIN]: " + p.name + " (" + p.level + ")" + "ran command: " + text + "\n");

            cmds[cmd].Invoke(parameters);
        }
        public void InsertBuildingKill(Player killer, int building)
        {
            using (MySqlConnection conn = new MySqlConnection(dbConnection))
            {
                conn.Open();

                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection = conn;

                cmd.CommandText = "INSERT INTO `building_kills` (killer, building) VALUES (@killer, @building)";

                cmd.Prepare();

                cmd.Parameters.AddWithValue("@killer", killer.steamid);
                cmd.Parameters.AddWithValue("@building", building);

                cmd.ExecuteNonQuery();

                conn.Close();
            }
        }
 public void RegisterPlayer(Player p)
 {
     p.Register();
 }
        public void LoadOnlinePlayers(List<Player> players)
        {
            using (MySqlConnection conn = new MySqlConnection(dbConnection))
            {
                conn.Open();

                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection = conn;

                cmd.CommandText = "SELECT * FROM `players` WHERE online = 1";

                MySqlDataReader rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    Player p = new Player(rdr.GetString("name"), rdr.GetString("ip"), rdr.GetInt64("steamid"));

                    for (int i = 0; i < Util.pi.Length; i++)
                        Util.pi[i].SetValue(p, rdr.GetValue(i + 3));

                    p.CalculateRequiredExperience();

                    players.Add(p);
                }

                rdr.Close();
                conn.Close();
            }
        }
        // Probably deprecated
        /*private void UpdateDamageTable()
        {
            MySqlTransaction trTmp = conn.BeginTransaction();

            MySqlCommand cmd = new MySqlCommand();
            cmd.Transaction = trTmp;

            foreach(KeyValuePair<string, int> i in Util.damageSources)
            {
                cmd.CommandText = "REPLACE INTO `damage` (id, value) VALUES (@id, @value)";

                cmd.Prepare();

                cmd.Parameters.AddWithValue("@id", i.Value);
                cmd.Parameters.AddWithValue("@value", i.Key);

                cmd.ExecuteNonQuery();

                cmd.Parameters.RemoveAt("@id");
                cmd.Parameters.RemoveAt("@value");
            }

            trTmp.Commit();
        }*/
        public void InsertKill(Player killer, Player victim, int damage)
        {
            using (MySqlConnection conn = new MySqlConnection(dbConnection))
            {
                conn.Open();

                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection = conn;

                Int64 killer_id = killer == null ? 0 : killer.steamid;
                Int64 victim_id = victim == null ? 0 : victim.steamid;

                cmd.CommandText = "INSERT INTO `kills` (killer, victim, damage) VALUES (@killer, @victim, @damage)";

                cmd.Prepare();

                cmd.Parameters.AddWithValue("@killer", killer_id);
                cmd.Parameters.AddWithValue("@victim", victim_id);
                cmd.Parameters.AddWithValue("@damage", damage);

                cmd.ExecuteNonQuery();

                conn.Close();
            }
        }
        public static void OnPlayerJoin(Match join)
        {
            string id = join.Groups[3].ToString().Substring(2).TrimEnd( '\r', '\n' );

            Player p = new Player(
                join.Groups[1].ToString(),
                join.Groups[2].ToString(),
                Int64.Parse(id, System.Globalization.NumberStyles.HexNumber)
            );

            Player currPlayer = FindPlayerByName(p.name);

            if (currPlayer != null)
            {
                if (debug)
                    Console.WriteLine("Attempting to remove player " + p.name + " already existed, we're removing his old instance!");

                players.Remove(currPlayer);
            }

            db.RegisterPlayer(p);

            if(p.banned == 1)
            {
                Console.WriteLine("Kicking " + p.name + " because he is banned!");
                RCON.Command("AdminKick " + p.name);
                return;
            }

            p.online = 1;

            players.Add(p);

            if(debug)
                Console.WriteLine("Added player: " + p.name + " with ID: " + p.steamid);
        }