-
Notifications
You must be signed in to change notification settings - Fork 0
/
Arma3 Database.sql
113 lines (96 loc) · 3.28 KB
/
Arma3 Database.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import sqlite3
conn = sqlite3.connect('arma3_clan.db')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS players (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
region_id INTEGER,
email TEXT UNIQUE,
password TEXT NOT NULL,
FOREIGN KEY(region_id) REFERENCES regions(id)
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS stats (
id INTEGER PRIMARY KEY AUTOINCREMENT,
player_id INTEGER,
games_played INTEGER,
games_won INTEGER,
kill_death_ratio REAL,
FOREIGN KEY(player_id) REFERENCES players(id)
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS mods (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
version TEXT NOT NULL,
description TEXT
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS regions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
timezone TEXT NOT NULL
)
''')
conn.commit()
conn.close()
def add_player(name, region_id, email, password):
conn = sqlite3.connect('arma3_clan.db')
cursor = conn.cursor()
cursor.execute('INSERT INTO players (name, region_id, email, password) VALUES (?, ?, ?, ?)', (name, region_id, email, password))
conn.commit()
conn.close()
def add_stat(player_id, games_played, games_won, kill_death_ratio):
conn = sqlite3.connect('arma3_clan.db')
cursor = conn.cursor()
cursor.execute('INSERT INTO stats (player_id, games_played, games_won, kill_death_ratio) VALUES (?, ?, ?, ?)', (player_id, games_played, games_won, kill_death_ratio))
conn.commit()
conn.close()
def add_mod(name, version, description):
conn = sqlite3.connect('arma3_clan.db')
cursor = conn.cursor()
cursor.execute('INSERT INTO mods (name, version, description) VALUES (?, ?, ?)', (name, version, description))
conn.commit()
conn.close()
def add_region(name, timezone):
conn = sqlite3.connect('arma3_clan.db')
cursor = conn.cursor()
cursor.execute('INSERT INTO regions (name, timezone) VALUES (?, ?)', (name, timezone))
conn.commit()
conn.close()
def get_player_stats(player_id):
conn = sqlite3.connect('arma3_clan.db')
cursor = conn.cursor()
cursor.execute('SELECT * FROM stats WHERE player_id = ?', (player_id,))
stats = cursor.fetchall()
conn.close()
return stats
#Data validation
def is_valid_email(email):
import re
return re.match(r'^[^@]+@[^@]+\.[^@]+$', email) is not None
def is_valid_player(name, email, password):
return name and is_valid_email(email) and password
def is_valid_stat(games_played, games_won, kill_death_ratio):
return isinstance(games_played, int) and isinstance(games_won, int) and isinstance(kill_death_ratio, float)
#Retrieve player info
def get_player_info(player_id):
conn = sqlite3.connect('arma3_clan.db')
cursor = conn.cursor()
cursor.execute('''
SELECT players.id, players.name, players.email, regions.name AS region_name, stats.games_played, stats.games_won, stats.kill_death_ratio
FROM players
LEFT JOIN regions ON players.region_id = regions.id
LEFT JOIN stats ON players.id = stats.player_id
WHERE players.id = ?
''', (player_id,))
player_info = cursor.fetchone()
conn.close()
return player_info
import hashlib
def hash_password(password):
return hashlib.sha256(password.encode()).hexdigest()