Skip to content

Commit

Permalink
- cleanup for release
Browse files Browse the repository at this point in the history
  • Loading branch information
atomy committed Mar 2, 2024
1 parent 2081b2a commit d591041
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 35 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

Frontend for [TF2-RCON-MISC](https://github.com/algo7/tf2_rcon_misc) CLI-Tool, showing players with additional steam-profile-information.

Work in progress.

![App overview](https://github.com/atomy/mannco-mastermind/blob/main/doc/app.png)

Work in progress. If you are a dev, you may be able to get it running, there's no release-pack available for now.

## Requirements
- NodeJS (I got 18.18.1)

## Run it
1) Tweak environment vars in `run.bat` to fit your setup.
2) Run `run.bat`, this should do the trick, better use console to see if it works or if there are issues.

Note: This program is using a sub-module called "tf2-rcon.exe", if it is not present, it will automatically download it from github.

# Development

## Install
Expand All @@ -18,6 +27,8 @@ npm install

## Starting Development

For

Start the app in the `dev` environment:

```bash
Expand All @@ -26,7 +37,12 @@ npm start

Note: Don't kill the program with CTL+C on windows, cause the sub-process (tf2-rcon) will still be running and not being able to start on next startup cause of blocked listening port.
(https://github.com/electron/electron/issues/5273)
You have to first close the electron window and then you can CTL+C.

### Team Fortress 2 Color Palette

https://lospec.com/palette-list/team-fortress-2-official

### Using TF2-RCON-Dev-Instance

You may want to look at usage of env var *ENVIRONMENT* (value: development) for direct usage of a tf2-rcon-copy. Otherwise a static release will be downloaded on start.
3 changes: 3 additions & 0 deletions run.bat
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
SET STEAM_KEY=abcdef
SET TF2_LOGPATH=M:\\SteamLibrary\\steamapps\\common\\Team Fortress 2\\tf\\console.log

npm start
45 changes: 29 additions & 16 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ let playerWarnings: PlayerWarning[] = [];
const playerWarningsFilepath = './doc/players.json';
const tf2RconFilepath = './tf2-rcon.exe';
const tf2RconDownloadSite =
'https://github.com/atomy/TF2-RCON-MISC/releases/download/1.0.0/main-windows-amd64.exe';
const tf2RconExpectedFilehash = 'f52642415a752c55d9f787e58a4dc3e9a2a2295a';
'https://github.com/atomy/TF2-RCON-MISC/releases/download/10.0.0/main-windows-amd64.exe';
const tf2RconExpectedFilehash = 'e88fbbc05b304fe3eb9b77f7dcc233e6d32fac60';

const currentSteamProfileInformation: PlayerInfo[] = [];
const currentSteamTF2Information: PlayerInfo[] = [];
Expand Down Expand Up @@ -186,11 +186,11 @@ const sendPlayerData = () => {
// Get all window instances
const windows = BrowserWindow.getAllWindows();

currentPlayerCollection.forEach((player) => {
if (!player.Team) {
console.log(`Sending players: ${player.Name} -- ${player.Team}`);
}
});
// currentPlayerCollection.forEach((player) => {
// if (!player.Team) {
// console.log(`Sending players: ${player.Name} -- ${player.Team}`);
// }
// });

// Send data to each window
windows.forEach((w) => {
Expand Down Expand Up @@ -526,9 +526,16 @@ const connectTf2rconWebsocket = () => {
updatePlayerWarns();
sendPlayerData();
} else if (incommingJson.type === 'application-log') {
const uniqueKey = () => {
const randomPart = Math.random().toString(36).substr(2, 9); // Using a random string
const timestampPart = new Date().getTime(); // Using a timestamp
return `${randomPart}-${timestampPart}`;
};

const logEntry: RconAppLogEntry = {
Timestamp: Date.now(), // Set the timestamp to the current time
Message: incommingJson.message,
Key: uniqueKey(),
};
sendApplicationLogData(logEntry);
} else {
Expand Down Expand Up @@ -672,16 +679,22 @@ const startTF2Rcon = () => {
console.log('TF2RCON not found, unable to start!');
} else {
console.log('Starting TF2RCON...');
// tf2rconChild = childProcess.spawn('.\\\\tf2-rcon.exe"', [''], {
// shell: true,
// });
tf2rconChild = childProcess.spawn(
'cmd /c "cd D:\\\\git\\\\TF2-RCON-MISC && .\\\\runDev.bat"',
[''],
{
if (
process.env.ENVIRONMENT &&
process.env.ENVIRONMENT === 'development'
) {
tf2rconChild = childProcess.spawn(
'cmd /c "cd D:\\\\git\\\\TF2-RCON-MISC && .\\\\runDev.bat"',
[''],
{
shell: true,
},
);
} else {
tf2rconChild = childProcess.spawn('.\\\\tf2-rcon.exe"', [''], {
shell: true,
},
);
});
}

// You can also use a variable to save the output for when the script closes later
tf2rconChild.on('error', (error) => {
Expand Down
4 changes: 4 additions & 0 deletions src/main/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const electronHandler = {
ipcRenderer.removeListener(channel, subscription);
};
},
// Add your custom removeListener functionality
removeListener(channel: string, func: (args: any) => void) {
ipcRenderer.removeListener(channel, func);
},
},
};

Expand Down
30 changes: 13 additions & 17 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,10 @@ function Main() {
return currentTime - playerInfo.LastSeen <= 60;
});

let foundMe = false;

filteredPlayerCollection.forEach((player) => {
// console.log(`Setting player: ${JSON.stringify(player)}`);
if (player.IsMe) {
foundMe = true;
}
});

setPlayers(filteredPlayerCollection);
};

const addRconClientLogMessage = (logEntry: RconAppLogEntry) => {
const uniqueKey = () => {
const randomPart = Math.random().toString(36).substr(2, 9); // Using a random string
const timestampPart = new Date().getTime(); // Using a timestamp
return `${randomPart}-${timestampPart}`;
};
logEntry.Key = uniqueKey();

const updatedLogs = [...rconClientLogs, logEntry];

// Sort the array by logEntry.Timestamp in descending order
Expand Down Expand Up @@ -85,7 +69,19 @@ function Main() {
'rcon-applog',
rconAppLogListener,
);
}); // Empty dependency array means this effect will run once, similar to componentDidMount

// Cleanup when the component is unmounted
return () => {
window.electron.ipcRenderer.removeListener(
'player-data',
playerDataListener,
);
window.electron.ipcRenderer.removeListener(
'rcon-applog',
rconAppLogListener,
);
};
}); // Empty dependency array means this effect runs once on mount and cleans up on unmount

return (
<div className="content">
Expand Down

0 comments on commit d591041

Please sign in to comment.