예제 #1
0
        public void Load()
        {
            Logger.Log("Loading " + Username + " from the database", LogType.Debug);
            DataTable playerdb = Database.fillData("SELECT * FROM _players WHERE Name='" + Username.SqlEscape() + "'");

            if (playerdb.Rows.Count == 0)
            {
                FirstLogin = DateTime.Now;
                LastLogin  = DateTime.Now;
                Money      = 0;
                Database.executeQuery("INSERT INTO _players (Name, IP, firstlogin, lastlogin, money, color) VALUES ('" + Username.SqlEscape() + "', '" + Ip.SqlEscape() + "', '" + FirstLogin.ToString("yyyy-MM-dd HH:mm:ss").SqlEscape() + "', '" + LastLogin.ToString("yyyy-MM-dd HH:mm:ss").SqlEscape() + "', 0, '" + Color.SqlEscape() + "')");
                DataTable temp = Database.fillData("SELECT * FROM _players WHERE Name='" + Username.SqlEscape() + "'");
                if (temp.Rows.Count != 0)
                {
                    UID = int.Parse(temp.Rows[0]["UID"].ToString());
                }
                temp.Dispose();
            }
            else
            {
                UID        = int.Parse(playerdb.Rows[0]["UID"].ToString());
                FirstLogin = DateTime.Parse(playerdb.Rows[0]["firstlogin"].ToString());
                LastLogin  = DateTime.Now;
                Money      = int.Parse(playerdb.Rows[0]["money"].ToString());
                Color      = playerdb.Rows[0]["color"].ToString();
                //TODO Add total login and total Blocks
            }
            playerdb.Dispose();
            LoadExtra();
            //Because milk
            this.OnPlayerDisconnect.Important += delegate {
                Save();
            };
        }