2020-11-03 04:52:41 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import { ServerContext } from '@/state/server';
|
|
|
|
import Modal from '@/components/elements/Modal';
|
|
|
|
import tw from 'twin.macro';
|
2020-11-03 05:06:47 +00:00
|
|
|
import Button from '@/components/elements/Button';
|
|
|
|
import saveFileContents from '@/api/server/files/saveFileContents';
|
|
|
|
import FlashMessageRender from '@/components/FlashMessageRender';
|
|
|
|
import useFlash from '@/plugins/useFlash';
|
2021-01-31 02:43:46 +00:00
|
|
|
import { SocketEvent, SocketRequest } from '@/components/server/events';
|
2020-11-03 04:52:41 +00:00
|
|
|
|
|
|
|
const EulaModalFeature = () => {
|
2022-06-26 19:13:52 +00:00
|
|
|
const [visible, setVisible] = useState(false);
|
|
|
|
const [loading, setLoading] = useState(false);
|
2020-11-03 05:06:47 +00:00
|
|
|
|
2022-06-26 19:13:52 +00:00
|
|
|
const uuid = ServerContext.useStoreState((state) => state.server.data!.uuid);
|
|
|
|
const status = ServerContext.useStoreState((state) => state.status.value);
|
2020-11-03 05:06:47 +00:00
|
|
|
const { clearFlashes, clearAndAddHttpError } = useFlash();
|
2022-06-26 19:13:52 +00:00
|
|
|
const { connected, instance } = ServerContext.useStoreState((state) => state.socket);
|
2020-11-03 04:52:41 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!connected || !instance || status === 'running') return;
|
|
|
|
|
|
|
|
const listener = (line: string) => {
|
|
|
|
if (line.toLowerCase().indexOf('you need to agree to the eula in order to run the server') >= 0) {
|
|
|
|
setVisible(true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-01-31 02:43:46 +00:00
|
|
|
instance.addListener(SocketEvent.CONSOLE_OUTPUT, listener);
|
2020-11-03 04:52:41 +00:00
|
|
|
|
|
|
|
return () => {
|
2021-01-31 02:43:46 +00:00
|
|
|
instance.removeListener(SocketEvent.CONSOLE_OUTPUT, listener);
|
2020-11-03 04:52:41 +00:00
|
|
|
};
|
2022-06-26 19:13:52 +00:00
|
|
|
}, [connected, instance, status]);
|
2020-11-03 04:52:41 +00:00
|
|
|
|
2020-11-03 05:06:47 +00:00
|
|
|
const onAcceptEULA = () => {
|
|
|
|
setLoading(true);
|
|
|
|
clearFlashes('feature:eula');
|
|
|
|
|
|
|
|
saveFileContents(uuid, 'eula.txt', 'eula=true')
|
|
|
|
.then(() => {
|
|
|
|
if (status === 'offline' && instance) {
|
2021-01-31 02:43:46 +00:00
|
|
|
instance.send(SocketRequest.SET_STATE, 'restart');
|
2020-11-03 05:06:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setLoading(false);
|
|
|
|
setVisible(false);
|
|
|
|
})
|
2022-06-26 19:13:52 +00:00
|
|
|
.catch((error) => {
|
2020-11-03 05:06:47 +00:00
|
|
|
console.error(error);
|
|
|
|
clearAndAddHttpError({ key: 'feature:eula', error });
|
|
|
|
})
|
|
|
|
.then(() => setLoading(false));
|
|
|
|
};
|
|
|
|
|
2021-08-03 03:32:10 +00:00
|
|
|
useEffect(() => {
|
2020-11-03 05:06:47 +00:00
|
|
|
clearFlashes('feature:eula');
|
|
|
|
}, []);
|
|
|
|
|
2020-11-03 04:52:41 +00:00
|
|
|
return (
|
2022-06-26 19:13:52 +00:00
|
|
|
<Modal
|
|
|
|
visible={visible}
|
|
|
|
onDismissed={() => setVisible(false)}
|
|
|
|
closeOnBackground={false}
|
|
|
|
showSpinnerOverlay={loading}
|
|
|
|
>
|
|
|
|
<FlashMessageRender key={'feature:eula'} css={tw`mb-4`} />
|
2021-08-03 03:32:10 +00:00
|
|
|
<h2 css={tw`text-2xl mb-4 text-neutral-100`}>Accept Minecraft® EULA</h2>
|
|
|
|
<p css={tw`text-neutral-200`}>
|
2022-06-26 19:13:52 +00:00
|
|
|
By pressing {'"I Accept"'} below you are indicating your agreement to the
|
2021-08-03 03:32:10 +00:00
|
|
|
<a
|
|
|
|
target={'_blank'}
|
|
|
|
css={tw`text-primary-300 underline transition-colors duration-150 hover:text-primary-400`}
|
|
|
|
rel={'noreferrer noopener'}
|
2022-06-26 19:13:52 +00:00
|
|
|
href='https://account.mojang.com/documents/minecraft_eula'
|
2021-08-03 03:32:10 +00:00
|
|
|
>
|
2022-06-26 19:13:52 +00:00
|
|
|
Minecraft® EULA
|
|
|
|
</a>
|
|
|
|
.
|
2021-08-03 03:32:10 +00:00
|
|
|
</p>
|
|
|
|
<div css={tw`mt-8 sm:flex items-center justify-end`}>
|
|
|
|
<Button isSecondary onClick={() => setVisible(false)} css={tw`w-full sm:w-auto border-transparent`}>
|
2022-06-26 19:13:52 +00:00
|
|
|
Cancel
|
2021-08-03 03:32:10 +00:00
|
|
|
</Button>
|
|
|
|
<Button onClick={onAcceptEULA} css={tw`mt-4 sm:mt-0 sm:ml-4 w-full sm:w-auto`}>
|
2022-06-26 19:13:52 +00:00
|
|
|
I Accept
|
2021-08-03 03:32:10 +00:00
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</Modal>
|
2020-11-03 04:52:41 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default EulaModalFeature;
|