diff --git a/README.md b/README.md index db9f6c5..1c3f7e7 100644 --- a/README.md +++ b/README.md @@ -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 @@ -18,6 +27,8 @@ npm install ## Starting Development +For + Start the app in the `dev` environment: ```bash @@ -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. diff --git a/run.bat b/run.bat index 0186425..09c0dd7 100644 --- a/run.bat +++ b/run.bat @@ -1 +1,4 @@ +SET STEAM_KEY=abcdef +SET TF2_LOGPATH=M:\\SteamLibrary\\steamapps\\common\\Team Fortress 2\\tf\\console.log + npm start diff --git a/src/main/main.ts b/src/main/main.ts index 3aadd4b..00a8c3d 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -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[] = []; @@ -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) => { @@ -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 { @@ -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) => { diff --git a/src/main/preload.ts b/src/main/preload.ts index 7578223..6ea3835 100644 --- a/src/main/preload.ts +++ b/src/main/preload.ts @@ -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); + }, }, }; diff --git a/src/renderer/App.tsx b/src/renderer/App.tsx index a9e2d41..13ecf9a 100644 --- a/src/renderer/App.tsx +++ b/src/renderer/App.tsx @@ -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 @@ -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 (