Ejemplo n.º 1
0
        public bool Stack_Purchase_Points(string incUser, string incUID)
        {
            Data_Server dServ    = new Data_Server();
            Stack       incStack = dServ.Stack_Get(incUID);
            int         i;

            if ((i = dServ.Player_Points_Get(incUser)) < incStack.Price_Points ||
                !Stack_Purchase(incUser, incUID))
            {
                return(false);
            }
            else
            {
                Player incPlayer = Player_Get(incUser);
                // Update the player's bank locally
                incPlayer.Points   -= incStack.Price_Points;
                incPlayer.Timestamp = DateTime.Now;
                SQLiteConnection db = new SQLiteConnection(dbPath);
                db.InsertOrReplace(incPlayer);
                db.Close();
                // And update the player's bank on the server
                dServ.Player_Purchase_Points(incUser, incStack.Price_Points, incStack.UID);

                return(true);
            }
        }
Ejemplo n.º 2
0
        public bool Stack_Purchase(string incUsername, string incUID)
        {
            if (Stack_Exists(incUID))
            {
                return(false);   // Purchase failed, stack already exists locally
            }
            SQLiteConnection db    = new SQLiteConnection(dbPath);
            Data_Server      dServ = new Data_Server();

            Stack incStack = dServ.Stack_Get(incUID);

            db.CreateTable <Stack>();
            db.Insert(incStack);
            db.Close();
            return(true);
        }
Ejemplo n.º 3
0
        public bool Player_Deposit_Quiz(string incUser, string incUID, int incPoints)
        {
            Data_Server dServ = new Data_Server();

            Player incPlayer = Player_Get(incUser);

            // Update the player's bank locally
            incPlayer.Points   += incPoints;
            incPlayer.Timestamp = DateTime.Now;
            SQLiteConnection db = new SQLiteConnection(dbPath);

            db.InsertOrReplace(incPlayer);
            db.Close();
            // And update the player's bank on the server
            dServ.Player_Deposit_Quiz(incUser, incPoints, incUID);

            return(true);
        }
Ejemplo n.º 4
0
        public Player Player_Default()
        {   // Query to see if any player exists locally
            Data_Server dServ = new Data_Server();

            SQLiteConnection db = new SQLiteConnection(dbPath);

            db.CreateTable <Player>();

            TableQuery <Player> qryPlayer = db.Table <Player>();

            if (qryPlayer.Count() == 0)
            {
                db.Close();
                return(null);
            }
            else
            {
                Player toReturn = qryPlayer.ElementAt(0);
                db.Close();
                return(Player_Get(toReturn.Username));
            }
        }
Ejemplo n.º 5
0
        public Player Player_Get(string incUser)
        {   // Returns the newest copy of the player
            Data_Server dServ = new Data_Server();

            SQLiteConnection db = new SQLiteConnection(dbPath);

            db.CreateTable <Player>();

            TableQuery <Player> qryPlayer = db.Table <Player>();

            Player remPlayer = dServ.Player_Get(incUser);
            Player locPlayer = null;

            foreach (Player eachPlayer in qryPlayer)
            {
                if (eachPlayer.Username == incUser)
                {
                    locPlayer = eachPlayer;
                }
            }

            if (DateTime.Compare(locPlayer.Timestamp, remPlayer.Timestamp) < 0)
            {
                bool existsLocally = locPlayer != null;
                locPlayer = remPlayer;
                if (existsLocally)
                {
                    db.InsertOrReplace(locPlayer);
                }
                db.Close();
                return(remPlayer);
            }
            else
            {
                dServ.Player_Update(locPlayer);
                return(locPlayer);
            }
        }