-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: vscode transmitter extensions upport (#57)
- Loading branch information
Showing
15 changed files
with
136 additions
and
3 deletions.
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 |
---|---|---|
|
@@ -29,6 +29,7 @@ webview/pages/plugins.ts | |
.env | ||
test/ | ||
tmp/ | ||
src/scratchpad/*.ts | ||
|
||
src/plugins/sandbox-* | ||
|
||
|
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,13 @@ | ||
# VSCode Transmitter Extension | ||
|
||
Rebar has built in support for the `Rebar Transmitter` extension. | ||
|
||
This allows you to open a scratchpad under `src/scratchpad` and write code. | ||
|
||
Once the code is written you can `SELECT THE CODE WITH YOUR CURSOR` and then right-click to execute it while the server is running. | ||
|
||
![](./static/transmitter-example.png) | ||
|
||
## Download | ||
|
||
[https://marketplace.visualstudio.com/items?itemName=stuyk.rebar-transmitter](https://marketplace.visualstudio.com/items?itemName=stuyk.rebar-transmitter) |
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
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,13 @@ | ||
import alt from 'alt-client'; | ||
import native from 'natives'; | ||
import { Events } from '../../shared/events/index.js'; | ||
|
||
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor; | ||
|
||
function handleCode(code: string) { | ||
new AsyncFunction('alt', 'native', 'natives', 'game', code)(alt, native, native, native); | ||
} | ||
|
||
if (alt.debug) { | ||
alt.onServer(Events.systems.transmitter.execute, handleCode); | ||
} |
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,58 @@ | ||
import * as alt from 'alt-server'; | ||
import { useRebar } from '@Server/index.js'; | ||
import http from 'http'; | ||
import { Events } from '../../shared/events/index.js'; | ||
|
||
const Rebar = useRebar(); | ||
const PORT = 9269; | ||
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor; | ||
|
||
if (alt.debug) { | ||
const server = http.createServer((req, res) => { | ||
if (req.method !== 'POST') { | ||
res.writeHead(405, { 'Content-Type': 'text/plain' }); | ||
res.end('Must be a POST request \n'); | ||
return; | ||
} | ||
|
||
let body = ''; | ||
req.on('data', (chunk) => { | ||
body += chunk.toString(); | ||
}); | ||
|
||
req.on('end', async () => { | ||
if (req.url === '/server') { | ||
await new AsyncFunction('alt', 'console', 'Rebar', body)( | ||
{ ...alt }, | ||
{ | ||
...console, | ||
}, | ||
{ ...Rebar }, | ||
); | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.end('Code Executed on Server \n'); | ||
return; | ||
} | ||
|
||
if (alt.Player.all.length <= 0) { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.end('No players on server to execute code against \n'); | ||
return; | ||
} | ||
|
||
for (let player of alt.Player.all) { | ||
if (!player || !player.valid) { | ||
return; | ||
} | ||
|
||
player.emit(Events.systems.transmitter.execute, body); | ||
} | ||
|
||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.end('Code Executed on Client \n'); | ||
return; | ||
}); | ||
}); | ||
|
||
server.listen(PORT); | ||
} |
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
Empty file.
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,13 @@ | ||
# Scratchpad | ||
|
||
Files in here will not be transpiled. | ||
|
||
You can create as many as you want and they'll safely be ignored. | ||
|
||
Pair your scratchpad with the Rebar Transmitter VSCode extension. | ||
|
||
## Transmitter Usage | ||
|
||
When selecting code, make sure not to select imports. | ||
|
||
Selecting imports will prevent your code from executing. |
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,4 @@ | ||
import * as alt from 'alt-client'; | ||
import * as native from 'natives'; | ||
|
||
// Execute anything below this line |
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,5 @@ | ||
import * as alt from 'alt-server'; | ||
import { useRebar } from '../main/server/index.js'; | ||
|
||
const Rebar = useRebar(); | ||
// Execute anything below this line |
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