-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ejs
More file actions
169 lines (144 loc) · 4.03 KB
/
index.ejs
File metadata and controls
169 lines (144 loc) · 4.03 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
<!DOCTYPE html>
<html>
<head>
<title>QuakeJS</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<style>
html, body {
height: 100%;
padding: 0;
margin: 0;
background: #000;
}
#viewport-frame {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
overflow: hidden;
background-image: url("https://i.imgur.com/b8HuMlo.gif");
background-repeat: no-repeat;
background-position: center;
background-size: 24em;
}
#viewport-frame:focus {
outline: none;
}
#viewport {
background: #000;
width: 100%;
height: 100%;
}
#viewport-frame:-moz-full-screen,
#viewport:-moz-full-screen {
display: block;
position: absolute;
left: 0;
top: 0;
margin: 0;
width: 100%;
height: 100%;
}
#viewport-frame:-webkit-full-screen,
#viewport:-webkit-full-screen {
display: block;
position: absolute;
left: 0;
top: 0;
margin: 0;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="viewport-frame"></div>
</body>
<script>
function getQueryCommands() {
var search = /([^&=]+)/g;
var query = window.location.search.substring(1);
var args = [];
var match;
while (match = search.exec(query)) {
var val = decodeURIComponent(match[1]);
val = val.split(" ");
val[0] = "+" + val[0];
args.push.apply(args, val);
}
return args;
}
function getCookie(key) {
const cookies = document.cookie.split("; ");
for (let cookie of cookies) {
let [cookieKey, cookieValue] = cookie.split("=");
if (cookieKey === key) {
return decodeURIComponent(cookieValue);
}
}
return null;
}
function setCookie(key, value, days) {
let expires = "";
if (days) {
let date = new Date();
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
expires = "; expires=" + date.toUTCString();
}
document.cookie = key + "=" + encodeURIComponent(value) + expires + "; path=/";
}
function getRandomItem(arr) {
const randomIndex = Math.floor(Math.random() * arr.length);
return arr[randomIndex];
}
window.onload = function () {
function resizeViewport() {
if (!ioq3.canvas) {
// ignore if the canvas hasn't yet initialized
return;
}
if ((document["webkitFullScreenElement"] || document["webkitFullscreenElement"] ||
document["mozFullScreenElement"] || document["mozFullscreenElement"] ||
document["fullScreenElement"] || document["fullscreenElement"])) {
// ignore resize events due to going fullscreen
return;
}
ioq3.setCanvasSize(ioq3.viewport.offsetWidth, ioq3.viewport.offsetHeight);
}
ioq3.viewport = document.getElementById("viewport-frame");
ioq3.elementPointerLock = true;
window.addEventListener("resize", resizeViewport);
// merge default args with query string args
var args = ["+set", "fs_cdn", "<%= content %>", "+set", "sv_master1", "<%= master %>"];
args.push.apply(args, getQueryCommands());
let username = getCookie( "username" )
if (!username) {
username = prompt(
"Please enter your nickname",
getRandomItem( [
// random player names here :>
"Gordon Freeman", "Alyx Vance",
"Eli Vance", "Isaac Kleiner",
"Barney Calhoun", "Judith Mossman",
"Wallace Breen", "Father Grigori",
"Leon", "Odessa Cubbage", "G-Man",
"Wallace Breen", "John Carmack"
] )
);
if (!username) {
window.location.reload();
return;
}
setCookie( "username", username, 30 );
args.push.apply( args, [ "+s_volume", "0.1" ] );
args.push.apply( args, [ "+s_musicvolume", "0.05" ] );
}
args.push.apply( args, [ "+name", username ] );
// uncomment the following line to connect all clients to a specific server automatically
// args.push.apply( args, [ "+connect", "q3js.changeme.com:27961" ] )
ioq3.callMain( args );
};
</script>
<script type="text/javascript" src="<%= ioquake3js %>"></script>
</html>