-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartServer.html
More file actions
197 lines (163 loc) · 4.61 KB
/
Copy pathstartServer.html
File metadata and controls
197 lines (163 loc) · 4.61 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Host Server</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');
body {
margin: 0;
background: #3b3b3b;
font-family: 'Press Start 2P', monospace;
color: white;
text-shadow: 2px 2px #000;
padding: 20px;
}
h2 {
margin-bottom: 20px;
}
.option {
margin-bottom: 25px;
}
label {
display: block;
font-size: 14px;
margin-bottom: 8px;
}
input {
width: 95%;
padding: 10px;
font-size: 14px;
border: 3px solid #000;
background: #d9d9d9;
}
button {
margin-top: 10px;
width: 100%;
padding: 15px;
background: #4c7f4c;
border: 4px solid #2e4d2e;
color: white;
cursor: pointer;
font-family: 'Press Start 2P';
}
button:hover {
background: #6aa96a;
}
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ffcf30;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: rgb(255, 255, 255);
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #2196F3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
</style>
</head>
<body>
<h2>Host Server</h2>
<div class="option">
<label>Server Name</label>
<input id="serverName" placeholder="My Awesome World">
</div>
<div class="option">
<label id="checkbox-label">Creating new Server</label>
<label class="switch">
<input type="checkbox" oninput="checkboxChanged()" checked>
<span class="slider"></span>
</label>
</div>
<div id="checked" style="display: none;" class="option">
<label>Only start server if no other server with this name is running</label>
</div>
<div id="unchecked" class="option">
<label>Seed Number</label>
<input id="seed" placeholder="123456789">
</div>
<button onclick="startServer()">Start Server</button>
<script type="module">
import { doesServerExist, createServer } from "./src/networking/server.js";
const checkbox = document.querySelector(".switch input");
const label = document.getElementById("checkbox-label");
const seedInput = document.getElementById("seed");
function checkboxChanged() {
if (checkbox.checked) {
label.textContent = "Creating new Server";
} else {
label.textContent = "Start an Already Created Server";
}
document.getElementById("unchecked").style.display = checkbox.checked ? "block" : "none";
document.getElementById("checked").style.display = checkbox.checked ? "none" : "block";
}
async function startServer() {
const name = document.getElementById("serverName").value;
if (name.trim() === "") {
alert("Please enter a valid server name.");
return;
}
const exists = await doesServerExist(name);
if (checkbox.checked) {
// Create new server
if (document.getElementById("seed").value.trim() === "") {
alert("Please enter a valid seed number.");
return;
}
if (exists) {
alert("A server with this name already exists. Please choose a different name or uncheck the box to start the existing server if it is not already running.");
return;
}
} else {
// Start existing server
if (!exists) {
alert("No server with this name exists. Please check the name or check the box to create a new server.");
return;
}
}
console.log("Starting server:", name);
if (checkbox.checked) {
// create new server with seed
await createServer(name, seedInput.value);
}
window.parent.location = `server.html?name=${encodeURIComponent(name)}`;
}
window.startServer = startServer;
window.checkboxChanged = checkboxChanged;
</script>
</body>
</html>