-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupload-full-version.html
More file actions
250 lines (224 loc) · 8.62 KB
/
upload-full-version.html
File metadata and controls
250 lines (224 loc) · 8.62 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="dark light">
<title>Upload full version - Quake III Arena Demo</title>
<style>
body:not(.reason-invalid-game-folder) .if-reason-invalid-game-folder,
body.reason-invalid-game-folder .if-not-reason-invalid-game-folder {
display: none;
}
</style>
</head>
<body>
<a href="/index.html">Home</a>
<br>
<br>
<!-- TODO perhaps the message text can be tailored
for when the user gets to this page by trying to join someone else's game,
and for when they click "unlock all maps" themselves. -->
<p class="if-reason-invalid-game-folder">
The player that is currently hosting the server
is running the full version of Quake III Arena,
but you only have the demo version.
</p>
<p class="if-reason-invalid-game-folder">
<!-- This paragraph is duplicated. -->
In order to play the full game together,
all players have to own the full game.
<!-- I tried connecting the two together, and was unable to. -->
</p>
<p>
Purchase the full Quake III Arena to unlock all maps and other content.
You can buy the game
<a
target="_blank"
href="http://store.steampowered.com/app/2200/"
>on Steam</a>
or
<a
target="_blank"
href="https://www.gog.com/game/quake_iii_arena"
>on GOG</a>.
</p>
<p class="if-not-reason-invalid-game-folder">
<!-- This paragraph is duplicated. -->
In order to play the full game together,
all players have to own the full game.
<!-- I tried connecting the two together, and was unable to. -->
</p>
<p>
After downloading the full game, locate the game directory,
and upload the pak0.pk3 - pak8.pk3 files
from the "baseq3" directory,
using the file picker below.
</p>
<p>
To find the game directory on Steam,
find the game in your Steam library,
right click it, then, under the "Manage" submenu,
click "Browse local files".
</p>
<p>
Don't worry: even after upgrading to the full game,
you will still be able to play the demo version with anyone.
</p>
<p>
For more info, see
<a
target="_blank"
href="https://ioquake3.org/help/players-guide"
>https://ioquake3.org/help/players-guide</a>.
</p>
<form id="gameFilesForm">
<label>
pak0.pk3 - pak8.pk3 files
<br>
<input id="gameFilesInput" type="file" accept=".pk3" multiple required />
</label>
<output>
<progress style="display: none" id="uploadProgress" min="0" max="33"></progress>
<p id="uploadError" style="display: none">Failed to upload</p>
</output>
</form>
<p class="if-reason-invalid-game-folder">
Alternatively, you can keep playing the demo version together.
Ask the current hoster to switch to the demo version,
or to let you host the game.
</p>
<script type="module">
// @ts-check
const ioquake3P = import("/ioquake3_opengl2.wasm32.js");
let goBackOnSuccess = false;
if (location.hash === '#go-back-on-success') {
goBackOnSuccess = true;
// Remove it immediately
// so that people don't share the URL like this.
location.hash = '';
}
const query = new URLSearchParams(window.location.search);
if (query.has('reason-invalid-game-folder')) {
document.body.classList.add('reason-invalid-game-folder');
}
/** @type {HTMLInputElement} */
const input = document.getElementById('gameFilesInput');
/** @type {HTMLFormElement} */
const form = document.getElementById('gameFilesForm');
input.onchange = async (event) => {
input.setCustomValidity('');
if (input.files == null || input.files.length === 0) {
return;
}
const expectedFileNames = [
'pak0.pk3',
'pak1.pk3',
'pak2.pk3',
'pak3.pk3',
'pak4.pk3',
'pak5.pk3',
'pak6.pk3',
'pak7.pk3',
'pak8.pk3',
]
let missingFiles = [...expectedFileNames];
// const extraneousFiles = [];
for (const actual of input.files) {
if (expectedFileNames.includes(actual.name)) {
missingFiles = missingFiles.filter(name => name !== actual.name)
} else {
// extraneousFiles.push(actual.name);
//
// Let's not prevent users from uploading extra `pk3` files.
}
}
/** @type {File | undefined} */
const pak0File = [...input.files].find(f => f.name === 'pak0.pk3')
if (pak0File != null && pak0File.size < 200_000_000) {
input.setCustomValidity(
`The size of the pak0.pk3 file is not the expected 457 MB. Are you sure this is a full game file and not a demo file?`
);
form.reportValidity();
return;
}
if (missingFiles.length > 0) {
input.setCustomValidity(
`Please select all files, including ${missingFiles.join(', ')}`
);
form.reportValidity();
return;
}
/** @type {File[]} */
const filesArr = [...input.files];
input.disabled = true;
/** @type {HTMLProgressElement} */
const progress = document.getElementById('uploadProgress');
progress.style.display = '';
const uploadStartedAt = Date.now()
const intervalId = setInterval(() => {
const secondsPassed = (Date.now() - uploadStartedAt) / 1000;
progress.value = secondsPassed;
// We expect to take this around 10-30 seconds.
// TODO better estimation somehow?
if (secondsPassed > 30) {
clearInterval(intervalId);
}
}, 100);
try {
const module = await (await ioquake3P).default();
const qhome = '/home/web_user/.q3a';
module.FS.mkdirTree(qhome);
module.FS.mount(module.FS.filesystems.IDBFS, {}, qhome);
await /** @type {Promise<void>} */ (new Promise((resolve, reject) =>{
module.FS.syncfs(true, (err) => {
if (err) {
reject(err);
return
}
resolve()
})
}));
const dir = `${qhome}/baseq3`;
module.FS.mkdirTree(dir);
await Promise.all(filesArr.map(async file => {
module.FS.writeFile(
`${dir}/${file.name}`,
new Uint8Array(await file.arrayBuffer())
);
}));
await /** @type {Promise<void>} */(new Promise((resolve, reject) => {
module.FS.syncfs(false, (err) => {
if (err) {
reject(err);
return
}
resolve()
});
}));
} catch (error) {
/** @type {HTMLElement} */
const errorEl = document.getElementById('uploadError');
errorEl.style.display = '';
errorEl.innerText += ' ' + error;
progress.style.display = 'none';
return
} finally {
clearInterval(intervalId);
}
console.log('Full game uploaded!')
progress.value = progress.max;
localStorage.setItem('haveFullVersion', 'true');
localStorage.setItem('defaultBasegame', 'baseq3');
if (goBackOnSuccess) {
history.back();
} else {
// Modify path, but preseve query string.
const nextUrl = new URL(location.href);
nextUrl.pathname = './index.html'
location.assign(nextUrl);
}
}
</script>
</body>
</html>