Ejemplo n.º 1
0
def withdraw_():
    check = wallet.check()
    if not check:
        return redirect("/")
    if request.method == "POST":
        if request.form.get("email"):
            email = request.form['email']
            check = db.members.find_one({"email":email})
            if check:
                flash("Email already exists in our database.")
                return redirect("/account/edit")
            db.members.update({"email":session['login']}, {"$set":{"email":email}})
            flash("Email updated successfully!")
            return redirect("/account/edit")
        if request.form.get("password"):
            password = protect.protect(request.form['password'])
            confirm = protect.protect(request.form['verifypassword'])
            if password != confirm:
                flash("Passwords do not match.")
                return redirect("/account/edit")
            else:
                db.members.update({"email":session['login']}, {"$set":{"password":password}})
                flash("Password updated successfully.")
                return redirect("/account/edit")
    return render_template("edit.html", user=check, admin=check['admin'])
Ejemplo n.º 2
0
def deposit_():
    check = wallet.check()
    if not check:
        return redirect("/")
    
    games = db.games.find({"rsname":check['rsname']}).sort("_id", -1)
    
    return render_template("games.html", games=games, admin=check['admin'])
Ejemplo n.º 3
0
def delete_(uid):
	user = wallet.check()
	user = db.members.find_one({"email":session['login']})
	check = db.games.find_one({"creator":user['rsname']})
	
	if check or user['admin']:
		if db.games.remove({"id":uid}):
			return redirect("/account/games")
		else:
			return "This game does not exist. <a href='javascript:history.back()'>Click</a> here to go back."
	else:
		return "Shame on you. This game does not belong to you."
Ejemplo n.º 4
0
def bank_():
    user = wallet.check()
    if not user or not user['admin']:
	    return redirect("/")

    total = db.bank.find_one()
    if not total:
        db.bank.insert({"total":0})
        total = db.bank.find_one()
    
    if request.method == "POST":
        if request.form.get("withdraw"):
            name = request.form['rsname']
            deposit = request.form['finalwithdraw']
            try:
                deposit = int(deposit)
            except:
                flash("Deposit must be an integer.")
                return redirect("/admin/bank")

            check = db.members.find_one({"rsname":name})
            if not check:
                flash("RSname does not exist on our site.")
                return redirect("/admin/bank")
            
            db.members.update({"rsname":name}, {"$set":{"wallet":check['wallet'] - deposit}})
            db.bank.update({"total":total['total']}, {"$set":{"total":total['total'] - deposit }})
            flash("Withdraw successful")
            return redirect("/admin/bank")
        if request.form.get("deposit"):
            name = request.form['rsname']
            deposit = request.form['finaldeposit']
            try:
                deposit = int(deposit)
            except:
                flash("Deposit must be an integer.")
                return redirect("/admin/bank")

            check = db.members.find_one({"rsname":name})
            if not check:
                flash("RSname does not exist on our site.")
                return redirect("/admin/bank")
            
            db.members.update({"rsname":name}, {"$set":{"wallet":check['wallet'] + deposit}})
            db.bank.update({"total":total['total']}, {"$set":{"total":total['total'] + deposit }})
            flash("Deposit successful")
            return redirect("/admin/bank")
    return render_template("bank.html", total=total)
Ejemplo n.º 5
0
def create_():
    check = wallet.check()
    if not check:
        return redirect("/")
    if request.method == "POST":
        if not request.form.get("amount"):
            
            flash("You need to bet an amount.")
            return redirect("/create/")
        amount = request.form['amount']
        try:
            amount = int(amount)
        except:
            flash("Amount needs to be an integer.")
            return redirect("/create/")
        if amount > check['wallet']:
            flash("You don't have enough gold.")
            return redirect("/create/")
        if amount < 10000:
            flash("You have to bet atleast 10000.")
            return redirect("/create/")
        gameid = uuid.uuid4().hex
        game = request.form['radios1']
        if game != "bank":
            try:
                players = int(request.form['radios'])
            except:
                flash("Number of players has to be an integer.")
                return redirect("/create/")
            db.games.insert({"type":"Dice Duel", "creator":check['rsname'], "rsname":check['rsname'], "id":gameid, "bet":amount, "participants":1, "max_participants":players, "win":None, "roll":None, "resullt":None})
            db.members.update({"rsname":check['rsname']}, {"$set":{"wallet":check['wallet'] - amount}})
        elif game == "bank":
            db.members.update({"rsname":check['rsname']}, {"$set":{"wallet":check['wallet'] - amount}})
            roll = random.randint(1, 101)
            if roll > 60:
                win = (amount * 2)
                win -= win * 0.05
                db.games.insert({"rsname":check['rsname'], "type":"Bank", "id":gameid, "bet":amount, "participants":1, "max_participants":1, "win":amount, "roll":roll, "result":"You won!"})
                db.members.update({"rsname":check['rsname']}, {"$set":{"wallet":check['wallet'] + win}})
            
            if roll <= 60:
                db.games.insert({"rsname":check['rsname'], "type":"Bank", "id":gameid, "bet":amount, "participants":1, "max_participants":1, "win":0, "roll":roll, "result":"You lost"})
            
        flash("Game has been created.")
        return redirect("/create/")
    return render_template("create.html", admin=check['admin'])
Ejemplo n.º 6
0
def match_(uid):
    user = wallet.check()
    if not user:
        return redirect("/")
    
    if request.method == "POST":
        check = db.games.find_one({"rsname":user['rsname'], "id":uid})
        if check:
            flash("You are already in this game.")
            return reirect("/match/"+uid)

        c2 = db.games.find_one({"id":uid})
        if c2['participants'] >= c2['max_participants']:
            flash("There are too many people in this game.")
            return redirect("/match/"+uid)
        
        if user['wallet'] < c2['bet']:
            flash("You don't have enough gold to bet.")
            return redirect("/match/"+uid)

        c3 = db.games.find({"id":uid})
        control = None
        for x in c3:
            participants = x['participants'] + 1
            db.games.update({"_id":ObjectId(x['_id'])}, {"$set":{"participants":x['participants']+1}})
            control = x

        db.games.insert({"type":"Dice Duel", "creator":control['creator'], "rsname":user['rsname'], "id":control['id'], "bet":control['bet'], "participants":control['participants']+1, "max_participants":control['max_participants'], "win":None, "roll":None, "resullt":None})
        db.members.update({"rsname":user['rsname']}, {"$set":{"wallet":user['wallet'] - control['bet']}})
        if control['max_participants'] == control['participants'] + 1:
    
            
            people = db.games.find({"id":uid}) 
            for x in people:
                while True:
                    roll = random.randint(1, 101)
                    if db.games.find_one({"id":uid, "roll":roll}):
                        pass
                    else:
                        db.games.update({"id":uid, "rsname":x['rsname']}, {"$set":{"roll":roll}})
                        break
            winner = {"roll":-5}
            check_winner = db.games.find({"id":uid})
            for x in check_winner:
                if x['roll'] > winner['roll']:
                    winner = x
            
            
            member = db.members.find_one({"rsname":winner['rsname']}) 
            final_update = db.games.find({"id":uid})
            for x in final_update:
                if x['rsname'] == winner['rsname']:
                    win = control['bet'] * x['participants']
                    win -= win * 0.05
                    win += member['wallet']
                    db.games.update({"rsname":x['rsname'], "id":uid}, {"$set":{"win":control['win'], "result":winner['rsname']+" Wins!"}})
                    db.members.update({"rsname":winner['rsname']}, {"$set":{"wallet":win}})
                else:
                    db.games.update({"rsname":x['rsname'], "id":uid}, {"$set":{"win":0, "result":winner['rsname']+" Wins!"}})

            return redirect("/match/"+uid)

    out = []
    data = db.games.find({"id":uid}).sort("_id", -1)
    for x in data:
        out.append(x)
    control = out[0]
    return render_template("match.html", games=out, control = x, admin=user['admin'])
Ejemplo n.º 7
0
def account_():
    check = wallet.check()
    if not check:
        return redirect("/")
    tickets = db.tickets.find({"rsname":check['rsname']}).sort("_id", -1)
    return render_template("dashboard.html", admin=check['admin'], tickets=tickets)
Ejemplo n.º 8
0
def tickets_():
    user = wallet.check()
    if not user or not user['admin']:
        return redirect("/")
    tickets = db.tickets.find({"status":"Not Completed"}).sort("_id", 1)
    return render_template("tickets.html", tickets=tickets)
Ejemplo n.º 9
0
def tickets_view(uid):
    user = wallet.check()
    if not user or not user['admin']:
        return redirect("/")
	return render_template("tickets_view.html")
Ejemplo n.º 10
0
def deny(oid):
    user = wallet.check()
    if not user or not user['admin']:
        return redirect("/")
    db.tickets.update({"_id":ObjectId(oid)}, {"$set":{"status":"Transaction could not be completed, try making another request."}})
    return redirect("/admin/tickets")
Ejemplo n.º 11
0
def complete(oid):
    user = wallet.check()
    if not user or not user['admin']:
        return redirect("/")
    db.tickets.update({"_id":ObjectId(oid)}, {"$set":{"status":"Transaction Complete"}})
    return redirect("/admin/tickets")