diff --git a/requirements.txt b/requirements.txt
index bcf2451..6ca9b0b 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,4 @@
-#psycopg2-binary
+psycopg2-binary
python-dotenv
flask-session
requests
diff --git a/src/routes/snake.py b/src/routes/snake.py
index beb49f6..c8a4a7b 100644
--- a/src/routes/snake.py
+++ b/src/routes/snake.py
@@ -20,10 +20,17 @@ log = logging.getLogger(__name__)
# Create database instance
-db = database.Database(db_name=env('DB_NAME', default='db.sqlite'))
-db.execute('CREATE TABLE IF NOT EXISTS snake_scores (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, score INTEGER)')
+db = database.Database(
+ host=env('DB_HOST', default='localhost'),
+ port=env('DB_PORT', default=5432),
+ user=env('DB_USER', default='user'),
+ password=env('DB_PASSWORD', default='password'),
+ db_name=env('DB_NAME', default='db_name')
+)
+
+db.execute('CREATE TABLE IF NOT EXISTS snake_scores (id SERIAL PRIMARY KEY, name TEXT, score INTEGER)')
db.execute('''CREATE TABLE IF NOT EXISTS snake_tokens (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
+ id SERIAL PRIMARY KEY,
token TEXT UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
ip TEXT UNIQUE NOT NULL
@@ -37,7 +44,7 @@ def valid_length(value, min_length=1, max_length=100):
def valid_score(score, game_token):
- start_time = db.execute('SELECT created_at FROM snake_tokens WHERE token = ?', (game_token,)).fetchone()
+ start_time = db.execute('SELECT created_at FROM snake_tokens WHERE token = %s', (game_token,)).fetchone()
if not start_time:
log.error("Game token not found.")
return False
@@ -59,7 +66,7 @@ def valid_score(score, game_token):
return False
# delete the token after score validation
- db.execute('DELETE FROM snake_tokens WHERE token = ?', (game_token,))
+ db.execute('DELETE FROM snake_tokens WHERE token = %s', (game_token,))
log.info(f"Score {score} validated successfully for token {game_token}.")
return True
@@ -90,8 +97,8 @@ def submit_score():
abort(400, "Score not vilid, so either you are trying to cheat the leaderboard or something is seriously wrong.")
try:
- db.execute('INSERT INTO snake_scores (name, score) VALUES (?, ?)', (name, int(score)))
- db.execute('DELETE FROM snake_tokens WHERE token = ?', (game_token,))
+ db.execute('INSERT INTO snake_scores (name, score) VALUES (%s, %s)', (name, int(score)))
+ db.execute('DELETE FROM snake_tokens WHERE token = %s', (game_token,))
log.info(f"Score submitted: {name} - {score}")
return redirect('/404')
@@ -106,13 +113,13 @@ def generate_start_token():
token = urandom(16).hex()
ip = request.headers.get('X-Forwarded-For', request.remote_addr)
- ip_token = db.execute('SELECT token FROM snake_tokens WHERE ip = ?', (ip,)).fetchone()
+ ip_token = db.execute('SELECT token FROM snake_tokens WHERE ip = %s', (ip,)).fetchone()
if ip_token:
log.info(f"Token already exists for IP: {ip}, reusing token.")
return ip_token[0]
log.info(f"Generated start token: {token}")
- db.execute('INSERT INTO snake_tokens (token, ip) VALUES (?, ?)', (token, ip))
+ db.execute('INSERT INTO snake_tokens (token, ip) VALUES (%s, %s)', (token, ip))
return token
@@ -134,7 +141,7 @@ def clear_old_tokens():
while True:
try:
one_hour_ago = datetime.datetime.now() - datetime.timedelta(hours=1)
- db.execute('DELETE FROM snake_tokens WHERE created_at < ?', (one_hour_ago,))
+ db.execute('DELETE FROM snake_tokens WHERE created_at < %s', (one_hour_ago,))
log.info("Old tokens cleared.")
except Exception as e:
log.error(f"Error clearing old tokens: {e}")
diff --git a/src/utils/database.py b/src/utils/database.py
index c8a36a2..8cc5d94 100644
--- a/src/utils/database.py
+++ b/src/utils/database.py
@@ -1,10 +1,15 @@
# Imports
-import sqlite3
+import psycopg2
-# Database class
class Database:
- def __init__(self, db_name='db.sqlite'):
- self.connection = sqlite3.connect(db_name, check_same_thread=False)
+ def __init__(self, host, port, user, password, db_name):
+ self.connection = psycopg2.connect(
+ host=host,
+ port=port,
+ user=user,
+ password=password,
+ database=db_name
+ )
self.cursor = self.connection.cursor()
def execute(self, query, params=None):
@@ -13,6 +18,6 @@ class Database:
self.cursor.execute(query, params)
self.connection.commit()
return self.cursor
-
+
def close(self):
self.connection.close()
\ No newline at end of file
diff --git a/static/content/buttons/8831.png b/static/content/buttons/8831.png
new file mode 100644
index 0000000..b978df8
Binary files /dev/null and b/static/content/buttons/8831.png differ
diff --git a/static/content/buttons/beeps.gif b/static/content/buttons/beeps.gif
new file mode 100644
index 0000000..0f0a2a0
Binary files /dev/null and b/static/content/buttons/beeps.gif differ
diff --git a/static/content/buttons/blinkiescafe.gif b/static/content/buttons/blinkiescafe.gif
new file mode 100644
index 0000000..189b8d4
Binary files /dev/null and b/static/content/buttons/blinkiescafe.gif differ
diff --git a/static/content/buttons/emmixis.gif b/static/content/buttons/emmixis.gif
new file mode 100644
index 0000000..5cb561f
Binary files /dev/null and b/static/content/buttons/emmixis.gif differ
diff --git a/static/content/buttons/insia.gif b/static/content/buttons/insia.gif
new file mode 100644
index 0000000..60121fc
Binary files /dev/null and b/static/content/buttons/insia.gif differ
diff --git a/static/content/buttons/ne0nbandit.png b/static/content/buttons/ne0nbandit.png
new file mode 100644
index 0000000..ee7c684
Binary files /dev/null and b/static/content/buttons/ne0nbandit.png differ
diff --git a/static/content/buttons/nekoweb.gif b/static/content/buttons/nekoweb.gif
new file mode 100644
index 0000000..59d6c9e
Binary files /dev/null and b/static/content/buttons/nekoweb.gif differ
diff --git a/static/content/buttons/neocities.gif b/static/content/buttons/neocities.gif
new file mode 100644
index 0000000..0d0d403
Binary files /dev/null and b/static/content/buttons/neocities.gif differ
diff --git a/static/content/buttons/s1nez.gif b/static/content/buttons/s1nez.gif
new file mode 100644
index 0000000..bfa3f4d
Binary files /dev/null and b/static/content/buttons/s1nez.gif differ
diff --git a/static/content/buttons/thnlqd.png b/static/content/buttons/thnlqd.png
new file mode 100644
index 0000000..33c8a54
Binary files /dev/null and b/static/content/buttons/thnlqd.png differ
diff --git a/static/content/buttons/tuxedodragon.gif b/static/content/buttons/tuxedodragon.gif
new file mode 100644
index 0000000..7cef099
Binary files /dev/null and b/static/content/buttons/tuxedodragon.gif differ
diff --git a/templates/bases/base.html b/templates/bases/base.html
index 44f434b..bc971f1 100644
--- a/templates/bases/base.html
+++ b/templates/bases/base.html
@@ -47,17 +47,18 @@