Compare commits
7 Commits
c367ebad1f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
694ccc14a4 | ||
|
|
6ee7a435e0 | ||
|
|
1d5b449d6d | ||
|
|
e0af5c2d33 | ||
|
|
78ed9e1daf | ||
|
|
1a81ae7f43 | ||
|
|
b75e03cd3e |
30
app.py
30
app.py
@@ -15,12 +15,11 @@ from typing import Any
|
|||||||
from libs.slow import (
|
from libs.slow import (
|
||||||
JSONAPI,
|
JSONAPI,
|
||||||
App,
|
App,
|
||||||
HTTPResponse,
|
|
||||||
JSONResponse,
|
|
||||||
Request,
|
Request,
|
||||||
redirect,
|
redirect,
|
||||||
render,
|
render,
|
||||||
)
|
)
|
||||||
|
from libs.slow.responses import HTTPResponse, JSONResponse
|
||||||
|
|
||||||
|
|
||||||
class Coord:
|
class Coord:
|
||||||
@@ -231,7 +230,7 @@ def room_key():
|
|||||||
@app.POST("/create_room")
|
@app.POST("/create_room")
|
||||||
async def new_room(request):
|
async def new_room(request):
|
||||||
if len(rooms) == len(letters) ** 4:
|
if len(rooms) == len(letters) ** 4:
|
||||||
return HTTPResponse(request, "Out of service", status=501)
|
return HTTPResponse("Out of service", status=501)
|
||||||
key = room_key()
|
key = room_key()
|
||||||
rooms[key] = Room()
|
rooms[key] = Room()
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
@@ -262,12 +261,13 @@ async def quick_match(request: Request):
|
|||||||
second = None
|
second = None
|
||||||
position: int = 0
|
position: int = 0
|
||||||
# UPDATE LOGIC
|
# UPDATE LOGIC
|
||||||
while not second and position < len(quick_queue):
|
while position < len(quick_queue):
|
||||||
if quick_queue[position] not in quick_map:
|
if quick_queue[position] not in quick_map:
|
||||||
if not first:
|
if not first:
|
||||||
first = quick_queue[position]
|
first = quick_queue[position]
|
||||||
else:
|
else:
|
||||||
second = quick_queue[position]
|
second = quick_queue[position]
|
||||||
|
break
|
||||||
position += 1
|
position += 1
|
||||||
if first and second:
|
if first and second:
|
||||||
room = Room()
|
room = Room()
|
||||||
@@ -278,21 +278,19 @@ async def quick_match(request: Request):
|
|||||||
|
|
||||||
qid = data["queue_id"]
|
qid = data["queue_id"]
|
||||||
if qid in quick_map:
|
if qid in quick_map:
|
||||||
return JSONResponse(request, {"room_id": quick_map[qid]})
|
return JSONResponse({"room_id": quick_map[qid]})
|
||||||
else:
|
else:
|
||||||
return JSONResponse(
|
return JSONResponse({}) # Client handles empty as continue to wait
|
||||||
request, {}
|
|
||||||
) # Client handles empty as continue to wait
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
qid = str(uuid.uuid4())
|
qid = str(uuid.uuid4())
|
||||||
quick_queue.append(qid)
|
quick_queue.append(qid)
|
||||||
return JSONResponse(request, {"queue_id": qid})
|
return JSONResponse({"queue_id": qid})
|
||||||
|
|
||||||
|
|
||||||
@app.GET("/")
|
@app.GET("/")
|
||||||
async def home(request):
|
async def home(request):
|
||||||
return render(request, "home.html")
|
return render("home.html")
|
||||||
|
|
||||||
|
|
||||||
@app.GET("/<id>")
|
@app.GET("/<id>")
|
||||||
@@ -301,13 +299,13 @@ async def game(request, id):
|
|||||||
return redirect("/")
|
return redirect("/")
|
||||||
if id not in rooms:
|
if id not in rooms:
|
||||||
return redirect("/")
|
return redirect("/")
|
||||||
return render(request, "game.html")
|
return render("game.html")
|
||||||
|
|
||||||
|
|
||||||
@app.POST("/join/<room_id>")
|
@app.POST("/join/<room_id>")
|
||||||
async def join(request, room_id):
|
async def join(request, room_id):
|
||||||
if room_id not in rooms:
|
if room_id not in rooms:
|
||||||
return JSONResponse(request, {"code": "NOGO", "error": "Room not found."}, 404)
|
return JSONResponse({"code": "NOGO", "error": "Room not found."}, 404)
|
||||||
room: Room = rooms[room_id]
|
room: Room = rooms[room_id]
|
||||||
player = room.add_player()
|
player = room.add_player()
|
||||||
if player:
|
if player:
|
||||||
@@ -473,7 +471,7 @@ def generate_valid_moves(
|
|||||||
king_safe = True
|
king_safe = True
|
||||||
for i in range(8):
|
for i in range(8):
|
||||||
for j in range(8):
|
for j in range(8):
|
||||||
p = board.grid[i][j]
|
p = board.grid[j][i]
|
||||||
if p != Piece.EMPTY and p.value.isupper() != is_white:
|
if p != Piece.EMPTY and p.value.isupper() != is_white:
|
||||||
# Enemy
|
# Enemy
|
||||||
enemy_moves = get_piece_moves(
|
enemy_moves = get_piece_moves(
|
||||||
@@ -663,11 +661,9 @@ async def static(request, fn):
|
|||||||
try:
|
try:
|
||||||
path = sanitize_filename(fn, Path("static/").resolve())
|
path = sanitize_filename(fn, Path("static/").resolve())
|
||||||
|
|
||||||
return HTTPResponse(
|
return HTTPResponse(path.read_bytes(), content_type="application/octet-stream")
|
||||||
request, path.read_bytes(), content_type="application/octet-stream"
|
|
||||||
)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return HTTPResponse(request, "404 File Not Found", status=404)
|
return HTTPResponse("404 File Not Found", status=404)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -194,7 +194,7 @@
|
|||||||
function setUI() {
|
function setUI() {
|
||||||
if (ready) {
|
if (ready) {
|
||||||
if (state == -1) {
|
if (state == -1) {
|
||||||
document.getElementById('stats').textCotnent = "";
|
document.getElementById('stats').innerText = "";
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const differenceMs = 30 * 60 * 1000 - Math.abs(start_time.getTime() - now.getTime());
|
const differenceMs = 30 * 60 * 1000 - Math.abs(start_time.getTime() - now.getTime());
|
||||||
const totalSeconds = Math.floor(differenceMs / 1000);
|
const totalSeconds = Math.floor(differenceMs / 1000);
|
||||||
@@ -210,7 +210,7 @@
|
|||||||
if (UID === undefined || turn != color) {
|
if (UID === undefined || turn != color) {
|
||||||
if (turn == 0) {
|
if (turn == 0) {
|
||||||
document.getElementById('turn').innerText = "White's Turn";
|
document.getElementById('turn').innerText = "White's Turn";
|
||||||
} else if (turn == 0) {
|
} else if (turn == 1) {
|
||||||
document.getElementById('turn').innerText = "Black's Turn";
|
document.getElementById('turn').innerText = "Black's Turn";
|
||||||
}
|
}
|
||||||
} else if (turn == color) {
|
} else if (turn == color) {
|
||||||
@@ -240,7 +240,7 @@
|
|||||||
mouse = [x, y];
|
mouse = [x, y];
|
||||||
i = Math.floor((x / width) * 8);
|
i = Math.floor((x / width) * 8);
|
||||||
j = Math.floor((y / height) * 8);
|
j = Math.floor((y / height) * 8);
|
||||||
if (ready && state == -1) {
|
if (ready && state == -1 && UID !== undefined) {
|
||||||
canvas.style.cursor = 'default';
|
canvas.style.cursor = 'default';
|
||||||
if (board) {
|
if (board) {
|
||||||
if (color == 0) {
|
if (color == 0) {
|
||||||
|
|||||||
@@ -154,7 +154,7 @@
|
|||||||
const code = document.getElementById("code");
|
const code = document.getElementById("code");
|
||||||
const pat = new RegExp("^[a-z0-9]{4}$")
|
const pat = new RegExp("^[a-z0-9]{4}$")
|
||||||
document.getElementById("join").addEventListener("click", () => {
|
document.getElementById("join").addEventListener("click", () => {
|
||||||
if (!reg.test(code.value)) {
|
if (!pat.test(code.value)) {
|
||||||
alert("Invalid ID");
|
alert("Invalid ID");
|
||||||
} else {
|
} else {
|
||||||
window.location.href = window.location.origin + "/" + code.value;
|
window.location.href = window.location.origin + "/" + code.value;
|
||||||
|
|||||||
2
libs
2
libs
Submodule libs updated: 24334d1def...fe65fafbe0
Reference in New Issue
Block a user