From eb6915b0194f689223cd35affe64868405a95d97 Mon Sep 17 00:00:00 2001 From: Chris Sprance Date: Fri, 23 Aug 2019 22:25:31 -0400 Subject: [PATCH] fixed a bunch of issues added the server init script --- .env | 2 - package.json | 2 +- src/components/ConfirmationDialog.tsx | 4 +- src/components/Menus/PlayerMenu.tsx | 5 +- src/components/RCONTerminal/defaults.tsx | 6 +- src/components/RCONTerminal/index.tsx | 10 +- .../ReactTerminal.tsx | 3 +- .../RCONTerminal/terminal-commands/server.tsx | 43 +++++- src/constants/hotkeys.ts | 7 + .../Dialogs/AddEditServerDialog.tsx | 114 ++++++++++------ src/containers/NavigationBar.tsx | 27 ++++ src/containers/Notifications.tsx | 11 +- src/containers/Terminal.tsx | 13 +- src/index.html | 1 - src/index.ts | 1 - .../__tests__/test_spfbi.spec.ts | 9 ++ .../run-spafbi-server-setup.ts | 40 ++++++ src/redux/app/actions.ts | 2 + src/redux/app/reducer.ts | 3 + src/redux/app/selectors.ts | 5 + src/redux/app/state.ts | 1 + src/redux/app/types.ts | 7 +- src/redux/bootstrap.ts | 20 ++- src/redux/hosting/types.ts | 4 +- src/redux/mismap/types.ts | 4 +- src/redux/players/actions.ts | 10 +- src/redux/rcon/actions.ts | 4 +- src/redux/rcon/selectors.ts | 4 +- src/redux/rcon/state.ts | 2 +- src/redux/servers/actions.ts | 18 +++ src/redux/servers/state.ts | 2 +- src/redux/servers/utils.ts | 1 + src/redux/terminal/actions.ts | 6 + src/redux/terminal/reducer.ts | 20 ++- src/redux/terminal/selectors.ts | 11 +- src/redux/terminal/state.ts | 13 +- src/redux/terminal/types.ts | 11 +- yarn.lock | 128 ++++-------------- 38 files changed, 371 insertions(+), 203 deletions(-) delete mode 100755 .env create mode 100755 src/lib/run-spafbi-server-setup/__tests__/test_spfbi.spec.ts create mode 100755 src/lib/run-spafbi-server-setup/run-spafbi-server-setup.ts diff --git a/.env b/.env deleted file mode 100755 index 529f19c3..00000000 --- a/.env +++ /dev/null @@ -1,2 +0,0 @@ -STEAM_API_KEY=thisisthesteamapikey -CRYPTO_SALT=ACryptoKeyOnlyIknow \ No newline at end of file diff --git a/package.json b/package.json index b97666de..ca84d54d 100755 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ }, "electronPackagerConfig": { "prune": true, - + "asar": true, "packageManager": "yarn", "icon": "src/resources/icon" }, diff --git a/src/components/ConfirmationDialog.tsx b/src/components/ConfirmationDialog.tsx index 757f918a..addd50c8 100755 --- a/src/components/ConfirmationDialog.tsx +++ b/src/components/ConfirmationDialog.tsx @@ -6,13 +6,13 @@ import DialogContentText from '@material-ui/core/DialogContentText'; import DialogTitle from '@material-ui/core/DialogTitle'; import * as React from 'react'; -export interface SimpleDialogProps { +export interface Props { title: string; description: string; onConfirm: () => void; onCancel: () => void; } -const ConfirmationDialog: React.FunctionComponent = ({ +const ConfirmationDialog: React.FunctionComponent = ({ description, title, onCancel, diff --git a/src/components/Menus/PlayerMenu.tsx b/src/components/Menus/PlayerMenu.tsx index 43f4f002..e336e499 100755 --- a/src/components/Menus/PlayerMenu.tsx +++ b/src/components/Menus/PlayerMenu.tsx @@ -3,8 +3,7 @@ import Menu from '@material-ui/core/Menu'; import MenuItem from '@material-ui/core/MenuItem'; import * as React from 'react'; -type Props = { - active: boolean; +interface Props { anchorEl: HTMLElement | null; banPlayer: () => void; closePlayerMenu: () => void; @@ -12,7 +11,7 @@ type Props = { viewPlayerProfile: () => void; openSteamCommunity: () => void; openSteamRep: () => void; -}; +} const PlayerMenu: React.FunctionComponent = ({ anchorEl, closePlayerMenu, diff --git a/src/components/RCONTerminal/defaults.tsx b/src/components/RCONTerminal/defaults.tsx index 97b21088..4e0349e3 100755 --- a/src/components/RCONTerminal/defaults.tsx +++ b/src/components/RCONTerminal/defaults.tsx @@ -1,9 +1,13 @@ -import { OutputFactory, Outputs } from 'async-javascript-terminal'; +import { History, OutputFactory, Outputs } from 'async-javascript-terminal'; import { OutputRecordType } from 'async-javascript-terminal/src/types'; import * as React from 'react'; import * as npmPackage from '../../../package.json'; +export const makeDefaultHistory = () => History.create([ + 'status', + 'help' +]); export const makeDefaultOutputs = ( ): OutputRecordType => { return Outputs.create([ diff --git a/src/components/RCONTerminal/index.tsx b/src/components/RCONTerminal/index.tsx index 00d72d0a..2aa4157a 100755 --- a/src/components/RCONTerminal/index.tsx +++ b/src/components/RCONTerminal/index.tsx @@ -14,18 +14,18 @@ import ReactTerminal from './react-terminal-component'; import themes from './react-terminal-component/themes'; import makeTerminalCommands from './terminal-commands'; -type Props = { +interface Props { themeName: string; activeTerminal: Terminal; activeServer: Server; dispatch: Dispatch; - rconHistory: () => string[]; -}; + history: string[]; +} const RCONTerminal: React.FunctionComponent = ({ activeTerminal, activeServer, dispatch, - rconHistory, + history, themeName }) => { return ( @@ -37,7 +37,7 @@ const RCONTerminal: React.FunctionComponent = ({ dispatch={dispatch} emulator={new Emulator()} emulatorState={EmulatorState.create({ - history: History.create(rconHistory()), + history: History.create(history), environmentVariables: EnvironmentVariables.create({ serverId: activeServer.id, password: activeServer.password, diff --git a/src/components/RCONTerminal/react-terminal-component/ReactTerminal.tsx b/src/components/RCONTerminal/react-terminal-component/ReactTerminal.tsx index 08f72e8b..2fbc08fd 100755 --- a/src/components/RCONTerminal/react-terminal-component/ReactTerminal.tsx +++ b/src/components/RCONTerminal/react-terminal-component/ReactTerminal.tsx @@ -9,7 +9,7 @@ import { ThemeProvider } from 'styled-components'; import { Dispatch } from '../../../redux/redux-types'; import { Server } from '../../../redux/servers'; -import { addInput, addOutput } from '../../../redux/terminal/actions'; +import {addHistory, addInput, addOutput} from '../../../redux/terminal/actions'; import CommandInput from './input/CommandInput'; import HeaderOutput from './output/HeaderOutput'; import TextErrorOutput from './output/TextErrorOutput'; @@ -91,6 +91,7 @@ class Terminal extends React.Component { this.plugins ); + this.props.dispatch(addHistory(commandStr, this.serverId)); this.props.dispatch(addOutput(newState.getOutputs(), this.serverId)); this.props.dispatch(addInput('', this.serverId)); diff --git a/src/components/RCONTerminal/terminal-commands/server.tsx b/src/components/RCONTerminal/terminal-commands/server.tsx index c5c53dea..a96c48fd 100755 --- a/src/components/RCONTerminal/terminal-commands/server.tsx +++ b/src/components/RCONTerminal/terminal-commands/server.tsx @@ -4,13 +4,17 @@ import * as React from 'react'; import logger from '../../../lib/logger'; import { Dispatch, GetStateFunc } from '../../../redux/redux-types'; -import {Server, serversActions} from '../../../redux/servers'; +import { Server, serversActions } from '../../../redux/servers'; import TerminalServerList from '../react-terminal-component/output/TerminalServerList'; +import { runSetupScript } from '../../../lib/run-spafbi-server-setup/run-spafbi-server-setup'; +import { activeServerSelector } from '../../../redux/servers/selectors'; +import { bg2, orange } from '../../../styles/colors'; const optDef = { '-a, --add': '', '-d, --id': '', '-i, --ip': '', + '-is, --init': '', // Initialize Server '-p, --port': '', '-a, --active': '', '-n, --name': '', @@ -24,13 +28,40 @@ const help = 'Add a task to the state from the terminal'; export default (dispatch: Dispatch, getState: GetStateFunc) => ({ function: async (_: EmulatorState, opts: string[]) => { try { - const { options } = getOpts(opts, optDef); + const { options, argv } = getOpts(opts, optDef); const ip = options.ip ? options.ip : 'localhost'; const port = options.port ? parseInt(options.port, 10) : -1; const name = options.name ? options.name.join(' ') : 'No Name'; const id = options.id ? Number(options.id) : Date.now(); const password = options.password ? options.password : ''; + if (options.init) { + const activeServer = activeServerSelector(getState()); + const rootPath = argv[0] ? argv[0] : activeServer.rootPath; + + await runSetupScript(rootPath); + return output( +
+

+ Server Root will be located at:{' '} + {rootPath} +

+

+ Starting the script in a new window. Please follow instructions. + When Miscreated server is running{' '} + console.log('Refreshing Server')} + href="" + > + refresh + {' '} + your server. +

+
+ ); + } + // Add a task if (options.add) { const server: Server = { @@ -44,18 +75,18 @@ export default (dispatch: Dispatch, getState: GetStateFunc) => ({ selfHosted: false, rootPath: '' }; - dispatch(serversActions.addServer(server)); + await dispatch(serversActions.addServerThunk(server)); return output(`Added server ${server.name}`); } // Remove a task if (options.rm) { if (options.id) { - dispatch(serversActions.removeServer(id)); + await dispatch(serversActions.removeServerThunk(id)); return output(`Removed task by id ${id}`); } if (options.name) { - dispatch(serversActions.removeServer(id)); + await dispatch(serversActions.removeServerThunk(id)); return output(`Removed task by name: ${name}`); } } @@ -95,7 +126,7 @@ export default (dispatch: Dispatch, getState: GetStateFunc) => ({ } catch (e) { logger.error(e); return { - output: OutputFactory.makeErrorOutput(e) + output: OutputFactory.makeTextOutput(String(e)) }; } }, diff --git a/src/constants/hotkeys.ts b/src/constants/hotkeys.ts index d19e2215..7b4acfa3 100755 --- a/src/constants/hotkeys.ts +++ b/src/constants/hotkeys.ts @@ -14,6 +14,11 @@ export const registerHotkeys = (dispatch: Dispatch) => { electron.remote.getCurrentWindow().reload(); }); + // Load Dev Tools + mousetrap.bind('ctrl+alt+i', () => { + electron.remote.getCurrentWindow().webContents.openDevTools(); + }); + // Task Dialog mousetrap.bind('ctrl+t', () => { dispatch(toggleAddTaskDialog()); @@ -28,4 +33,6 @@ export const registerHotkeys = (dispatch: Dispatch) => { mousetrap.bind('ctrl+w', () => { dispatch(toggleAddWhitelistDialog()); }); + + }; diff --git a/src/containers/Dialogs/AddEditServerDialog.tsx b/src/containers/Dialogs/AddEditServerDialog.tsx index 49916330..5ce195b5 100755 --- a/src/containers/Dialogs/AddEditServerDialog.tsx +++ b/src/containers/Dialogs/AddEditServerDialog.tsx @@ -4,9 +4,10 @@ import Dialog from '@material-ui/core/Dialog'; import FormControlLabel from '@material-ui/core/FormControlLabel'; import InputAdornment from '@material-ui/core/InputAdornment'; import TextField from '@material-ui/core/TextField'; +import Tooltip from '@material-ui/core/Tooltip'; import Typography from '@material-ui/core/Typography'; import { remote } from 'electron'; -import { ErrorMessage, Form, Formik } from 'formik'; +import { Form, Formik } from 'formik'; import * as React from 'react'; import { useDispatch, useSelector } from 'react-redux'; import styled from 'styled-components'; @@ -21,6 +22,7 @@ import { import { Server } from '../../redux/servers'; import { addServerThunk, + initServerThunk, testConnectionThunk, updateServerThunk } from '../../redux/servers/actions'; @@ -44,8 +46,6 @@ const InnerWrapper = styled.div` padding: 20px; flex-direction: column; width: 400px; - height: 650px; - max-height: 650px; align-items: center; justify-content: flex-start; `; @@ -56,7 +56,9 @@ const CenterSection = styled.div` flex-grow: 1; width: 100%; `; - +interface ServerAndForm extends Server { + init: boolean; +} interface Props { variant: 'edit' | 'add'; } @@ -65,11 +67,12 @@ const AddEditServerDialog: React.FunctionComponent = ({ variant }) => { variant === 'add' ? { ...defaultServer, + avatar: 'https://api.adorable.io/avatars/285/' + Date.now(), port: 64094, id: Date.now(), - avatar: 'https://api.adorable.io/avatars/285/' + Date.now() + init: false } - : useSelector(activeServerSelector); + : (useSelector(activeServerSelector) as ServerAndForm); const noServers = useSelector(noServersSelector); const showing = variant === 'add' @@ -78,7 +81,7 @@ const AddEditServerDialog: React.FunctionComponent = ({ variant }) => { const dispatch = useDispatch(); const addServer = (server: Server) => dispatch(addServerThunk(server)); const updateServer = (server: Server) => dispatch(updateServerThunk(server)); - const action = variant === 'add' ? addServer : updateServer; + const addOrUpdateServer = variant === 'add' ? addServer : updateServer; const closeDialog = () => dispatch(closeAllDialogs()); const testConnection = async (server: Server) => dispatch(testConnectionThunk(server)); @@ -95,12 +98,20 @@ const AddEditServerDialog: React.FunctionComponent = ({ variant }) => { { + const { init, ...serverFormValues } = values; closeDialog(); - action({ - ...values + if (init) { + dispatch(initServerThunk(serverFormValues.rootPath)); + } + addOrUpdateServer({ + ...serverFormValues }); }} > @@ -133,37 +144,33 @@ const AddEditServerDialog: React.FunctionComponent = ({ variant }) => { onChange={handleChange} fullWidth name={'name'} - label={'Server Name'} + label={'The name of the server (15 Characters)'} /> - - - - = ({ variant }) => { label="Self Hosted Server?" /> {values.selfHosted && ( - - { - const rootPath = remote.dialog.showOpenDialog({ - properties: ['openDirectory'] - }); - if (rootPath) { - setFieldValue('rootPath', rootPath[0]); - } - }} - /> - - ) - }} - /> + <> + {variant !== 'edit' ? ( + + { + setFieldValue('init', !values.init); + }} + color="secondary" + /> + } + label="Initialize Server?" + /> + + ) : ( + '' + )} + + + { + const rootPath = remote.dialog.showOpenDialog( + { + properties: ['openDirectory'] + } + ); + if (rootPath) { + setFieldValue('rootPath', rootPath[0]); + } + }} + /> + + ) + }} + /> + )}