This repository has been archived by the owner on Feb 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const serverIp = '127.0.0.1' | ||
const serverPort = '8769' | ||
const serverURI = `ws://${serverIp}:${serverPort}` | ||
|
||
const packetDelayMs = 100 | ||
|
||
module.exports = { | ||
serverIp, | ||
serverPort, | ||
serverURI, | ||
packetDelayMs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const WebSocket = require('ws') | ||
|
||
const config = require('./config') | ||
const { startScriptLoaderShell } = require('./utils') | ||
|
||
const ws = new WebSocket(config.serverURI) | ||
|
||
ws.on('open', async () => { | ||
ws.send('hello') | ||
startScriptLoaderShell(ws) | ||
}) | ||
|
||
ws.on('message', data => { | ||
// Log sniffing data | ||
console.log(data) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "js", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"ws": "^7.2.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const { pause, receivePacket, sendPacket } = require('../utils') | ||
|
||
const run = async wsClient => { | ||
// Turn your player | ||
for (let i = 0; i <= 30; i++) | ||
await sendPacket(wsClient, `eD${i}`) | ||
} | ||
|
||
module.exports = { run } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
const readline = require('readline') | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const config = require('./config') | ||
|
||
/** | ||
* Start a shell `RPC>` which will load any scripts from the `scripts` directory | ||
* @param {any} wsClient WebSocket client | ||
*/ | ||
const startScriptLoaderShell = (wsClient) => { | ||
let shell = readline.createInterface(process.stdin, process.stdout) | ||
shell.setPrompt('RPC> ') | ||
shell.prompt() | ||
shell.on('line', async line => { | ||
// A script was asked, read the scripts directory | ||
const scripts = await fs.promises.readdir(path.resolve(__dirname, 'scripts')) | ||
|
||
// The script was found, run it | ||
if (scripts.find(x => x.toLowerCase() === line.toLowerCase())) { | ||
console.log(`Running the script "${line}".`) | ||
// TODO: loaded script is cached so can't be edited on-the-fly | ||
const loadedScript = require(path.resolve(__dirname, 'scripts', line)) | ||
loadedScript.run(wsClient) | ||
} | ||
else console.log(`The script "${line}" was not found in the "scripts" directory.`) | ||
shell.prompt() | ||
}).on('close', () => process.exit(0)) | ||
} | ||
|
||
|
||
/** | ||
* Pause execution | ||
* @param {number} ms Number of milliseconds to wait | ||
*/ | ||
const pause = ms => new Promise(res => setTimeout(res, ms)) | ||
|
||
/** | ||
* RPC call | ||
* @param {any} wsClient WebSocket client | ||
* @param {string[]} packetList List of packets to send | ||
* @param {number} delayBetweenPackets Delay between each packet sending | ||
*/ | ||
const call = (wsClient, command, packet, delayBetweenPackets = config.packetDelayMs) => { | ||
wsClient.send(`${command} ${packet}`) | ||
return pause(delayBetweenPackets) | ||
} | ||
|
||
/** | ||
* RPC ask to send a packet | ||
* @param {any} wsClient WebSocket client | ||
* @param {string[]} packetList List of packets to send | ||
* @param {number} delayBetweenPackets Delay between each packet sending | ||
*/ | ||
const sendPacket = (wsClient, packet, delayBetweenPackets = config.packetDelayMs) => | ||
call(wsClient, 'send', packet, delayBetweenPackets) | ||
|
||
/** | ||
* RPC ask to receive a packet | ||
* @param {any} wsClient WebSocket client | ||
* @param {string[]} packetList List of packets to send | ||
* @param {number} delayBetweenPackets Delay between each packet sending | ||
*/ | ||
const receivePacket = (wsClient, packet, delayBetweenPackets = config.packetDelayMs) => | ||
call(wsClient, 'receive', packet, delayBetweenPackets) | ||
|
||
module.exports = { | ||
startScriptLoaderShell, | ||
pause, | ||
sendPacket, | ||
receivePacket | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
ws@^7.2.1: | ||
version "7.2.1" | ||
resolved "https://registry.yarnpkg.com/ws/-/ws-7.2.1.tgz#03ed52423cd744084b2cf42ed197c8b65a936b8e" | ||
integrity sha512-sucePNSafamSKoOqoNfBd8V0StlkzJKL2ZAhGQinCfNQ+oacw+Pk7lcdAElecBF2VkLNZRiIb5Oi1Q5lVUVt2A== |