included "database" and primitive balance checking
let's make it so we have a way to integrate it with sql in later stages. PLEASE FIX the "fstring" in the js and the id to balance sequence
This commit is contained in:
BIN
Server/__pycache__/databasefornow.cpython-36.pyc
Normal file
BIN
Server/__pycache__/databasefornow.cpython-36.pyc
Normal file
Binary file not shown.
7
Server/databasefornow.py
Normal file
7
Server/databasefornow.py
Normal file
@ -0,0 +1,7 @@
|
||||
userNames = {"1":"boyan", "2":"nikola"}
|
||||
usersCoins = {"1":"200", "2":"100"}
|
||||
|
||||
def checkBalance(ID):
|
||||
userName = userNames[f"{ID}"]
|
||||
userCoins = usersCoins[f"{ID}"]
|
||||
return userName, userCoins
|
@ -1,12 +1,19 @@
|
||||
import asyncio
|
||||
import websockets
|
||||
import logging
|
||||
|
||||
from ratelimit import limits
|
||||
import time
|
||||
from databasefornow import *
|
||||
|
||||
logger = logging.getLogger('websockets')
|
||||
logger.setLevel(logging.INFO)
|
||||
logger.addHandler(logging.StreamHandler())
|
||||
|
||||
print("Ready")
|
||||
|
||||
# calls in number of requests
|
||||
# period in seconds
|
||||
@limits(calls=20, period=5)
|
||||
async def serveStuff(websocket, path):
|
||||
requestText = await websocket.recv()
|
||||
print(requestText)
|
||||
@ -15,6 +22,11 @@ async def serveStuff(websocket, path):
|
||||
currencyStatus = file.readline()
|
||||
file.close()
|
||||
await websocket.send(currencyStatus)
|
||||
|
||||
# bad way to send balance to given user - FIX!!!
|
||||
elif requestText == "STATUSONUSER":
|
||||
name, balance = checkBalance("1")
|
||||
await websocket.send(balance)
|
||||
else:
|
||||
await websocket.send("We don't accept DoS")
|
||||
|
||||
|
Reference in New Issue
Block a user