Skip to content

Commit

Permalink
fixed a bunch of issues added the server init script
Browse files Browse the repository at this point in the history
  • Loading branch information
csprance committed Aug 24, 2019
1 parent a3546b8 commit eb6915b
Show file tree
Hide file tree
Showing 38 changed files with 371 additions and 203 deletions.
2 changes: 0 additions & 2 deletions .env

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"electronPackagerConfig": {
"prune": true,

"asar": true,
"packageManager": "yarn",
"icon": "src/resources/icon"
},
Expand Down
4 changes: 2 additions & 2 deletions src/components/ConfirmationDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<SimpleDialogProps> = ({
const ConfirmationDialog: React.FunctionComponent<Props> = ({
description,
title,
onCancel,
Expand Down
5 changes: 2 additions & 3 deletions src/components/Menus/PlayerMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ 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;
kickPlayer: () => void;
viewPlayerProfile: () => void;
openSteamCommunity: () => void;
openSteamRep: () => void;
};
}
const PlayerMenu: React.FunctionComponent<Props> = ({
anchorEl,
closePlayerMenu,
Expand Down
6 changes: 5 additions & 1 deletion src/components/RCONTerminal/defaults.tsx
Original file line number Diff line number Diff line change
@@ -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([
Expand Down
10 changes: 5 additions & 5 deletions src/components/RCONTerminal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Props> = ({
activeTerminal,
activeServer,
dispatch,
rconHistory,
history,
themeName
}) => {
return (
Expand All @@ -37,7 +37,7 @@ const RCONTerminal: React.FunctionComponent<Props> = ({
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -91,6 +91,7 @@ class Terminal extends React.Component<Props, State> {
this.plugins
);

this.props.dispatch(addHistory(commandStr, this.serverId));
this.props.dispatch(addOutput(newState.getOutputs(), this.serverId));
this.props.dispatch(addInput('', this.serverId));

Expand Down
43 changes: 37 additions & 6 deletions src/components/RCONTerminal/terminal-commands/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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': '<id>',
'-i, --ip': '<ip>',
'-is, --init': '', // Initialize Server
'-p, --port': '<port>',
'-a, --active': '<active>',
'-n, --name': '<name...>',
Expand All @@ -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(
<div>
<p>
Server Root will be located at:{' '}
<span style={{ background: bg2, padding: 10 }}>{rootPath}</span>
</p>
<p>
Starting the script in a new window. Please follow instructions.
When Miscreated server is running{' '}
<a
style={{ color: orange }}
onClick={() => console.log('Refreshing Server')}
href=""
>
refresh
</a>{' '}
your server.
</p>
</div>
);
}

// Add a task
if (options.add) {
const server: Server = {
Expand All @@ -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}`);
}
}
Expand Down Expand Up @@ -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))
};
}
},
Expand Down
7 changes: 7 additions & 0 deletions src/constants/hotkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -28,4 +33,6 @@ export const registerHotkeys = (dispatch: Dispatch) => {
mousetrap.bind('ctrl+w', () => {
dispatch(toggleAddWhitelistDialog());
});


};
Loading

0 comments on commit eb6915b

Please sign in to comment.