Added a check to make sure the server doesn't exist before creating it
This commit is contained in:
parent
4007b99833
commit
54199bf7c8
@ -2,6 +2,18 @@ body{
|
||||
background-color: #e6e6e6;
|
||||
}
|
||||
|
||||
input[type=submit]:disabled,
|
||||
button:disabled{
|
||||
background-color: darkgrey;
|
||||
}
|
||||
input[type=submit]:disabled:hover,
|
||||
button:disabled:hover{
|
||||
background-color: darkgrey;
|
||||
border: 1px solid #bbb;
|
||||
color: #555;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* set the max-width for centered content */
|
||||
.container{
|
||||
max-width: 1100px;
|
||||
|
@ -1,7 +1,11 @@
|
||||
$(document).ready(function () {
|
||||
// periodically check for server status updates
|
||||
$('.serverItem').each(function() {
|
||||
setInterval(updateServer, 5000, $(this));
|
||||
});
|
||||
|
||||
// set the serverName input field to check if the server exists
|
||||
$('input#serverName').on('change', checkServerExists);
|
||||
});
|
||||
|
||||
function updateServer(elem) {
|
||||
@ -10,3 +14,16 @@ function updateServer(elem) {
|
||||
elem.children('.serverState').eq(0).text(data.state);
|
||||
});
|
||||
}
|
||||
|
||||
function checkServerExists() {
|
||||
$.get('/server/' + $(this).val() + '/status', function(data, state) {
|
||||
if (data.exists) {
|
||||
$('input#createSubmit').prop('disabled', true);
|
||||
alert('That server name is already used; please use another name!');
|
||||
} else {
|
||||
if ($('input#createSubmit').prop('disabled')) {
|
||||
$('input#createSubmit').prop('disabled', false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -73,9 +73,17 @@ $app->get('/server/{serverName}/status', function (Request $request, Response $r
|
||||
$config = $this->get('config');
|
||||
$serverDir = join('/', array($config->get('server_directory'), $args['serverName']));
|
||||
|
||||
// check if the server exists - if not, return a false result
|
||||
if (!is_dir($serverDir)) {
|
||||
$response->getBody()->write(json_encode(array('exists' => false)));
|
||||
return $response
|
||||
->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
// create server object and pass info back to client as JSON data
|
||||
$server = new Server($serverDir);
|
||||
$serverData = [
|
||||
'exists' => true,
|
||||
'name' => $server->getName(),
|
||||
'version' => $server->getVersion(),
|
||||
'state' => $server->getState() ? 'Running' : 'Stopped',
|
||||
|
@ -16,16 +16,16 @@
|
||||
<div class="row">
|
||||
<div class="columns six">
|
||||
<label for="serverName">Server name:</label>
|
||||
<input id="serverName" name="serverName" class="u-full-width" type="text" placeholder="MyServer">
|
||||
<input id="serverName" name="serverName" class="u-full-width" type="text" placeholder="MyServer" required>
|
||||
</div>
|
||||
|
||||
<div class="columns six">
|
||||
<label for="serverVersion">Minecraft version:</label>
|
||||
<input id="serverVersion" name="serverVersion" class="u-full-width" type="text" placeholder="1.19.2">
|
||||
<input id="serverVersion" name="serverVersion" class="u-full-width" type="text" placeholder="1.19.2" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="submit" value="Submit">
|
||||
<input id="createSubmit" type="submit" value="Submit">
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
|
Loading…
Reference in New Issue
Block a user