-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdatabase.rules.json
180 lines (180 loc) · 7.42 KB
/
database.rules.json
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
{
"rules": {
"games": {
"$gameId": {
".read": "auth != null",
"startedAt": {
".write": "auth != null && auth.uid == data.parent().child('host').val() && !data.exists() && newData.exists()",
".validate": "newData.isNumber() && newData.val() == now"
},
"status": {
".write": "auth != null && auth.uid == data.parent().child('host').val() && newData.exists()",
".validate": "newData.isString() && (data.val() == 'waiting' && newData.val() == 'ingame')"
},
"users": {
"$userId": {
".write": "auth != null && auth.uid == $userId && data.parent().parent().child('status').val() == 'waiting' && !(root.hasChild('users/' + auth.uid + '/banned') && now < root.child('users/' + auth.uid + '/banned').val())",
".validate": "newData.isNumber() && newData.val() == now"
}
},
"mode": {
".write": "auth != null && auth.uid == data.parent().child('host').val() && newData.exists()",
".validate": "newData.isString() && newData.val().matches(/^normal|junior|setchain|ultraset|ultrachain|ultra9|megaset|ghostset|puzzle|memory$/)"
},
"enableHint": {
".write": "auth != null && auth.uid == data.parent().child('host').val() && newData.exists()",
".validate": "newData.isBoolean() && data.parent().child('access').val() == 'private'"
}
}
},
"gameData": {
"$gameId": {
".read": "auth != null",
"hints": {
".write": "auth != null && root.hasChild('games/' + $gameId + '/users/' + auth.uid) && root.child('games/' + $gameId + '/enableHint').val() == true && root.child('games/' + $gameId + '/status').val() == 'ingame'",
".validate": "newData.isNumber() && auth.uid == root.child('games/' + $gameId + '/host').val()"
},
"pause": {
".write": "auth != null && auth.uid == root.child('games/' + $gameId + '/host').val() && root.child('games/' + $gameId + '/enableHint').val() == true && root.child('games/' + $gameId + '/status').val() == 'ingame'",
"start": {
".validate": "newData.isNumber() && (newData.val() == data.val() || newData.val() == now)"
},
"end": {
".validate": "newData.isNumber() && newData.val() == now"
},
"previous": {
".validate": "newData.isNumber() && (newData.val() == data.val() || newData.val() == (data.exists() ? data.val() : 0) + (data.parent().child('end').val() - data.parent().child('start').val()))"
},
"$other": {
".validate": false
}
},
"events": {
"$eventId": {
".write": "!data.exists() && newData.exists() && auth != null && root.hasChild('games/' + $gameId + '/users/' + auth.uid) && root.child('games/' + $gameId + '/status').val() == 'ingame'",
".validate": "newData.hasChildren(['user', 'time', 'c1', 'c2', 'c3']) && (newData.hasChild('c4') == root.child('games/' + $gameId + '/mode').val().matches(/^ultraset|ultrachain|ultra9|ghostset$/)) && (newData.hasChildren(['c5', 'c6']) == (root.child('games/' + $gameId + '/mode').val() == 'ghostset'))",
"user": {
".validate": "newData.isString() && newData.val() == auth.uid"
},
"time": {
".validate": "newData.isNumber() && newData.val() == now"
},
"c1": {
".validate": "newData.isString() && newData.val().matches(/^[0-2]{3,5}$/)"
},
"c2": {
".validate": "newData.isString() && newData.val().matches(/^[0-2]{3,5}$/)"
},
"c3": {
".validate": "newData.isString() && newData.val().matches(/^[0-2]{3,5}$/)"
},
"c4": {
".validate": "newData.isString() && newData.val().matches(/^[0-2]{3,5}$/)"
},
"c5": {
".validate": "newData.isString() && newData.val().matches(/^[0-2]{3,5}$/)"
},
"c6": {
".validate": "newData.isString() && newData.val().matches(/^[0-2]{3,5}$/)"
},
"$other": {
".validate": false
}
}
}
}
},
"users": {
".indexOn": "connections",
"$userId": {
".read": "auth != null",
".write": "auth != null && (auth.uid == $userId || root.child('users/' + auth.uid + '/admin').val() == true)",
".validate": "newData.hasChildren(['color', 'name']) && (newData.hasChild('banned') || !data.hasChild('banned') || root.child('users/' + auth.uid + '/admin').val() == true)",
"color": {
".validate": "newData.isString()"
},
"name": {
".validate": "newData.isString() && newData.val().length > 0 && newData.val().length <= 25"
},
"lastOnline": {
".validate": "newData.isNumber() && newData.val() == now"
},
"connections": {
"$connectionId": {
".validate": "newData.isString()"
}
},
"banned": {
".validate": "newData.isNumber() && root.child('users/' + auth.uid + '/admin').val() == true"
},
"$other": {
".validate": false
}
}
},
"userGames": {
"$userId": {
".read": "auth != null",
".indexOn": ".value",
"$gameId": {
".write": "auth != null && auth.uid == $userId",
".validate": "newData.isNumber() && newData.val() == root.child('games/' + $gameId + '/createdAt').val()"
}
}
},
"userStats": {
"$userId": {
".read": "auth != null"
}
},
"publicGames": {
".read": "auth != null",
".indexOn": ".value"
},
"chats": {
"$chatId": {
".read": "auth != null",
".indexOn": ["time", "user"],
"$messageId": {
".write": "auth != null && (!data.exists() || root.child('users/' + auth.uid + '/admin').val() == true) && !(root.hasChild('users/' + auth.uid + '/banned') && now < root.child('users/' + auth.uid + '/banned').val())",
".validate": "newData.hasChildren(['user', 'message', 'time'])",
"user": {
".validate": "newData.isString() && newData.val() == auth.uid"
},
"message": {
".validate": "newData.isString() && newData.val().length > 0 && newData.val().length <= 250"
},
"time": {
".validate": "newData.isNumber() && newData.val() == now"
},
"$other": {
".validate": false
}
}
}
},
"lobbyChat": {
".read": "auth != null",
".indexOn": ["time", "user"],
"$messageId": {
".write": "auth != null && (!data.exists() || root.child('users/' + auth.uid + '/admin').val() == true) && !(root.hasChild('users/' + auth.uid + '/banned') && now < root.child('users/' + auth.uid + '/banned').val())",
".validate": "newData.hasChildren(['user', 'message', 'time'])",
"user": {
".validate": "newData.isString() && newData.val() == auth.uid"
},
"message": {
".validate": "newData.isString() && newData.val().length > 0 && newData.val().length <= 250"
},
"time": {
".validate": "newData.isNumber() && newData.val() == now"
},
"$other": {
".validate": false
}
}
},
"stats": {
".read": "auth != null"
}
}
}